Skip to content

Commit

Permalink
Support multiple annotation version in E4 Injector
Browse files Browse the repository at this point in the history
and specifically support jakarta.annotation version 3.0.

Fixes eclipse-platform#1565
  • Loading branch information
HannesWell committed Sep 26, 2024
1 parent 3dfb816 commit b65cc75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public class AnnotationLookup {
private AnnotationLookup() {
}

public static record AnnotationProxy(List<Class<? extends Annotation>> classes) {
public AnnotationProxy {
classes = List.copyOf(classes);
static record AnnotationProxy(List<Class<? extends Annotation>> classes, List<String> classNames) {

public AnnotationProxy(List<Class<? extends Annotation>> classes) {
this(List.copyOf(classes), classes.stream().map(Class::getCanonicalName).toList());
}

public boolean isPresent(AnnotatedElement element) {
for (Class<? extends Annotation> annotationClass : classes) {
if (element.isAnnotationPresent(annotationClass)) {
for (Annotation annotation : element.getAnnotations()) {
if (classNames.contains(annotation.annotationType().getCanonicalName())) {
return true;
}
}
Expand Down

0 comments on commit b65cc75

Please sign in to comment.