本文整理汇总了Java中org.codehaus.groovy.runtime.InvokerHelper.getMetaClass方法的典型用法代码示例。如果您正苦于以下问题:Java InvokerHelper.getMetaClass方法的具体用法?Java InvokerHelper.getMetaClass怎么用?Java InvokerHelper.getMetaClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.runtime.InvokerHelper
的用法示例。
在下文中一共展示了InvokerHelper.getMetaClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addListeners
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Add listeners to a specific object. Updates the bould flags and update set
*
* @param listener This listener to attach.
* @param newObject The object we should read our property off of.
* @param updateSet The list of objects we have added listeners to
*/
public void addListeners(PropertyChangeListener listener, Object newObject, Set updateSet) {
removeListeners();
if (newObject != null) {
// check for local synthetics
TriggerBinding syntheticTrigger = getSyntheticTriggerBinding(newObject);
MetaClass mc = InvokerHelper.getMetaClass(newObject);
if (syntheticTrigger != null) {
PropertyBinding psb = new PropertyBinding(newObject, propertyName);
PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding(newObject, propertyName, listener);
syntheticFullBinding = syntheticTrigger.createBinding(psb, proxytb);
syntheticFullBinding.bind();
updateSet.add(newObject);
} else if (!mc.respondsTo(newObject, "addPropertyChangeListener", NAME_PARAMS).isEmpty()) {
InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", new Object[] {propertyName, listener});
localListener = listener;
updateSet.add(newObject);
} else if (!mc.respondsTo(newObject, "addPropertyChangeListener", GLOBAL_PARAMS).isEmpty()) {
InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", listener);
globalListener = listener;
updateSet.add(newObject);
}
}
currentObject = newObject;
}
示例2: createPojoMetaClassGetPropertySite
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private CallSite createPojoMetaClassGetPropertySite(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;
}
示例3: testSetPropertyWithArray
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testSetPropertyWithArray() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
// test int[]
int[] ints = new int[]{
0, 1, 2, 3
};
metaClass.setProperty(dymmyClass, "ints", ints);
assertEquals(ints, metaClass.getProperty(dymmyClass, "ints"));
// test Integer[]
Integer[] integers = new Integer[]{
new Integer(0), new Integer(1), new Integer(2), new Integer(3)
};
metaClass.setProperty(dymmyClass, "integers", integers);
assertEquals(integers, metaClass.getProperty(dymmyClass, "integers"));
}
示例4: checkPropNames
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public static void checkPropNames(Object instance, Map<String, Object> args) {
final MetaClass metaClass = InvokerHelper.getMetaClass(instance);
for (String k : args.keySet()) {
if (metaClass.hasProperty(instance, k) == null)
throw new MissingPropertyException(k, instance.getClass());
}
}
示例5: createCallConstructorSite
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
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;
}
示例6: lookupObjectMetaClass
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private MetaClass lookupObjectMetaClass(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;
}
示例7: getMetaMethods
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Get info about instance and class Methods that are dynamically added through Groovy.
*
* @return Array of StringArrays that can be indexed with the MEMBER_xxx_IDX constants
*/
public Object[] getMetaMethods() {
MetaClass metaClass = InvokerHelper.getMetaClass(objectUnderInspection);
List metaMethods = metaClass.getMetaMethods();
Object[] result = new Object[metaMethods.size()];
int i = 0;
for (Iterator iter = metaMethods.iterator(); iter.hasNext(); i++) {
MetaMethod metaMethod = (MetaMethod) iter.next();
result[i] = methodInfo(metaMethod);
}
return result;
}
示例8: testSetPropertyWithDoubleArray
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testSetPropertyWithDoubleArray() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
Double[][] matrix2 =
{
{
new Double(35), new Double(50), new Double(120)
},
{
new Double(75), new Double(80), new Double(150)
}
};
metaClass.setProperty(dymmyClass, "matrix", matrix2);
metaClass.setProperty(dymmyClass, "matrix2", matrix2);
}
示例9: testPublicField
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testPublicField() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
assertEquals(metaClass.getProperty(dymmyClass, "x"), new Integer(0));
assertEquals(metaClass.getProperty(dymmyClass, "y"), "none");
metaClass.setProperty(dymmyClass, "x", new Integer(25));
assertEquals(dymmyClass.x, 25);
metaClass.setProperty(dymmyClass, "y", "newvalue");
assertEquals(dymmyClass.y, "newvalue");
}
示例10: GroovyRuntimeBeanReference
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public GroovyRuntimeBeanReference(String beanName, GroovyBeanDefinitionWrapper beanDefinition, boolean toParent) {
super(beanName, toParent);
this.beanDefinition = beanDefinition;
this.metaClass = InvokerHelper.getMetaClass(this);
}
示例11: setDelegate
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Sets the delegation target.
*/
public void setDelegate(Object delegate) {
this.delegate = delegate;
this.metaClass = InvokerHelper.getMetaClass(delegate.getClass());
}
示例12: size
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private static int size(ManagedConcurrentValueMap<String, Object> map) {
MetaClass metaClass = InvokerHelper.getMetaClass(map);
ConcurrentHashMap<String, Object> internalMap = (ConcurrentHashMap<String, Object>)metaClass.getProperty(map, "internalMap");
return internalMap.size();
}
示例13: testSetPropertyWithInt
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testSetPropertyWithInt() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
metaClass.setProperty(dymmyClass, "anInt", new Integer(10));
}
示例14: getDefaultMetaClass
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private MetaClass getDefaultMetaClass() {
return InvokerHelper.getMetaClass(this.getClass());
}
示例15: ExpandoMetaClass
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public ExpandoMetaClass(MetaClassRegistry registry, Class theClass, boolean register, boolean allowChangesAfterInit, MetaMethod[] add) {
super(registry, theClass, add);
this.myMetaClass = InvokerHelper.getMetaClass(getClass());
this.inRegistry = register;
this.allowChangesAfterInit = allowChangesAfterInit;
}