Class DeclarationAnnotationHelper

java.lang.Object
org.benf.cfr.reader.bytecode.analysis.types.DeclarationAnnotationHelper

public class DeclarationAnnotationHelper extends Object
  • Field Details

    • EMPTY_DECOMPILER_COMMENTS

      private static final DecompilerComments EMPTY_DECOMPILER_COMMENTS
  • Constructor Details

    • DeclarationAnnotationHelper

      private DeclarationAnnotationHelper()
  • Method Details

    • getDeclAndTypeUseAnnotationTypes

      private static Set<JavaTypeInstance> getDeclAndTypeUseAnnotationTypes(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations)
    • getCommonInnerClassAnnotationIndex

      private static Integer getCommonInnerClassAnnotationIndex(List<AnnotationTableTypeEntry> typeAnnotations)
      Returns for the annotations the common inner class annotation index, or null if there is no common index. For example with A and B being inner classes:
      
       @TypeUse1 @TypeUse2 A.B f; // Common index: 0
       A. @TypeUse1 @TypeUse2 B f; // Common index: 1
       @TypeUse1 A.@TypeUse2 B f; // No common index
       
      Parameters:
      typeAnnotations - For which the common inner annotation index should be determined
      Returns:
      Common annotation index or null
    • canTypeAnnotationBeMovedToDecl

      private static boolean canTypeAnnotationBeMovedToDecl(JavaTypeInstance annotatedType, AnnotationTableTypeEntry typeAnnotation, Integer commonInnerAnnotationIndex)
      Returns whether the type annotation can be moved to the declaration. For example:
      
       // Can be moved
       public @TypeUse String[] f;
       // when moved:
       @TypeUse
       public String[] f;
      
       // Cannot be moved
       public String @TypeUse[] f;
       
      The common inner annotation index is used to be not too restrictive if the outer class has no annotations and therefore the type annotation could be moved (relies on JavaRefTypeInstance to only refer to the first annotated type). For example with A and B being inner classes:
      
       public @TypeUse A.@TypeUse B f; // Not movable
      
       // Can be moved if B is not qualified using outer class
       public @TypeUse1 @TypeUse2 B f;
       
      Parameters:
      annotatedType - Type to be annotated
      typeAnnotation - Annotation for the type
      commonInnerAnnotationIndex - Nullable index of the common annotation position for inner classes
      Returns:
      Whether the annotation can be moved to the declaration
    • areAnnotationsEqual

      private static boolean areAnnotationsEqual(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations)
    • getDeclarationInfo

      public static DeclarationAnnotationHelper.DeclarationAnnotationsInfo getDeclarationInfo(JavaTypeInstance nullableAnnotatedType, List<AnnotationTableEntry> declarationAnnotations, List<AnnotationTableTypeEntry> typeAnnotations)
      Calculates information about where to place declaration and ElementType.TYPE_USE annotations for a place where both can occur.
      Parameters:
      nullableAnnotatedType - Type for which the TYPE_USE annotations apply, null if there is no type (e.g. for constructor declarations)
      declarationAnnotations - Annotations for the declaration, e.g. ElementType.FIELD
      typeAnnotations - Annotations for the type, i.e. ElementType.TYPE_USE
      Returns:
      Information about how to place the annotations