use of org.codehaus.groovy.ast.AnnotationNode in project groovy-core by groovy.
the class SynchronizedASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode()))
return;
String value = getMemberStringValue(node, "value");
if (parent instanceof MethodNode) {
MethodNode mNode = (MethodNode) parent;
if (mNode.isAbstract()) {
addError("Error during " + MY_TYPE_NAME + " processing: annotation not allowed on abstract method '" + mNode.getName() + "'", mNode);
return;
}
ClassNode cNode = mNode.getDeclaringClass();
String lockExpr = determineLock(value, cNode, mNode);
if (lockExpr == null)
return;
Statement origCode = mNode.getCode();
Statement newCode = new SynchronizedStatement(varX(lockExpr), origCode);
mNode.setCode(newCode);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy-core by groovy.
the class CompileDynamicProcessor method visit.
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) {
AnnotationNode node = new AnnotationNode(COMPILESTATIC_NODE);
node.addMember("value", new PropertyExpression(new ClassExpression(TYPECHECKINGMODE_NODE), "SKIP"));
return Collections.singletonList(node);
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy-core by groovy.
the class EqualsAndHashCodeASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode anno = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(anno.getClassNode()))
return;
if (parent instanceof ClassNode) {
ClassNode cNode = (ClassNode) parent;
if (!checkNotInterface(cNode, MY_TYPE_NAME))
return;
boolean callSuper = memberHasValue(anno, "callSuper", true);
boolean cacheHashCode = memberHasValue(anno, "cache", true);
boolean useCanEqual = !memberHasValue(anno, "useCanEqual", false);
if (callSuper && cNode.getSuperClass().getName().equals("java.lang.Object")) {
addError("Error during " + MY_TYPE_NAME + " processing: callSuper=true but '" + cNode.getName() + "' has no super class.", anno);
}
boolean includeFields = memberHasValue(anno, "includeFields", true);
List<String> excludes = getMemberList(anno, "excludes");
List<String> includes = getMemberList(anno, "includes");
if (hasAnnotation(cNode, CanonicalASTTransformation.MY_TYPE)) {
AnnotationNode canonical = cNode.getAnnotations(CanonicalASTTransformation.MY_TYPE).get(0);
if (excludes == null || excludes.isEmpty())
excludes = getMemberList(canonical, "excludes");
if (includes == null || includes.isEmpty())
includes = getMemberList(canonical, "includes");
}
if (!checkIncludeExclude(anno, excludes, includes, MY_TYPE_NAME))
return;
createHashCode(cNode, cacheHashCode, includeFields, callSuper, excludes, includes);
createEquals(cNode, includeFields, callSuper, useCanEqual, excludes, includes);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy-core by groovy.
the class InheritConstructorsASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (!MY_TYPE.equals(node.getClassNode()))
return;
if (parent instanceof ClassNode) {
processClass((ClassNode) parent, node);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy-core by groovy.
the class InheritConstructorsASTTransformation method processClass.
private void processClass(ClassNode cNode, AnnotationNode node) {
if (cNode.isInterface()) {
addError("Error processing interface '" + cNode.getName() + "'. " + MY_TYPE_NAME + " only allowed for classes.", cNode);
return;
}
boolean copyConstructorAnnotations = memberHasValue(node, "constructorAnnotations", true);
boolean copyParameterAnnotations = memberHasValue(node, "parameterAnnotations", true);
ClassNode sNode = cNode.getSuperClass();
List<AnnotationNode> superAnnotations = sNode.getAnnotations(MY_TYPE);
if (superAnnotations.size() == 1) {
// We need @InheritConstructors from parent classes processed first
// so force that order here. The transformation is benign on an already
// processed node so processing twice in any order won't matter bar
// a very small time penalty.
processClass(sNode, node);
}
for (ConstructorNode cn : sNode.getDeclaredConstructors()) {
addConstructorUnlessAlreadyExisting(cNode, cn, copyConstructorAnnotations, copyParameterAnnotations);
}
}
Aggregations