use of groovy.lang.GroovyObject in project groovy by apache.
the class NodePrinterTest method testClosureClassLoaderBug.
public void testClosureClassLoaderBug() throws Exception {
GroovyObject object = compile("src/test/groovy/tree/ClosureClassLoaderBug.groovy");
object.invokeMethod("testTree", null);
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class NodePrinterTest method testNestedClosureBug.
public void testNestedClosureBug() throws Exception {
GroovyObject object = compile("src/test/groovy/tree/NestedClosureBugTest.groovy");
object.invokeMethod("testNestedClosureBug", null);
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class Demo method compile.
protected GroovyObject compile(String fileName) throws Exception {
Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
GroovyObject object = (GroovyObject) groovyClass.newInstance();
assertTrue(object != null);
return object;
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class ProxyGeneratorAdapter method visit.
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
Set<String> interfacesSet = new LinkedHashSet<String>();
if (interfaces != null)
Collections.addAll(interfacesSet, interfaces);
for (Class extraInterface : classList) {
if (extraInterface.isInterface())
interfacesSet.add(BytecodeHelper.getClassInternalName(extraInterface));
}
final boolean addGroovyObjectSupport = !GroovyObject.class.isAssignableFrom(superClass);
if (addGroovyObjectSupport)
interfacesSet.add("groovy/lang/GroovyObject");
if (generateDelegateField) {
classList.add(GeneratedGroovyProxy.class);
interfacesSet.add("groovy/lang/GeneratedGroovyProxy");
}
super.visit(V1_5, ACC_PUBLIC, proxyName, signature, BytecodeHelper.getClassInternalName(superClass), interfacesSet.toArray(new String[interfacesSet.size()]));
visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
addDelegateFields();
if (addGroovyObjectSupport) {
createGroovyObjectSupport();
}
for (Class clazz : classList) {
visitClass(clazz);
}
}
use of groovy.lang.GroovyObject in project groovy by apache.
the class ProxyGeneratorAdapter method delegatingProxy.
@SuppressWarnings("unchecked")
public GroovyObject delegatingProxy(Object delegate, Map<Object, Object> map, Object... constructorArgs) {
if (constructorArgs == null && cachedNoArgConstructor != null) {
// if there isn't any argument, we can make invocation faster using the cached constructor
try {
return (GroovyObject) cachedNoArgConstructor.newInstance(map, delegate);
} catch (InstantiationException e) {
throw new GroovyRuntimeException(e);
} catch (IllegalAccessException e) {
throw new GroovyRuntimeException(e);
} catch (InvocationTargetException e) {
throw new GroovyRuntimeException(e);
}
}
if (constructorArgs == null)
constructorArgs = EMPTY_ARGS;
Object[] values = new Object[constructorArgs.length + 2];
System.arraycopy(constructorArgs, 0, values, 0, constructorArgs.length);
values[values.length - 2] = map;
values[values.length - 1] = delegate;
return DefaultGroovyMethods.<GroovyObject>newInstance(cachedClass, values);
}
Aggregations