Class DeclarationAnnotationHelper.DeclarationAnnotationsInfo
java.lang.Object
org.benf.cfr.reader.bytecode.analysis.types.DeclarationAnnotationHelper.DeclarationAnnotationsInfo
- Enclosing class:
- DeclarationAnnotationHelper
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final List<AnnotationTableEntry>
private final List<AnnotationTableEntry>
private final boolean
private final List<AnnotationTableTypeEntry>
private final List<AnnotationTableTypeEntry>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
DeclarationAnnotationsInfo
(List<AnnotationTableEntry> declAnnotationsAdmissible, List<AnnotationTableEntry> declAnnotationsNonAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsNonAdmissible, boolean requiresNonAdmissibleType) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkCanProvideAnnotations
(boolean usesAdmissibleType) getDeclarationAnnotations
(boolean usesAdmissibleType) getTypeAnnotations
(boolean usesAdmissibleType) private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo
possibleAdmissible
(List<AnnotationTableEntry> declAnnotationsAdmissible, List<AnnotationTableEntry> declAnnotationsNonAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsNonAdmissible) private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo
possibleAdmissible
(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations) boolean
private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo
requiringNonAdmissible
(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations)
-
Field Details
-
declAnnotationsAdmissible
-
declAnnotationsNonAdmissible
-
typeAnnotationsAdmissible
-
typeAnnotationsNonAdmissible
-
requiresNonAdmissibleType
private final boolean requiresNonAdmissibleType
-
-
Constructor Details
-
DeclarationAnnotationsInfo
private DeclarationAnnotationsInfo(List<AnnotationTableEntry> declAnnotationsAdmissible, List<AnnotationTableEntry> declAnnotationsNonAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsNonAdmissible, boolean requiresNonAdmissibleType)
-
-
Method Details
-
possibleAdmissible
private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo possibleAdmissible(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations) -
possibleAdmissible
private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo possibleAdmissible(List<AnnotationTableEntry> declAnnotationsAdmissible, List<AnnotationTableEntry> declAnnotationsNonAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsAdmissible, List<AnnotationTableTypeEntry> typeAnnotationsNonAdmissible) -
requiringNonAdmissible
private static DeclarationAnnotationHelper.DeclarationAnnotationsInfo requiringNonAdmissible(List<AnnotationTableEntry> declAnnotations, List<AnnotationTableTypeEntry> typeAnnotations) -
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
- Parameters:
usesAdmissibleType
- Whether the caller writes the type in a way that makes placingTYPE_USE
annotations in front of it admissible- Returns:
- Annotations to place on the declaration
- Throws:
IllegalArgumentException
- If annotations for an admissible type are requested, but this placement information does not support it
-
getTypeAnnotations
- Parameters:
usesAdmissibleType
- Whether the caller writes the type in a way that makes placingTYPE_USE
annotations in front of it admissible- Returns:
- Annotations to place on the type
- Throws:
IllegalArgumentException
- If annotations for an admissible type are requested, but this placement information does not support it
-