1.1 --- a/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Mon Oct 29 13:05:56 2012 +0100
1.2 +++ b/htmlpage/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Tue Oct 30 12:23:13 2012 +0100
1.3 @@ -39,6 +39,7 @@
1.4 import javax.lang.model.element.Modifier;
1.5 import javax.lang.model.element.PackageElement;
1.6 import javax.lang.model.element.TypeElement;
1.7 +import javax.lang.model.type.TypeMirror;
1.8 import javax.tools.Diagnostic;
1.9 import javax.tools.FileObject;
1.10 import javax.tools.StandardLocation;
1.11 @@ -138,6 +139,7 @@
1.12 }
1.13
1.14 private boolean initializeOnClick(PackageElement pe, Writer w, ProcessPage pp) throws IOException {
1.15 + TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
1.16 for (Element clazz : pe.getEnclosedElements()) {
1.17 if (clazz.getKind() != ElementKind.CLASS) {
1.18 continue;
1.19 @@ -146,28 +148,40 @@
1.20 for (Element method : clazz.getEnclosedElements()) {
1.21 OnClick oc = method.getAnnotation(OnClick.class);
1.22 if (oc != null) {
1.23 - if (pp.tagNameForId(oc.id()) == null) {
1.24 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + oc.id() + " does not exist in the HTML page. Found only " + pp.ids(), method);
1.25 - return false;
1.26 - }
1.27 - ExecutableElement ee = (ExecutableElement)method;
1.28 - if (!ee.getParameters().isEmpty()) {
1.29 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method can't take arguments", ee);
1.30 - return false;
1.31 - }
1.32 - if (!ee.getModifiers().contains(Modifier.STATIC)) {
1.33 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method has to be static", ee);
1.34 - return false;
1.35 - }
1.36 - if (ee.getModifiers().contains(Modifier.PRIVATE)) {
1.37 - processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClose method can't be private", ee);
1.38 - return false;
1.39 - }
1.40 - w.append(" ").append(cnstnt(oc.id())).
1.41 - append(".addOnClick(new Runnable() { public void run() {\n");
1.42 - w.append(" ").append(type.getSimpleName().toString()).
1.43 - append('.').append(ee.getSimpleName()).append("();\n");
1.44 - w.append(" }});\n");
1.45 + for (String id : oc.id()) {
1.46 + if (pp.tagNameForId(id) == null) {
1.47 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + oc.id() + " does not exist in the HTML page. Found only " + pp.ids(), method);
1.48 + return false;
1.49 + }
1.50 + ExecutableElement ee = (ExecutableElement)method;
1.51 + boolean hasParam;
1.52 + if (ee.getParameters().isEmpty()) {
1.53 + hasParam = false;
1.54 + } else {
1.55 + if (ee.getParameters().size() != 1 || ee.getParameters().get(0).asType() != stringType) {
1.56 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method should either have no arguments or one String argument", ee);
1.57 + return false;
1.58 + }
1.59 + hasParam = true;
1.60 + }
1.61 + if (!ee.getModifiers().contains(Modifier.STATIC)) {
1.62 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method has to be static", ee);
1.63 + return false;
1.64 + }
1.65 + if (ee.getModifiers().contains(Modifier.PRIVATE)) {
1.66 + processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@OnClick method can't be private", ee);
1.67 + return false;
1.68 + }
1.69 + w.append(" ").append(cnstnt(id)).
1.70 + append(".addOnClick(new Runnable() { public void run() {\n");
1.71 + w.append(" ").append(type.getSimpleName().toString()).
1.72 + append('.').append(ee.getSimpleName()).append("(");
1.73 + if (hasParam) {
1.74 + w.append("\"").append(id).append("\"");
1.75 + }
1.76 + w.append(");\n");
1.77 + w.append(" }});\n");
1.78 + }
1.79 }
1.80 }
1.81 }