use of org.codehaus.groovy.ast.AnnotatedNode in project groovy-core by groovy.
the class StaticTypesTransformation method visit.
// @Override
public void visit(ASTNode[] nodes, SourceUnit source) {
AnnotationNode annotationInformation = (AnnotationNode) nodes[0];
Map<String, Expression> members = annotationInformation.getMembers();
Expression extensions = members.get("extensions");
AnnotatedNode node = (AnnotatedNode) nodes[1];
StaticTypeCheckingVisitor visitor = null;
if (node instanceof ClassNode) {
ClassNode classNode = (ClassNode) node;
visitor = newVisitor(source, classNode);
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
visitor.initialize();
visitor.visitClass(classNode);
} else if (node instanceof MethodNode) {
MethodNode methodNode = (MethodNode) node;
visitor = newVisitor(source, methodNode.getDeclaringClass());
visitor.setCompilationUnit(compilationUnit);
addTypeCheckingExtensions(visitor, extensions);
visitor.setMethodsToBeVisited(Collections.singleton(methodNode));
visitor.initialize();
visitor.visitMethod(methodNode);
} else {
source.addError(new SyntaxException(STATIC_ERROR_PREFIX + "Unimplemented node type", node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()));
}
if (visitor != null) {
visitor.performSecondPass();
}
}
use of org.codehaus.groovy.ast.AnnotatedNode in project groovy-core by groovy.
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.AnnotatedNode in project groovy-core by groovy.
the class LazyASTTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source);
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode node = (AnnotationNode) nodes[0];
if (parent instanceof FieldNode) {
final FieldNode fieldNode = (FieldNode) parent;
visitField(node, fieldNode);
}
}
use of org.codehaus.groovy.ast.AnnotatedNode in project groovy-core by groovy.
the class MyIntegerAnnoTraceASTTransformation method visit.
public void visit(ASTNode[] nodes, final SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new RuntimeException("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
File f = new File("temp/log.txt");
try {
ResourceGroovyMethods.append(f, parent.getClass().getSimpleName() + " " + parent.getAnnotations().get(0).getMember("value").getText() + " ");
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.codehaus.groovy.ast.AnnotatedNode in project grails-core by grails.
the class DelegateAsyncTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode annotationNode = (AnnotationNode) nodes[0];
if (parent instanceof ClassNode) {
Expression value = annotationNode.getMember("value");
if (value instanceof ClassExpression) {
ClassNode targetApi = value.getType().getPlainNodeReference();
ClassNode classNode = (ClassNode) parent;
final String fieldName = '$' + Introspector.decapitalize(targetApi.getNameWithoutPackage());
FieldNode fieldNode = classNode.getField(fieldName);
if (fieldNode == null) {
fieldNode = new FieldNode(fieldName, Modifier.PRIVATE, targetApi, classNode, new ConstructorCallExpression(targetApi, NO_ARGS));
classNode.addField(fieldNode);
}
applyDelegateAsyncTransform(classNode, targetApi, fieldName);
}
} else if (parent instanceof FieldNode) {
FieldNode fieldNode = (FieldNode) parent;
ClassNode targetApi = fieldNode.getType().getPlainNodeReference();
ClassNode classNode = fieldNode.getOwner();
applyDelegateAsyncTransform(classNode, targetApi, fieldNode.getName());
}
}
Aggregations