Annotation Type UsedByReflection
-
@Target({TYPE,FIELD,METHOD,CONSTRUCTOR}) @Retention(CLASS) public @interface UsedByReflection
Annotation to mark a class, field or method as being accessed reflectively.Note: Before using this annotation, consider if instead you can annotate the code that is doing reflection with
UsesReflection
. Annotating the reflecting code is generally more clear and maintainable, and it also naturally gives rise to edges that describe just the reflected aspects of the program. TheUsedByReflection
annotation is suitable for cases where the reflecting code is not under user control, or in migrating away from rules.When a class is annotated, member patterns can be used to define which members are to be kept. When no member patterns are specified the default pattern is to match just the class.
When a member is annotated, the member patterns cannot be used as the annotated member itself fully defines the item to be kept (i.e., itself).
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description KeepTarget[]
additionalTargets
Additional targets to be kept in addition to the annotated class/members.AnnotationPattern[]
constrainAnnotations
Patterns for annotations that must remain on the item.KeepConstraint[]
constraintAdditions
Add additional usage constraints of the target.KeepConstraint[]
constraints
Define the usage constraints of the target.java.lang.String
description
Optional description to document the reason for this annotation.FieldAccessFlags[]
fieldAccess
Define the field-access pattern by matching on access flags.java.lang.Class<?>
fieldAnnotatedByClassConstant
Define the field-annotated-by pattern by reference to a Class constant.java.lang.String
fieldAnnotatedByClassName
Define the field-annotated-by pattern by fully qualified class name.ClassNamePattern
fieldAnnotatedByClassNamePattern
Define the field-annotated-by pattern by reference to a class-name pattern.java.lang.String
fieldName
Define the field-name pattern by an exact field name.StringPattern
fieldNamePattern
Define the field-name pattern by a string pattern.java.lang.String
fieldType
Define the field-type pattern by a fully qualified type.java.lang.Class<?>
fieldTypeConstant
Define the field-type pattern by a class constant.TypePattern
fieldTypePattern
Define the field-type pattern by a pattern on types.KeepItemKind
kind
Specify the kind of this item pattern.MemberAccessFlags[]
memberAccess
Define the member-access pattern by matching on access flags.java.lang.Class<?>
memberAnnotatedByClassConstant
Define the member-annotated-by pattern by reference to a Class constant.java.lang.String
memberAnnotatedByClassName
Define the member-annotated-by pattern by fully qualified class name.ClassNamePattern
memberAnnotatedByClassNamePattern
Define the member-annotated-by pattern by reference to a class-name pattern.MethodAccessFlags[]
methodAccess
Define the method-access pattern by matching on access flags.java.lang.Class<?>
methodAnnotatedByClassConstant
Define the method-annotated-by pattern by reference to a Class constant.java.lang.String
methodAnnotatedByClassName
Define the method-annotated-by pattern by fully qualified class name.ClassNamePattern
methodAnnotatedByClassNamePattern
Define the method-annotated-by pattern by reference to a class-name pattern.java.lang.String
methodName
Define the method-name pattern by an exact method name.StringPattern
methodNamePattern
Define the method-name pattern by a string pattern.java.lang.String[]
methodParameters
Define the method parameters pattern by a list of fully qualified types.TypePattern[]
methodParameterTypePatterns
Define the method parameters pattern by a list of patterns on types.java.lang.String
methodReturnType
Define the method return-type pattern by a fully qualified type or 'void'.java.lang.Class<?>
methodReturnTypeConstant
Define the method return-type pattern by a class constant.TypePattern
methodReturnTypePattern
Define the method return-type pattern by a type pattern.KeepCondition[]
preconditions
Conditions that should be satisfied for the annotation to be in effect.
-
-
-
-
preconditions
KeepCondition[] preconditions
Conditions that should be satisfied for the annotation to be in effect.- Returns:
- The list of preconditions. Defaults to no conditions, thus trivially/unconditionally satisfied.
- Default:
- {}
-
-
-
additionalTargets
KeepTarget[] additionalTargets
Additional targets to be kept in addition to the annotated class/members.- Returns:
- List of additional target consequences. Defaults to no additional target consequences.
- Default:
- {}
-
-
-
kind
KeepItemKind kind
Specify the kind of this item pattern.If unspecified the default kind depends on the annotated item.
When annotating a class the default kind is:
KeepItemKind.ONLY_CLASS
if no member patterns are defined;KeepItemKind.CLASS_AND_METHODS
if method patterns are defined;KeepItemKind.CLASS_AND_FIELDS
if field patterns are defined;KeepItemKind.CLASS_AND_MEMBERS
otherwise.
When annotating a method the default kind is:
KeepItemKind.ONLY_METHODS
When annotating a field the default kind is:
KeepItemKind.ONLY_FIELDS
It is not possible to use
KeepItemKind.ONLY_CLASS
if annotating a member.- Returns:
- The kind for this pattern.
- Default:
- com.android.tools.r8.keepanno.annotations.KeepItemKind.DEFAULT
-
-
-
constraints
KeepConstraint[] constraints
Define the usage constraints of the target.The specified constraints must remain valid for the target.
The default constraints depend on the kind of the target. For all targets the default constraints include:
For classes the default constraints also include:
For methods the default constraints also include:
For fields the default constraints also include:
Mutually exclusive with the property `constraintAdditions` also defining constraints.
- Returns:
- Usage constraints for the target.
- Default:
- {}
-
-
-
constraintAdditions
KeepConstraint[] constraintAdditions
Add additional usage constraints of the target.The specified constraints must remain valid for the target in addition to the default constraints.
The default constraints are documented in
constraints()
Mutually exclusive with the property `constraints` also defining constraints.
- Returns:
- Additional usage constraints for the target.
- Default:
- {}
-
-
-
constrainAnnotations
AnnotationPattern[] constrainAnnotations
Patterns for annotations that must remain on the item.The annotations matching any of the patterns must remain on the item if the annotation types remain in the program.
Note that if the annotation types themselves are unused/removed, then their references on the item will be removed too. If the annotation types themselves are used reflectively then they too need a keep annotation or rule to ensure they remain in the program.
By default no annotation patterns are defined and no annotations are required to remain.
- Returns:
- Annotation patterns
- Default:
- {}
-
-
-
memberAnnotatedByClassName
java.lang.String memberAnnotatedByClassName
Define the member-annotated-by pattern by fully qualified class name.Mutually exclusive with the following other properties defining member-annotated-by:
- memberAnnotatedByClassConstant
- memberAnnotatedByClassNamePattern
Mutually exclusive with all field and method properties as use restricts the match to both types of members.
If none are specified the default is to match any member regardless of what the member is annotated by.
- Returns:
- The qualified class name that defines the annotation.
- Default:
- ""
-
-
-
memberAnnotatedByClassConstant
java.lang.Class<?> memberAnnotatedByClassConstant
Define the member-annotated-by pattern by reference to a Class constant.Mutually exclusive with the following other properties defining member-annotated-by:
- memberAnnotatedByClassName
- memberAnnotatedByClassNamePattern
Mutually exclusive with all field and method properties as use restricts the match to both types of members.
If none are specified the default is to match any member regardless of what the member is annotated by.
- Returns:
- The class-constant that defines the annotation.
- Default:
- java.lang.Object.class
-
-
-
memberAnnotatedByClassNamePattern
ClassNamePattern memberAnnotatedByClassNamePattern
Define the member-annotated-by pattern by reference to a class-name pattern.Mutually exclusive with the following other properties defining member-annotated-by:
- memberAnnotatedByClassName
- memberAnnotatedByClassConstant
Mutually exclusive with all field and method properties as use restricts the match to both types of members.
If none are specified the default is to match any member regardless of what the member is annotated by.
- Returns:
- The class-name pattern that defines the annotation.
- Default:
- @com.android.tools.r8.keepanno.annotations.ClassNamePattern(unqualifiedName="")
-
-
-
memberAccess
MemberAccessFlags[] memberAccess
Define the member-access pattern by matching on access flags.Mutually exclusive with all field and method properties as use restricts the match to both types of members.
- Returns:
- The member access-flag constraints that must be met.
- Default:
- {}
-
-
-
methodAnnotatedByClassName
java.lang.String methodAnnotatedByClassName
Define the method-annotated-by pattern by fully qualified class name.Mutually exclusive with the following other properties defining method-annotated-by:
- methodAnnotatedByClassConstant
- methodAnnotatedByClassNamePattern
Mutually exclusive with all field properties.
If none are specified the default is to match any method regardless of what the method is annotated by.
- Returns:
- The qualified class name that defines the annotation.
- Default:
- ""
-
-
-
methodAnnotatedByClassConstant
java.lang.Class<?> methodAnnotatedByClassConstant
Define the method-annotated-by pattern by reference to a Class constant.Mutually exclusive with the following other properties defining method-annotated-by:
- methodAnnotatedByClassName
- methodAnnotatedByClassNamePattern
Mutually exclusive with all field properties.
If none are specified the default is to match any method regardless of what the method is annotated by.
- Returns:
- The class-constant that defines the annotation.
- Default:
- java.lang.Object.class
-
-
-
methodAnnotatedByClassNamePattern
ClassNamePattern methodAnnotatedByClassNamePattern
Define the method-annotated-by pattern by reference to a class-name pattern.Mutually exclusive with the following other properties defining method-annotated-by:
- methodAnnotatedByClassName
- methodAnnotatedByClassConstant
Mutually exclusive with all field properties.
If none are specified the default is to match any method regardless of what the method is annotated by.
- Returns:
- The class-name pattern that defines the annotation.
- Default:
- @com.android.tools.r8.keepanno.annotations.ClassNamePattern(unqualifiedName="")
-
-
-
methodAccess
MethodAccessFlags[] methodAccess
Define the method-access pattern by matching on access flags.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any method-access flags.
- Returns:
- The method access-flag constraints that must be met.
- Default:
- {}
-
-
-
methodName
java.lang.String methodName
Define the method-name pattern by an exact method name.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any method name.
Mutually exclusive with the property `methodNamePattern` also defining method-name.
- Returns:
- The exact method name of the method.
- Default:
- ""
-
-
-
methodNamePattern
StringPattern methodNamePattern
Define the method-name pattern by a string pattern.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any method name.
Mutually exclusive with the property `methodName` also defining method-name.
- Returns:
- The string pattern of the method name.
- Default:
- @com.android.tools.r8.keepanno.annotations.StringPattern(exact="")
-
-
-
methodReturnType
java.lang.String methodReturnType
Define the method return-type pattern by a fully qualified type or 'void'.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any return type.
Mutually exclusive with the following other properties defining return-type:
- methodReturnTypeConstant
- methodReturnTypePattern
- Returns:
- The qualified type name of the method return type.
- Default:
- ""
-
-
-
methodReturnTypeConstant
java.lang.Class<?> methodReturnTypeConstant
Define the method return-type pattern by a class constant.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any return type.
Mutually exclusive with the following other properties defining return-type:
- methodReturnType
- methodReturnTypePattern
- Returns:
- A class constant denoting the type of the method return type.
- Default:
- java.lang.Object.class
-
-
-
methodReturnTypePattern
TypePattern methodReturnTypePattern
Define the method return-type pattern by a type pattern.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any return type.
Mutually exclusive with the following other properties defining return-type:
- methodReturnType
- methodReturnTypeConstant
- Returns:
- The pattern of the method return type.
- Default:
- @com.android.tools.r8.keepanno.annotations.TypePattern(name="")
-
-
-
methodParameters
java.lang.String[] methodParameters
Define the method parameters pattern by a list of fully qualified types.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any parameters.
Mutually exclusive with the property `methodParameterTypePatterns` also defining parameters.
- Returns:
- The list of qualified type names of the method parameters.
- Default:
- {""}
-
-
-
methodParameterTypePatterns
TypePattern[] methodParameterTypePatterns
Define the method parameters pattern by a list of patterns on types.Mutually exclusive with all field properties.
If none, and other properties define this item as a method, the default matches any parameters.
Mutually exclusive with the property `methodParameters` also defining parameters.
- Returns:
- The list of type patterns for the method parameters.
- Default:
- {@com.android.tools.r8.keepanno.annotations.TypePattern(name="")}
-
-
-
fieldAnnotatedByClassName
java.lang.String fieldAnnotatedByClassName
Define the field-annotated-by pattern by fully qualified class name.Mutually exclusive with the following other properties defining field-annotated-by:
- fieldAnnotatedByClassConstant
- fieldAnnotatedByClassNamePattern
Mutually exclusive with all method properties.
If none are specified the default is to match any field regardless of what the field is annotated by.
- Returns:
- The qualified class name that defines the annotation.
- Default:
- ""
-
-
-
fieldAnnotatedByClassConstant
java.lang.Class<?> fieldAnnotatedByClassConstant
Define the field-annotated-by pattern by reference to a Class constant.Mutually exclusive with the following other properties defining field-annotated-by:
- fieldAnnotatedByClassName
- fieldAnnotatedByClassNamePattern
Mutually exclusive with all method properties.
If none are specified the default is to match any field regardless of what the field is annotated by.
- Returns:
- The class-constant that defines the annotation.
- Default:
- java.lang.Object.class
-
-
-
fieldAnnotatedByClassNamePattern
ClassNamePattern fieldAnnotatedByClassNamePattern
Define the field-annotated-by pattern by reference to a class-name pattern.Mutually exclusive with the following other properties defining field-annotated-by:
- fieldAnnotatedByClassName
- fieldAnnotatedByClassConstant
Mutually exclusive with all method properties.
If none are specified the default is to match any field regardless of what the field is annotated by.
- Returns:
- The class-name pattern that defines the annotation.
- Default:
- @com.android.tools.r8.keepanno.annotations.ClassNamePattern(unqualifiedName="")
-
-
-
fieldAccess
FieldAccessFlags[] fieldAccess
Define the field-access pattern by matching on access flags.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any field-access flags.
- Returns:
- The field access-flag constraints that must be met.
- Default:
- {}
-
-
-
fieldName
java.lang.String fieldName
Define the field-name pattern by an exact field name.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any field name.
Mutually exclusive with the property `fieldNamePattern` also defining field-name.
- Returns:
- The exact field name of the field.
- Default:
- ""
-
-
-
fieldNamePattern
StringPattern fieldNamePattern
Define the field-name pattern by a string pattern.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any field name.
Mutually exclusive with the property `fieldName` also defining field-name.
- Returns:
- The string pattern of the field name.
- Default:
- @com.android.tools.r8.keepanno.annotations.StringPattern(exact="")
-
-
-
fieldType
java.lang.String fieldType
Define the field-type pattern by a fully qualified type.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any type.
Mutually exclusive with the following other properties defining field-type:
- fieldTypeConstant
- fieldTypePattern
- Returns:
- The qualified type name for the field type.
- Default:
- ""
-
-
-
fieldTypeConstant
java.lang.Class<?> fieldTypeConstant
Define the field-type pattern by a class constant.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any type.
Mutually exclusive with the following other properties defining field-type:
- fieldType
- fieldTypePattern
- Returns:
- The class constant for the field type.
- Default:
- java.lang.Object.class
-
-
-
fieldTypePattern
TypePattern fieldTypePattern
Define the field-type pattern by a pattern on types.Mutually exclusive with all method properties.
If none, and other properties define this item as a field, the default matches any type.
Mutually exclusive with the following other properties defining field-type:
- fieldType
- fieldTypeConstant
- Returns:
- The type pattern for the field type.
- Default:
- @com.android.tools.r8.keepanno.annotations.TypePattern(name="")
-
-