本文整理汇总了Java中org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl类的典型用法代码示例。如果您正苦于以下问题:Java MetaClassRegistryImpl类的具体用法?Java MetaClassRegistryImpl怎么用?Java MetaClassRegistryImpl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetaClassRegistryImpl类属于org.codehaus.groovy.runtime.metaclass包,在下文中一共展示了MetaClassRegistryImpl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetaClass
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
/**
* Gives the meta class to an Object.
*/
public void getMetaClass() {
Object receiver = args[0];
if (receiver == null) {
mc = NullObject.getNullObject().getMetaClass();
} else if (receiver instanceof GroovyObject) {
mc = ((GroovyObject) receiver).getMetaClass();
} else if (receiver instanceof Class) {
Class c = (Class) receiver;
ClassLoader cl = c.getClassLoader();
try {
Class.forName(c.getName(), true, cl);
} catch (ClassNotFoundException e) {}
mc = GroovySystem.getMetaClassRegistry().getMetaClass(c);
this.cache &= !ClassInfo.getClassInfo(c).hasPerInstanceMetaClasses();
} else {
mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(receiver);
this.cache &= !ClassInfo.getClassInfo(receiver.getClass()).hasPerInstanceMetaClasses();
}
mc.initialize();
}
示例2: invokePropertyOrMissing
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
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);
}
示例3: setMetaClass
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
/**
* Set the metaclass for an object.
* @param self the object whose metaclass we want to set
* @param metaClass the new metaclass value
* @since 1.6.0
*/
public static void setMetaClass(Object self, MetaClass metaClass) {
if (metaClass instanceof HandleMetaClass)
metaClass = ((HandleMetaClass)metaClass).getAdaptee();
if (self instanceof Class) {
GroovySystem.getMetaClassRegistry().setMetaClass((Class) self, metaClass);
} else {
((MetaClassRegistryImpl)GroovySystem.getMetaClassRegistry()).setMetaClass(self, metaClass);
}
}
示例4: clean
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public synchronized void clean() {
try {
cleaning = true;
MetaClassRegistryImpl registry = (MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry();
cleanMetaClassOfClass(registry);
cleanMetaClassOfInstance(registry);
} finally {
cleaning = false;
}
}
示例5: cleanMetaClassOfInstance
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
private void cleanMetaClassOfInstance(MetaClassRegistryImpl registry) {
List<IdentityWeakReference> keys = new ArrayList<IdentityWeakReference>(alteredInstances.keySet());
for (IdentityWeakReference key : keys) {
Object instance = key.get();
if (instance != null) {
Object alteredMetaClass = alteredInstances.get(key);
if (alteredMetaClass == NO_CUSTOM_METACLASS) {
alteredMetaClass = null;
}
registry.setMetaClass(instance, (MetaClass) alteredMetaClass);
}
}
alteredInstances.clear();
}
示例6: cleanMetaClassOfClass
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
private void cleanMetaClassOfClass(MetaClassRegistryImpl registry) {
Set<Class> classes = new HashSet<Class>(alteredClasses.keySet());
for (Class aClass : classes) {
Object alteredMetaClass = alteredClasses.get(aClass);
if (alteredMetaClass == NO_CUSTOM_METACLASS) {
registry.removeMetaClass(aClass);
}
else {
registry.setMetaClass(aClass, (MetaClass) alteredMetaClass);
}
}
alteredClasses.clear();
}
示例7: getMetaClass
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
private MetaClass getMetaClass(Object proxy) {
MetaClass mc = metaClass;
if (mc == null) {
mc = ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(proxy);
metaClass = mc;
}
return mc;
}
示例8: getProperty
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public static Object getProperty(Object object, String property) {
if (object == null) {
object = NullObject.getNullObject();
}
if (object instanceof GroovyObject) {
GroovyObject pogo = (GroovyObject) object;
return pogo.getProperty(property);
} else if (object instanceof Class) {
Class c = (Class) object;
return metaRegistry.getMetaClass(c).getProperty(object, property);
} else {
return ((MetaClassRegistryImpl) metaRegistry).getMetaClass(object).getProperty(object, property);
}
}
示例9: setProperty
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public static void setProperty(Object object, String property, Object newValue) {
if (object == null) {
object = NullObject.getNullObject();
}
if (object instanceof GroovyObject) {
GroovyObject pogo = (GroovyObject) object;
pogo.setProperty(property, newValue);
} else if (object instanceof Class) {
metaRegistry.getMetaClass((Class) object).setProperty((Class) object, property, newValue);
} else {
((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object).setProperty(object, property, newValue);
}
}
示例10: findDGMMethodsForClassNode
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
/**
* @deprecated Use {@link #findDGMMethodsForClassNode(ClassLoader, ClassNode,String)} instead
*/
@Deprecated
protected static Set<MethodNode> findDGMMethodsForClassNode(ClassNode clazz, String name) {
return findDGMMethodsForClassNode(MetaClassRegistryImpl.class.getClassLoader(), clazz, name);
}
示例11: findDGMMethodsByNameAndArguments
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
/**
* @deprecated Use {@link #findDGMMethodsByNameAndArguments(ClassLoader, ClassNode, String, ClassNode[], List)} instead
*/
@Deprecated
public static List<MethodNode> findDGMMethodsByNameAndArguments(final ClassNode receiver, final String name, final ClassNode[] args) {
return findDGMMethodsByNameAndArguments(MetaClassRegistryImpl.class.getClassLoader(), receiver, name, args);
}
示例12: getMetaClass
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public static MetaClass getMetaClass(Object object) {
if (object instanceof GroovyObject)
return ((GroovyObject) object).getMetaClass();
else
return ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).getMetaClass(object);
}
示例13: testRegistry
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public void testRegistry () {
final MetaClassRegistryImpl metaClassRegistry = new MetaClassRegistryImpl();
final Object [] instanceMethods = metaClassRegistry.getInstanceMethods().getArray();
assertTrue(instanceMethods.length > 0);
}
示例14: ExpectObjectWrapperWrapper
import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; //导入依赖的package包/类
public ExpectObjectWrapperWrapper(Object realValue){
this.realValue = realValue;
registry = MetaClassRegistryImpl.getInstance(MetaClassRegistryImpl.LOAD_DEFAULT);
}