From 87831977360ef8b7ac9fbd9e6c38d83cc43e721c Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Mon, 23 Sep 2024 19:19:08 +0200 Subject: [PATCH] Support multiple annotation version in E4 Injector and specifically support jakarta.annotation version 3.0. Fixes https://github.com/eclipse-platform/eclipse.platform/issues/1565 --- .../org.eclipse.e4.core.di/META-INF/MANIFEST.MF | 2 +- .../eclipse/e4/core/internal/di/AnnotationLookup.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/runtime/bundles/org.eclipse.e4.core.di/META-INF/MANIFEST.MF b/runtime/bundles/org.eclipse.e4.core.di/META-INF/MANIFEST.MF index 29b2880e429..4c3e797e3fa 100644 --- a/runtime/bundles/org.eclipse.e4.core.di/META-INF/MANIFEST.MF +++ b/runtime/bundles/org.eclipse.e4.core.di/META-INF/MANIFEST.MF @@ -15,7 +15,7 @@ Export-Package: org.eclipse.e4.core.di;version="1.7.0", org.eclipse.e4.core.internal.di.osgi;x-internal:=true, org.eclipse.e4.core.internal.di.shared;x-friends:="org.eclipse.e4.core.contexts,org.eclipse.e4.core.di.extensions.supplier" Require-Bundle: org.eclipse.e4.core.di.annotations;bundle-version="[1.4.0,2.0.0)";visibility:=reexport -Import-Package: jakarta.annotation;version="[2,3)", +Import-Package: jakarta.annotation;version="[2,4)", jakarta.inject;version="[2,3)", javax.annotation;version="[1.3.0,2.0.0)";resolution:=optional, javax.inject;version="[1.0.0,2.0.0)";resolution:=optional, diff --git a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java b/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java index d6793c24280..568257b3a9b 100644 --- a/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java +++ b/runtime/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/AnnotationLookup.java @@ -42,14 +42,15 @@ public class AnnotationLookup { private AnnotationLookup() { } - public static record AnnotationProxy(List> classes) { - public AnnotationProxy { - classes = List.copyOf(classes); + static record AnnotationProxy(List> classes, List classNames) { + + public AnnotationProxy(List> classes) { + this(List.copyOf(classes), classes.stream().map(Class::getCanonicalName).toList()); } public boolean isPresent(AnnotatedElement element) { - for (Class annotationClass : classes) { - if (element.isAnnotationPresent(annotationClass)) { + for (Annotation annotation : element.getAnnotations()) { + if (classNames.contains(annotation.annotationType().getCanonicalName())) { return true; } }