public Class getParameterType(int index) { CachedClass c = parameterTypes[index]; if (c==null) return Object.class; return c.getTheClass(); } }
protected static boolean equal(CachedClass[] a, Class[] b) { if (a.length == b.length) { for (int i = 0, size = a.length; i < size; i++) { if (!a[i].getTheClass().equals(b[i])) { return false; } } return true; } return false; }
public int getSuperClassDistance() { if (distance>=0) return distance; int distance = 0; for (Class klazz= getTheClass(); klazz != null; klazz = klazz.getSuperclass()) { distance++; } this.distance = distance; return distance; }
public Set<CachedClass> initValue() { Set<CachedClass> res = new HashSet<CachedClass> (0); Class[] classes = getTheClass().getInterfaces(); for (Class cls : classes) { res.add(ReflectionCache.getCachedClass(cls)); } return res; } };
public CachedClass initValue() { if (!isArray) return ReflectionCache.getCachedClass(getTheClass().getSuperclass()); else if (cachedClass.getComponentType().isPrimitive() || cachedClass.getComponentType() == Object.class) return ReflectionCache.OBJECT_CLASS; else return ReflectionCache.OBJECT_ARRAY_CLASS; } };
private synchronized void getNativeParameterTypes0() { if (nativeParamTypes != null) return; Class[] npt; if (parameterTypes != null) { npt = new Class[parameterTypes.length]; for (int i = 0; i != parameterTypes.length; ++i) { npt[i] = parameterTypes[i].getTheClass(); } } else npt = getPT(); nativeParamTypes = npt; }
private void updateAddNewMopMethods(List<MetaMethod> arr) { List<MetaMethod> res = new ArrayList<MetaMethod>(); res.addAll(Arrays.asList(classInfo.newMetaMethods)); res.addAll(arr); classInfo.newMetaMethods = res.toArray(MetaMethod.EMPTY_ARRAY); Class theClass = classInfo.getCachedClass().getTheClass(); if (theClass==Closure.class || theClass==Class.class) { ClosureMetaClass.resetCachedMetaClasses(); } }
public void putAt(Class key, Object value) { for (MixinInMetaClass mixin : mixinClasses) if (mixin.getMixinClass().getTheClass() == key) { mixin.setMixinInstance(object, value); return; } throw new RuntimeException("Class " + key + " isn't mixed in " + object.getClass()); } }
public Object castToMixedType(Object obj, Class type) { for (MixinInMetaClass mixin : mixinClasses) { if (type.isAssignableFrom(mixin.getMixinClass().getTheClass())) return mixin.getMixinInstance(obj); } return null; }
private void use(Class categoryClass) { CachedClass cachedClass = ReflectionCache.getCachedClass(categoryClass); LinkedList<CachedClass> classStack = new LinkedList<CachedClass>(); for (CachedClass superClass = cachedClass; superClass.getTheClass()!=Object.class; superClass = superClass.getCachedSuperClass()) { classStack.add(superClass); } while (!classStack.isEmpty()) { CachedClass klazz = classStack.removeLast(); applyUse(klazz); } }
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; }
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 static boolean packageLocal(CachedField mfp, CachedClass klass) { if (klass == null) return false; return isDefaultVisibility(mfp.getModifiers()) && inSamePackage(mfp.field.getDeclaringClass(), klass.getTheClass()); }
protected Object noSuchMethod(CachedMethod method, Object object, Object[] arguments) { throw new MissingMethodException(method.getName(), method.getDeclaringClass().getTheClass(), arguments, false); } }
/** *Adds an instance method to this metaclass. * * @param method The method to be added */ public void addNewInstanceMethod(Method method) { final CachedMethod cachedMethod = CachedMethod.find(method); NewInstanceMetaMethod newMethod = new NewInstanceMetaMethod(cachedMethod); final CachedClass declaringClass = newMethod.getDeclaringClass(); addNewInstanceMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass())); }
/** *Adds a static method to this metaclass. * * @param method The method to be added */ public void addNewStaticMethod(Method method) { final CachedMethod cachedMethod = CachedMethod.find(method); NewStaticMetaMethod newMethod = new NewStaticMetaMethod(cachedMethod); final CachedClass declaringClass = newMethod.getDeclaringClass(); addNewStaticMethodToIndex(newMethod, metaMethodIndex.getHeader(declaringClass.getTheClass())); }
public static ClosureMetaMethod copy(ClosureMetaMethod closureMethod) { if (closureMethod instanceof MethodClosureMetaMethod) return new MethodClosureMetaMethod(closureMethod.getName(), closureMethod.getDeclaringClass().getTheClass(), closureMethod.getClosure(), closureMethod.getDoCall()); else return new ClosureMetaMethod(closureMethod.getName(), closureMethod.getDeclaringClass().getTheClass(), closureMethod.getClosure(), closureMethod.getDoCall()); }
public CallSite createConstructorSite(CallSite site, Object[] args) { Class[] params = MetaClassHelper.convertToTypeArray(args); MetaMethod method = pickMethod(GROOVY_CONSTRUCTOR, params); if (method != null && method.getParameterTypes().length == args.length) { if (method.getDeclaringClass().getTheClass().equals(getTheClass())) { return new ConstructorMetaMethodSite(site, this, method, params); } } return super.createConstructorSite(site, args); }
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); }