Search in sources :

Example 1 with MixinNode

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

the class AntlrParserPlugin method innerClassDef.

protected void innerClassDef(AST classDef) {
    List<AnnotationNode> annotations = new ArrayList<AnnotationNode>();
    if (isType(TRAIT_DEF, classDef)) {
        annotations.add(new AnnotationNode(ClassHelper.make("groovy.transform.Trait")));
    }
    AST node = classDef.getFirstChild();
    int modifiers = Opcodes.ACC_PUBLIC;
    if (isType(MODIFIERS, node)) {
        modifiers = modifiers(node, annotations, modifiers);
        checkNoInvalidModifier(classDef, "Class", modifiers, Opcodes.ACC_SYNCHRONIZED, "synchronized");
        node = node.getNextSibling();
    }
    String name = identifier(node);
    node = node.getNextSibling();
    GenericsType[] genericsType = null;
    if (isType(TYPE_PARAMETERS, node)) {
        genericsType = makeGenericsType(node);
        node = node.getNextSibling();
    }
    ClassNode superClass = null;
    if (isType(EXTENDS_CLAUSE, node)) {
        superClass = makeTypeWithArguments(node);
        node = node.getNextSibling();
    }
    ClassNode[] interfaces = ClassNode.EMPTY_ARRAY;
    if (isType(IMPLEMENTS_CLAUSE, node)) {
        interfaces = interfaces(node);
        node = node.getNextSibling();
    }
    // TODO read mixins
    MixinNode[] mixins = {};
    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);
        if (classNode.isInterface()) {
            modifiers |= Opcodes.ACC_STATIC;
        }
        classNode = new InnerClassNode(classNode, fullName, modifiers, superClass, interfaces, mixins);
    } else {
        classNode = new ClassNode(dot(getPackageName(), name), modifiers, superClass, interfaces, mixins);
    }
    classNode.addAnnotations(annotations);
    classNode.setGenericsTypes(genericsType);
    classNode.setSyntheticPublic(syntheticPublic);
    configureAST(classNode, classDef);
    // we put the class already in output to avoid the most inner classes
    // will be used as first class later in the loader. The first class
    // there determines what GCL#parseClass for example will return, so we
    // have here to ensure it won't be the inner class
    output.addClass(classNode);
    int oldClassCount = innerClassCounter;
    assertNodeType(OBJBLOCK, node);
    objectBlock(node);
    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) ArrayList(java.util.ArrayList) InnerClassNode(org.codehaus.groovy.ast.InnerClassNode) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) GenericsType(org.codehaus.groovy.ast.GenericsType) MixinNode(org.codehaus.groovy.ast.MixinNode)

Aggregations

AST (antlr.collections.AST)1 ArrayList (java.util.ArrayList)1 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)1 ClassNode (org.codehaus.groovy.ast.ClassNode)1 EnumConstantClassNode (org.codehaus.groovy.ast.EnumConstantClassNode)1 GenericsType (org.codehaus.groovy.ast.GenericsType)1 InnerClassNode (org.codehaus.groovy.ast.InnerClassNode)1 MixinNode (org.codehaus.groovy.ast.MixinNode)1