public String getName() { return metaMethod.getName(); }
public String getName() { return method.getName(); }
private static boolean isGetPropertyMethod(MetaMethod metaMethod) { return GET_PROPERTY_METHOD.equals(metaMethod.getName()); }
public static boolean isGenericSetMethod(MetaMethod method) { return (method.getName().equals("set")) && method.getParameterTypes().length == 2; }
private static boolean isSetPropertyMethod(MetaMethod metaMethod) { return SET_PROPERTY_METHOD.equals(metaMethod.getName()) && metaMethod.getParameterTypes().length == 2; }
private static boolean isInvokeMethod(MetaMethod metaMethod) { return INVOKE_METHOD_METHOD.equals(metaMethod.getName()) && metaMethod.getParameterTypes().length == 2; }
private static boolean isGenericGetMethod(MetaMethod method) { if (method.getName().equals("get")) { CachedClass[] parameterTypes = method.getParameterTypes(); return parameterTypes.length == 1 && parameterTypes[0].getTheClass() == String.class; } return false; }
/** *Returns true if this this metamethod represents the same method as the argument. * * @param method A metaMethod instance * @return true if method is for the same method as this method, false otherwise. */ public boolean isMethod(MetaMethod method) { return getName().equals(method.getName()) && getModifiers() == method.getModifiers() && getReturnType().equals(method.getReturnType()) && equal(getParameterTypes(), method.getParameterTypes()); }
public void registerSubclassInstanceMethod(MetaMethod metaMethod) { modified = true; final String name = metaMethod.getName(); Object methodOrList = expandoSubclassMethods.get(name); if (methodOrList == null) { expandoSubclassMethods.put(name, metaMethod); } else { if (methodOrList instanceof MetaMethod) { FastArray arr = new FastArray(2); arr.add(methodOrList); arr.add(metaMethod); expandoSubclassMethods.put(name, arr); } else { ((FastArray) methodOrList).add(metaMethod); } } }
/** * @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()); }
public String getMopName() { if (mopName == null) { String name = getName(); CachedClass declaringClass = getDeclaringClass(); if (Modifier.isPrivate(getModifiers())) mopName = "this$" + declaringClass.getSuperClassDistance() + "$" + name; else mopName = "super$" + declaringClass.getSuperClassDistance() + "$" + name; } return mopName; }
public void call() { Class type = newValue == null ? Object.class : newValue.getClass(); MetaBeanProperty mbp = newValue instanceof MetaBeanProperty ? (MetaBeanProperty) newValue : new ThreadManagedMetaBeanProperty(theClass, property, type, newValue); final MetaMethod getter = mbp.getGetter(); final MethodKey getterKey = new DefaultCachedMethodKey(theClass, getter.getName(), CachedClass.EMPTY_ARRAY, false); final MetaMethod setter = mbp.getSetter(); final MethodKey setterKey = new DefaultCachedMethodKey(theClass, setter.getName(), setter.getParameterTypes(), false); addMetaMethod(getter); addMetaMethod(setter); expandoMethods.put(setterKey, setter); expandoMethods.put(getterKey, getter); expandoProperties.put(mbp.getName(), mbp); addMetaBeanProperty(mbp); performRegistryCallbacks(); }
/** * Returns a string representation of this method */ public String toString() { return super.toString() + "[name: " + getName() + " params: " + InvokerHelper.toString(getParameterTypes()) + " returns: " + getReturnType() + " owner: " + getDeclaringClass() + "]"; }
/** * Checks that the given parameters are valid to call this method * * @param arguments the arguments to check * @throws IllegalArgumentException if the parameters are not valid */ public void checkParameters(Class[] arguments) { // lets check that the argument types are valid if (!isValidMethod(arguments)) { throw new IllegalArgumentException( "Parameters to method: " + getName() + " do not match types: " + InvokerHelper.toString(getParameterTypes()) + " for arguments: " + InvokerHelper.toString(arguments)); } }
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()); } }
private void addMethodWithKey(final MetaMethod metaMethodFromSuper) { inheritedMetaMethods.add(metaMethodFromSuper); if (metaMethodFromSuper instanceof ClosureMetaMethod) { ClosureMetaMethod closureMethod = (ClosureMetaMethod)metaMethodFromSuper; String name = metaMethodFromSuper.getName(); final Class declaringClass = metaMethodFromSuper.getDeclaringClass().getTheClass(); ClosureMetaMethod localMethod = ClosureMetaMethod.copy(closureMethod); addMetaMethod(localMethod); MethodKey key = new DefaultCachedMethodKey(declaringClass, name, localMethod.getParameterTypes(), false); checkIfGroovyObjectMethod(localMethod); expandoMethods.put(key, localMethod); } } });
public void testMetaMethodsOnlyAddedOnce() { MetaClass metaClass = InvokerHelper.getMetaClass("some String"); List methods = metaClass.getMetaMethods(); for (Iterator iter = methods.iterator(); iter.hasNext();) { MetaMethod method = (MetaMethod) iter.next(); int count = 0; for (Iterator inner = methods.iterator(); inner.hasNext();) { MetaMethod runner = (MetaMethod) inner.next(); if (method.equals(runner)) { System.out.println("runner = " + runner); System.out.println("method = " + method); count++; } } assertEquals("count of Method " + method.getName(), 1, count); } }
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 RankableMethod(String name, Class[] argumentTypes, MetaMethod m2) { this.m = m2; int nameDist = delDistance(name, m2.getName()); //unbox primitives Class[] mArgs = new Class[m2.getParameterTypes().length]; for(int i =0; i < mArgs.length; i++){ //All args have to be boxed since argumentTypes is always boxed mArgs[i] = boxVar(m2.getParameterTypes()[i].getTheClass()); } int argDist = damerauLevenshteinDistance(argumentTypes,mArgs); this.score = nameDist + argDist; }
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); }