|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.objectweb.asm.ClassVisitor org.codehaus.groovy.runtime.ProxyGeneratorAdapter
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 Foowill 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.
Constructor Summary | |
ProxyGeneratorAdapter(java.util.Map closureMap, java.lang.Class superClass, java.lang.Class[] interfaces, java.lang.ClassLoader proxyLoader, boolean emptyBody, java.lang.Class delegateClass)
Construct a proxy generator. |
Method Summary | |
---|---|
GroovyObject
|
delegatingProxy(java.lang.Object delegate, java.util.Map map, java.lang.Object... constructorArgs)
|
static Closure
|
ensureClosure(java.lang.Object o)
|
protected org.objectweb.asm.MethodVisitor
|
makeDelegateCall(java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions, int accessFlags)
|
protected org.objectweb.asm.MethodVisitor
|
makeDelegateToClosureCall(java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions, int accessFlags)
|
GroovyObject
|
proxy(java.util.Map map, java.lang.Object... constructorArgs)
|
void
|
visit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)
|
org.objectweb.asm.MethodVisitor
|
visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.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#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#visitAttribute(org.objectweb.asm.Attribute), org.objectweb.asm.ClassVisitor#visitInnerClass(java.lang.String, java.lang.String, java.lang.String, int), 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 java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
public ProxyGeneratorAdapter(java.util.Map closureMap, java.lang.Class superClass, java.lang.Class[] interfaces, java.lang.ClassLoader proxyLoader, boolean emptyBody, java.lang.Class delegateClass)
closureMap
- the delegates implementationssuperClass
- corresponding to the superclass class visitorinterfaces
- extra interfaces the proxy should implementproxyLoader
- the class loader which should be used to load the generated proxydelegateClass
- if not null, generate a delegate field with the corresponding classemptyBody
- if set to true, the unimplemented abstract methods will receive an empty body instead of
throwing an java.lang.UnsupportedOperationException.
Method Detail |
---|
|| arg == Type.BYTE_TYPE public GroovyObject delegatingProxy(java.lang.Object delegate, java.util.Map map, java.lang.Object... constructorArgs)
} public static Closure ensureClosure(java.lang.Object o)
protected org.objectweb.asm.MethodVisitor makeDelegateCall(java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions, int accessFlags)
protected org.objectweb.asm.MethodVisitor makeDelegateToClosureCall(java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions, int accessFlags)
if (type == Type.DOUBLE_TYPE) return DLOAD; public GroovyObject proxy(java.util.Map map, java.lang.Object... constructorArgs)
if (addGroovyObjectSupport) { public void visit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)
return makeDelegateCall(name, desc, signature, exceptions, accessFlags); public org.objectweb.asm.MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
Groovy Documentation