use of groovy.lang.MetaClassImpl in project groovy by apache.
the class ClosureMetaClass method getDelegateMethod.
private MetaMethod getDelegateMethod(final Closure closure, final Object delegate, final String methodName, final Class[] argClasses) {
if (delegate == closure || delegate == null)
return null;
if (delegate instanceof Class) {
for (Class superClass = (Class) delegate; superClass != Object.class && superClass != null; superClass = superClass.getSuperclass()) {
MetaClass mc = registry.getMetaClass(superClass);
MetaMethod method = mc.getStaticMetaMethod(methodName, argClasses);
if (method != null)
return method;
}
return null;
} else if (delegate instanceof GroovyInterceptable) {
MetaClass delegateMetaClass = lookupObjectMetaClass(delegate);
// GROOVY-3015: must route calls through GroovyObject#invokeMethod(String,Object)
MetaMethod interceptMethod = delegateMetaClass.pickMethod("invokeMethod", new Class[] { String.class, Object.class });
return new TransformMetaMethod(interceptMethod) {
@Override
public Object invoke(final Object object, final Object[] arguments) {
return super.invoke(object, new Object[] { methodName, arguments });
}
};
} else {
MetaClass delegateMetaClass = lookupObjectMetaClass(delegate);
MetaMethod method = delegateMetaClass.pickMethod(methodName, argClasses);
if (method != null) {
return method;
}
if (delegateMetaClass instanceof ExpandoMetaClass) {
method = ((ExpandoMetaClass) delegateMetaClass).findMixinMethod(methodName, argClasses);
if (method != null) {
onMixinMethodFound(method);
return method;
}
}
if (delegateMetaClass instanceof MetaClassImpl) {
method = MetaClassImpl.findMethodInClassHierarchy(getTheClass(), methodName, argClasses, this);
if (method != null) {
onSuperMethodFoundInHierarchy(method);
return method;
}
}
return method;
}
}
use of groovy.lang.MetaClassImpl in project groovy by apache.
the class CachedClass method addNewMopMethods.
public void addNewMopMethods(List<MetaMethod> arr) {
final MetaClass metaClass = classInfo.getStrongMetaClass();
if (metaClass != null) {
if (metaClass.getClass() == MetaClassImpl.class) {
classInfo.setStrongMetaClass(null);
List<MetaMethod> res = new ArrayList<>();
Collections.addAll(res, classInfo.newMetaMethods);
res.addAll(arr);
updateSetNewMopMethods(res);
MetaClassImpl answer = new MetaClassImpl(((MetaClassImpl) metaClass).getRegistry(), metaClass.getTheClass());
answer.initialize();
classInfo.setStrongMetaClass(answer);
return;
}
if (metaClass.getClass() == ExpandoMetaClass.class) {
ExpandoMetaClass emc = (ExpandoMetaClass) metaClass;
classInfo.setStrongMetaClass(null);
updateAddNewMopMethods(arr);
ExpandoMetaClass newEmc = new ExpandoMetaClass(metaClass.getTheClass());
for (MetaMethod mm : emc.getExpandoMethods()) {
newEmc.registerInstanceMethod(mm);
}
newEmc.initialize();
classInfo.setStrongMetaClass(newEmc);
return;
}
throw new GroovyRuntimeException("Can't add methods to class " + getTheClass().getName() + ". Strong custom meta class already set.");
}
classInfo.setWeakMetaClass(null);
updateAddNewMopMethods(arr);
}
use of groovy.lang.MetaClassImpl in project groovy by apache.
the class CachedClass method setNewMopMethods.
public void setNewMopMethods(List<MetaMethod> arr) {
final MetaClass metaClass = classInfo.getStrongMetaClass();
if (metaClass != null) {
if (metaClass.getClass() == MetaClassImpl.class) {
classInfo.setStrongMetaClass(null);
updateSetNewMopMethods(arr);
MetaClassImpl mci = new MetaClassImpl(metaClass.getTheClass());
mci.initialize();
classInfo.setStrongMetaClass(mci);
return;
}
if (metaClass.getClass() == ExpandoMetaClass.class) {
classInfo.setStrongMetaClass(null);
updateSetNewMopMethods(arr);
ExpandoMetaClass newEmc = new ExpandoMetaClass(metaClass.getTheClass());
newEmc.initialize();
classInfo.setStrongMetaClass(newEmc);
return;
}
throw new GroovyRuntimeException("Can't add methods to class " + getTheClass().getName() + ". Strong custom meta class already set.");
}
classInfo.setWeakMetaClass(null);
updateSetNewMopMethods(arr);
}
use of groovy.lang.MetaClassImpl in project groovy by apache.
the class AbstractCallSite method createPojoMetaClassGetPropertySite.
private CallSite createPojoMetaClassGetPropertySite(final Object receiver) {
final MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
CallSite site;
if (metaClass.getClass() != MetaClassImpl.class || GroovyCategorySupport.hasCategoryInCurrentThread()) {
site = new PojoMetaClassGetPropertySite(this);
} else {
final MetaProperty effective = ((MetaClassImpl) metaClass).getEffectiveGetMetaProperty(receiver.getClass(), receiver, name, false);
if (effective != null) {
if (effective instanceof CachedField)
site = new GetEffectivePojoFieldSite(this, (MetaClassImpl) metaClass, (CachedField) effective);
else
site = new GetEffectivePojoPropertySite(this, (MetaClassImpl) metaClass, effective);
} else {
site = new PojoMetaClassGetPropertySite(this);
}
}
array.array[index] = site;
return site;
}
use of groovy.lang.MetaClassImpl in project groovy by apache.
the class CallSiteArray method createCallCurrentSite.
private static CallSite createCallCurrentSite(CallSite callSite, GroovyObject receiver, Object[] args, Class sender) {
CallSite site;
if (receiver instanceof GroovyInterceptable) {
site = new PogoInterceptableSite(callSite);
} else {
MetaClass metaClass = receiver.getMetaClass();
Class theClass = metaClass.getTheClass();
if (receiver.getClass() != theClass && !theClass.isInterface()) {
site = new PogoInterceptableSite(callSite);
} else if (metaClass instanceof MetaClassImpl) {
site = ((MetaClassImpl) metaClass).createPogoCallCurrentSite(callSite, sender, args);
} else {
site = new PogoMetaClassSite(callSite, metaClass);
}
}
replaceCallSite(callSite, site);
return site;
}
Aggregations