本文整理了Java中groovy.lang.MetaClass.respondsTo()
方法的一些代码示例,展示了MetaClass.respondsTo()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.respondsTo()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:respondsTo
暂无
代码示例来源:origin: org.codehaus.groovy/groovy
public List<MetaMethod> respondsTo(Object obj, String name) {
return delegate.respondsTo(obj, name);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes) {
return delegate.respondsTo(obj, name, argTypes);
}
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* <p>Returns an object satisfying Groovy truth if the implementing MetaClass responds to
* a method with the given name regardless of the arguments.
*
* <p>Note that this method's return value is based on realised methods and does not take into account
* objects or classes that implement invokeMethod or methodMissing
*
* <p>This method is "safe" in that it will always return a value and never throw an exception
*
* @param self The object to inspect
* @param name The name of the method of interest
* @return A List of MetaMethods matching the given name or an empty list if no matching methods exist
* @see groovy.lang.MetaObjectProtocol#respondsTo(java.lang.Object, java.lang.String)
* @since 1.6.1
*/
public static List<MetaMethod> respondsTo(Object self, String name) {
return InvokerHelper.getMetaClass(self).respondsTo(self, name);
}
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* <p>Returns an object satisfying Groovy truth if the implementing MetaClass responds to
* a method with the given name and arguments types.
*
* <p>Note that this method's return value is based on realised methods and does not take into account
* objects or classes that implement invokeMethod or methodMissing
*
* <p>This method is "safe" in that it will always return a value and never throw an exception
*
* @param self The object to inspect
* @param name The name of the method of interest
* @param argTypes The argument types to match against
* @return A List of MetaMethods matching the argument types which will be empty if no matching methods exist
* @see groovy.lang.MetaObjectProtocol#respondsTo(java.lang.Object, java.lang.String, java.lang.Object[])
* @since 1.6.0
*/
public static List<MetaMethod> respondsTo(Object self, String name, Object[] argTypes) {
return InvokerHelper.getMetaClass(self).respondsTo(self, name, argTypes);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.respondsTo(owner, name, argTypes);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public List<MetaMethod> respondsTo(Object obj, String name) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.respondsTo(owner, name);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object invokeMethod(Object object, String methodName, Object arguments) {
try {
return delegate.invokeMethod(object, methodName, arguments);
} catch (MissingMethodException mme) {
// attempt builder resolution
try {
if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
// dispatch to factories if it is not a literal method
return builder.invokeMethod(methodName, arguments);
} else {
return InvokerHelper.invokeMethod(builder, methodName, arguments);
}
} catch (MissingMethodException mme2) {
// chain secondary exception
Throwable root = mme;
while (root.getCause() != null) {
root = root.getCause();
}
root.initCause(mme2);
// throw original
throw mme;
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public MethodClosure(Object owner, String method) {
super(owner);
this.method = method;
final Class clazz = owner.getClass()==Class.class?(Class) owner:owner.getClass();
maximumNumberOfParameters = 0;
parameterTypes = EMPTY_CLASS_ARRAY;
List<MetaMethod> methods = InvokerHelper.getMetaClass(clazz).respondsTo(owner, method);
for(MetaMethod m : methods) {
if (m.getParameterTypes().length > maximumNumberOfParameters) {
Class[] pt = m.getNativeParameterTypes();
maximumNumberOfParameters = pt.length;
parameterTypes = pt;
}
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object invokeMethod(Object object, String methodName, Object[] arguments) {
try {
return delegate.invokeMethod(object, methodName, arguments);
} catch (MissingMethodException mme) {
// attempt builder resolution
try {
if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
// dispatch to factories if it is not a literal method
return builder.invokeMethod(methodName, arguments);
} else {
return InvokerHelper.invokeMethod(builder, methodName, arguments);
}
} catch (MissingMethodException mme2) {
// chain secondary exception
Throwable root = mme;
while (root.getCause() != null) {
root = root.getCause();
}
root.initCause(mme2);
// throw original
throw mme;
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* This method is invoked by Groovy when a method that's not defined in Java is invoked.
* We use that as a syntax for bean definition.
*/
public Object methodMissing(String name, Object arg) {
Object[] args = (Object[])arg;
if(args.length == 0)
throw new MissingMethodException(name,getClass(),args);
if(args[0] instanceof Closure) {
// abstract bean definition
return invokeBeanDefiningMethod(name, args);
}
else if(args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
return invokeBeanDefiningMethod(name, args);
}
else if (args.length > 1 && args[args.length -1] instanceof Closure) {
return invokeBeanDefiningMethod(name, args);
}
WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
if(!mc.respondsTo(ctx, name, args).isEmpty()){
return mc.invokeMethod(ctx,name, args);
}
return this;
}
代码示例来源:origin: spring-projects/spring-framework
if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){
return mc.invokeMethod(getRegistry(), name, args);
代码示例来源:origin: groovy/groovy-core
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;
代码示例来源:origin: org.springframework/spring-beans
if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){
return mc.invokeMethod(getRegistry(), name, args);
代码示例来源:origin: org.codehaus.groovyfx/groovyfx
static public ReadOnlyProperty getJavaFXProperty(Object instance, String propertyName) {
MetaClass mc = InvokerHelper.getMetaClass(instance);
String fxPropertyAccessor = propertyName + "Property";
if (!mc.respondsTo(instance, fxPropertyAccessor, null).isEmpty()) {
return (ReadOnlyProperty)InvokerHelper.invokeMethod(instance, fxPropertyAccessor, null);
}else {
return null;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.respondsTo(owner, name, argTypes);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
public List respondsTo(Object obj, String name, Object[] argTypes) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.respondsTo(owner, name, argTypes);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.respondsTo(owner, name, argTypes);
}
代码示例来源:origin: com.anrisoftware.sscontrol/sscontrol-core
private Object tryServiceProperty(String name) throws ServiceException {
String getter = format("get%s", capitalize(name));
MetaClass metaclass = InvokerHelper.getMetaClass(service);
List<MetaMethod> methods = metaclass.respondsTo(service, getter);
if (methods.size() > 0) {
getLog().returnServiceProperty(this, name);
return methods.get(0).doMethodInvoke(service, EMPTY_OBJECT_ARRAY);
} else {
return methodMissing(name, null);
}
}
代码示例来源:origin: org.codehaus.gpars/gpars
/**
* Invokes the method on itself or creates an expression, which will invoke the method n the bound value,
* once it is available.
*/
@Override
public final Object invokeMethod(final String name, final Object args) {
if (getMetaClass().respondsTo(this, name).isEmpty()) {
return new DataflowInvocationExpression(this, name, (Object[]) args);
}
return InvokerHelper.invokeMethod(this, name, args);
}
代码示例来源:origin: org.codehaus.groovyfx/groovyfx
static public boolean isJavaBeanPropertyWritable(Object instance, String propertyName) {
MetaClass mc = InvokerHelper.getMetaClass(instance);
MetaProperty metaProperty = mc.getMetaProperty(propertyName);
if(metaProperty != null) {
String setterName = MetaProperty.getSetterName(propertyName);
return !mc.respondsTo(instance, setterName, new Class[]{metaProperty.getType()}).isEmpty();
} else if(instance instanceof Script) {
return ((Script)instance).getProperty(propertyName) != null;
}
return false;
}
内容来源于网络,如有侵权,请联系作者删除!