use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
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 by apache.
the class ToStringASTTransformation 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 includeSuper = memberHasValue(anno, "includeSuper", true);
boolean includeSuperProperties = memberHasValue(anno, "includeSuperProperties", true);
boolean cacheToString = memberHasValue(anno, "cache", true);
List<String> excludes = getMemberStringList(anno, "excludes");
List<String> includes = getMemberStringList(anno, "includes");
if (includes != null && includes.contains("super")) {
includeSuper = true;
}
if (includeSuper && cNode.getSuperClass().getName().equals("java.lang.Object")) {
addError("Error during " + MY_TYPE_NAME + " processing: includeSuper=true but '" + cNode.getName() + "' has no super class.", anno);
}
boolean includeNames = memberHasValue(anno, "includeNames", true);
boolean includeFields = memberHasValue(anno, "includeFields", true);
boolean ignoreNulls = memberHasValue(anno, "ignoreNulls", true);
boolean includePackage = !memberHasValue(anno, "includePackage", false);
boolean allProperties = !memberHasValue(anno, "allProperties", false);
boolean allNames = memberHasValue(anno, "allNames", true);
if (!checkIncludeExcludeUndefinedAware(anno, excludes, includes, MY_TYPE_NAME))
return;
if (!checkPropertyList(cNode, includes != null ? DefaultGroovyMethods.minus(includes, "super") : null, "includes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties))
return;
if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields, includeSuperProperties, allProperties))
return;
createToString(cNode, includeSuper, includeFields, excludes, includes, includeNames, ignoreNulls, includePackage, cacheToString, includeSuperProperties, allProperties, allNames);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
the class IndexedPropertyASTTransformation 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 FieldNode) {
FieldNode fNode = (FieldNode) parent;
ClassNode cNode = fNode.getDeclaringClass();
if (cNode.getProperty(fNode.getName()) == null) {
addError("Error during " + MY_TYPE_NAME + " processing. Field '" + fNode.getName() + "' doesn't appear to be a property; incorrect visibility?", fNode);
return;
}
ClassNode fType = fNode.getType();
if (fType.isArray()) {
addArraySetter(fNode);
addArrayGetter(fNode);
} else if (fType.isDerivedFrom(LIST_TYPE)) {
addListSetter(fNode);
addListGetter(fNode);
} else {
addError("Error during " + MY_TYPE_NAME + " processing. Non-Indexable property '" + fNode.getName() + "' found. Type must be array or list but found " + fType.getName(), fNode);
}
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
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);
}
}
use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.
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);
}
}
Aggregations