if (!method.isStatic() || !method.isPublic()) continue; if (method.getCachedMethod().getAnnotation(Deprecated.class) != null) continue; if (method.getParameterTypes().length == 0) continue; final Class returnType = method.getReturnType(); records.add(record); record.methodName = method.getName(); record.returnType = method.getReturnType(); record.parameters = method.getNativeParameterTypes(); record.className = className; final String methodDescriptor = BytecodeHelper.getMethodDescriptor(returnType, method.getNativeParameterTypes());
List<CachedMethod> mopMethods = new ArrayList<CachedMethod>(declaredMethods.length); for (int i = 0; i != declaredMethods.length; ++i) { final CachedMethod cachedMethod = new CachedMethod(CachedClass.this, declaredMethods[i]); final String name = cachedMethod.getName();
CachedMethod cachedGetter = CachedMethod.find(method); getter = cachedGetter == null ? null : findMethod(cachedGetter); } else { method = pd.getWriteMethod(); if (method != null) { CachedMethod cachedSetter = CachedMethod.find(method); setter = cachedSetter == null ? null : findMethod(cachedSetter); } else {
public int compareTo(Object o) { if (o instanceof CachedMethod) return compareToCachedMethod((CachedMethod)o); else return compareToMethod((Method)o); }
public String getSignature() { return getName() + getDescriptor(); }
protected Object noSuchMethod(CachedMethod method, Object object, Object[] arguments) { throw new MissingMethodException(method.getName(), method.getDeclaringClass().getTheClass(), arguments, false); } }
Class callClass = cachedMethod.getDeclaringClass().getTheClass(); boolean useInterface = callClass.isInterface(); String descriptor = BytecodeHelper.getMethodDescriptor(cachedMethod.getReturnType(), cachedMethod.getNativeParameterTypes()); if (cachedMethod.isStatic()) { invokeMethodCode = Opcodes.INVOKESTATIC; } else { Method method = cachedMethod.setAccessible(); Class<?>[] parameters = method.getParameterTypes(); int size = parameters.length; mv.visitMethodInsn(invokeMethodCode, type, cachedMethod.getName(), descriptor, useInterface); BytecodeHelper.box(mv, cachedMethod.getReturnType()); if (cachedMethod.getReturnType() == void.class) { mv.visitInsn(Opcodes.ACONST_NULL);
for (int i = 0, cur = 0; i < cachedMethods.length; i++) { CachedMethod method = cachedMethods[i]; if (!method.isStatic() || !method.isPublic()) continue; if (method.getParameterTypes().length == 0) continue; final Class returnType = method.getReturnType(); final String methodDescriptor = BytecodeHelper.getMethodDescriptor(returnType, method.getNativeParameterTypes()); mv.visitCode(); mv.visitVarInsn(ALOAD,1); helper.doCast(method.getParameterTypes()[0].getTheClass()); loadParameters(method,2,mv); mv.visitMethodInsn(INVOKESTATIC, "org/codehaus/groovy/runtime/DefaultGroovyMethods", method.getName(), methodDescriptor); helper.box(returnType); if (method.getReturnType() == void.class) { mv.visitInsn(ACONST_NULL); helper = new BytecodeHelper(mv); mv.visitCode(); if (method.getParamsCount() == 2 && method.getParameterTypes()[0].isNumber && method.getParameterTypes()[1].isNumber) { mv.visitVarInsn(ALOAD,1); helper.doCast(method.getParameterTypes()[0].getTheClass()); Class type = method.getParameterTypes()[1].getTheClass(); if (type.isPrimitive()) { helper.unbox(type);
private int compareToCachedMethod(CachedMethod other) { if (other == null) return -1; final int strComp = getName().compareTo(other.getName()); if (strComp != 0) return strComp; final int retComp = getReturnType().getName().compareTo(other.getReturnType().getName()); if (retComp != 0) return retComp; CachedClass[] params = getParameterTypes(); CachedClass[] otherParams = other.getParameterTypes(); final int pd = params.length - otherParams.length; if (pd != 0) return pd; for (int i = 0; i != params.length; ++i) { final int nameComp = params[i].getName().compareTo(otherParams[i].getName()); if (nameComp != 0) return nameComp; } final int classComp = cachedClass.toString().compareTo(other.getDeclaringClass().toString()); if (classComp != 0) return classComp; throw new RuntimeException("Should never happen"); }
private void applyUse(CachedClass cachedClass) { CachedMethod[] methods = cachedClass.getMethods(); for (CachedMethod cachedMethod : methods) { if (cachedMethod.isStatic() && cachedMethod.isPublic()) { CachedClass[] paramTypes = cachedMethod.getParameterTypes(); if (paramTypes.length > 0) { CachedClass metaClass = paramTypes[0]; CategoryMethod mmethod = new CategoryMethod(cachedMethod, metaClass.getTheClass()); final String name = cachedMethod.getName(); CategoryMethodList list = get(name); if (list == null || list.level != level) { list = new CategoryMethodList(name, level, list); put(name, list); } list.add(mmethod); Collections.sort(list); cachePropertyAccessor(mmethod); } } } }
public static Constructor compilePogoMethod(CachedMethod cachedMethod) { ClassWriter cw = makeClassWriter(); final CachedClass declClass = cachedMethod.getDeclaringClass(); final CallSiteClassLoader callSiteLoader = declClass.getCallSiteLoader(); final String name = callSiteLoader.createClassName(cachedMethod.setAccessible()); final byte[] bytes = genPogoMetaMethodSite(cachedMethod, cw, name); return callSiteLoader.defineClassAndGetConstructor(name, bytes); }
private static boolean hasAnnotation(CachedMethod method, Class<Internal> annotationClass) { return method.getCachedMethod().getAnnotation(annotationClass) != null; }
final int mod = method.getModifiers(); if (Modifier.isStatic(mod) && Modifier.isPublic(mod) && method.getCachedMethod().getAnnotation(Deprecated.class) == null) { CachedClass[] paramTypes = method.getParameterTypes(); if (paramTypes.length > 0) { List<MetaMethod> arr = map.get(paramTypes[0]);
private static void createMetaMethods(final Class extensionClass, final List<MetaMethod> metaMethods, final boolean isStatic) { CachedClass cachedClass = ReflectionCache.getCachedClass(extensionClass); CachedMethod[] methods = cachedClass.getMethods(); for (CachedMethod method : methods) { if (method.isStatic() && method.isPublic() && method.getParamsCount() > 0) { // an extension method is found metaMethods.add(isStatic?new NewStaticMetaMethod(method) : new NewInstanceMetaMethod(method)); } } }
if(getter instanceof CachedMethod) { CachedMethod cm = (CachedMethod)getter; ModelSkip skipAnn = cm.getCachedMethod().getAnnotation(ModelSkip.class); if(skipAnn!=null) { continue; if(cm.isStatic()){ continue; if(!cm.getCachedMethod().getDeclaringClass().equals(c)) { Method override = c.getDeclaredMethod(cm.getCachedMethod().getName(), cm.getCachedMethod().getParameterTypes()); if(override.getAnnotation(ModelSkip.class) !=null) { continue;
public PogoCachedMethodSite(CallSite site, MetaClassImpl metaClass, CachedMethod metaMethod, Class[] params) { super(site, metaClass, metaMethod, params); reflect = metaMethod.setAccessible(); }
static void doIt () { new A ().protectedMethod(); try { CachedMethod m = CachedMethod.find(A.class.getDeclaredMethod("protectedMethod", new Class [0] )); Object[] arguments = new Object[0]; m.setAccessible().invoke(new A(), arguments); } catch (NoSuchMethodException e) { } catch (IllegalAccessException e) { } catch (InvocationTargetException e) { } } }
public int compare(Object o1, Object o2) { if (o1 instanceof CachedMethod) return ((CachedMethod)o1).compareTo(o2); else if (o2 instanceof CachedMethod) return -((CachedMethod)o2).compareTo(o1); else // really, this should never happen, it's evidence of corruption if it does throw new ClassCastException("One of the two comparables must be a CachedMethod"); } }
/** * Delegated to from the global use(CategoryClass) method. It scans the Category class for static methods * that take 1 or more parameters. The first parameter is the class you are adding the category method to, * additional parameters are those parameters needed by that method. A use statement cannot be undone and * is valid only for the current thread. * * @param categoryClass the class containing category methods */ private static void use(Class categoryClass) { Map properties = getProperties(); List stack = (List) LOCAL.get(); LinkedList clonedLists = new LinkedList(); Method[] methods = categoryClass.getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (Modifier.isStatic(method.getModifiers())) { final CachedMethod cachedMethod = CachedMethod.find(method); CachedClass[] paramTypes = cachedMethod.getParameterTypes(); if (paramTypes.length > 0) { CachedClass metaClass = paramTypes[0]; Map metaMethodsMap = getMetaMethods(properties, metaClass.getTheClass()); List methodList = getMethodList(metaMethodsMap, method.getName()); MetaMethod mmethod = new CategoryMethod(cachedMethod, metaClass.getTheClass()); methodList.add(mmethod); Collections.sort(methodList); } } } }
if (LOG_ENABLED) LOG.info("meta method is CachedMethod instance"); CachedMethod cm = (CachedMethod) metaMethod; isVargs = cm.isVargsMethod(); try { Method m = cm.getCachedMethod(); handle = correctClassForNameAndUnReflectOtherwise(m); if (LOG_ENABLED) LOG.info("successfully unreflected method");