Annotation Interface UsesReflection


@Target({TYPE,FIELD,METHOD,CONSTRUCTOR}) @Retention(CLASS) public @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 Elements
    Modifier and Type
    Required Element
    Description
    Consequences that must be kept if the annotation is in effect.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Additional preconditions for the annotation to be in effect.
    Optional description to document the reason for this annotation.
  • Element Details

    • description

      String description
      Optional description to document the reason for this annotation.
      Returns:
      The descriptive message. Defaults to no description.
      Default:
      ""
    • value

      KeepTarget[] value
      Consequences that must be kept if the annotation is in effect.
      Returns:
      The list of target consequences.
    • additionalPreconditions

      KeepCondition[] additionalPreconditions
      Additional preconditions for the annotation to be in effect.
      Returns:
      The list of additional preconditions. Defaults to no additional preconditions.
      Default:
      {}