use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class RadioButtonPatcher method initClass.
@InitMethod
static void initClass(CtClass c) throws CannotCompileException, NotFoundException {
// add overrided RadioButton.setValue method
CtMethod setValue = CtMethod.make("public void setValue(Boolean value, boolean fireEvents) { super.setValue($1, $2); " + RadioButtonManager.class.getName() + ".onRadioGroupChanged(this, $1, $2); }", c);
c.addMethod(setValue);
// add behavior to RadioButton.setName method
CtMethod setName = c.getMethod("setName", "(Ljava/lang/String;)V");
setName.insertBefore(RadioButtonManager.class.getName() + ".beforeSetName(this, $1);");
// Add overrided RadioButton.onLoad method
CtMethod onLoad = CtMethod.make("protected void onLoad() { super.onLoad(); " + RadioButtonManager.class.getName() + ".onLoad(this); }", c);
c.addMethod(onLoad);
// Add overrided RadioButton.onUnLoad method
CtMethod onUnload = CtMethod.make("protected void onUnLoad() { super.onUnload(); " + RadioButtonManager.class.getName() + ".onUnload(this); }", c);
c.addMethod(onUnload);
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class DomEventPatcher method initClass.
@InitMethod
static void initClass(CtClass c) throws CannotCompileException, NotFoundException {
CtMethod fireNativeEvent = c.getMethod("fireNativeEvent", "(Lcom/google/gwt/dom/client/NativeEvent;Lcom/google/gwt/event/shared/HasHandlers;Lcom/google/gwt/dom/client/Element;)V");
// fire browser event loop first because some command or async callback may modify the DOM
// structure + fire NativePreviewHandler
fireNativeEvent.insertBefore(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd(); " + DomEventPatcher.class.getName() + ".triggerNativeEvent($1, $3);");
// fire browser event loop at the end because some command may have been scheduled or RPC call
// made when the event was dispatched.
fireNativeEvent.insertAfter(BrowserSimulatorImpl.class.getName() + ".get().fireLoopEnd();");
}
use of javassist.CtMethod in project gwt-test-utils by gwt-test-utils.
the class WidgetPatcher method initClass.
@InitMethod
static void initClass(CtClass c) throws CannotCompileException, NotFoundException {
// add behavior to Widget.onAttach method
CtMethod onAttach = c.getMethod("onAttach", "()V");
onAttach.insertBefore(GwtFinder.class.getName() + ".onAttach(this);");
// add behavior to RadioButton.setName method
CtMethod onDetach = c.getMethod("onDetach", "()V");
onDetach.insertBefore(GwtFinder.class.getName() + ".onDetach(this);");
}
use of javassist.CtMethod in project hibernate-orm by hibernate.
the class MethodWriter method addSetter.
public static CtMethod addSetter(CtClass target, String field, String name) {
CtField actualField = null;
try {
actualField = target.getField(field);
log.debugf("Writing setter method [%s] into [%s] for field [%s]", name, target.getName(), field);
CtMethod method = CtNewMethod.setter(name, actualField);
target.addMethod(method);
return method;
} catch (CannotCompileException cce) {
try {
// Fall back to create a getter from delegation.
CtMethod method = CtNewMethod.delegator(CtNewMethod.setter(name, actualField), target);
target.addMethod(method);
return method;
} catch (CannotCompileException ignored) {
String msg = String.format("Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field);
throw new EnhancementException(msg, cce);
}
} catch (NotFoundException nfe) {
String msg = String.format("Could not enhance class [%s] to add method [%s] for field [%s]", target.getName(), name, field);
throw new EnhancementException(msg, nfe);
}
}
use of javassist.CtMethod in project hibernate-orm by hibernate.
the class MethodWriter method write.
/* --- */
/**
* convenience method that builds a method from a format string. {@see String.format} for more details
*
* @throws CannotCompileException
*/
public static CtMethod write(CtClass target, String format, Object... args) throws CannotCompileException {
String body = String.format(format, args);
// System.out.printf( "writing method into [%s]:%n%s%n", target.getName(), body );
log.debugf("writing method into [%s]:%n%s", target.getName(), body);
CtMethod method = CtNewMethod.make(body, target);
target.addMethod(method);
return method;
}
Aggregations