public List<MetaMethod> respondsTo(Object obj, String name) { return delegate.respondsTo(obj, name); }
public List<MetaMethod> respondsTo(Object obj, String name, Object[] argTypes) { return delegate.respondsTo(obj, name, argTypes); }
/** * <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); }
/** * <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); }
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); }
public List<MetaMethod> respondsTo(Object obj, String name) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.respondsTo(owner, name); }
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; } } }
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; } } }
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; } } } }
/** * 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; }
if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
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;
if (!mc.respondsTo(getRegistry(), name, args).isEmpty()){ return mc.invokeMethod(getRegistry(), name, args);
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; } }
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); }
public List respondsTo(Object obj, String name, Object[] argTypes) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.respondsTo(owner, name, argTypes); }
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); }
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); } }
/** * 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); }
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; }