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);
}
}
}
}
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;
}
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;
}
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);
}
}
}
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);
}
}
}
Aggregations