Class AnnotationTargetUtils
java.lang.Object
io.micronaut.sourcegen.bytecode.core.AnnotationTargetUtils
Resolves
Target metadata for annotations represented by the Sourcegen model.
Annotation-processing class elements are checked before class loading because an annotation type may be one of the source files currently being compiled.
- Since:
- 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic TypeDefannotatedType(TypeDef typeDef, List<AnnotationDef> annotations, @Nullable ClassLoader classLoader) The type of a declaration, carrying those of the declaration's annotations that annotate a type use.static List<AnnotationDef> declarationAnnotations(List<AnnotationDef> annotations, ElementType elementType, @Nullable ClassLoader classLoader) The annotations of a declaration that belong among its declaration annotations, which is every one of them but those a compiler writes as type annotations instead.static Optional<RetentionPolicy> declaredRetentionOf(ObjectDef objectDef) static Optional<Set<ElementType>> declaredTargetsOf(ObjectDef objectDef) static booleanisArrayMember(AnnotationDef annotation, String member, @Nullable ClassLoader classLoader) Whether a member of an annotation is declared with an array type.static RetentionPolicyretentionOf(AnnotationDef annotation, @Nullable ClassLoader classLoader) The retention of an annotation, resolved the way the ASM backend resolves it.static Optional<Set<ElementType>> targetsOf(AnnotationDef annotation, @Nullable ClassLoader classLoader) static Set<ElementType> toElementTypes(@Nullable Object value) Converts the model's representation of aTarget.value()member.static List<AnnotationDef> typeUseAnnotations(List<AnnotationDef> annotations, @Nullable ClassLoader classLoader)
-
Method Details
-
targetsOf
public static Optional<Set<ElementType>> targetsOf(AnnotationDef annotation, @Nullable ClassLoader classLoader) - Parameters:
annotation- The annotationclassLoader- The fallback class loader- Returns:
- Declared targets, or empty when the annotation has no usable target declaration
-
declaredTargetsOf
- Parameters:
objectDef- An annotation definition- Returns:
- Declared targets, or empty when none can be read
-
toElementTypes
Converts the model's representation of aTarget.value()member.- Parameters:
value- The member value- Returns:
- Element types
-
declarationAnnotations
public static List<AnnotationDef> declarationAnnotations(List<AnnotationDef> annotations, ElementType elementType, @Nullable ClassLoader classLoader) The annotations of a declaration that belong among its declaration annotations, which is every one of them but those a compiler writes as type annotations instead. An annotation whoseTargetnamesElementType.TYPE_USEbut not the declaration itself annotates the type of the declaration and nothing else, the wayorg.jspecify.annotations.Nullabledoes; one that names both is written in both places, and one that names neither is left where it was put rather than dropped.- Parameters:
annotations- The annotations of the declarationelementType- The kind of declaration they are written onclassLoader- The fallback class loader- Returns:
- The annotations that belong among the declaration annotations
-
typeUseAnnotations
public static List<AnnotationDef> typeUseAnnotations(List<AnnotationDef> annotations, @Nullable ClassLoader classLoader) - Parameters:
annotations- The annotations of a declarationclassLoader- The fallback class loader- Returns:
- Those of them that annotate a type use
-
annotatedType
public static TypeDef annotatedType(TypeDef typeDef, List<AnnotationDef> annotations, @Nullable ClassLoader classLoader) The type of a declaration, carrying those of the declaration's annotations that annotate a type use. A compiler writes such an annotation against the type of the declaration and not against the declaration itself, so that a reader finds it on the annotated type.- Parameters:
typeDef- The declared typeannotations- The annotations of the declarationclassLoader- The fallback class loader- Returns:
- The type, annotated when any of them belongs on it
-
retentionOf
public static RetentionPolicy retentionOf(AnnotationDef annotation, @Nullable ClassLoader classLoader) The retention of an annotation, resolved the way the ASM backend resolves it.- Parameters:
annotation- The annotationclassLoader- The fallback class loader- Returns:
- Its retention
-
declaredRetentionOf
- Parameters:
objectDef- An annotation definition- Returns:
- The retention it declares, or empty when it declares none
-
isArrayMember
public static boolean isArrayMember(AnnotationDef annotation, String member, @Nullable ClassLoader classLoader) Whether a member of an annotation is declared with an array type.A single value is a legal source form for an array member -
@Target(TYPE)means@Target({TYPE})- but a class file has no such shorthand, so a writer has to know the declared type to wrap the value. The declaration is read from the definition of an annotation type generated in this same round, from the source element of one still being compiled, and otherwise from the loaded class.- Parameters:
annotation- The annotationmember- The name of the memberclassLoader- The fallback class loader- Returns:
- Whether the member is declared as an array
-