Search in sources :

Example 6 with InitMethod

use of com.googlecode.gwt.test.patchers.InitMethod in project gwt-test-utils by gwt-test-utils.

the class AutomaticPatcher method initClass.

public void initClass(CtClass c) throws Exception {
    if (initMethod == null) {
        return;
    }
    Class<?> clazz = GwtReflectionUtils.getClass(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;
        }
    }
}
Also used : CtMethod(javassist.CtMethod) PatchMethod(com.googlecode.gwt.test.patchers.PatchMethod) InitMethod(com.googlecode.gwt.test.patchers.InitMethod) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NotFoundException(javassist.NotFoundException) GwtTestPatchException(com.googlecode.gwt.test.exceptions.GwtTestPatchException)

Example 7 with InitMethod

use of com.googlecode.gwt.test.patchers.InitMethod in project gwt-test-utils by gwt-test-utils.

the class AbstractRemoteServiceServletPatcher method addMockedGetServletConfigMethod.

@InitMethod
static void addMockedGetServletConfigMethod(CtClass c) throws CannotCompileException {
    StringBuilder sb = new StringBuilder();
    sb.append("public javax.servlet.ServletConfig getServletConfig() { return ");
    sb.append(AbstractRemoteServiceServletPatcher.class.getName()).append(".ensureServletMockProvider(this, \"getServletConfig()\").getMockedConfig(this); }");
    CtMethod m = CtMethod.make(sb.toString(), c);
    c.addMethod(m);
}
Also used : CtMethod(javassist.CtMethod) InitMethod(com.googlecode.gwt.test.patchers.InitMethod)

Example 8 with InitMethod

use of com.googlecode.gwt.test.patchers.InitMethod in project gwt-test-utils by gwt-test-utils.

the class ValueBoxBasePatcher method initClass.

@InitMethod
static void initClass(CtClass c) throws CannotCompileException {
    CtConstructor cons = JavassistUtils.findConstructor(c, Element.class, Renderer.class, Parser.class);
    cons.insertAfter("setText(\"\");");
}
Also used : CtConstructor(javassist.CtConstructor) InitMethod(com.googlecode.gwt.test.patchers.InitMethod)

Example 9 with InitMethod

use of com.googlecode.gwt.test.patchers.InitMethod in project gwt-test-utils by gwt-test-utils.

the class GwtPatcher method init.

@InitMethod
static void init(CtClass ctClass) throws CannotCompileException {
    CtConstructor staticInitializer = ctClass.makeClassInitializer();
    staticInitializer.insertAfter("setBridge(" + GwtTestGWTBridge.class.getName() + ".get());");
}
Also used : GwtTestGWTBridge(com.googlecode.gwt.test.internal.handlers.GwtTestGWTBridge) CtConstructor(javassist.CtConstructor) InitMethod(com.googlecode.gwt.test.patchers.InitMethod)

Example 10 with InitMethod

use of com.googlecode.gwt.test.patchers.InitMethod 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();");
}
Also used : CtMethod(javassist.CtMethod) InitMethod(com.googlecode.gwt.test.patchers.InitMethod)

Aggregations

InitMethod (com.googlecode.gwt.test.patchers.InitMethod)11 CtMethod (javassist.CtMethod)7 GwtTestPatchException (com.googlecode.gwt.test.exceptions.GwtTestPatchException)2 CtClass (javassist.CtClass)2 CtConstructor (javassist.CtConstructor)2 CtField (javassist.CtField)2 NotFoundException (javassist.NotFoundException)2 GwtTestGWTBridge (com.googlecode.gwt.test.internal.handlers.GwtTestGWTBridge)1 RadioButtonManager (com.googlecode.gwt.test.internal.utils.RadioButtonManager)1 PatchMethod (com.googlecode.gwt.test.patchers.PatchMethod)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1