Groovy 2.2.1

org.codehaus.groovy.runtime
[Java] Class ProxyGeneratorAdapter

java.lang.Object
  org.objectweb.asm.ClassVisitor
      org.codehaus.groovy.runtime.ProxyGeneratorAdapter
All Implemented Interfaces:
org.objectweb.asm.Opcodes

public class ProxyGeneratorAdapter
extends org.objectweb.asm.ClassVisitor

A proxy generator responsible for mapping a map of closures to a class implementing a list of interfaces. For example, the following code:

     abstract class Foo {
         abstract void bar();
         abstract void baz();
     }
     def dyn = [bar: { println 'hello' }, baz: { println 'world'}] as Foo
 
will generate a proxy class which extends class Foo and delegates method calls to the provided closures. The generated proxy implements the GroovyObject interface. Additionaly, this proxy generator supports delegation to another object. In that case, if a method is defined both in the closure map and the delegate, the version from the map is preferred. This allows overriding methods from delegates with ease. Internally, the proxy generator makes use of ASM to generate bytecode, for improved performance as compared to the legacy proxy generation mechanism which made use of string templates.
Authors:
Cedric Champeau
Since:
2.0.0


Constructor Summary
ProxyGeneratorAdapter(Map closureMap, Class superClass, Class[] interfaces, ClassLoader proxyLoader, boolean emptyBody, Class delegateClass)

Construct a proxy generator.

 
Method Summary
GroovyObject delegatingProxy(Object delegate, Map map, Object... constructorArgs)

static Closure ensureClosure(Object o)

protected org.objectweb.asm.MethodVisitor makeDelegateCall(String name, String desc, String signature, String[] exceptions, int accessFlags)

protected org.objectweb.asm.MethodVisitor makeDelegateToClosureCall(String name, String desc, String signature, String[] exceptions, int accessFlags)

GroovyObject proxy(Map map, Object... constructorArgs)

void visit(int version, int access, String name, String signature, String superName, String[] interfaces)

org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)

 
Methods inherited from class org.objectweb.asm.ClassVisitor
org.objectweb.asm.ClassVisitor#visit(int, int, java.lang.String, java.lang.String, java.lang.String, [Ljava.lang.String;), org.objectweb.asm.ClassVisitor#visitMethod(int, java.lang.String, java.lang.String, java.lang.String, [Ljava.lang.String;), org.objectweb.asm.ClassVisitor#visitAnnotation(java.lang.String, boolean), org.objectweb.asm.ClassVisitor#visitEnd(), org.objectweb.asm.ClassVisitor#visitField(int, java.lang.String, java.lang.String, java.lang.String, java.lang.Object), org.objectweb.asm.ClassVisitor#visitAttribute(org.objectweb.asm.Attribute), org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int), org.objectweb.asm.ClassVisitor#visitOuterClass(java.lang.String, java.lang.String, java.lang.String), org.objectweb.asm.ClassVisitor#visitSource(java.lang.String, java.lang.String), org.objectweb.asm.ClassVisitor#wait(long, int), org.objectweb.asm.ClassVisitor#wait(long), org.objectweb.asm.ClassVisitor#wait(), org.objectweb.asm.ClassVisitor#equals(java.lang.Object), org.objectweb.asm.ClassVisitor#toString(), org.objectweb.asm.ClassVisitor#hashCode(), org.objectweb.asm.ClassVisitor#getClass(), org.objectweb.asm.ClassVisitor#notify(), org.objectweb.asm.ClassVisitor#notifyAll()
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

ProxyGeneratorAdapter

public ProxyGeneratorAdapter(Map closureMap, Class superClass, Class[] interfaces, ClassLoader proxyLoader, boolean emptyBody, Class delegateClass)
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.
Parameters:
closureMap - the delegates implementations
superClass - corresponding to the superclass class visitor
interfaces - extra interfaces the proxy should implement
proxyLoader - the class loader which should be used to load the generated proxy
delegateClass - if not null, generate a delegate field with the corresponding class
emptyBody - if set to true, the unimplemented abstract methods will receive an empty body instead of throwing an UnsupportedOperationException.


 
Method Detail

delegatingProxy

@SuppressWarnings|| arg == Type.BYTE_TYPE
public GroovyObject delegatingProxy(Object delegate, Map map, Object... constructorArgs)


ensureClosure

@SuppressWarnings}
public static Closure ensureClosure(Object o)


makeDelegateCall

protected org.objectweb.asm.MethodVisitor makeDelegateCall(String name, String desc, String signature, String[] exceptions, int accessFlags)


makeDelegateToClosureCall

protected org.objectweb.asm.MethodVisitor makeDelegateToClosureCall(String name, String desc, String signature, String[] exceptions, int accessFlags)


proxy

@SuppressWarningsif (type == Type.DOUBLE_TYPE) return DLOAD;
public GroovyObject proxy(Map map, Object... constructorArgs)


visit

@OverrideaddDelegateFields();
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)


visitMethod

@Overridereturn makeDelegateCall(name, desc,  signature, exceptions, accessFlags);
public org.objectweb.asm.MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)


 

Copyright © 2003-2013 The Codehaus. All rights reserved.