本文整理了Java中groovy.lang.MetaClass.setProperty()
方法的一些代码示例,展示了MetaClass.setProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.setProperty()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:setProperty
[英]Retrieves a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
[中]检索给定接收器上指定参数的属性。sender是从对象请求属性的类。元类将根据提供的名称和参数尝试建立要调用的方法。
isCallToSuper和FromInsidelClass可帮助Groovy运行时在调用时执行优化,以便在必要时直接转到超级类
代码示例来源:origin: spring-projects/spring-framework
public void setProperty(String property, Object newValue) {
this.metaClass.setProperty(this, property, newValue);
}
代码示例来源:origin: org.springframework/spring-web
public void setProperty(String property, Object newValue) {
this.metaClass.setProperty(this, property, newValue);
}
代码示例来源:origin: spring-projects/spring-framework
public void setProperty(String property, Object newValue) {
if (newValue instanceof BeanDefinition) {
registerBeanDefinition(property, (BeanDefinition) newValue);
}
else {
this.metaClass.setProperty(this, property, newValue);
}
}
代码示例来源:origin: org.springframework/spring-context
public void setProperty(String property, Object newValue) {
if (newValue instanceof BeanDefinition) {
registerBeanDefinition(property, (BeanDefinition) newValue);
}
else {
this.metaClass.setProperty(this, property, newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* This method is called by he handle to realize the bean constructor
* with property map.
*/
public static Object setBeanProperties(MetaClass mc, Object bean, Map properties) {
for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String key = entry.getKey().toString();
Object value = entry.getValue();
mc.setProperty(bean, key, value);
}
return bean;
}
代码示例来源:origin: groovy/groovy-core
public void setProperty(final String property, final Object newValue) {
this.metaClass.setProperty(this, property, newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public void setProperty(String property, Object newValue) {
try {
metaClass.setProperty(delegate,property,newValue);
} catch (MissingPropertyException e) {
super.setProperty(property,newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static void setPropertySafe(Object object, MetaClass mc, String key, Object value) {
try {
mc.setProperty(object, key, value);
} catch (MissingPropertyException mpe) {
// Ignore
} catch (InvokerInvocationException iie) {
// GROOVY-5802 IAE for missing properties with classes that extend List
Throwable cause = iie.getCause();
if (!(cause instanceof IllegalArgumentException)) throw iie;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public void setProperty(Object object, String property, Object newValue) {
if (property.startsWith("@")) {
setAttribute(object, property.substring(1), newValue);
return;
}
delegate.setProperty(object, property, newValue);
}
代码示例来源:origin: groovy/groovy-core
public void setProperty(final String property, final Object newValue) {
this.metaClass.setProperty(this, property, newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setProperty(String property, Object newValue) {
getMetaClass().setProperty(this, property, newValue);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setProperty(String property, Object newValue) {
try {
getMetaClass().setProperty(this, property, newValue);
}
catch (MissingPropertyException e) {
if (delegate instanceof GroovyObject)
((GroovyObject) delegate).setProperty(property, newValue);
else
throw e;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setProperty(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
ownerMetaClass.setProperty(sender, owner, messageName, messageValue, useSuper, fromInsideClass);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setProperty(Object object, String property, Object newValue) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
ownerMetaClass.setProperty(object, property, newValue);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) {
if (object instanceof Class) {
getStaticMetaClass().setProperty(sender, object, name, newValue, useSuper, fromInsideClass);
} else {
CLOSURE_METACLASS.setProperty(sender, object, name, newValue, useSuper, fromInsideClass);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
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);
}
}
代码示例来源:origin: groovy/groovy-core
public void testSetPropertyWithList() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
// test list
ArrayList list = new ArrayList();
list.add(new Integer(120));
list.add(new Integer(150));
// test int[]
metaClass.setProperty(dymmyClass, "ints", list);
// test Integer[]
metaClass.setProperty(dymmyClass, "integers", list);
}
代码示例来源:origin: groovy/groovy-core
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);
}
代码示例来源:origin: groovy/groovy-core
public void testSetPropertyWithInt() {
DymmyClass dymmyClass = new DymmyClass();
MetaClass metaClass = InvokerHelper.getMetaClass(dymmyClass);
metaClass.setProperty(dymmyClass, "anInt", new Integer(10));
}
代码示例来源:origin: groovy/groovy-core
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");
}
内容来源于网络,如有侵权,请联系作者删除!