Refine search
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); }
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()); } } } }
public final Object[] coerceArgumentsToClasses(Object[] argumentArray) { // Uncomment if at some point this method can be called before parameterTypes initialized // getParameterTypes(); argumentArray = correctArguments(argumentArray); final CachedClass[] pt = parameterTypes; final int len = argumentArray.length; for (int i = 0; i < len; i++) { final Object argument = argumentArray[i]; if (argument != null) { argumentArray[i] = pt[i].coerceArgument(argument); } } return argumentArray; }
public LinkedList<ClassInfo> initValue() { Set<ClassInfo> res = new LinkedHashSet<ClassInfo> (); res.add(classInfo); for (CachedClass iface : getDeclaredInterfaces()) res.addAll(iface.getHierarchy()); final CachedClass superClass = getCachedSuperClass(); if (superClass != null) res.addAll(superClass.getHierarchy()); if (isInterface) res.add(ReflectionCache.OBJECT_CLASS.classInfo); return new LinkedList<ClassInfo> (res); } };
public Set<CachedClass> initValue() { Set<CachedClass> res = new HashSet<CachedClass> (0); if (getTheClass().isInterface()) res.add(CachedClass.this); Class[] classes = getTheClass().getInterfaces(); for (Class cls : classes) { final CachedClass aClass = ReflectionCache.getCachedClass(cls); if (!res.contains(aClass)) res.addAll(aClass.getInterfaces()); } final CachedClass superClass = getCachedSuperClass(); if (superClass != null) res.addAll(superClass.getInterfaces()); return res; } };
public MetaMethodIndex(CachedClass theCachedClass) { init(DEFAULT_CAPACITY); CachedClass last = null; if (!theCachedClass.isInterface()) { for (CachedClass c = theCachedClass; c != null; c = c.getCachedSuperClass()) { final SingleKeyHashMap.Entry e = methodHeaders.getOrPut(c.getTheClass()); e.value = new Header (c.getTheClass(), last == null ? null : last.getTheClass()); last = c; } } else { final SingleKeyHashMap.Entry e = methodHeaders.getOrPut(Object.class); e.value = new Header (Object.class, theCachedClass.getTheClass()); } }
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 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()); } }
for (MetaProperty prop : cachedCategoryClass.getFields()) if (self.getMetaProperty(prop.getName()) == null) { mc.registerBeanProperty(prop.getName(), new MixinInstanceMetaProperty(prop, mixin)); 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 list; } else { if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface() && !method.isStatic())) { return method; } else if (!methodC.isAssignableFrom(matchC.getTheClass())) { return method; if (match.isPrivate() || (!isNonRealMethod(match) && match.getDeclaringClass().isInterface() && !method.getDeclaringClass().isInterface() && !method.isStatic())) { list.set(found, method); } else if (!methodC.isAssignableFrom(matchC.getTheClass())) { list.set(found, method);
private static MetaMethod getCategoryMethodMissing(Class sender) { List possibleGenericMethods = GroovyCategorySupport.getCategoryMethods("methodMissing"); if (possibleGenericMethods != null) { for (Iterator iter = possibleGenericMethods.iterator(); iter.hasNext();) { MetaMethod mmethod = (MetaMethod) iter.next(); if (!mmethod.getDeclaringClass().getTheClass().isAssignableFrom(sender)) continue; CachedClass[] paramTypes = mmethod.getParameterTypes(); if (paramTypes.length == 2 && paramTypes[0].getTheClass() == String.class) { return mmethod; } } } return null; }
/** * 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; }
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; }
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); } } });
private static boolean isValidVarargsMethod(Class[] arguments, int size, CachedClass[] pt, int paramMinus1) { // first check normal number of parameters for (int i = 0; i < paramMinus1; i++) { if (pt[i].isAssignableFrom(arguments[i])) continue; return false; } // check direct match CachedClass varg = pt[paramMinus1]; Class clazz = varg.getTheClass().getComponentType(); if (size == pt.length && (varg.isAssignableFrom(arguments[paramMinus1]) || testComponentAssignable(clazz, arguments[paramMinus1]))) { return true; } // check varged for (int i = paramMinus1; i < size; i++) { if (MetaClassHelper.isAssignableFrom(clazz, arguments[i])) continue; return false; } return true; }
if (parameter.getTheClass() == argument) return 0; if (parameter.isInterface()) { int dist = getMaximumInterfaceDistance(argument, parameter.getTheClass()) << INTERFACE_SHIFT; if (dist>-1 || !(argument!=null && Closure.class.isAssignableFrom(argument))) { return dist; long pd = getPrimitiveDistance(parameter.getTheClass(), argument); if (pd != -1) return pd << PRIMITIVE_SHIFT; if (clazz == parameter.getTheClass()) break; if (clazz == GString.class && parameter.getTheClass() == String.class) { objectDistance += 2; break; Class clazz = parameter.getTheClass(); if (clazz.isPrimitive()) { objectDistance += 2;
private static MetaMethod findSubClassMethod(Class instanceKlazz, Class[] arguments, MetaMethod method, MetaMethod m) { if (m.getDeclaringClass().getTheClass().isAssignableFrom(instanceKlazz)) { if (m.isValidExactMethod(arguments)) { if (method == null) method = m; else { method = mostSpecific (method, m, instanceKlazz); } } } return method; }
private MethodSignature getSignature(MetaMethod method) { String[] parameters = new String[method.getParameterTypes().length]; for (int i = 0; i < parameters.length; i++) { parameters[i] = Utilities.translateClassLoaderTypeName(method.getParameterTypes()[i].getName()); } return new MethodSignature(method.getName(), parameters); }
MetaClass metaClass = mixinClass.classInfo.getMetaClassForClass(); if (metaClass == null) { metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(mixinClass.getTheClass()); if (metaMethod == null && metaClass instanceof MetaClassImpl) { MetaClassImpl mc = (MetaClassImpl) metaClass; for (CachedClass cl = mc.getTheCachedClass().getCachedSuperClass(); cl != null; cl = cl.getCachedSuperClass()) { metaMethod = mc.getMethodWithoutCaching(cl.getTheClass(), methodName, arguments, false); if (metaMethod != null) break; MetaMethod method = new MixinInstanceMetaMethod(metaMethod, mixin); if (method.getParameterTypes().length == 1 && !method.getParameterTypes()[0].isPrimitive) { MetaMethod noParam = pickMethod(methodName, EMPTY_CLASS_ARRAY);
private static MetaMethod mostSpecific(MetaMethod method, MetaMethod newMethod, Class instanceKlazz) { Class newMethodC = newMethod.getDeclaringClass().getTheClass(); Class methodC = method.getDeclaringClass().getTheClass(); if (!newMethodC.isAssignableFrom(instanceKlazz)) return method; if (newMethodC == methodC) return newMethod; if (newMethodC.isAssignableFrom(methodC)) { return method; } if (methodC.isAssignableFrom(newMethodC)) { return newMethod; } return newMethod; }