use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class ListWrapperPatcher method initClass.
@InitMethod
static void initClass(CtClass c) throws CannotCompileException, NotFoundException {
CtMethod flushMethod = c.getDeclaredMethod("flush");
flushMethod.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();");
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method findPatchMethod.
private CtMethod findPatchMethod(CtMethod m) throws Exception {
for (CtMethod patchMethod : patchMethods) {
PatchMethod annotation = (PatchMethod) patchMethod.getAnnotation(PatchMethod.class);
String methodName = (annotation.value().length() > 0) ? annotation.value() : patchMethod.getName();
if (m.getName().equals(methodName) && hasCompatibleSignature(m, patchMethod)) {
return patchMethod;
}
}
return null;
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getInitMethod.
private CtMethod getInitMethod(Set<CtClass> patchClasses) {
List<CtMethod> initMethods = new ArrayList<CtMethod>();
for (CtClass patchClass : patchClasses) {
for (CtMethod ctMethod : patchClass.getDeclaredMethods()) {
if (ctMethod.hasAnnotation(InitMethod.class)) {
if (!Modifier.isStatic(ctMethod.getModifiers())) {
throw new GwtTestPatchException("@" + InitMethod.class.getSimpleName() + " has to be static : '" + ctMethod.getLongName() + "'");
}
try {
if (ctMethod.getParameterTypes().length != 1 || ctMethod.getParameterTypes()[0] != GwtClassPool.getCtClass(CtClass.class)) {
throw new GwtTestPatchException("@" + InitMethod.class.getName() + " method must have one and only one parameter of type '" + CtClass.class.getName() + "'");
}
} catch (NotFoundException e) {
// should never happen
throw new GwtTestPatchException(e);
}
initMethods.add(ctMethod);
}
}
}
CtMethod initMethod = getMethodToUse(initMethods, InitMethod.class);
if (initMethod != null) {
initMethod.setModifiers(Modifier.PUBLIC + Modifier.STATIC);
}
return initMethod;
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class AutomaticPatcher method getNewBody.
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();
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class DirectoryTestReader method initTestMethods.
private void initTestMethods(Class<?> clazz, CsvDirectory csvDirectory) throws Exception {
testMethods = new ArrayList<Method>();
CtClass newClazz = GwtClassPool.get().makeClass(clazz.getName() + ".generated" + System.nanoTime());
newClazz.setSuperclass(GwtClassPool.getCtClass(clazz));
List<String> methodList = new ArrayList<String>();
for (Entry<String, List<List<String>>> entry : tests.entrySet()) {
String fileAbsolutePath = entry.getKey();
String methodName = getTestName(fileAbsolutePath, csvDirectory.extension());
CtMethod m = new CtMethod(CtClass.voidType, methodName, new CtClass[0], newClazz);
methodList.add(methodName);
m.setBody("launchTest(\"" + StringEscapeUtils.escapeJava(fileAbsolutePath) + "\");");
newClazz.addMethod(m);
}
generatedClazz = newClazz.toClass(getClass().getClassLoader(), null);
for (String methodName : methodList) {
Method m = generatedClazz.getMethod(methodName);
testMethods.add(m);
}
}
Aggregations