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

        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

        CachedClass[] paramTypes = method.getParameterTypes();

        if (paramTypes.length == 0)
            return;

        NewInstanceMetaMethod metaMethod;
        if (paramTypes[0].isAssignableFrom(self.getTheClass())) {
            if (paramTypes[0].getTheClass() == self.getTheClass())
                metaMethod = new NewInstanceMetaMethod(method);
            else
                metaMethod = new NewInstanceMetaMethod(method) {
                    public CachedClass getDeclaringClass() {
                        return ReflectionCache.getCachedClass(self.getTheClass());
                    }
                };
            arr.add(metaMethod);
        } else {
            if (self.getTheClass().isAssignableFrom(paramTypes[0].getTheClass())) {
                metaMethod = new NewInstanceMetaMethod(method);
                arr.add(metaMethod);
            }
        }
    }
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

    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

        CachedClass cachedClass = ReflectionCache.getCachedClass(extensionClass);
        CachedMethod[] methods = cachedClass.getMethods();
        for (CachedMethod method : methods) {
            if (method.isStatic() && method.isPublic() && method.getParamsCount() > 0) {
                // an extension method is found
                metaMethods.add(isStatic?new NewStaticMetaMethod(method) : new NewInstanceMetaMethod(method));
            }
        }
    }
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.