本文整理了Java中groovy.lang.MetaClass.setAttribute()
方法的一些代码示例,展示了MetaClass.setAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.setAttribute()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:setAttribute
[英]Sets the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.
[中]设置属性(字段)的值。这种方法是为了支持Groovy运行时,而不是用于一般的客户端API。
代码示例来源:origin: org.codehaus.groovy/groovy
public void setAttribute(Object object, String attribute, Object newValue) {
delegate.setAttribute(object, attribute, newValue);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) {
this.delegate.setAttribute(sender, receiver, messageName, messageValue, useSuper, fromInsideClass);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static void setAttribute(Object object, String attribute, Object newValue) {
if (object == null) {
object = NullObject.getNullObject();
}
if (object instanceof Class) {
metaRegistry.getMetaClass((Class) object).setAttribute(object, attribute, newValue);
} else if (object instanceof GroovyObject) {
((GroovyObject) object).getMetaClass().setAttribute(object, attribute, newValue);
} else {
metaRegistry.getMetaClass(object.getClass()).setAttribute(object, attribute, newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setAttribute(Object object, String attribute, Object newValue) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
ownerMetaClass.setAttribute(object, attribute, newValue);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public void setAttribute(Class sender, Object receiver, String messageName, Object messageValue, boolean useSuper, boolean fromInsideClass) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
ownerMetaClass.setAttribute(sender, owner, messageName, messageValue, useSuper, fromInsideClass);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static void setGroovyObjectField(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
try {
receiver.getMetaClass().setAttribute(receiver, messageName, messageArgument);
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static void setGroovyObjectFieldSafe(Object messageArgument, Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
if (receiver == null) return;
try {
receiver.getMetaClass().setAttribute(receiver, messageName, messageArgument);
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static void setFieldOnSuper(Object messageArgument, Class senderClass, Object receiver, String messageName) throws Throwable {
try {
if (receiver instanceof Class) {
InvokerHelper.setAttribute(receiver, messageName, messageArgument);
} else {
MetaClass mc = ((GroovyObject) receiver).getMetaClass();
mc.setAttribute(senderClass, receiver, messageName, messageArgument, true, true);
}
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public void setAttribute(Class sender, Object object, String attribute,
Object newValue, boolean useSuper, boolean fromInsideClass) {
if (object instanceof Class) {
getStaticMetaClass().setAttribute(sender, object, attribute, newValue, useSuper, fromInsideClass);
} else {
if (!attributeInitDone) initAttributes();
CachedField mfp = attributes.get(attribute);
if (mfp == null) {
CLOSURE_METACLASS.setAttribute(sender, object, attribute, newValue, useSuper, fromInsideClass);
} else {
mfp.setProperty(object, newValue);
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
if (isStatic && object != theClass) {
MetaClass mc = registry.getMetaClass((Class) object);
mc.setAttribute(sender, object, attribute, newValue, useSuper, fromInsideClass);
return;
代码示例来源:origin: groovy/groovy-core
obj.getMetaClass().setAttribute(obj, "x", newX1);
代码示例来源:origin: groovy/groovy-core
obj.getMetaClass().setAttribute(obj, "x", newX1);
代码示例来源:origin: groovy/groovy-core
obj.getMetaClass().setAttribute(obj, "x", newX1);
代码示例来源:origin: groovy/groovy-core
obj.getMetaClass().setAttribute(obj, "x", newX1);
代码示例来源:origin: groovy/groovy-core
public void testMetaClassNameHandling() {
final Tt1gi obj = new Tt1gi(); // Test class implementing GroovyObject
final String newX = "new x";
final String newX1 = "new x1";
final String newX2 = "new x2";
final String newX3 = "new x3";
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == obj.x);
assertTrue("dynamic method".equals(obj.invokeMethod("x", new Object[]{})));
obj.setProperty("x", newX);
obj.getMetaClass().setAttribute(obj, "x", newX1);
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX1);
obj.setX(newX2);
obj.x = newX3;
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
}
代码示例来源:origin: groovy/groovy-core
public void testMetaClassNameHandling1() {
final Tt1gi obj = new Tt1gi() {
}; // repeat test with subclass
final String newX = "new x";
final String newX1 = "new x1";
final String newX2 = "new x2";
final String newX3 = "new x3";
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == obj.x);
assertTrue("dynamic method".equals(obj.invokeMethod("x", new Object[]{})));
obj.setProperty("x", newX);
obj.getMetaClass().setAttribute(obj, "x", newX1);
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX1);
obj.setX(newX2);
obj.x = newX3;
assertTrue("dynamic property".equals(obj.getProperty("x")));
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
}
代码示例来源:origin: groovy/groovy-core
public void testObjectSupportNameHandling() {
final Tt1go obj = new Tt1go(); // Test subclass of GroovyObjectSupport
final String newX = "new x";
final String newX1 = "new x1";
final String newX2 = "new x2";
final String newX3 = "new x3";
assertTrue(obj.getProperty("x") == obj.getX());
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == obj.x);
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
obj.setProperty("x", newX);
obj.getMetaClass().setAttribute(obj, "x", newX1);
assertTrue(obj.getProperty("x") == newX);
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX1);
obj.setX(newX2);
obj.x = newX3;
assertTrue(obj.getProperty("x") == newX2);
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
}
代码示例来源:origin: groovy/groovy-core
public void testObjectSupportNameHandling1() {
final Tt1go obj = new Tt1go() {
}; // repeat test with subclass
final String newX = "new x";
final String newX1 = "new x1";
final String newX2 = "new x2";
final String newX3 = "new x3";
assertTrue(obj.getProperty("x") == obj.getX());
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == obj.x);
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
obj.setProperty("x", newX);
obj.getMetaClass().setAttribute(obj, "x", newX1);
assertTrue(obj.getProperty("x") == newX);
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX1);
obj.setX(newX2);
obj.x = newX3;
assertTrue(obj.getProperty("x") == newX2);
assertTrue(obj.getMetaClass().getAttribute(obj, "x") == newX3);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
public static void setAttribute(Object object, String attribute, Object newValue) {
if (object == null) {
object = NullObject.getNullObject();
}
if (object instanceof Class) {
metaRegistry.getMetaClass((Class) object).setAttribute(object, attribute, newValue);
} else if (object instanceof GroovyObject) {
((GroovyObject) object).getMetaClass().setAttribute(object, attribute, newValue);
} else {
metaRegistry.getMetaClass(object.getClass()).setAttribute(object, attribute, newValue);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
public static void setFieldOnSuper(Object messageArgument, Class senderClass, Object receiver, String messageName) throws Throwable {
try {
if (receiver instanceof Class) {
InvokerHelper.setAttribute(receiver, messageName, messageArgument);
} else {
MetaClass mc = ((GroovyObject) receiver).getMetaClass();
mc.setAttribute(senderClass, receiver, messageName, messageArgument, true, true);
}
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
内容来源于网络,如有侵权,请联系作者删除!