Search in sources :

Example 11 with AnnotationNode

use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.

the class AntlrParserPlugin method innerInterfaceDef.

protected void innerInterfaceDef(AST classDef) {
    List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();
    AST node = classDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(classDef, "Interface", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized");
        node = node.getNextSibling();
    }
    modifiers |= Opcodes.ACC_ABSTRACT | Opcodes.ACC_INTERFACE;
    String name = identifier(node);
    node = node.getNextSibling();
    ClassNode superClass = ClassHelper.OBJECT_TYPE;
    GenericsType[] genericsType = null;
    if (isType(TYPE_PARAMETERS, node)) {
        genericsType = makeGenericsType(node);
        node = node.getNextSibling();
    }
    ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
    if (isType(EXTENDS_CLAUSE, node)) {
        interfaces = interfaces(node);
        node = node.getNextSibling();
    }
    ClassNode outerClass = classNode;
    boolean syntheticPublic = ((modifiers & Opcodes.ACC_SYNTHETIC) != 0);
    modifiers &= ~Opcodes.ACC_SYNTHETIC;
    if (classNode != null) {
        name = classNode.getNameWithoutPackage() + "$" + name;
        String fullName = dot(classNode.getPackageName(), name);
        classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, null);
    } else {
        classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, null);
    }
    classNode.setSyntheticPublic(syntheticPublic);
    classNode.addAnnotations(annotations);
    classNode.setGenericsTypes(genericsType);
    configureAST(classNode, classDef);
    int oldClassCount = innerClassCounter;
    assertNodeType(OBJBLOCK, node);
    objectBlock(node);
    output.addClass(classNode);
    classNode = outerClass;
    innerClassCounter = oldClassCount;
}
Also used : EnumConstantClassNode(org.codehaus.groovy.ast.EnumConstantClassNode) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) ClassNode(org.codehaus.groovy.ast.ClassNode) AST(antlr.collections.AST) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ArrayList(java.util.ArrayList) GenericsType(org.codehaus.groovy.ast.GenericsType) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode)

Example 12 with AnnotationNode

use of org.codehaus.groovy.ast.AnnotationNode in project groovy by apache.

the class NotYetImplementedASTTransformation method visit.

public void visit(ASTNode[] nodes, 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));
    }
    AnnotationNode annotationNode = (AnnotationNode) nodes[0];
    ASTNode node = nodes[1];
    if (!(node instanceof MethodNode)) {
        addError("@NotYetImplemented must only be applied on test methods!", node);
        return;
    }
    MethodNode methodNode = (MethodNode) node;
    ArrayList<Statement> statements = new ArrayList<Statement>();
    Statement statement = methodNode.getCode();
    if (statement instanceof BlockStatement) {
        statements.addAll(((BlockStatement) statement).getStatements());
    }
    if (statements.isEmpty())
        return;
    BlockStatement rewrittenMethodCode = new BlockStatement();
    rewrittenMethodCode.addStatement(tryCatchAssertionFailedError(annotationNode, methodNode, statements));
    rewrittenMethodCode.addStatement(throwAssertionFailedError(annotationNode));
    methodNode.setCode(rewrittenMethodCode);
}
Also used : MethodNode(org.codehaus.groovy.ast.MethodNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) Statement(org.codehaus.groovy.ast.stmt.Statement) ReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement) EmptyStatement(org.codehaus.groovy.ast.stmt.EmptyStatement) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement) TryCatchStatement(org.codehaus.groovy.ast.stmt.TryCatchStatement) AnnotatedNode(org.codehaus.groovy.ast.AnnotatedNode) ASTNode(org.codehaus.groovy.ast.ASTNode) ArrayList(java.util.ArrayList) BlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement)

Example 13 with AnnotationNode

use of org.codehaus.groovy.ast.AnnotationNode in project spring-boot by spring-projects.

the class SpringBootCompilerAutoConfiguration method addEnableAutoConfigurationAnnotation.

private void addEnableAutoConfigurationAnnotation(SourceUnit source, ClassNode classNode) {
    if (!hasEnableAutoConfigureAnnotation(classNode)) {
        AnnotationNode annotationNode = new AnnotationNode(ClassHelper.make("EnableAutoConfiguration"));
        classNode.addAnnotation(annotationNode);
    }
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode)

Example 14 with AnnotationNode

use of org.codehaus.groovy.ast.AnnotationNode in project spock by spockframework.

the class SpecAnnotator method addBlockMetadata.

private void addBlockMetadata(Block block, BlockKind kind) {
    AnnotationNode blockAnn = new AnnotationNode(nodeCache.BlockMetadata);
    blockAnn.setMember(BlockMetadata.KIND, new PropertyExpression(new ClassExpression(nodeCache.BlockKind), kind.name()));
    ListExpression textExprs = new ListExpression();
    for (String text : block.getDescriptions()) textExprs.addExpression(new ConstantExpression(text));
    blockAnn.setMember(BlockMetadata.TEXTS, textExprs);
    blockAnnElems.addExpression(new AnnotationConstantExpression(blockAnn));
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode)

Example 15 with AnnotationNode

use of org.codehaus.groovy.ast.AnnotationNode in project spock by spockframework.

the class SpecAnnotator method addFieldMetadata.

private void addFieldMetadata(Field field) {
    AnnotationNode ann = new AnnotationNode(nodeCache.FieldMetadata);
    ann.setMember(FieldMetadata.NAME, new ConstantExpression(field.getName()));
    ann.setMember(FieldMetadata.ORDINAL, new ConstantExpression(field.getOrdinal()));
    ann.setMember(FieldMetadata.LINE, new ConstantExpression(field.getAst().getLineNumber()));
    field.getAst().addAnnotation(ann);
}
Also used : AnnotationNode(org.codehaus.groovy.ast.AnnotationNode)

Aggregations

AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)248 ClassNode (org.codehaus.groovy.ast.ClassNode)158 AnnotatedNode (org.codehaus.groovy.ast.AnnotatedNode)78 Expression (org.codehaus.groovy.ast.expr.Expression)68 ConstantExpression (org.codehaus.groovy.ast.expr.ConstantExpression)64 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)60 MethodNode (org.codehaus.groovy.ast.MethodNode)57 FieldNode (org.codehaus.groovy.ast.FieldNode)54 ArrayList (java.util.ArrayList)53 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)49 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)48 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)44 ListExpression (org.codehaus.groovy.ast.expr.ListExpression)36 ArgumentListExpression (org.codehaus.groovy.ast.expr.ArgumentListExpression)35 BinaryExpression (org.codehaus.groovy.ast.expr.BinaryExpression)30 ClosureExpression (org.codehaus.groovy.ast.expr.ClosureExpression)30 Parameter (org.codehaus.groovy.ast.Parameter)29 DeclarationExpression (org.codehaus.groovy.ast.expr.DeclarationExpression)29 PropertyExpression (org.codehaus.groovy.ast.expr.PropertyExpression)29 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)28