Search in sources :

Example 16 with GroovyObject

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);
}
Also used : GroovyObject(groovy.lang.GroovyObject)

Example 17 with GroovyObject

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);
}
Also used : GroovyObject(groovy.lang.GroovyObject)

Example 18 with GroovyObject

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;
}
Also used : GroovyCodeSource(groovy.lang.GroovyCodeSource) File(java.io.File) GroovyObject(groovy.lang.GroovyObject)

Example 19 with GroovyObject

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GroovyClass(org.codehaus.groovy.tools.GroovyClass) GroovyObject(groovy.lang.GroovyObject)

Example 20 with GroovyObject

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);
}
Also used : GroovyRuntimeException(groovy.lang.GroovyRuntimeException) GroovyObject(groovy.lang.GroovyObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) GroovyObject(groovy.lang.GroovyObject)

Aggregations

GroovyObject (groovy.lang.GroovyObject)141 GroovyClassLoader (groovy.lang.GroovyClassLoader)14 Closure (groovy.lang.Closure)11 Map (java.util.Map)8 Decorator (com.opensymphony.module.sitemesh.Decorator)7 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)7 MetaClass (groovy.lang.MetaClass)7 File (java.io.File)7 HashMap (java.util.HashMap)7 GrailsWebRequest (org.grails.web.servlet.mvc.GrailsWebRequest)7 Page (com.opensymphony.module.sitemesh.Page)5 HTMLPageParser (com.opensymphony.module.sitemesh.parser.HTMLPageParser)5 Config (grails.config.Config)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ServletContext (javax.servlet.ServletContext)5 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)5 MockApplicationContext (org.grails.support.MockApplicationContext)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 MockServletConfig (org.springframework.mock.web.MockServletConfig)5 ArrayList (java.util.ArrayList)4