.extend()
.publicOverridesMethod(handlerType.getMethods()[0].getName(), Parameter.of(eventType, "event"));
listenerBuiler.append(InjectUtil.invokePublicOrPrivateMethod(ctx.getInjectionContext(), component,
method, Stmt.loadVariable("event")));
ObjectBuilder listenerInstance = listenerBuiler.finish().finish();
int eventsToSink = Event.FOCUSEVENTS | Event.GESTUREEVENTS | Event.KEYEVENTS | Event.MOUSEEVENTS
| Event.TOUCHEVENTS;
if (method.isAnnotationPresent(SinkNative.class)) {
eventsToSink = method.getAnnotation(SinkNative.class).value();
}
for (String name : targetDataFieldNames) {
if (processedNativeHandlers.contains(name) || processedEventHandlers.contains(name)) {
throw new GenerationException(
"Cannot specify more than one @EventHandler method when @SyncNative is used for data-field ["
+ name + "] in class ["
+ declaringClass.getFullyQualifiedName()
+ "].");
}
else {
processedNativeHandlers.add(name);
}
if (dataFieldTypes.containsKey(name)) {
MetaClass dataFieldType = dataFieldTypes.get(name);
if (!dataFieldType.isAssignableTo(Element.class)) {
/*
* We have a GWT or other Widget type.
*/
throw new GenerationException("@DataField [" + name + "] of type [" + dataFieldType.getName()
+ "] in class [" + declaringClass.getFullyQualifiedName() + "] is not assignable to ["
+ Element.class.getName() + "] specified by @EventHandler method " + method.getName()
+ "("
+ eventType.getName() + ")]");
}
else {
/*
* We have a wrapped native Element reference
*/
throw new GenerationException("Cannot attach native DOM events to @DataField [" + name
+ "] of type ["
+ dataFieldType.getName() + "] in class [" + declaringClass.getFullyQualifiedName()
+ "] specified by @EventHandler method " + method.getName() + "(" + eventType.getName()
+ ")] - Use the corresponding GWT 'EventHandler' types instead.");
}
}
else {
/*
* We are completely native and have no reference to this data-field
* Element in Java
*/
builder.append(Stmt.invokeStatic(TemplateUtil.class, "setupNativeEventListener", component,
Stmt.loadVariable(dataFieldElementsVarName).invoke("get", name), listenerInstance,
eventsToSink));
}
}
}
else {
/*
* We have a GWT Widget type
*/
MetaClass handlerType;
try {
handlerType = getHandlerForEvent(eventType);
}
catch (GenerationException e) {
/*
* see ERRAI-373 for details on this crazy inference (without this message, the cause of the
* problem is nearly impossible to diagnose)
*/
if (declaringClass.getClass() == JavaReflectionClass.class) {
throw new GenerationException(
"The type " + declaringClass.getFullyQualifiedName() + " looks like a client-side" +
" @Templated class, but it is not known to GWT. This probably means that " +
declaringClass.getName() + " or one of its supertypes contains non-translatable code." +
" Run the GWT compiler with logLevel=DEBUG to pinpoint the problem.", e);
}
throw e;
}
BlockBuilder<AnonymousClassStructureBuilder> listenerBuiler = ObjectBuilder.newInstanceOf(handlerType)
.extend()
.publicOverridesMethod(handlerType.getMethods()[0].getName(), Parameter.of(eventType, "event"));
listenerBuiler.append(InjectUtil.invokePublicOrPrivateMethod(ctx.getInjectionContext(),
component, method, Stmt.loadVariable("event")));
ObjectBuilder listenerInstance = listenerBuiler.finish().finish();
MetaClass hasHandlerType = MetaClassFactory.get("com.google.gwt.event.dom.client.Has"
+ handlerType.getName()
+ "s");