Search in sources :

Example 1 with MetaMethod

use of groovy.lang.MetaMethod in project groovy by apache.

the class TestDgmConverter method testConverter.

public void testConverter() throws URISyntaxException {
    File dgmClassDirectory = new File(TestDgmConverter.class.getResource(REFERENCE_CLASS).toURI()).getParentFile();
    final File[] files = dgmClassDirectory.listFiles();
    Arrays.sort(files, new Comparator<File>() {

        public int compare(final File o1, final File o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(o1.getName(), o2.getName());
        }
    });
    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        final String name = file.getName();
        if (name.startsWith("dgm$")) {
            final String className = "org.codehaus.groovy.runtime." + name.substring(0, name.length() - ".class".length());
            try {
                Class cls = Class.forName(className, false, DefaultGroovyMethods.class.getClassLoader());
                Constructor[] declaredConstructors = cls.getDeclaredConstructors();
                assertEquals(1, declaredConstructors.length);
                Constructor constructor = declaredConstructors[0];
                final MetaMethod metaMethod = (MetaMethod) constructor.newInstance(null, null, null, null);
            } catch (ClassNotFoundException e) {
                fail("Failed to load " + className);
            } catch (IllegalAccessException e) {
                fail("Failed to instantiate " + className);
            } catch (InstantiationException e) {
                fail("Failed to instantiate " + className);
            } catch (InvocationTargetException e) {
                fail("Failed to instantiate " + className);
            }
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) DefaultGroovyMethods(org.codehaus.groovy.runtime.DefaultGroovyMethods) Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) File(java.io.File)

Example 2 with MetaMethod

use of groovy.lang.MetaMethod in project groovy by apache.

the class Inspector method getMetaMethods.

/**
     * Get info about instance and class Methods that are dynamically added through Groovy.
     *
     * @return Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
     */
public Object[] getMetaMethods() {
    MetaClass metaClass = InvokerHelper.getMetaClass(objectUnderInspection);
    List metaMethods = metaClass.getMetaMethods();
    Object[] result = new Object[metaMethods.size()];
    int i = 0;
    for (Iterator iter = metaMethods.iterator(); iter.hasNext(); i++) {
        MetaMethod metaMethod = (MetaMethod) iter.next();
        result[i] = methodInfo(metaMethod);
    }
    return result;
}
Also used : MetaMethod(groovy.lang.MetaMethod) MetaClass(groovy.lang.MetaClass) GroovyObject(groovy.lang.GroovyObject)

Example 3 with MetaMethod

use of groovy.lang.MetaMethod in project groovy by apache.

the class MetaMethodIndex method findMatchingMethod.

private static int findMatchingMethod(FastArray list, MetaMethod method) {
    int len = list.size();
    Object[] data = list.getArray();
    for (int j = 0; j != len; ++j) {
        MetaMethod aMethod = (MetaMethod) data[j];
        if (isMatchingMethod(aMethod, method))
            return j;
    }
    return -1;
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod)

Example 4 with MetaMethod

use of groovy.lang.MetaMethod in project groovy by apache.

the class MetaMethodIndex method copyNonPrivateMethodsFromSuper.

private void copyNonPrivateMethodsFromSuper(Entry e) {
    Object oldListOrMethod = e.methodsForSuper;
    if (oldListOrMethod == null)
        return;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (method.isPrivate())
                continue;
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (!method.isPrivate()) {
            e.methods = addMethodToList(e.methods, method);
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Example 5 with MetaMethod

use of groovy.lang.MetaMethod in project groovy by apache.

the class MetaMethodIndex method copyAllMethods.

private void copyAllMethods(Entry from, Header to) {
    Object oldListOrMethod = from.methods;
    if (oldListOrMethod instanceof FastArray) {
        FastArray oldList = (FastArray) oldListOrMethod;
        Entry e = null;
        int len1 = oldList.size();
        Object[] list = oldList.getArray();
        for (int j = 0; j != len1; ++j) {
            MetaMethod method = (MetaMethod) list[j];
            if (e == null)
                e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    } else {
        MetaMethod method = (MetaMethod) oldListOrMethod;
        if (!method.isPrivate()) {
            Entry e = getOrPutMethods(from.name, to);
            e.methods = addMethodToList(e.methods, method);
        }
    }
}
Also used : MetaMethod(groovy.lang.MetaMethod) GeneratedMetaMethod(org.codehaus.groovy.reflection.GeneratedMetaMethod) FastArray(org.codehaus.groovy.util.FastArray)

Aggregations

MetaMethod (groovy.lang.MetaMethod)35 GeneratedMetaMethod (org.codehaus.groovy.reflection.GeneratedMetaMethod)14 CachedClass (org.codehaus.groovy.reflection.CachedClass)13 FastArray (org.codehaus.groovy.util.FastArray)12 ArrayList (java.util.ArrayList)8 MetaClass (groovy.lang.MetaClass)5 LinkedList (java.util.LinkedList)4 NewInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.NewInstanceMetaMethod)4 DelegatingMetaClass (groovy.lang.DelegatingMetaClass)3 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)3 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)3 GroovyObject (groovy.lang.GroovyObject)2 MetaProperty (groovy.lang.MetaProperty)2 File (java.io.File)2 Constructor (java.lang.reflect.Constructor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2 CachedConstructor (org.codehaus.groovy.reflection.CachedConstructor)2 CachedMethod (org.codehaus.groovy.reflection.CachedMethod)2 ClassInfo (org.codehaus.groovy.reflection.ClassInfo)2