Refine search
public Object invoke(Object object, Object[] arguments) { return metaMethod.invoke(object, arguments); } }
protected String[] methodInfo(MetaMethod method) { String[] result = new String[MEMBER_EXCEPTIONS_IDX + 1]; int mod = method.getModifiers(); result[MEMBER_ORIGIN_IDX] = GROOVY; result[MEMBER_MODIFIER_IDX] = Modifier.toString(mod); result[MEMBER_DECLARER_IDX] = shortName(method.getDeclaringClass().getTheClass()); result[MEMBER_TYPE_IDX] = shortName(method.getReturnType()); result[MEMBER_NAME_IDX] = method.getName(); result[MEMBER_PARAMS_IDX] = makeParamsInfo(method.getNativeParameterTypes()); result[MEMBER_EXCEPTIONS_IDX] = NOT_APPLICABLE; // no exception info for Groovy MetaMethods return withoutNulls(result); }
@Override public void write(Object value) { setterLikeMethod.doMethodInvoke(owner, GroovyRuntimeUtil.asArgumentArray(value)); } }
/** * @param method the method to compare against * @return true if the given method has the same name, parameters, return type * and modifiers but may be defined on another type */ public final boolean isSame(MetaMethod method) { return getName().equals(method.getName()) && compatibleModifiers(getModifiers(), method.getModifiers()) && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
/** * 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); } } }
public static boolean isGenericSetMethod(MetaMethod method) { return (method.getName().equals("set")) && method.getParameterTypes().length == 2; }
if (sender != theClass) { MetaClass mc = registry.getMetaClass(sender); return mc.invokeStaticMethod(sender, methodName, arguments); return method.doMethodInvoke(object, arguments); while (superClass != Object.class && superClass != null) { MetaClass mc = registry.getMetaClass(superClass); method = mc.getStaticMetaMethod(methodName, argClasses); if (method != null) return method.doMethodInvoke(object, arguments); prop = mc.getProperty(superClass, superClass, methodName, false, false); } catch (MissingPropertyException mpe) {
if (isStatic && object != theClass) { MetaClass mc = registry.getMetaClass((Class) object); mc.getProperty(sender, object, name, useSuper, fromInsideClass); return; new Class[]{method.getParameterTypes()[0].getTheClass()}, new ConvertedClosure((Closure) newValue, name)); arguments = new Object[]{proxy}; if (method == null && genericSetMethod != null && !(!genericSetMethod.isStatic() && isStatic)) { arguments = new Object[]{name, newValue}; method = genericSetMethod; newValue = DefaultTypeTransformation.castToType( newValue, method.getParameterTypes()[0].getTheClass()); arguments[0] = newValue; } else { newValue = DefaultTypeTransformation.castToType( newValue, method.getParameterTypes()[1].getTheClass()); arguments[1] = newValue; method.doMethodInvoke(object, arguments); return;
if (isStatic && object != theClass) { MetaClass mc = registry.getMetaClass((Class) object); return mc.getProperty(sender, object, name, useSuper, false); if (method == null && genericGetMethod != null && !(!genericGetMethod.isStatic() && isStatic)) { arguments = new Object[]{name}; method = genericGetMethod; return mc.getProperty(Class.class, object, name, useSuper, false); } else if (object instanceof Collection) { return DefaultGroovyMethods.getAt((Collection) object, name); return method.doMethodInvoke(object, arguments);
public static void mixinClassesToMetaClass(MetaClass self, List<Class> categoryClasses) { final Class selfClass = self.getTheClass(); final List<MetaProperty> propList = metaClass.getProperties(); for (MetaProperty prop : propList) if (self.getMetaProperty(prop.getName()) == null) { mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin)); for (MetaProperty prop : cachedCategoryClass.getFields()) if (self.getMetaProperty(prop.getName()) == null) { mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin)); for (MetaMethod method : metaClass.getMethods()) { final int mod = method.getModifiers(); if (method instanceof CachedMethod) staticMethod(self, arr, (CachedMethod) method); } else if (method.getDeclaringClass().getTheClass() != Object.class || method.getName().equals("toString")) { if (metaMethod.getDeclaringClass().isAssignableFrom(selfClass)) mc.registerInstanceMethod(metaMethod); else {
/** * return false: add method * null: ignore method * true: replace */ private static Boolean getMatchKindForCategory(MetaMethod aMethod, MetaMethod categoryMethod) { CachedClass[] params1 = aMethod.getParameterTypes(); CachedClass[] params2 = categoryMethod.getParameterTypes(); if (params1.length != params2.length) return Boolean.FALSE; for (int i = 0; i < params1.length; i++) { if (params1[i] != params2[i]) return Boolean.FALSE; } Class aMethodClass = aMethod.getDeclaringClass().getTheClass(); Class categoryMethodClass = categoryMethod.getDeclaringClass().getTheClass(); if (aMethodClass==categoryMethodClass) return Boolean.TRUE; boolean match = aMethodClass.isAssignableFrom(categoryMethodClass); if (match) return Boolean.TRUE; return null; }
private void appendMethods(StringBuilder buffer) { for (int i = 0; i < methods.size; i++) { buffer.append("\n "); Object methodOrConstructor = methods.get(i); if (methodOrConstructor instanceof MetaMethod) { MetaMethod method = (MetaMethod) methodOrConstructor; buffer.append(Modifier.toString(method.getModifiers())); buffer.append(" ").append(method.getReturnType().getName()); buffer.append(" ").append(method.getDeclaringClass().getName()); buffer.append("#"); buffer.append(method.getName()); appendClassNames(buffer,method.getNativeParameterTypes()); } else { CachedConstructor method = (CachedConstructor) methodOrConstructor; buffer.append(Modifier.toString(method.cachedConstructor.getModifiers())); buffer.append(" ").append(method.cachedConstructor.getDeclaringClass().getName()); buffer.append("#<init>"); appendClassNames(buffer,method.getNativeParameterTypes()); } } } }
/** * Returns a string representation of this method */ public String toString() { return super.toString() + "[name: " + getName() + " params: " + InvokerHelper.toString(getParameterTypes()) + " returns: " + getReturnType() + " owner: " + getDeclaringClass() + "]"; }
MetaMethod metaMethod = delegate.pickMethod(methodName, ReflectionUtil.getTypes(arguments)); Method method = GroovyRuntimeUtil.toMethod(metaMethod); if (!isStatic && !ReflectionUtil.isFinalMethod(method) && !configuration.isGlobal()) { return metaMethod.invoke(target, arguments); if (metaMethod != null && metaMethod.getDeclaringClass().getTheClass() == GroovyObject.class) { if ("invokeMethod".equals(methodName)) { return invokeMethod(target, (String) arguments[0], GroovyRuntimeUtil.asArgumentArray(arguments[1]));
public void checkIfStdMethod(MetaMethod method) { if (method.getClass() != NewInstanceMetaMethod.class) { String name = method.getName(); if (method.getParameterTypes().length != 1) return; if (!method.getParameterTypes()[0].isNumber && method.getParameterTypes()[0].getTheClass() != Object.class) return; if (!NAMES.contains(name)) return; checkNumberOps(name, method.getDeclaringClass().getTheClass()); } }
return list; } else { if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface() && !method.isStatic())) { CachedClass methodC = method.getDeclaringClass(); CachedClass matchC = match.getDeclaringClass(); if (methodC == matchC) { if (isNonRealMethod(method)) { return method; MetaMethod match = (MetaMethod) list.get(found); if (match==method) return o; if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface() && !method.isStatic())) { CachedClass methodC = method.getDeclaringClass(); CachedClass matchC = match.getDeclaringClass(); if (methodC == matchC) { if (isNonRealMethod(method)) {
/** * @return the matching method which should be found */ private MetaMethod findMethod(CachedMethod aMethod) { Object methods = getMethods(theClass, aMethod.getName(), false); if (methods instanceof FastArray) { FastArray m = (FastArray) methods; final int len = m.size; final Object data[] = m.getArray(); for (int i = 0; i != len; ++i) { MetaMethod method = (MetaMethod) data[i]; if (method.isMethod(aMethod)) { return method; } } } else { MetaMethod method = (MetaMethod) methods; if (method.getName().equals(aMethod.getName()) // TODO: should be better check for case when only diff in modifiers can be SYNTHETIC flag // && method.getModifiers() == aMethod.getModifiers() && method.getReturnType().equals(aMethod.getReturnType()) && MetaMethod.equal(method.getParameterTypes(), aMethod.getParameterTypes())) { return method; } } return aMethod; }
/** * Returns the signature of this method * * @return The signature of this method */ public synchronized String getSignature() { if (signature == null) { CachedClass [] parameters = getParameterTypes(); final String name = getName(); StringBuilder buf = new StringBuilder(name.length()+parameters.length*10); buf.append(getReturnType().getName()); buf.append(' '); buf.append(name); buf.append('('); for (int i = 0; i < parameters.length; i++) { if (i > 0) { buf.append(", "); } buf.append(parameters[i].getName()); } buf.append(')'); signature = buf.toString(); } return signature; }
protected void addMetaMethodToIndex(MetaMethod method, MetaMethodIndex.Header header) { checkIfStdMethod(method); String name = method.getName(); MetaMethodIndex.Entry e = metaMethodIndex.getOrPutMethods(name, header); if (method.isStatic()) { e.staticMethods = metaMethodIndex.addMethodToList(e.staticMethods, method); } e.methods = metaMethodIndex.addMethodToList(e.methods, method); }
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; } } }