Package org.codehaus.groovy.runtime.metaclass

Examples of org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod


    public void testInvokeMetaMethod() throws Exception {
        Method method = getClass().getMethod("dummyMethod", new Class[]{String.class, String.class});
        assertTrue("Should have found a method", method != null);

        NewInstanceMetaMethod metaMethod = createNewMetaMethod(method);

        Object answer = metaMethod.invoke("abc", new Object[]{"xyz"});
        assertEquals("def", answer);

        assertTrue("Should not appear as static method", !metaMethod.isStatic());
    }
View Full Code Here


    public void testInvokeDefaultGroovyMethod() throws Exception {
        Method method = DefaultGroovyMethods.class.getMethod("plus", new Class[]{String.class, Object.class});
        assertTrue("Should have found a method", method != null);

        NewInstanceMetaMethod metaMethod = createNewMetaMethod(method);

        Object answer = metaMethod.invoke("abc", new Object[]{"123"});
        assertEquals("abc123", answer);

        System.out.println("Found: " + answer);
    }
View Full Code Here

        assertEquals("xyz", bar);
        return "def";
    }

    protected NewInstanceMetaMethod createNewMetaMethod(Method method) {
        return new NewInstanceMetaMethod(CachedMethod.find(method));
    }
View Full Code Here

     *
     * @param method The method to be added
     */
    public void addNewInstanceMethod(Method method) {
        final CachedMethod cachedMethod = CachedMethod.find(method);
        NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
        final CachedClass declaringClass = newMethod.getDeclaringClass();
        addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
    }
View Full Code Here

        return false// MetaClassImpl not designed for modification, just return false
    }

    public void addNewInstanceMethod(Method method) {
        final CachedMethod cachedMethod = CachedMethod.find(method);
        NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod);
        final CachedClass declaringClass = newMethod.getDeclaringClass();
        addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass()));
    }
View Full Code Here

TOP

Related Classes of org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.