Class DeclarationAnnotationHelper.DeclarationAnnotationsInfo

  • Enclosing class:
    DeclarationAnnotationHelper

    public static class DeclarationAnnotationHelper.DeclarationAnnotationsInfo
    extends java.lang.Object
    Represents information about where to place declaration and ElementType.TYPE_USE annotations for a place where both can occur.

    This information differentiates between admissible and non-admissible types. What this means is defined in JLS 9.7.4. Depending on whether a type is admissible or not annotation placement has to be adjusted.

    Examples for annotation @DeclTypeUse with target TYPE_USE and FIELD:

     // Applies both to declaration and type; placement in front of type is admissible
     @TypeUse
     public String f;
    
     // Would consider the annotation repeated
     @TypeUse
     public @TypeUse String f;
    
     // Applies only to type
     public java.lang.@TypeUse String f;
    
     // Applies both to declaration and type
     // Probably javac bug (JDK-8223936) and should only apply to declaration
     @TypeUse
     public java.lang.String f;
     

    So depending on how the type is written by the decompiler (maybe the qualified name is used to resolve type collisions) the annotations have to be placed differently. Additionally the annotations present in the class files can require creating a non-admissible type, e.g. because the annotation is only present on the type, but not on the declaration, or because it was different values or appears in a different order.

    • Field Detail

      • declAnnotationsAdmissible

        private final java.util.List<AnnotationTableEntry> declAnnotationsAdmissible
      • declAnnotationsNonAdmissible

        private final java.util.List<AnnotationTableEntry> declAnnotationsNonAdmissible
      • requiresNonAdmissibleType

        private final boolean requiresNonAdmissibleType
    • Method Detail

      • requiresNonAdmissibleType

        public boolean requiresNonAdmissibleType()
        Returns:
        Whether the type has to be written in a way that makes placing TYPE_USE annotations in front of it non-admissible, e.g. using the qualified name or qualifying it using a non-admissible outer class (StaticOuter.StaticInner f;)
      • checkCanProvideAnnotations

        private void checkCanProvideAnnotations​(boolean usesAdmissibleType)
      • getDeclarationAnnotations

        public java.util.List<AnnotationTableEntry> getDeclarationAnnotations​(boolean usesAdmissibleType)
        Parameters:
        usesAdmissibleType - Whether the caller writes the type in a way that makes placing TYPE_USE annotations in front of it admissible
        Returns:
        Annotations to place on the declaration
        Throws:
        java.lang.IllegalArgumentException - If annotations for an admissible type are requested, but this placement information does not support it
      • getTypeAnnotations

        public java.util.List<AnnotationTableTypeEntry> getTypeAnnotations​(boolean usesAdmissibleType)
        Parameters:
        usesAdmissibleType - Whether the caller writes the type in a way that makes placing TYPE_USE annotations in front of it admissible
        Returns:
        Annotations to place on the type
        Throws:
        java.lang.IllegalArgumentException - If annotations for an admissible type are requested, but this placement information does not support it