use of groovy.lang.MetaClassImpl in project groovy-core by groovy.
the class CallSiteArray method createCallConstructorSite.
private static CallSite createCallConstructorSite(CallSite callSite, Class receiver, Object[] args) {
MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
CallSite site;
if (metaClass instanceof MetaClassImpl) {
site = ((MetaClassImpl) metaClass).createConstructorSite(callSite, args);
} else
site = new MetaClassConstructorSite(callSite, metaClass);
replaceCallSite(callSite, site);
return site;
}
use of groovy.lang.MetaClassImpl in project groovy-core by groovy.
the class Selector method getMetaClassImpl.
/**
* Returns the MetaClassImpl if the given MetaClass is one of
* MetaClassImpl, AdaptingMetaClass or ClosureMetaClass. If
* none of these cases matches, this method returns null.
*/
private static MetaClassImpl getMetaClassImpl(MetaClass mc, boolean includeEMC) {
Class mcc = mc.getClass();
boolean valid = mcc == MetaClassImpl.class || mcc == AdaptingMetaClass.class || mcc == ClosureMetaClass.class || (includeEMC && mcc == ExpandoMetaClass.class);
if (!valid) {
if (LOG_ENABLED)
LOG.info("meta class is neither MetaClassImpl, nor AdoptingMetaClass, nor ClosureMetaClass, normal method selection path disabled.");
return null;
}
if (LOG_ENABLED)
LOG.info("meta class is a recognized MetaClassImpl");
return (MetaClassImpl) mc;
}
use of groovy.lang.MetaClassImpl in project groovity by disney.
the class TestModel method testMeta.
@SuppressWarnings("rawtypes")
@Test
public void testMeta() throws Exception {
ModelCheck mc = new ModelCheck();
mc.setFoo("bar");
Map mc1 = (Map) Model.mapObject(mc);
Assert.assertEquals(1, mc1.size());
Assert.assertEquals("bar", mc1.get("foo"));
AtomicReference<String> abcref = new AtomicReference<String>(null);
MetaClassImpl meta = new MetaClassImpl(ModelCheck.class);
meta.initialize();
MetaBeanProperty abc = new MetaBeanProperty("abc", String.class, new MetaMethod() {
@Override
public Object invoke(Object arg0, Object[] arg1) {
return abcref.get();
}
@Override
public Class getReturnType() {
return String.class;
}
@Override
public String getName() {
return "getAbc";
}
@Override
public int getModifiers() {
return Modifier.PUBLIC;
}
@Override
public CachedClass getDeclaringClass() {
return ReflectionCache.getCachedClass(ModelCheck.class);
}
}, new MetaMethod() {
@Override
public Object invoke(Object arg0, Object[] arg1) {
abcref.set((String) arg1[0]);
return null;
}
@Override
public Class getReturnType() {
return null;
}
@Override
public String getName() {
return "setAbc";
}
@Override
public int getModifiers() {
return Modifier.PUBLIC;
}
@Override
public CachedClass getDeclaringClass() {
return ReflectionCache.getCachedClass(ModelCheck.class);
}
});
meta.addMetaBeanProperty(abc);
GroovySystem.getMetaClassRegistry().setMetaClass(ModelCheck.class, meta);
Map mc2 = (Map) Model.mapObject(mc);
Assert.assertEquals(2, mc2.size());
Assert.assertNull(mc2.get("abc"));
Model.put(mc, "abc", "xyz");
Map mc3 = (Map) Model.mapObject(mc);
Assert.assertEquals("xyz", mc3.get("abc"));
MetaClassImpl meta2 = new MetaClassImpl(ModelCheck.class);
meta2.initialize();
GroovySystem.getMetaClassRegistry().setMetaClass(ModelCheck.class, meta2);
Map mc4 = (Map) Model.mapObject(mc);
Assert.assertEquals(1, mc4.size());
}
Aggregations