{
ClassTransformation ct = newClassTransformation();
MutableComponentModel model = newMutableComponentModel();
OnEvent annotation = newOnEvent();
MethodSignature signature = new MethodSignature(Modifier.PRIVATE, "void", "foo",
new String[]
{ "java.lang.String", OnEventWorker.OBJECT_ARRAY_TYPE, "java.lang.Integer" }, null);
train_findMethods(ct, signature);
train_getMethodAnnotation(ct, signature, OnEvent.class, annotation);
train_value(annotation, new String[0]);
train_component(annotation, new String[0]);
train_getClassName(ct, "foo.Bar");
// Notice that the context doesn't affect the indexing of the other parameters. Though it is
// unlikely that a method would use both a context array and explicit context parameters.
train_extendMethod(
ct,
TransformConstants.HANDLE_COMPONENT_EVENT,
"{",
BOILERPLATE_1,
BOILERPLATE_2,
String.format("$1.setSource(this, \"foo.Bar.%s\");", signature
.getMediumDescription()),
"foo((java.lang.String)$1.coerceContext(0, \"java.lang.String\"), ",
"$1.getContext(), ",
"(java.lang.Integer)$1.coerceContext(1, \"java.lang.Integer\"));",
"}");