use of groovy.lang.MetaClass in project groovy by apache.
the class MetaClassRegistryImpl method setMetaClass.
public void setMetaClass(Object obj, MetaClass theMetaClass) {
Class theClass = obj.getClass();
final ClassInfo info = ClassInfo.getClassInfo(theClass);
MetaClass oldMC = null;
info.lock();
try {
oldMC = info.getPerInstanceMetaClass(obj);
info.setPerInstanceMetaClass(obj, theMetaClass);
} finally {
info.unlock();
}
fireConstantMetaClassUpdate(obj, theClass, oldMC, theMetaClass);
}
use of groovy.lang.MetaClass in project groovy by apache.
the class ClosureMetaClass method getStaticMetaClass.
private static synchronized MetaClass getStaticMetaClass() {
if (classMetaClass == null) {
classMetaClass = new MetaClassImpl(Class.class);
classMetaClass.initialize();
}
return classMetaClass;
}
use of groovy.lang.MetaClass 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.MetaClass in project groovy by apache.
the class ClosureMetaClass method lookupObjectMetaClass.
private MetaClass lookupObjectMetaClass(final Object object) {
if (object instanceof GroovyObject) {
GroovyObject go = (GroovyObject) object;
return go.getMetaClass();
}
Class ownerClass = object.getClass();
if (ownerClass == Class.class) {
ownerClass = (Class) object;
return registry.getMetaClass(ownerClass);
}
MetaClass metaClass = InvokerHelper.getMetaClass(object);
return metaClass;
}
use of groovy.lang.MetaClass in project groovy by apache.
the class OwnedMetaClass method invokeMethod.
@Override
public Object invokeMethod(Class sender, Object receiver, String methodName, Object[] arguments, boolean isCallToSuper, boolean fromInsideClass) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.invokeMethod(sender, owner, methodName, arguments, isCallToSuper, fromInsideClass);
}
Aggregations