public Object invoke(Object object, Object[] arguments) { return metaMethod.invoke(object, arguments); } }
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.invoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } }
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.invoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } }
public final Object invoke(Object receiver, Object[] args) throws Throwable { try { return metaMethod.invoke(receiver, args); } catch (GroovyRuntimeException gre) { throw ScriptBytecodeAdapter.unwrap(gre); } } }
public Object invoke(Object object, Object[] arguments) { return proxy().invoke(object, arguments); }
/** * Overrides default implementation just in case setProperty method has been overridden by ExpandoMetaClass * * @see MetaClassImpl#setProperty(Class, Object, String, Object, boolean, boolean) */ public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) { if (setPropertyMethod != null && !name.equals(META_CLASS_PROPERTY) && getJavaClass().isInstance(object)) { setPropertyMethod.invoke(object, new Object[]{name, newValue}); return; } super.setProperty(sender, object, name, newValue, useSuper, fromInsideClass); }
/** * Overrides default implementation just in case invokeMethod has been overridden by ExpandoMetaClass * * @see groovy.lang.MetaClassImpl#invokeMethod(Class, Object, String, Object[], boolean, boolean) */ public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) { if (invokeMethodMethod != null) { MetaClassHelper.unwrap(originalArguments); return invokeMethodMethod.invoke(object, new Object[]{methodName, originalArguments}); } return super.invokeMethod(sender, object, methodName, originalArguments, isCallToSuper, fromInsideClass); }
private Object invokeStaticMissingMethod(Class sender, String methodName, Object[] arguments) { MetaMethod metaMethod = getStaticMetaMethod(STATIC_METHOD_MISSING, METHOD_MISSING_ARGS); if (metaMethod != null) { return metaMethod.invoke(sender, new Object[]{methodName, arguments}); } throw new MissingMethodException(methodName, sender, arguments, true); }
/** * Overrides default implementation just in case getProperty method has been overridden by ExpandoMetaClass * * @see MetaClassImpl#getProperty(Object, String) */ public Object getProperty(Object object, String name) { if (hasOverrideGetProperty(name) && getJavaClass().isInstance(object)) { return getPropertyMethod.invoke(object, new Object[]{name}); } return super.getProperty(object, name); }
/** * Invokes the method this object represents. This method is not final but it should be overloaded very carefully and only by generated methods * there is no guarantee that it will be called * * @param object The object the method is to be called at. * @param argumentArray Arguments for the method invocation. * @return The return value of the invoked method. */ public Object doMethodInvoke(Object object, Object[] argumentArray) { argumentArray = coerceArgumentsToClasses(argumentArray); try { return invoke(object, argumentArray); } catch (Exception e) { throw processDoMethodInvokeException(e, object, argumentArray); } } }
/** * Overrides default implementation just in case getProperty method has been overridden by ExpandoMetaClass * * @see MetaClassImpl#getProperty(Class, Object, String, boolean, boolean) */ public Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass) { if (hasOverrideGetProperty(name) && getJavaClass().isInstance(object)) { return getPropertyMethod.invoke(object, new Object[]{name}); } if ("mixedIn".equals(name)) { return new MixedInAccessor(object, mixinClasses); } return super.getProperty(sender, object, name, useSuper, fromInsideClass); }
public Object invoke(Object object, Object[] arguments) { // make sure parameterTypes gets set method.getParameterTypes(); return method.invoke(mixinInMetaClass.getMixinInstance(object), method.correctArguments(arguments)); }
@Override public Object getProperty(Object object) { MetaMethod getter = getGetter(); if (getter == null) { if (field != null) return field.getProperty(object); throw new GroovyRuntimeException("Cannot read write-only property: " + name); } return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY); }
/** * Get the property of the given object. * * @param object which to be got * @return the property of the given object * @throws RuntimeException if the property could not be evaluated */ public Object getProperty(Object object) { MetaMethod getter = getGetter(); if (getter == null) { if (field != null) return field.getProperty(object); //TODO: create a WriteOnlyException class? throw new GroovyRuntimeException("Cannot read write-only property: " + name); } return getter.invoke(object, MetaClassHelper.EMPTY_ARRAY); }
public Object invokeConstructor(Object[] arguments) { // TODO This is the only area where this MetaClass needs to do some interception because Groovy's current // MetaClass uses hard coded references to the java.lang.reflect.Constructor class so you can't simply // inject Constructor like you can do properties, methods and fields. When Groovy's MetaClassImpl is // refactored we can fix this Class[] argClasses = MetaClassHelper.convertToTypeArray(arguments); MetaMethod method = pickMethod(GROOVY_CONSTRUCTOR, argClasses); if (method != null && method.getParameterTypes().length == arguments.length) { return method.invoke(theClass, arguments); } return super.invokeConstructor(arguments); }
/** * Hook to deal with the case of MissingProperty for static properties. The method will look attempt to look up * "propertyMissing" handlers and invoke them otherwise thrown a MissingPropertyException * * @param instance The instance * @param propertyName The name of the property * @param optionalValue The value in the case of a setter * @param isGetter True if its a getter * @return The value in the case of a getter or a MissingPropertyException */ protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) { MetaClass mc = instance instanceof Class ? registry.getMetaClass((Class) instance) : this; if (isGetter) { MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, GETTER_MISSING_ARGS); if (propertyMissing != null) { return propertyMissing.invoke(instance, new Object[]{propertyName}); } } else { MetaMethod propertyMissing = mc.getMetaMethod(STATIC_PROPERTY_MISSING, SETTER_MISSING_ARGS); if (propertyMissing != null) { return propertyMissing.invoke(instance, new Object[]{propertyName, optionalValue}); } } if (instance instanceof Class) { throw new MissingPropertyException(propertyName, (Class) instance); } throw new MissingPropertyException(propertyName, theClass); }
/** * Set the property on the given object to the new value. * * @param object on which to set the property * @param newValue the new value of the property * @throws RuntimeException if the property could not be set */ public void setProperty(Object object, Object newValue) { MetaMethod setter = getSetter(); if (setter == null) { if (field != null && !Modifier.isFinal(field.getModifiers())) { field.setProperty(object, newValue); return; } throw new GroovyRuntimeException("Cannot set read-only property: " + name); } newValue = DefaultTypeTransformation.castToType(newValue, getType()); setter.invoke(object, new Object[]{newValue}); }
if(method != null) { onMixinMethodFound(method); return method.invoke(instance, arguments); if(method != null) { onSuperMethodFoundInHierarchy(method); return method.invoke(instance, arguments); if(method instanceof ClosureMetaMethod) { onInvokeMethodFoundInHierarchy(method); return method.invoke(instance, invokeMethodArgs); method = getCategoryMethodMissing(instanceKlazz); if (method != null) { return method.invoke(instance, new Object[]{methodName, arguments}); return methodMissing.invoke(instance, new Object[]{methodName, arguments}); } catch (InvokerInvocationException iie) { if (methodMissing instanceof ClosureMetaMethod && iie.getCause() instanceof MissingMethodException) {
if(method instanceof ClosureMetaMethod) { onGetPropertyFoundInHierarchy(method); return method.invoke(instance,new Object[]{propertyName}); if(method instanceof ClosureMetaMethod) { onSetPropertyFoundInHierarchy(method); return method.invoke(instance, new Object[]{propertyName, optionalValue}); if (isGetter) { if (propertyMissingGet != null) { return propertyMissingGet.invoke(instance, new Object[]{propertyName}); return propertyMissingSet.invoke(instance, new Object[]{propertyName, optionalValue});
if (!isStatic && !ReflectionUtil.isFinalMethod(method) && !configuration.isGlobal()) { return metaMethod.invoke(target, arguments);