protected String methodDescription(CtMethod method) { return method.getDeclaringClass().getName() + "|" + method.getName() + "|" + method.getSignature(); }
/* 66: */ /* 67: */ private boolean matchClass(String name, ClassPool pool) /* 68: */ { /* 69: 84 */ if (this.classname.equals(name)) { /* 70: 85 */ return true; /* 71: */ } /* 72: */ try /* 73: */ { /* 74: 88 */ CtClass clazz = pool.get(name); /* 75: 89 */ CtClass declClazz = pool.get(this.classname); /* 76: 90 */ if (clazz.subtypeOf(declClazz)) { /* 77: */ try /* 78: */ { /* 79: 92 */ CtMethod m = clazz.getMethod(this.methodname, this.methodDescriptor); /* 80: 93 */ return m.getDeclaringClass().getName().equals(this.classname); /* 81: */ } /* 82: */ catch (NotFoundException e) /* 83: */ { /* 84: 97 */ return true; /* 85: */ } /* 86: */ } /* 87: */ } /* 88: */ catch (NotFoundException e) /* 89: */ { /* 90:101 */ return false; /* 91: */ } /* 92:104 */ return false; /* 93: */ }
private static CtMember getMemberForAnnotatedInterfaceMethod(CtMethod member) throws InvalidComponentClassException, ClassNotFoundException, NotFoundException { CtMethod newMember = null; List<CtClass> interfaces = new ArrayList<CtClass>(); CtClass clazz = member.getDeclaringClass(); while (clazz != null) { interfaces.addAll(Arrays.asList(clazz.getInterfaces())); clazz = clazz.getSuperclass(); } for (CtClass ctclass : interfaces) { try { CtMethod newMethodMember = ctclass.getDeclaredMethod(member.getName(), member.getParameterTypes()); DialogField tempDialogProperty = (DialogField) newMethodMember.getAnnotation(DialogField.class); if (tempDialogProperty != null) { if (newMember == null) { newMember = newMethodMember; } else { throw new InvalidComponentClassException( "Class has multiple interfaces that have the same method signature annotated"); } } } catch (NotFoundException e) { } } if (newMember != null) { member = newMember; } return newMember; }
public static DialogFieldConfig getDialogFieldFromSuperClasses(CtMethod method) throws NotFoundException, ClassNotFoundException, InvalidComponentClassException { DialogFieldConfig dialogFieldConfig = null; List<CtClass> classes = new ArrayList<CtClass>(); CtClass clazz = method.getDeclaringClass(); classes.add(clazz); while (clazz.getSuperclass() != null) { classes.add(clazz.getSuperclass()); clazz = clazz.getSuperclass(); } Collections.reverse(classes); CtMember interfaceMember = getMemberForAnnotatedInterfaceMethod(method); if (interfaceMember != null) { dialogFieldConfig = new DialogFieldConfig( (DialogField) interfaceMember.getAnnotation(DialogField.class), interfaceMember); } for (CtClass ctclass : classes) { try { CtMethod superClassMethod = ctclass.getDeclaredMethod(method.getName(), method.getParameterTypes()); if (superClassMethod.hasAnnotation(DialogField.class)) { dialogFieldConfig = new DialogFieldConfig( (DialogField) superClassMethod.getAnnotation(DialogField.class), superClassMethod); } else if (superClassMethod.hasAnnotation(DialogFieldOverride.class)) { mergeDialogFields(dialogFieldConfig, superClassMethod); } } catch (NotFoundException e) { } } return dialogFieldConfig; }
public String getNewBody(CtMethod m) throws Exception { CtMethod patchMethod = findPatchMethod(m); if (patchMethod == null) { return null; } processedMethods.add(patchMethod); // construction of the redirection code StringBuilder buffer = new StringBuilder(); buffer.append("{"); buffer.append("return "); buffer.append(patchMethod.getDeclaringClass().getName() + "." + patchMethod.getName()); buffer.append("("); boolean append = false; if (!Modifier.isStatic(m.getModifiers())) { buffer.append("this"); append = true; } for (int i = 0; i < m.getParameterTypes().length; i++) { if (append) { buffer.append(", "); } int j = i + 1; buffer.append("$" + j); append = true; } buffer.append(");"); buffer.append("}"); return buffer.toString(); }
// throws NotFoundException if fails to get names // (for example when class of method argument type has not been loaded by class loader) private String generateMethodKey(CtMethod method) throws NotFoundException { String classQualifiedName = method.getDeclaringClass().getName(); String methodSimpleName = method.getName(); List<String> argClassQualifiedNames = getArgClassQualifiedNames(method); return TestMethod.generateMethodKey( classQualifiedName, methodSimpleName, argClassQualifiedNames); }
/* 31: */ /* 32: */ public TransformCall(Transformer next, String oldMethodName, CtMethod substMethod) /* 33: */ { /* 34: 44 */ super(next); /* 35: 45 */ this.methodname = oldMethodName; /* 36: 46 */ this.methodDescriptor = substMethod.getMethodInfo2().getDescriptor(); /* 37: 47 */ this.classname = (this.newClassname = substMethod.getDeclaringClass().getName()); /* 38: 48 */ this.newMethodname = substMethod.getName(); /* 39: 49 */ this.constPool = null; /* 40: 50 */ this.newMethodIsPrivate = Modifier.isPrivate(substMethod.getModifiers()); /* 41: */ }
/** * Creates a new static class field, for the declaring class of the callee method. * * @param ctClass the class * @param ctMethod the method * @return the name of the field */ private String addCalleeMethodDeclaringClassField(final CtClass ctClass, final CtMethod ctMethod) throws NotFoundException, CannotCompileException { String fieldName = TransformationUtil.STATIC_CLASS_FIELD + TransformationUtil.DELIMITER + "method" + TransformationUtil.DELIMITER + ctMethod.getDeclaringClass().getName().replace('.', '_'); boolean hasField = false; CtField[] fields = ctClass.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { CtField field = fields[i]; if (field.getName().equals(fieldName)) { hasField = true; break; } } if (!hasField) { CtField field = new CtField(ctClass.getClassPool().get("java.lang.Class"), fieldName, ctClass); field.setModifiers(Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL); ctClass.addField( field, "java.lang.Class#forName(\"" + ctMethod.getDeclaringClass().getName().replace('/', '.') + "\")"); } return fieldName; }
public void initClass(CtClass c) throws Exception { if (initMethod == null) { return; } Class<?> clazz = Class.forName(initMethod.getDeclaringClass().getName()); Method compiledMethod = clazz.getDeclaredMethod(initMethod.getName(), CtClass.class); // TODO : this should not be mandatory since AutomaticPatcher set every // initMethod to public when loaded by GwtClassLoader GwtReflectionUtils.makeAccessible(compiledMethod); try { compiledMethod.invoke(null, c); } catch (InvocationTargetException e) { if (Exception.class.isInstance(e)) { throw (Exception) e.getCause(); } else { throw e; } } }
private boolean hasCompatibleSignature(CtMethod methodFound, CtMethod patchMethod) throws Exception { CtClass[] methodFoundParams = methodFound.getParameterTypes(); CtClass[] patchMethodParams = patchMethod.getParameterTypes(); boolean compat = hasSameSignature(patchMethodParams, methodFoundParams); // account for the case where the method is non static in the original class // and we need to pass the object into the static patching method if (!compat && patchMethodParams.length >= 1 && methodFound.getDeclaringClass().subtypeOf(patchMethodParams[0])) { CtClass[] classesWithoutThis = new CtClass[patchMethodParams.length - 1]; for (int i = 1; i < patchMethodParams.length; i++) { classesWithoutThis[i - 1] = patchMethodParams[i]; } compat = hasSameSignature(classesWithoutThis, methodFoundParams); } return compat; }
private List<Pair<CtMethod, TestMethod>> allMethodsSub(TestMethodTable table, CtClass ctClass) { CtMethod[] allMethods = ctClass.getMethods(); List<Pair<CtMethod, TestMethod>> result = new ArrayList<Pair<CtMethod, TestMethod>>(allMethods.length); for (CtMethod ctMethod : allMethods) { if (!ctMethod.getDeclaringClass().getName().equals(ctClass.getName())) { // methods defined on superclass are also included in the result list of // CtClass.getMethods, so exclude such methods continue; } try { TestMethod testMethod = table.getByKey(generateMethodKey(ctMethod)); if (testMethod != null) { result.add(Pair.of(ctMethod, testMethod)); } } catch (NotFoundException e) { // just ignore this method logger.log(Level.INFO, "ignore exceptin for " + ctMethod.getLongName(), e); } } return result; }
/* 25: */ /* 26: */ public TransformCall(Transformer next, CtMethod origMethod, CtMethod substMethod) /* 27: */ { /* 28: 37 */ this(next, origMethod.getName(), substMethod); /* 29: 38 */ this.classname = origMethod.getDeclaringClass().getName(); /* 30: */ }