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

The following examples show how to use org.codehaus.groovy.ast.ClassNode#getEnclosingMethod() . 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: StaticTypeCheckingSupport.java    From groovy with Apache License 2.0 5 votes vote down vote up
private static Map<GenericsTypeName, GenericsType> getGenericsParameterMapOfThis(final ClassNode cn) {
    if (cn == null) return null;
    Map<GenericsTypeName, GenericsType> map = null;
    if (cn.getEnclosingMethod() != null) {
        map = extractGenericsParameterMapOfThis(cn.getEnclosingMethod());
    } else if (cn.getOuterClass() != null) {
        map = getGenericsParameterMapOfThis(cn.getOuterClass());
    }
    map = mergeGenerics(map, cn.getGenericsTypes());
    return map;
}
 
Example 2
Source File: DummyClassGenerator.java    From groovy with Apache License 2.0 4 votes vote down vote up
public void visitClass(ClassNode classNode) {
    try {
        this.classNode = classNode;
        this.internalClassName = BytecodeHelper.getClassInternalName(classNode);

        //System.out.println("Generating class: " + classNode.getName());

        this.internalBaseClassName = BytecodeHelper.getClassInternalName(classNode.getSuperClass());

        cv.visit(
                Opcodes.V1_3,
                classNode.getModifiers(),
                internalClassName,
                null,
                internalBaseClassName,
                BytecodeHelper.getClassInternalNames(classNode.getInterfaces())
        );

        classNode.visitContents(this);

        for (ClassNode innerClass : innerClasses) {
            ClassNode innerClassType = innerClass;
            String innerClassInternalName = BytecodeHelper.getClassInternalName(innerClassType);
            String outerClassName = internalClassName; // default for inner classes
            MethodNode enclosingMethod = innerClass.getEnclosingMethod();
            if (enclosingMethod != null) {
                // local inner classes do not specify the outer class name
                outerClassName = null;
            }
            cv.visitInnerClass(
                    innerClassInternalName,
                    outerClassName,
                    innerClassType.getName(),
                    innerClass.getModifiers());
        }
        cv.visitEnd();
    }
    catch (GroovyRuntimeException e) {
        e.setModule(classNode.getModule());
        throw e;
    }
}