本文整理了Java中groovy.lang.MetaClass.getAttribute()
方法的一些代码示例,展示了MetaClass.getAttribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.getAttribute()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:getAttribute
[英]Retrieves 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 Object getAttribute(Object object, String attribute) {
return delegate.getAttribute(object, attribute);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper) {
return this.delegate.getAttribute(sender, receiver, messageName, useSuper);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Object getAttribute(Object object, String attribute) {
if (object == null) {
object = NullObject.getNullObject();
}
if (object instanceof Class) {
return metaRegistry.getMetaClass((Class) object).getAttribute(object, attribute);
} else if (object instanceof GroovyObject) {
return ((GroovyObject) object).getMetaClass().getAttribute(object, attribute);
} else {
return metaRegistry.getMetaClass(object.getClass()).getAttribute(object, attribute);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object getAttribute(Object object, String attribute) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.getAttribute(owner, attribute);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Object getGroovyObjectField(Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
try {
return receiver.getMetaClass().getAttribute(receiver, messageName);
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object getAttribute(Class sender, Object receiver, String messageName, boolean useSuper) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.getAttribute(sender, receiver, messageName, useSuper);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Object getGroovyObjectFieldSafe(Class senderClass, GroovyObject receiver, String messageName) throws Throwable {
if (receiver == null) return null;
try {
return receiver.getMetaClass().getAttribute(receiver, messageName);
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public static Object getFieldOnSuper(Class senderClass, Object receiver, String messageName) throws Throwable {
try {
if (receiver instanceof Class) {
return InvokerHelper.getAttribute(receiver, messageName);
} else {
MetaClass mc = ((GroovyObject) receiver).getMetaClass();
return mc.getAttribute(senderClass, receiver, messageName, true);
}
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
@Override
public Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass) {
if (object instanceof Class) {
return getStaticMetaClass().getAttribute(sender, object, attribute, useSuper);
} else {
if (!attributeInitDone) initAttributes();
CachedField mfp = attributes.get(attribute);
if (mfp == null) {
return CLOSURE_METACLASS.getAttribute(sender, object, attribute, useSuper);
} else {
return mfp.getProperty(object);
}
}
}
代码示例来源:origin: groovy/groovy-core
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
代码示例来源:origin: groovy/groovy-core
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
代码示例来源:origin: groovy/groovy-core
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
代码示例来源: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
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == obj.x.call());
assertTrue(obj.invokeMethod("x", new Object[]{}) == obj.x());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX1.call());
assertTrue(((Closure) obj.getMetaClass().getAttribute(obj, "x")).call() == newX3.call());
代码示例来源:origin: org.codehaus.groovy/groovy
if (isStatic && object != theClass) {
MetaClass mc = registry.getMetaClass((Class) object);
return mc.getAttribute(sender, object, attribute, useSuper);
代码示例来源: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: org.grails/grails-datastore-gorm
@Override
public Object getAttribute(Object object, String attribute) {
if (attribute.equals("id")) {
return getKey();
} else if (attribute.equals("initialized")) {
return isProxyInitiated();
} else if (attribute.equals("target")) {
return getProxyTarget();
} else {
return delegate.getAttribute(getProxyTarget(), attribute);
}
}
代码示例来源:origin: org.kohsuke.droovy/groovy
public static Object getFieldOnSuper(Class senderClass, Object receiver, String messageName) throws Throwable {
try {
if (receiver instanceof Class) {
return InvokerHelper.getAttribute(receiver, messageName);
} else {
MetaClass mc = ((GroovyObject) receiver).getMetaClass();
return mc.getAttribute(senderClass, receiver, messageName, true);
}
} catch (GroovyRuntimeException gre) {
throw unwrap(gre);
}
}
内容来源于网络,如有侵权,请联系作者删除!