Skip to content

Commit

Permalink
remove support for metaannotations for NoAutoStart annotation
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Apr 11, 2024
1 parent 4476edd commit f32ed30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class NoAutoStartUtil {
/**
* Returns true if the class of the object 'o' passed as parameter is *not*
* marked with the NoAutoStart annotation. Return true otherwise.
*
*
* @param o
* @return true for classes not marked with the NoAutoStart annotation
*/
Expand All @@ -48,7 +48,6 @@ public static boolean notMarkedWithNoAutoStart(Object o) {
* <p>The algorithm operates as follows:
* <ol>
* <li>Search for the annotation on the given class and return it if found.
* <li>Recursively search through all annotations that the given class declares.
* <li>Recursively search through all interfaces that the given class declares.
* <li>Recursively search through the superclass hierarchy of the given class.
* </ol>
Expand All @@ -62,7 +61,7 @@ public static boolean notMarkedWithNoAutoStart(Object o) {
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType) {
return findAnnotation(clazz, annotationType, new HashSet<>());
}

/**
* Perform the search algorithm for {@link #findAnnotation(Class, Class)},
* avoiding endless recursion by tracking which annotations have already
Expand All @@ -75,21 +74,12 @@ private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A>
@SuppressWarnings("unchecked")
private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) {

Annotation[] anns = clazz.getDeclaredAnnotations();
for (Annotation ann : anns) {
if (ann.annotationType() == annotationType) {
return (A) ann;
}
}
for (Annotation ann : anns) {
if (visited.add(ann)) {
A annotation = findAnnotation(ann.annotationType(), annotationType, visited);
if (annotation != null) {
return annotation;
}
}
Annotation foundAnnotation = clazz.getAnnotation(annotationType);
if(foundAnnotation != null) {
return (A) foundAnnotation;
}


for (Class<?> ifc : clazz.getInterfaces()) {
A annotation = findAnnotation(ifc, annotationType, visited);
if (annotation != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -83,25 +82,5 @@ public void noAutoStartOnInterfaceImplementedByAncestor() {

private static class ComponentWithAncestorImplementingInterfaceWithNoAutoStart extends ComponentWithNoAutoStartOnInterface {
}



/*
* Custom annotation annotated with @NoAutoStart
*/
@Test
public void noAutoStartAsMetaAnnotation() {
ComponentWithMetaAnnotation o = new ComponentWithMetaAnnotation();
assertFalse(NoAutoStartUtil.notMarkedWithNoAutoStart(o));
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@NoAutoStart
public @interface MetaNoAutoStart {
}

@MetaNoAutoStart
private static class ComponentWithMetaAnnotation {
}
}

0 comments on commit f32ed30

Please sign in to comment.