- java.lang.Object
-
- org.scijava.common3.Annotations
-
public final class Annotations extends Object
Useful methods for working with Java annotations.- Author:
- Mark Hiner, Curtis Rueden
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <A extends Annotation>
List<Field>annotatedFields(Class<?> c, Class<A> annotationClass)Gets the given class'sFields marked with the annotation of the specified class.static <A extends Annotation>
voidannotatedFields(Class<?> c, Class<A> annotationClass, List<Field> fields)Gets the given class'sFields marked with the annotation of the specified class.static <A extends Annotation>
List<Method>annotatedMethods(Class<?> c, Class<A> annotationClass)Gets the given class'sMethods marked with the annotation of the specified class.static <A extends Annotation>
voidannotatedMethods(Class<?> c, Class<A> annotationClass, List<Method> methods)Gets the given class'sMethods marked with the annotation of the specified class.
-
-
-
Method Detail
-
annotatedMethods
public static <A extends Annotation> List<Method> annotatedMethods(Class<?> c, Class<A> annotationClass)
Gets the given class'sMethods marked with the annotation of the specified class.Unlike
Class.getMethods(), the result will include any non-public methods, including methods defined in supertypes of the given class.- Parameters:
c- The class to scan for annotated methods.annotationClass- The type of annotation for which to scan.- Returns:
- A list containing all methods with the requested annotation. Note that for performance reasons, lists may be cached and reused, so it is best to make a copy of the result if you need to modify it.
-
annotatedMethods
public static <A extends Annotation> void annotatedMethods(Class<?> c, Class<A> annotationClass, List<Method> methods)
Gets the given class'sMethods marked with the annotation of the specified class.Unlike
Class.getMethods(), the result will include any non-public methods, including methods defined in supertypes of the given class.- Parameters:
c- The class to scan for annotated methods.annotationClass- The type of annotation for which to scan.methods- The list to which matching methods will be added.
-
annotatedFields
public static <A extends Annotation> List<Field> annotatedFields(Class<?> c, Class<A> annotationClass)
Gets the given class'sFields marked with the annotation of the specified class.Unlike
Class.getFields(), the result will include any non-public fields, including fields defined in supertypes of the given class.- Parameters:
c- The class to scan for annotated fields.annotationClass- The type of annotation for which to scan.- Returns:
- A list containing all fields with the requested annotation. Note that for performance reasons, lists may be cached and reused, so it is best to make a copy of the result if you need to modify it.
-
annotatedFields
public static <A extends Annotation> void annotatedFields(Class<?> c, Class<A> annotationClass, List<Field> fields)
Gets the given class'sFields marked with the annotation of the specified class.Unlike
Class.getFields(), the result will include any non-public fields, including fields defined in supertypes of the given class.- Parameters:
c- The class to scan for annotated fields.annotationClass- The type of annotation for which to scan.fields- The list to which matching fields will be added.
-
-