public abstract class AbstractASTTransformation
extends Object
implements ASTTransformation, ErrorCollecting
Abstract base class for AST transformations.
Provides utility methods for extracting annotation members, validating properties/fields, and filtering members based on include/exclude specifications.
| Modifiers | Name | Description |
|---|---|---|
static ClassNode |
RETENTION_CLASSNODE |
A shared ClassNode representing the Retention annotation. |
protected SourceUnit |
sourceUnit |
The source unit associated with the compilation context. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addError(String msg, ASTNode node)Records a transformation error message associated with an AST node. |
|
protected boolean |
checkIncludeExcludeUndefinedAware(AnnotationNode node, List<String> excludes, List<String> includes, String typeName)Validates that only one of 'includes' or 'excludes' is specified, not both. |
|
protected void |
checkIncludeExcludeUndefinedAware(AnnotationNode node, List<String> excludes, List<String> includes, List<ClassNode> excludeTypes, List<ClassNode> includeTypes, String typeName)Validates that only one filtering list is specified among 'includes', 'excludes', 'includeTypes', and 'excludeTypes'. |
|
protected boolean |
checkNotInterface(ClassNode cNode, String annotationName)Validates that the target class node is not an interface. |
|
public boolean |
checkPropertyList(ClassNode cNode, List<String> propertyNameList, String listName, AnnotationNode anno, String typeName, boolean includeFields)Validates that all property names in the given list exist in the target class. |
|
public boolean |
checkPropertyList(ClassNode cNode, List<String> propertyNameList, String listName, AnnotationNode anno, String typeName, boolean includeFields, boolean includeSuperProperties, boolean allProperties)Validates that all property names in the given list exist in the target class. |
|
public boolean |
checkPropertyList(ClassNode cNode, List<String> propertyNameList, String listName, AnnotationNode anno, String typeName, boolean includeFields, boolean includeSuperProperties, boolean allProperties, boolean includeSuperFields, boolean includeStatic)Validates that all property names in the given list exist in the target class. |
|
protected List<AnnotationNode> |
copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, String myTypeName)Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS. |
|
protected List<AnnotationNode> |
copyAnnotatedNodeAnnotations(AnnotatedNode annotatedNode, String myTypeName, boolean includeGenerated)Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS. |
|
public static boolean |
deemedInternal(AnnotatedNode node)
|
|
public static boolean |
deemedInternalName(String name)Determines whether a name is considered internal and should typically be excluded. |
|
public String |
getAnnotationName()If the transform is associated with a single annotation, returns a name suitable for displaying in error messages. |
|
public List<ClassNode> |
getMemberClassList(AnnotationNode anno, String name)Retrieves a list of ClassNode values from a list-type annotation member. |
|
public ClassNode |
getMemberClassValue(AnnotationNode node, String name)Retrieves the ClassNode value of an annotation member. |
|
public ClassNode |
getMemberClassValue(AnnotationNode node, String name, ClassNode defaultValue)Retrieves the ClassNode value of an annotation member with a default fallback. |
|
public int |
getMemberIntValue(AnnotationNode node, String name)Retrieves the integer value of an annotation member. |
|
public static List<String> |
getMemberStringList(AnnotationNode anno, String name)Retrieves a list of string values from a list-type annotation member. |
|
public static String |
getMemberStringValue(AnnotationNode node, String name, String defaultValue)Retrieves the string value of an annotation member with a default fallback. |
|
public static String |
getMemberStringValue(AnnotationNode node, String name)Retrieves the string value of an annotation member. |
|
public Object |
getMemberValue(AnnotationNode node, String name)Retrieves the value of an annotation member that is a constant expression. |
|
public boolean |
hasAnnotation(ClassNode node, ClassNode annotation)Checks whether a class node has a specific annotation. |
|
protected void |
init(ASTNode[] nodes, SourceUnit sourceUnit)Initializes the transformation with the annotation and source unit context. |
|
public static void |
markAsInternal(AnnotatedNode node)
|
|
public boolean |
memberHasValue(AnnotationNode node, String name, Object value)Checks whether an annotation member has a specific value. |
|
public static boolean |
shouldSkip(String name, List<String> excludes, List<String> includes)Determines whether a name should be skipped based on include/exclude filters. |
|
public static boolean |
shouldSkip(String name, List<String> excludes, List<String> includes, boolean allNames)Determines whether a name should be skipped based on include/exclude filters. |
|
public static boolean |
shouldSkip(AnnotatedNode node, List<String> excludes, List<String> includes, boolean allNames)Variant that checks both the name and @Internal annotation. |
|
public static boolean |
shouldSkipOnDescriptorUndefinedAware(boolean checkReturn, Map genericsSpec, MethodNode mNode, List<ClassNode> excludeTypes, List<ClassNode> includeTypes)Determines whether a method should be skipped based on method descriptor matching against include/exclude type lists. |
|
public static boolean |
shouldSkipUndefinedAware(String name, List<String> excludes, List<String> includes)Determines whether a name should be skipped based on include/exclude filters and the undefined marker semantics. |
|
public static boolean |
shouldSkipUndefinedAware(String name, List<String> excludes, List<String> includes, boolean allNames)Determines whether a name should be skipped based on include/exclude filters with support for the undefined marker semantics. |
|
public static boolean |
shouldSkipUndefinedAware(AnnotatedNode node, List<String> excludes, List<String> includes, boolean allNames)Variant that checks both the name and @Internal annotation. |
|
public static List<String> |
tokenize(String rawExcludes)Tokenizes a string into a list of individual tokens using comma and space as delimiters. |
A shared ClassNode representing the Retention annotation. Used for checking retention policy of annotations during AST transformation.
The source unit associated with the compilation context. Provides access to error collection and source file information during AST transformation.
Records a transformation error message associated with an AST node. The error is collected and reported at the end of compilation. This method implements ErrorCollecting.addError.
msg - the error message to reportnode - the AST node associated with the error for source location trackingValidates that only one of 'includes' or 'excludes' is specified, not both. Generates an error if both are provided.
node - the annotation node associated with this check for error reportingexcludes - the excludes list, or nullincludes - the includes list, or nulltypeName - the transformation type name for error reportingValidates that only one filtering list is specified among 'includes', 'excludes', 'includeTypes', and 'excludeTypes'. Generates an error if more than one filtering specification is provided.
node - the annotation node associated with this check for error reportingexcludes - the string excludes list, or nullincludes - the string includes list, or nullexcludeTypes - the type excludes list, or nullincludeTypes - the type includes list, or nulltypeName - the transformation type name for error reportingValidates that the target class node is not an interface. Generates an error if the target is an interface since transformation cannot be applied.
cNode - the class node to validateannotationName - the name of the annotation for error reportingValidates that all property names in the given list exist in the target class. This is a convenience overload that calls checkPropertyList(ClassNode, List, String, AnnotationNode, String, boolean, boolean, boolean, boolean, boolean) with defaults: includeSuperProperties=false, allProperties=false, includeSuperFields=false, includeStatic=false.
cNode - the class node to validate properties againstpropertyNameList - the list of property names to verify, or nulllistName - the name of the list (for error reporting, e.g., "includes" or "excludes")anno - the annotation node for error reportingtypeName - the transformation type name for error reportingincludeFields - whether to also check for matching field namesValidates that all property names in the given list exist in the target class. This is a convenience overload that calls checkPropertyList(ClassNode, List, String, AnnotationNode, String, boolean, boolean, boolean, boolean, boolean) with defaults: includeSuperFields=false, includeStatic=false.
cNode - the class node to validate properties againstpropertyNameList - the list of property names to verify, or nulllistName - the name of the list (for error reporting, e.g., "includes" or "excludes")anno - the annotation node for error reportingtypeName - the transformation type name for error reportingincludeFields - whether to also check for matching field namesincludeSuperProperties - whether to include inherited propertiesallProperties - whether to include all accessible propertiesValidates that all property names in the given list exist in the target class. Checks both properties and optionally fields in the class and its superclasses. Generates errors for any properties or fields that cannot be found.
cNode - the class node to validate properties againstpropertyNameList - the list of property names to verify, or nulllistName - the name of the list (for error reporting, e.g., "includes" or "excludes")anno - the annotation node for error reportingtypeName - the transformation type name for error reportingincludeFields - whether to also check for matching field names in the current classincludeSuperProperties - whether to include inherited properties from superclassesallProperties - whether to include all accessible properties or only declared onesincludeSuperFields - whether to also check superclass fieldsincludeStatic - whether to include static propertiesCopies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS.
Annotations with GeneratedClosure members are not supported for now.
Copies all candidateAnnotations with retention policy RetentionPolicy.RUNTIME and RetentionPolicy.CLASS.
Annotations with GeneratedClosure members are not supported for now.
Determines whether a name is considered internal and should typically be excluded. A name is considered internal if it contains a dollar sign ('$'), which is commonly used for generated member names.
name - the name to checkIf the transform is associated with a single annotation, returns a name suitable for displaying in error messages.
Retrieves a list of ClassNode values from a list-type annotation member. Handles both single ClassExpression members and ListExpression members. Generates errors for invalid expression types and returns null if the member is undefined.
anno - the annotation node to queryname - the name of the annotation memberRetrieves the ClassNode value of an annotation member. This is a convenience overload that calls getMemberClassValue(AnnotationNode, String, ClassNode) with null as the default value.
node - the annotation node to queryname - the name of the annotation memberRetrieves the ClassNode value of an annotation member with a default fallback. Validates that the member is a ClassExpression and generates errors for invalid expression types (VariableExpression or ConstantExpression).
node - the annotation node to queryname - the name of the annotation memberdefaultValue - the value to return if the member is missing or not a valid ClassExpressionRetrieves the integer value of an annotation member.
node - the annotation node to queryname - the name of the annotation memberRetrieves a list of string values from a list-type annotation member. Handles both ListExpression members and comma/space-separated string values. Returns null if the member is the undefined marker.
anno - the annotation node to queryname - the name of the annotation memberRetrieves the string value of an annotation member with a default fallback. Returns the default value if the member is undefined (see Undefined).
node - the annotation node to queryname - the name of the annotation memberdefaultValue - the value to return if the member is missing or undefinedRetrieves the string value of an annotation member. This is a convenience overload that calls getMemberStringValue(AnnotationNode, String, String) with null as the default value.
node - the annotation node to queryname - the name of the annotation memberRetrieves the value of an annotation member that is a constant expression.
node - the annotation node to queryname - the name of the annotation memberChecks whether a class node has a specific annotation.
node - the class node to checkannotation - the annotation ClassNode to look forInitializes the transformation with the annotation and source unit context. This method must be called before the transformation processes any AST nodes.
nodes - An array containing exactly 2 elements: the first must be an AnnotationNode
specifying the annotation driving the transformation, and the second must be
an AnnotatedNode to which the annotation is applied.sourceUnit - The source compilation unit providing error collection and source info
Checks whether an annotation member has a specific value.
node - the annotation node to checkname - the name of the annotation membervalue - the expected value to match againstDetermines whether a name should be skipped based on include/exclude filters. This method provides a convenient overload that calls shouldSkip(String, List, List, boolean) with allNames set to false.
name - the name to checkexcludes - a list of names to exclude, or nullincludes - a list of names to include, or null (if non-empty and name not in it, name is skipped)Determines whether a name should be skipped based on include/exclude filters.
name - the name to checkexcludes - a list of names to exclude, or nullincludes - a list of names to include, or null (if non-empty and name not in it, name is skipped)allNames - if false, also skips names that are deemed internal (containing '$');
if true, only respects explicit include/exclude listsVariant that checks both the name and @Internal annotation.
Determines whether a method should be skipped based on method descriptor matching against include/exclude type lists. Allows filtering methods by their signature and return type for selective processing during transformations that handle multiple methods.
checkReturn - if true, compares full method descriptors including return type;
if false, compares only parameter descriptors excluding return typegenericsSpec - a map of generic type specifications for resolving generic method signaturesmNode - the method node to evaluateexcludeTypes - a list of ClassNodes specifying methods to exclude, or nullincludeTypes - a list of ClassNodes specifying methods to include, or nullDetermines whether a name should be skipped based on include/exclude filters and the undefined marker semantics. This method provides a convenient overload that calls shouldSkipUndefinedAware(String, List, List, boolean) with allNames set to false.
name - the name to checkexcludes - a list of names to exclude, or nullincludes - a list of names to include, or nullDetermines whether a name should be skipped based on include/exclude filters with support for the undefined marker semantics.
name - the name to checkexcludes - a list of names to exclude, or nullincludes - a list of names to include, or nullallNames - if false, also skips names that are deemed internal (containing '$');
if true, only respects explicit include/exclude listsVariant that checks both the name and @Internal annotation.