Annotation Interface UsesReflection
Annotation to declare the reflective usages made by a class, method or field.
The annotation's 'value' is a list of targets to be kept if the annotated item is used. The annotated item is a precondition for keeping any of the specified targets. Thus, if an annotated method is determined to be unused by the program, the annotation itself will not be in effect and the targets will not be kept (assuming nothing else is otherwise keeping them).
The annotation's 'additionalPreconditions' is optional and can specify additional conditions that should be satisfied for the annotation to be in effect.
The translation of the UsesReflection annotation into a KeepEdge is as
follows:
Assume the item of the annotation is denoted by 'CTX' and referred to as its context.
@UsesReflection(value = targets, [additionalPreconditions = preconditions])
==>
@KeepEdge(
consequences = targets,
preconditions = {createConditionFromContext(CTX)} + preconditions
)
where
KeepCondition createConditionFromContext(ctx) {
if (ctx.isClass()) {
return new KeepCondition(classTypeName = ctx.getClassTypeName());
}
if (ctx.isMethod()) {
return new KeepCondition(
classTypeName = ctx.getClassTypeName(),
methodName = ctx.getMethodName(),
methodReturnType = ctx.getMethodReturnType(),
methodParameterTypes = ctx.getMethodParameterTypes());
}
if (ctx.isField()) {
return new KeepCondition(
classTypeName = ctx.getClassTypeName(),
fieldName = ctx.getFieldName()
fieldType = ctx.getFieldType());
}
// unreachable
}
-
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionConsequences that must be kept if the annotation is in effect. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionAdditional preconditions for the annotation to be in effect.Optional description to document the reason for this annotation.
-
Element Details
-
description
String descriptionOptional description to document the reason for this annotation.- Returns:
- The descriptive message. Defaults to no description.
- Default:
""
-
value
KeepTarget[] valueConsequences that must be kept if the annotation is in effect.- Returns:
- The list of target consequences.
-
additionalPreconditions
KeepCondition[] additionalPreconditionsAdditional preconditions for the annotation to be in effect.- Returns:
- The list of additional preconditions. Defaults to no additional preconditions.
- Default:
{}
-