Package org.codehaus.groovy.classgen
Class AnnotationVisitor
java.lang.Object
org.codehaus.groovy.classgen.AnnotationVisitor
An Annotation visitor responsible for:
- reading annotation metadata (@Retention, @Target, attribute types)
- verify that an
AnnotationNodeconforms to annotation meta - enhancing an
AnnotationNodeAST to reflect real annotation meta
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationVisitor(SourceUnit source, ErrorCollector errorCollector) Creates a new annotation visitor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidReports an error against the current annotation.protected voidReports an error against the supplied AST node.voidcheckCircularReference(ClassNode searchClass, ClassNode attrType, Expression startExp) Checks for circular references in nested annotations, which would cause infinite recursion.voidcheckReturnType(ClassNode attrType, ASTNode node) Verifies that an annotation member return type is valid under Java annotation rules.voidsetReportClass(ClassNode node) Sets the class to report errors against.visit(AnnotationNode node) Visits and validates an annotation node, checking that it conforms to annotation metadata and enhancing the AST to reflect real annotation semantics.protected voidvisitAnnotationExpression(String attrName, AnnotationConstantExpression valueExpr, ClassNode attrType) Validates a nested annotation attribute.protected voidvisitConstantExpression(String attrName, ConstantExpression valueExpr, ClassNode attrType) Validates a constant-valued annotation attribute.protected voidvisitEnumExpression(String attrName, PropertyExpression valueExpr, ClassNode attrType) Validates an enum-valued annotation attribute.protected voidvisitExpression(String attrName, Expression valueExpr, ClassNode attrType) Validates an annotation attribute value against its declared type.protected voidvisitListExpression(String attrName, ListExpression listExpr, ClassNode elementType) Validates each element of an array-valued annotation attribute.
-
Constructor Details
-
AnnotationVisitor
Creates a new annotation visitor.- Parameters:
source- the source unit being compilederrorCollector- the error collector for reporting validation errors
-
-
Method Details
-
setReportClass
Sets the class to report errors against.- Parameters:
node- the class node for error reporting
-
visit
Visits and validates an annotation node, checking that it conforms to annotation metadata and enhancing the AST to reflect real annotation semantics.- Parameters:
node- the annotation node to visit and validate- Returns:
- the validated and potentially modified annotation node
-
visitExpression
Validates an annotation attribute value against its declared type.- Parameters:
attrName- the attribute namevalueExpr- the supplied value expressionattrType- the declared attribute type
-
checkReturnType
Verifies that an annotation member return type is valid under Java annotation rules.- Parameters:
attrType- the declared return typenode- the node to report against on error
-
visitListExpression
Validates each element of an array-valued annotation attribute.- Parameters:
attrName- the attribute namelistExpr- the list expression representing the attribute valueelementType- the declared component type
-
visitEnumExpression
protected void visitEnumExpression(String attrName, PropertyExpression valueExpr, ClassNode attrType) Validates an enum-valued annotation attribute.- Parameters:
attrName- the attribute namevalueExpr- the enum constant expressionattrType- the declared enum type
-
visitConstantExpression
protected void visitConstantExpression(String attrName, ConstantExpression valueExpr, ClassNode attrType) Validates a constant-valued annotation attribute.- Parameters:
attrName- the attribute namevalueExpr- the constant expressionattrType- the declared attribute type
-
visitAnnotationExpression
protected void visitAnnotationExpression(String attrName, AnnotationConstantExpression valueExpr, ClassNode attrType) Validates a nested annotation attribute.- Parameters:
attrName- the attribute namevalueExpr- the nested annotation expressionattrType- the declared annotation type
-
addError
Reports an error against the current annotation.- Parameters:
msg- the error message
-
addError
Reports an error against the supplied AST node.- Parameters:
msg- the error messagenode- the node to associate with the error
-
checkCircularReference
Checks for circular references in nested annotations, which would cause infinite recursion.- Parameters:
searchClass- the annotation class being searched for in the dependency chainattrType- the attribute type to checkstartExp- the expression where the check started, for error reporting
-