Java Code Examples for org.codehaus.groovy.ast.ClassNode#getInnerClasses()

The following examples show how to use org.codehaus.groovy.ast.ClassNode#getInnerClasses() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableScopeVisitor.java    From groovy with Apache License 2.0 6 votes vote down vote up
@Override
public void visitClass(final ClassNode node) {
    // AIC are already done, doing them here again will lead to wrong scopes
    if (isAnonymous(node)) return;

    pushState();
    inClosure = false;
    currentClass = node;
    currentScope.setClassScope(node);

    super.visitClass(node);
    if (recurseInnerClasses) {
        for (Iterator<InnerClassNode> innerClasses = node.getInnerClasses(); innerClasses.hasNext(); ) {
            visitClass(innerClasses.next());
        }
    }
    popState();
}
 
Example 2
Source File: AutoFinalASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void processClass(ClassNode cNode, final ClassCodeVisitorSupport visitor) {
    if (!isEnabled(cNode)) return;
    if (cNode.isInterface()) {
        addError("Error processing interface '" + cNode.getName() +
                "'. " + MY_TYPE_NAME + " only allowed for classes.", cNode);
        return;
    }

    for (ConstructorNode cn : cNode.getDeclaredConstructors()) {
        if (hasNoExplicitAutoFinal(cn)) {
            processConstructorOrMethod(cn, visitor);
        }
    }

    for (MethodNode mn : cNode.getAllDeclaredMethods()) {
        if (hasNoExplicitAutoFinal(mn)) {
            processConstructorOrMethod(mn, visitor);
        }
    }

    Iterator<InnerClassNode> it = cNode.getInnerClasses();
    while (it.hasNext()) {
        InnerClassNode in = it.next();
        if (in.getAnnotations(MY_TYPE).isEmpty()) {
            processClass(in, visitor);
        }
    }

    visitor.visitClass(cNode);
}
 
Example 3
Source File: StaticCompilationVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void addPrivateFieldAndMethodAccessors(final ClassNode node) {
    addPrivateBridgeMethods(node);
    addPrivateFieldsAccessors(node);
    for (Iterator<InnerClassNode> it = node.getInnerClasses(); it.hasNext(); ) {
        addPrivateFieldAndMethodAccessors(it.next());
    }
}
 
Example 4
Source File: TraitASTTransformation.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void checkInnerClasses(final ClassNode cNode) {
    Iterator<InnerClassNode> it = cNode.getInnerClasses();
    while (it.hasNext()) {
        InnerClassNode origin = it.next();
        if ((origin.getModifiers() & ACC_STATIC) == 0) {
            unit.addError(new SyntaxException("Cannot have non-static inner class inside a trait ("+origin.getName()+")", origin.getLineNumber(), origin.getColumnNumber()));
        }
    }
}
 
Example 5
Source File: MacroGroovyMethods.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static ListExpression buildSubstitutions(final SourceUnit source, final ASTNode expr) {
    final ListExpression listExpression = new ListExpression();

    ClassCodeVisitorSupport visitor = new ClassCodeVisitorSupport() {
        @Override
        protected SourceUnit getSourceUnit() {
            return null;
        }

        @Override
        public void visitClass(final ClassNode node) {
            super.visitClass(node);
            Iterator<InnerClassNode> it = node.getInnerClasses();
            while (it.hasNext()) {
                InnerClassNode next = it.next();
                visitClass(next);
            }
        }

        @Override
        public void visitMethodCallExpression(MethodCallExpression call) {
            super.visitMethodCallExpression(call);

            if (DOLLAR_VALUE.equals(call.getMethodAsString())) {
                ClosureExpression substitutionClosureExpression = getClosureArgument(source, call);

                if (substitutionClosureExpression == null) {
                    return;
                }

                Statement code = substitutionClosureExpression.getCode();
                if (code instanceof BlockStatement) {
                    ((BlockStatement) code).setVariableScope(null);
                }

                listExpression.addExpression(substitutionClosureExpression);
            }
        }
    };
    if (expr instanceof ClassNode) {
        visitor.visitClass((ClassNode) expr);
    } else {
        expr.visit(visitor);
    }
    return listExpression;
}