use of groovy.lang.GroovyObject in project groovy-core by groovy.
the class RunClosureTest method testBytecode6Bug.
public void testBytecode6Bug() throws Exception {
GroovyObject object = compile("src/test/groovy/bugs/Bytecode6Bug.groovy");
object.invokeMethod("testPreFixReturn", null);
}
use of groovy.lang.GroovyObject in project groovy-core by groovy.
the class RunClosureTest method testStaticClosureBug.
public void testStaticClosureBug() throws Exception {
GroovyObject object = compile("src/test/groovy/bugs/StaticClosurePropertyBug.groovy");
object.invokeMethod("testCallStaticClosure", null);
}
use of groovy.lang.GroovyObject in project groovy-core by groovy.
the class GPathResult method getBody.
/**
* Creates a Closure representing the body of this GPathResult.
*
* @return the body of this GPathResult, converted to a <code>Closure</code>
*/
public Closure getBody() {
return new Closure(this.parent, this) {
public void doCall(Object[] args) {
final GroovyObject delegate = (GroovyObject) getDelegate();
final GPathResult thisObject = (GPathResult) getThisObject();
Node node = (Node) thisObject.getAt(0);
List children = node.children();
for (Object child : children) {
delegate.getProperty("mkp");
if (child instanceof Node) {
delegate.invokeMethod("yield", new Object[] { new NodeChild((Node) child, thisObject, "*", null) });
} else {
delegate.invokeMethod("yield", new Object[] { child });
}
}
}
};
}
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