Java Code Examples for org.codehaus.groovy.control.CompilerConfiguration#ASM_API_VERSION

The following examples show how to use org.codehaus.groovy.control.CompilerConfiguration#ASM_API_VERSION . 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: GroovySunClassLoader.java    From groovy with Apache License 2.0 5 votes vote down vote up
private void loadAbstract(int parsingOptions) throws IOException {
    try (final InputStream asStream = GroovySunClassLoader.class.getClassLoader().getResourceAsStream(resName("org.codehaus.groovy.runtime.callsite.AbstractCallSite"))) {
        ClassReader reader = new ClassReader(asStream);
        final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        final ClassVisitor cv = new ClassVisitor(CompilerConfiguration.ASM_API_VERSION, cw) {
            public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
                super.visit(version, access, name, signature, "sun/reflect/GroovyMagic", interfaces);
            }
        };
        reader.accept(cv, parsingOptions);
        define(cw.toByteArray(), "org.codehaus.groovy.runtime.callsite.AbstractCallSite");
    }
}
 
Example 2
Source File: AsmDecompiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
public DecompilingVisitor() {
    super(CompilerConfiguration.ASM_API_VERSION);
}
 
Example 3
Source File: AsmDecompiler.java    From groovy with Apache License 2.0 4 votes vote down vote up
public AnnotationReader() {
    super(CompilerConfiguration.ASM_API_VERSION);
}
 
Example 4
Source File: FormalParameterParser.java    From groovy with Apache License 2.0 4 votes vote down vote up
public FormalParameterParser(AsmReferenceResolver resolver) {
    super(CompilerConfiguration.ASM_API_VERSION);
    this.resolver = resolver;
}
 
Example 5
Source File: TypeSignatureParser.java    From groovy with Apache License 2.0 4 votes vote down vote up
public TypeSignatureParser(final AsmReferenceResolver resolver) {
    super(CompilerConfiguration.ASM_API_VERSION);
    this.resolver = resolver;
}
 
Example 6
Source File: LoggableTextifier.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LoggableTextifier() {
    super(CompilerConfiguration.ASM_API_VERSION);
}
 
Example 7
Source File: LoggableClassVisitor.java    From groovy with Apache License 2.0 4 votes vote down vote up
public LoggableClassVisitor(final ClassVisitor cv) {
    super(CompilerConfiguration.ASM_API_VERSION, new TraceClassVisitor(cv, new LoggableTextifier(), null));
}
 
Example 8
Source File: ProxyGeneratorAdapter.java    From groovy with Apache License 2.0 4 votes vote down vote up
/**
     * Construct a proxy generator. This generator is used when we need to create a proxy object for a class or an
     * interface given a map of closures.
     *
     * @param closureMap    the delegates implementations
     * @param superClass    corresponding to the superclass class visitor
     * @param interfaces    extra interfaces the proxy should implement
     * @param proxyLoader   the class loader which should be used to load the generated proxy
     * @param delegateClass if not null, generate a delegate field with the corresponding class
     * @param emptyBody     if set to true, the unimplemented abstract methods will receive an empty body instead of
     *                      throwing an {@link UnsupportedOperationException}.
     */
    public ProxyGeneratorAdapter(
            final Map<Object, Object> closureMap,
            final Class superClass,
            final Class[] interfaces,
            final ClassLoader proxyLoader,
            final boolean emptyBody,
            final Class delegateClass) {
        super(CompilerConfiguration.ASM_API_VERSION, new ClassWriter(0));
        this.loader = proxyLoader != null ? createInnerLoader(proxyLoader, interfaces) : findClassLoader(superClass, interfaces);
        this.visitedMethods = new LinkedHashSet<Object>();
        this.delegatedClosures = closureMap.isEmpty() ? EMPTY_DELEGATECLOSURE_MAP : new HashMap<String, Boolean>();
        boolean wildcard = false;
        for (Map.Entry<Object, Object> entry : closureMap.entrySet()) {
            String name = entry.getKey().toString();
            if ("*".equals(name)) {
                wildcard = true;
            }
            this.delegatedClosures.put(name, Boolean.FALSE);
        }
        this.hasWildcard = wildcard;

        Class fixedSuperClass = adjustSuperClass(superClass, interfaces);
        // if we have to delegate to another object, generate the appropriate delegate field
        // and collect the name of the methods for which delegation is active
        this.generateDelegateField = delegateClass != null;
        this.objectDelegateMethods = generateDelegateField ? createDelegateMethodList(fixedSuperClass, delegateClass, interfaces) : EMPTY_STRING_SET;
        this.delegateClass = delegateClass;

        // a proxy is supposed to be a concrete class, so it cannot extend an interface.
        // If the provided superclass is an interface, then we replace the superclass with Object
        // and add this interface to the list of implemented interfaces
        this.superClass = fixedSuperClass;

        // create the base list of classes which have possible methods to be overloaded
        this.classList = new LinkedHashSet<Class>();
        this.classList.add(superClass);
        if (generateDelegateField) {
            classList.add(delegateClass);
            Collections.addAll(this.classList, delegateClass.getInterfaces());
        }
        if (interfaces != null) {
            Collections.addAll(this.classList, interfaces);
        }
        this.proxyName = proxyName();
        this.emptyBody = emptyBody;

        // generate bytecode
        ClassWriter writer = (ClassWriter) cv;
        this.visit(Opcodes.V1_5, ACC_PUBLIC, proxyName, null, null, null);
        byte[] b = writer.toByteArray();
//        CheckClassAdapter.verify(new ClassReader(b), true, new PrintWriter(System.err));
        cachedClass = loader.defineClass(proxyName.replace('/', '.'), b);
        // cache no-arg constructor
        Class[] args = generateDelegateField ? new Class[]{Map.class, delegateClass} : new Class[]{Map.class};
        Constructor constructor;
        try {
            constructor = cachedClass.getConstructor(args);
        } catch (NoSuchMethodException e) {
            constructor = null;
        }
        cachedNoArgConstructor = constructor;
    }
 
Example 9
Source File: GenericsTestBase.java    From groovy with Apache License 2.0 4 votes vote down vote up
GenericsTester(ClassVisitor cv) {
    super(CompilerConfiguration.ASM_API_VERSION, cv);
}
 
Example 10
Source File: AnnotationsTestBase.java    From groovy with Apache License 2.0 4 votes vote down vote up
FieldAnnotationScanner(String field) {
    super(CompilerConfiguration.ASM_API_VERSION);
    this.field = field;
}
 
Example 11
Source File: AnnotationsTestBase.java    From groovy with Apache License 2.0 4 votes vote down vote up
MethodAnnotationScanner(String method) {
    super(CompilerConfiguration.ASM_API_VERSION);
    this.method = method;
}
 
Example 12
Source File: AnnotationsTestBase.java    From groovy with Apache License 2.0 4 votes vote down vote up
AnnotationsTester(ClassVisitor cv) {
    super(CompilerConfiguration.ASM_API_VERSION, cv);
}