use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project groovy by apache.
the class TestDgmConverter method testRegistry.
public void testRegistry() {
final MetaClassRegistryImpl metaClassRegistry = new MetaClassRegistryImpl();
final Object[] instanceMethods = metaClassRegistry.getInstanceMethods().getArray();
assertTrue(instanceMethods.length > 0);
}
use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project grails-core by grails.
the class DefaultGrailsApplication method initialiseGroovyExtensionModules.
protected static void initialiseGroovyExtensionModules() {
if (extensionMethodsInitialized)
return;
extensionMethodsInitialized = true;
Map<CachedClass, List<MetaMethod>> map = new HashMap<CachedClass, List<MetaMethod>>();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
Enumeration<URL> resources = classLoader.getResources(ExtensionModuleScanner.MODULE_META_INF_FILE);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
if (url.getPath().contains("groovy-all")) {
// already registered
continue;
}
Properties properties = new Properties();
InputStream inStream = null;
try {
inStream = url.openStream();
properties.load(inStream);
((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).registerExtensionModuleFromProperties(properties, classLoader, map);
} catch (IOException e) {
throw new GroovyRuntimeException("Unable to load module META-INF descriptor", e);
} finally {
if (inStream != null) {
inStream.close();
}
}
}
} catch (IOException ignored) {
}
for (Map.Entry<CachedClass, List<MetaMethod>> moduleMethods : map.entrySet()) {
CachedClass cls = moduleMethods.getKey();
cls.addNewMopMethods(moduleMethods.getValue());
}
}
use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project groovy-core by groovy.
the class MetaClassImpl method invokePropertyOrMissing.
private Object invokePropertyOrMissing(Object object, String methodName, Object[] originalArguments, boolean fromInsideClass, boolean isCallToSuper) {
// if no method was found, try to find a closure defined as a field of the class and run it
Object value = null;
final MetaProperty metaProperty = this.getMetaProperty(methodName, false);
if (metaProperty != null)
value = metaProperty.getProperty(object);
else {
if (object instanceof Map)
value = ((Map) object).get(methodName);
}
if (value instanceof Closure) {
// This test ensures that value != this If you ever change this ensure that value != this
Closure closure = (Closure) value;
MetaClass delegateMetaClass = closure.getMetaClass();
return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, fromInsideClass);
}
if (object instanceof Script) {
Object bindingVar = ((Script) object).getBinding().getVariables().get(methodName);
if (bindingVar != null) {
MetaClass bindingVarMC = ((MetaClassRegistryImpl) registry).getMetaClass(bindingVar);
return bindingVarMC.invokeMethod(bindingVar, CLOSURE_CALL_METHOD, originalArguments);
}
}
return invokeMissingMethod(object, methodName, originalArguments, null, isCallToSuper);
}
use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project groovy-core by groovy.
the class TestDgmConverter method testRegistry.
public void testRegistry() {
final MetaClassRegistryImpl metaClassRegistry = new MetaClassRegistryImpl();
final Object[] instanceMethods = metaClassRegistry.getInstanceMethods().getArray();
for (int i = 0; i < instanceMethods.length; i++) {
System.out.println(instanceMethods[i]);
}
}
use of org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl in project grails-core by grails.
the class MetaClassRegistryCleaner method clean.
public synchronized void clean() {
try {
cleaning = true;
MetaClassRegistryImpl registry = (MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry();
cleanMetaClassOfClass(registry);
cleanMetaClassOfInstance(registry);
} finally {
cleaning = false;
}
}
Aggregations