Hopefully resuscitating the original code from rev. 146ae7b52b64 by manual merge elements
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 02 May 2013 10:08:35 +0200
branchelements
changeset 10739321b4016d5c
parent 1072 3800d11c0bdb
child 1074 3ab2f70b300d
Hopefully resuscitating the original code from rev. 146ae7b52b64 by manual merge
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Attributes.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ElementGenerator.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PredefinedFields.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java
javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java
javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ElementGeneratorTest.java
javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageTest.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/Attributes.java	Thu May 02 10:08:35 2013 +0200
     1.3 @@ -0,0 +1,57 @@
     1.4 +/**
     1.5 + * Back 2 Browser Bytecode Translator
     1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     1.7 + *
     1.8 + * This program is free software: you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License as published by
    1.10 + * the Free Software Foundation, version 2 of the License.
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program. Look for COPYING file in the top folder.
    1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    1.20 + */
    1.21 +package org.apidesign.bck2brwsr.htmlpage;
    1.22 +
    1.23 +import java.util.HashMap;
    1.24 +import java.util.Map;
    1.25 +
    1.26 +/**
    1.27 + * Temporary storing the type of attributes here. This should be implemented in HTML 5 model
    1.28 + *
    1.29 + * @author Jan Horvath <jhorvath@netbeans.org>
    1.30 + */
    1.31 +public class Attributes {
    1.32 +    
    1.33 +    static final Map<String, String> TYPES = new HashMap<String, String>() {
    1.34 +        {
    1.35 +            // HTML Global Attributes
    1.36 +            // id attribute is already defined in Element, don't add it again
    1.37 +            put("accesskey", "String");
    1.38 +            put("class", "String");
    1.39 +            put("contenteditable", "Boolean");
    1.40 +            put("contextmenu", "String");
    1.41 +            put("dir", "String");
    1.42 +            put("draggable", "Boolean");
    1.43 +            put("dropzone", "String");
    1.44 +            put("hidden", "Boolean");
    1.45 +            put("lang", "String");
    1.46 +            put("spellcheck", "Boolean");
    1.47 +            put("style", "String");
    1.48 +            put("tabindex", "String");
    1.49 +            put("title", "String");
    1.50 +            put("translate", "Boolean");
    1.51 +            put("width", "Integer");
    1.52 +            put("height", "Integer");
    1.53 +            
    1.54 +            put("value", "String");
    1.55 +            put("disabled", "Boolean");
    1.56 +            
    1.57 +//          put("text", "String"); 'text' field is used to set innerHTML of element
    1.58 +        }
    1.59 +    };
    1.60 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ElementGenerator.java	Thu May 02 10:08:35 2013 +0200
     2.3 @@ -0,0 +1,175 @@
     2.4 +/**
     2.5 + * Back 2 Browser Bytecode Translator
     2.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, version 2 of the License.
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program. Look for COPYING file in the top folder.
    2.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    2.20 + */
    2.21 +package org.apidesign.bck2brwsr.htmlpage;
    2.22 +
    2.23 +import java.io.IOException;
    2.24 +import java.io.OutputStreamWriter;
    2.25 +import java.io.Writer;
    2.26 +import java.util.Arrays;
    2.27 +import java.util.Collections;
    2.28 +import java.util.HashMap;
    2.29 +import java.util.Map;
    2.30 +import java.util.Map.Entry;
    2.31 +import java.util.ServiceLoader;
    2.32 +import javax.annotation.processing.ProcessingEnvironment;
    2.33 +import javax.lang.model.element.Element;
    2.34 +import javax.tools.Diagnostic;
    2.35 +import javax.tools.FileObject;
    2.36 +import org.netbeans.modules.html.editor.lib.api.HtmlVersion;
    2.37 +import org.netbeans.modules.html.editor.lib.api.model.HtmlModel;
    2.38 +import org.netbeans.modules.html.editor.lib.api.model.HtmlModelProvider;
    2.39 +import org.netbeans.modules.html.editor.lib.api.model.HtmlTag;
    2.40 +import org.netbeans.modules.html.editor.lib.api.model.HtmlTagAttribute;
    2.41 +
    2.42 +/**
    2.43 + *
    2.44 + * @author Jan Horvath <jhorvath@netbeans.org>
    2.45 + */
    2.46 +public class ElementGenerator {
    2.47 +
    2.48 +    static final Map<String, String> NAMING_EXCEPTIONS = new HashMap<String, String>() {
    2.49 +        {
    2.50 +            put("img", "Image");
    2.51 +            put("class", "Clazz");
    2.52 +        }
    2.53 +    };
    2.54 +    
    2.55 +    static final String javaKeywords[] = {
    2.56 +        "abstract", "assert", "boolean", "break", "byte", "case",
    2.57 +        "catch", "char", "class", "const", "continue", "default", 
    2.58 +        "do", "double", "else", "extends", "false", "final", "finally", 
    2.59 +        "float", "for", "goto", "if", "implements", "import", 
    2.60 +        "instanceof", "int", "interface", "long", "native", "new",
    2.61 +        "null", "package", "private", "protected", "public",
    2.62 +        "return", "short", "static", "strictfp", "super",
    2.63 +        "switch", "synchronized", "this", "throw", "throws",
    2.64 +        "transient", "true", "try", "void", "volatile", "while"
    2.65 +    };
    2.66 +    
    2.67 +    private static Map<String, String> elements = new HashMap<String, String>();
    2.68 +    private final ProcessingEnvironment processingEnv;
    2.69 +    private HtmlModel model = null;
    2.70 +
    2.71 +    ElementGenerator(ProcessingEnvironment processingEnv) {
    2.72 +        this.processingEnv = processingEnv;
    2.73 +    }
    2.74 +
    2.75 +    String getType(String pkg, String tag, Element e) {
    2.76 +        String className = elements.get(tag);
    2.77 +        if (className == null) {
    2.78 +            className = createClass(pkg, tag, e);
    2.79 +            elements.put(tag, className);
    2.80 +        }
    2.81 +        return className;
    2.82 +    }
    2.83 +
    2.84 +    private String createClass(String pkg, String tag, Element e) {
    2.85 +        String className = className(tag);
    2.86 +        Writer w;
    2.87 +        try {
    2.88 +            FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + className, e);
    2.89 +            w = new OutputStreamWriter(java.openOutputStream());
    2.90 +            try {
    2.91 +                w.append("package " + pkg + ";\n\n");
    2.92 +                w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
    2.93 +                PredefinedFields.appendImports(w, tag);
    2.94 +                w.append("\n");
    2.95 +                
    2.96 +                w.append("class ").append(className).append(" extends Element {\n\n");
    2.97 +                w.append("    public ").append(className).append("(String id) {\n");
    2.98 +                w.append("        super(id);\n");
    2.99 +                w.append("    }\n\n");
   2.100 +                for (Entry<String, String> entry : getAttributes(tag).entrySet()) {
   2.101 +                    String attrName = entry.getKey();
   2.102 +                    String attrType = entry.getValue();
   2.103 +                    // getter
   2.104 +                    w.append("    public ").append(attrType).append(" ")
   2.105 +                            .append("get").append(className(attrName)).append("() {\n");
   2.106 +                    w.append("        return (").append(attrType).append(")getAttribute(\"")
   2.107 +                            .append(attrName).append("\");\n");
   2.108 +                    w.append("    }\n\n");
   2.109 +                    // setter
   2.110 +                    w.append("    public void ")
   2.111 +                            .append("set").append(className(attrName)).append("(")
   2.112 +                            .append(attrType).append(" ").append(attributeName(attrName)).append(") {\n");
   2.113 +                    w.append("        setAttribute(\"").append(attrName).append("\", ").append(attributeName(attrName)).append(");\n");
   2.114 +                    w.append("    }\n\n");
   2.115 +                }
   2.116 +                PredefinedFields.appendFields(w, tag);
   2.117 +                w.append("}\n");
   2.118 +            } finally {
   2.119 +                w.close();
   2.120 +            }
   2.121 +        } catch (IOException ex) {
   2.122 +            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + className + ".java", e);
   2.123 +            return null;
   2.124 +        }
   2.125 +        return className;
   2.126 +    }
   2.127 +
   2.128 +    Map<String, String> getAttributes(String tagName) {
   2.129 +        Map<String, String> result = new HashMap<String, String>();
   2.130 +
   2.131 +        if (model == null) {
   2.132 +            // HtmlModelProvider modelProvider = Lookup.getDefault().lookup(HtmlModelProvider.class);
   2.133 +            ServiceLoader<HtmlModelProvider> hmpLoader = 
   2.134 +                    ServiceLoader.load(HtmlModelProvider.class, this.getClass().getClassLoader());
   2.135 +            for (HtmlModelProvider htmlModelProvider : hmpLoader) {
   2.136 +                model = htmlModelProvider.getModel(HtmlVersion.HTML5);
   2.137 +                if (model != null) {
   2.138 +                    break;
   2.139 +                }
   2.140 +            }
   2.141 +        }
   2.142 +        
   2.143 +        if (model == null) {
   2.144 +            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 
   2.145 +                    "HTML 5 model provider was not found on classpath");
   2.146 +            return Collections.emptyMap();
   2.147 +        }
   2.148 +        HtmlTag tag = model.getTag(tagName);
   2.149 +        for (HtmlTagAttribute attr : tag.getAttributes()) {
   2.150 +            String name = attr.getName();
   2.151 +            String type = Attributes.TYPES.get(name);
   2.152 +            if (type != null) {
   2.153 +                result.put(name, type);
   2.154 +            }
   2.155 +        }
   2.156 +        
   2.157 +        return result;
   2.158 +    }
   2.159 +
   2.160 +    private String className(String s) {
   2.161 +        if (s.length() == 0) {
   2.162 +            return s;
   2.163 +        }
   2.164 +        String name = NAMING_EXCEPTIONS.get(s.toLowerCase());
   2.165 +        if (name == null) {
   2.166 +            name = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
   2.167 +        }
   2.168 +        return name;
   2.169 +    }
   2.170 +
   2.171 +    private String attributeName(String s) {
   2.172 +        if (Arrays.binarySearch(javaKeywords, s) >= 0) {
   2.173 +            return String.format("%sAttr", s);
   2.174 +        }
   2.175 +        return s;
   2.176 +    }
   2.177 +    
   2.178 +}
     3.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Thu May 02 09:18:22 2013 +0200
     3.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java	Thu May 02 10:08:35 2013 +0200
     3.3 @@ -299,109 +299,85 @@
     3.4          }
     3.5          String pkg = findPkgName(e);
     3.6  
     3.7 -        ProcessPage pp;
     3.8 -        try (InputStream is = openStream(pkg, p.xhtml())) {
     3.9 -            pp = ProcessPage.readPage(is);
    3.10 -            is.close();
    3.11 -        } catch (IOException iOException) {
    3.12 -            error("Can't read " + p.xhtml() + " as " + iOException.getMessage(), e);
    3.13 -            ok = false;
    3.14 -            pp = null;
    3.15 -        }
    3.16 -        Writer w;
    3.17 -        String className = p.className();
    3.18 -        if (className.isEmpty()) {
    3.19 -            int indx = p.xhtml().indexOf('.');
    3.20 -            className = p.xhtml().substring(0, indx);
    3.21 -        }
    3.22 -        try {
    3.23 -            StringWriter body = new StringWriter();
    3.24 -            List<String> propsGetSet = new ArrayList<>();
    3.25 -            List<String> functions = new ArrayList<>();
    3.26 -            Map<String, Collection<String>> propsDeps = new HashMap<>();
    3.27 -            Map<String, Collection<String>> functionDeps = new HashMap<>();
    3.28 -            
    3.29 -            Prprt[] props = createProps(e, p.properties());
    3.30 -            if (!generateComputedProperties(body, props, e.getEnclosedElements(), propsGetSet, propsDeps)) {
    3.31 -                ok = false;
    3.32 +            ProcessPage pp;
    3.33 +            ElementGenerator eGen = new ElementGenerator(processingEnv);
    3.34 +            try {
    3.35 +                InputStream is = openStream(pkg, p.xhtml());
    3.36 +                pp = ProcessPage.readPage(is);
    3.37 +                is.close();
    3.38 +            } catch (IOException iOException) {
    3.39 +                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't read " + p.xhtml(), e);
    3.40 +                return false;
    3.41              }
    3.42 -            if (!generateOnChange(e, propsDeps, props, className, functionDeps)) {
    3.43 -                ok = false;
    3.44 +            Writer w;
    3.45 +            String className = p.className();
    3.46 +            if (className.isEmpty()) {
    3.47 +                int indx = p.xhtml().indexOf('.');
    3.48 +                className = p.xhtml().substring(0, indx);
    3.49              }
    3.50 -            if (!generateProperties(e, body, props, propsGetSet, propsDeps, functionDeps)) {
    3.51 -                ok = false;
    3.52 -            }
    3.53 -            if (!generateFunctions(e, body, className, e.getEnclosedElements(), functions)) {
    3.54 -                ok = false;
    3.55 -            }
    3.56 -            if (!generateReceive(e, body, className, e.getEnclosedElements(), functions)) {
    3.57 -                ok = false;
    3.58 -            }
    3.59 -            
    3.60 -            FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + className, e);
    3.61 -            w = new OutputStreamWriter(java.openOutputStream());
    3.62              try {
    3.63 -                w.append("package " + pkg + ";\n");
    3.64 -                w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
    3.65 -                w.append("import org.apidesign.bck2brwsr.htmlpage.KOList;\n");
    3.66 -                w.append("final class ").append(className).append(" {\n");
    3.67 -                w.append("  private boolean locked;\n");
    3.68 -                if (!initializeOnClick(className, (TypeElement) e, w, pp)) {
    3.69 -                    ok = false;
    3.70 -                } else {
    3.71 -                    if (pp != null) for (String id : pp.ids()) {
    3.72 +                FileObject java = processingEnv.getFiler().createSourceFile(pkg + '.' + className, e);
    3.73 +                w = new OutputStreamWriter(java.openOutputStream());
    3.74 +                try {
    3.75 +                    w.append("package " + pkg + ";\n");
    3.76 +                    w.append("import org.apidesign.bck2brwsr.htmlpage.api.*;\n");
    3.77 +                    w.append("final class ").append(className).append(" {\n");
    3.78 +                    w.append("  private boolean locked;\n");
    3.79 +                    if (!initializeOnClick(className, (TypeElement) e, w, pp)) {
    3.80 +                        return false;
    3.81 +                    }
    3.82 +                    for (String id : pp.ids()) {
    3.83                          String tag = pp.tagNameForId(id);
    3.84 -                        String type = type(tag);
    3.85 +                        String type = eGen.getType(pkg, tag, e);
    3.86                          w.append("  ").append("public final ").
    3.87                              append(type).append(' ').append(cnstnt(id)).append(" = new ").
    3.88                              append(type).append("(\"").append(id).append("\");\n");
    3.89                      }
    3.90 +                    List<String> propsGetSet = new ArrayList<String>();
    3.91 +                    Map<String, Collection<String>> functionDeps = new HashMap<>();
    3.92 +                    Map<String,Collection<String>> propsDeps = new HashMap<String, Collection<String>>();
    3.93 +                    List<String> functions = new ArrayList<>();
    3.94 +                    Prprt[] props = createProps(e, p.properties());
    3.95 +                    if (!generateComputedProperties(w, props, e.getEnclosedElements(), propsGetSet, propsDeps)) {
    3.96 +                        ok = false;
    3.97 +                    }
    3.98 +                    if (!generateOnChange(e, propsDeps, props, className, functionDeps)) {
    3.99 +                        ok = false;
   3.100 +                    }
   3.101 +                    if (!generateProperties(e, w, props, propsGetSet, propsDeps, functionDeps)) {
   3.102 +                        ok = false;
   3.103 +                    }
   3.104 +                    if (!generateFunctions(e, w, className, e.getEnclosedElements(), functions)) {
   3.105 +                        ok = false;
   3.106 +                    }
   3.107 +                    if (!generateReceive(e, w, className, e.getEnclosedElements(), functions)) {
   3.108 +                        ok = false;
   3.109 +                    }                    
   3.110 +                    w.append("  private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
   3.111 +                    if (!propsGetSet.isEmpty()) {
   3.112 +                        w.write("public " + className + " applyBindings() {\n");
   3.113 +                        w.write("  ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(");
   3.114 +                        w.write(className + ".class, this, ");
   3.115 +                        writeStringArray(propsGetSet, w);
   3.116 +                        w.append(", ");
   3.117 +                        writeStringArray(functions, w);
   3.118 +                        w.write(");\n  return this;\n}\n");
   3.119 +
   3.120 +                        w.write("public void triggerEvent(Element e, OnEvent ev) {\n");
   3.121 +                        w.write("  org.apidesign.bck2brwsr.htmlpage.Knockout.triggerEvent(e.getId(), ev.getElementPropertyName());\n");
   3.122 +                        w.write("}\n");
   3.123 +                    }
   3.124 +                    w.append("}\n");
   3.125 +                } finally {
   3.126 +                    w.close();
   3.127                  }
   3.128 -                w.append("  private org.apidesign.bck2brwsr.htmlpage.Knockout ko;\n");
   3.129 -                w.append(body.toString());
   3.130 -                if (!propsGetSet.isEmpty()) {
   3.131 -                    w.write("public " + className + " applyBindings() {\n");
   3.132 -                    w.write("  ko = org.apidesign.bck2brwsr.htmlpage.Knockout.applyBindings(");
   3.133 -                    w.write(className + ".class, this, ");
   3.134 -                    writeStringArray(propsGetSet, w);
   3.135 -                    w.append(", ");
   3.136 -                    writeStringArray(functions, w);
   3.137 -                    w.write(");\n  return this;\n}\n");
   3.138 -
   3.139 -                    w.write("public void triggerEvent(Element e, OnEvent ev) {\n");
   3.140 -                    w.write("  org.apidesign.bck2brwsr.htmlpage.Knockout.triggerEvent(e.getId(), ev.getElementPropertyName());\n");
   3.141 -                    w.write("}\n");
   3.142 -                }
   3.143 -                w.append("}\n");
   3.144 -            } finally {
   3.145 -                w.close();
   3.146 +            } catch (IOException ex) {
   3.147 +                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Can't create " + className + ".java", e);
   3.148 +                return false;
   3.149              }
   3.150 -        } catch (IOException ex) {
   3.151 -            error("Can't create " + className + ".java", e);
   3.152 -            return false;
   3.153 -        }
   3.154          return ok;
   3.155      }
   3.156  
   3.157 -    private static String type(String tag) {
   3.158 -        if (tag.equals("title")) {
   3.159 -            return "Title";
   3.160 -        }
   3.161 -        if (tag.equals("button")) {
   3.162 -            return "Button";
   3.163 -        }
   3.164 -        if (tag.equals("input")) {
   3.165 -            return "Input";
   3.166 -        }
   3.167 -        if (tag.equals("canvas")) {
   3.168 -            return "Canvas";
   3.169 -        }
   3.170 -        if (tag.equals("img")) {
   3.171 -            return "Image";
   3.172 -        }
   3.173 -        return "Element";
   3.174 -    }
   3.175 -
   3.176      private static String cnstnt(String id) {
   3.177          return id.replace('.', '_').replace('-', '_');
   3.178      }
   3.179 @@ -409,7 +385,6 @@
   3.180      private boolean initializeOnClick(
   3.181          String className, TypeElement type, Writer w, ProcessPage pp
   3.182      ) throws IOException {
   3.183 -        boolean ok = true;
   3.184          TypeMirror stringType = processingEnv.getElementUtils().getTypeElement("java.lang.String").asType();
   3.185          { //for (Element clazz : pe.getEnclosedElements()) {
   3.186            //  if (clazz.getKind() != ElementKind.CLASS) {
   3.187 @@ -422,27 +397,58 @@
   3.188                  On oc = method.getAnnotation(On.class);
   3.189                  if (oc != null) {
   3.190                      for (String id : oc.id()) {
   3.191 -                        if (pp == null) {
   3.192 -                            error("id = " + id + " not found in HTML page.", method);
   3.193 -                            ok = false;
   3.194 -                            continue;
   3.195 -                        }
   3.196                          if (pp.tagNameForId(id) == null) {
   3.197 -                            error("id = " + id + " does not exist in the HTML page. Found only " + pp.ids(), method);
   3.198 -                            ok = false;
   3.199 -                            continue;
   3.200 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "id = " + id + " does not exist in the HTML page. Found only " + pp.ids(), method);
   3.201 +                            return false;
   3.202                          }
   3.203                          ExecutableElement ee = (ExecutableElement)method;
   3.204 -                        CharSequence params = wrapParams(ee, id, className, "ev", null);
   3.205 +                        StringBuilder params = new StringBuilder();
   3.206 +                        {
   3.207 +                            boolean first = true;
   3.208 +                            for (VariableElement ve : ee.getParameters()) {
   3.209 +                                if (!first) {
   3.210 +                                    params.append(", ");
   3.211 +                                }
   3.212 +                                first = false;
   3.213 +                                if (ve.asType() == stringType) {
   3.214 +                                    if (ve.getSimpleName().contentEquals("id")) {
   3.215 +                                        params.append('"').append(id).append('"');
   3.216 +                                        continue;
   3.217 +                                    }
   3.218 +                                    params.append("org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toString(ev, \"");
   3.219 +                                    params.append(ve.getSimpleName().toString());
   3.220 +                                    params.append("\")");
   3.221 +                                    continue;
   3.222 +                                }
   3.223 +                                if (processingEnv.getTypeUtils().getPrimitiveType(TypeKind.DOUBLE) == ve.asType()) {
   3.224 +                                    params.append("org.apidesign.bck2brwsr.htmlpage.ConvertTypes.toDouble(ev, \"");
   3.225 +                                    params.append(ve.getSimpleName().toString());
   3.226 +                                    params.append("\")");
   3.227 +                                    continue;
   3.228 +                                }
   3.229 +                                String rn = ve.asType().toString();
   3.230 +                                int last = rn.lastIndexOf('.');
   3.231 +                                if (last >= 0) {
   3.232 +                                    rn = rn.substring(last + 1);
   3.233 +                                }
   3.234 +                                if (rn.equals(className)) {
   3.235 +                                    params.append(className).append(".this");
   3.236 +                                    continue;
   3.237 +                                }
   3.238 +                                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, 
   3.239 +                                    "@On method can only accept String named 'id' or " + className + " arguments",
   3.240 +                                    ee
   3.241 +                                );
   3.242 +                                return false;
   3.243 +                            }
   3.244 +                        }
   3.245                          if (!ee.getModifiers().contains(Modifier.STATIC)) {
   3.246 -                            error("@On method has to be static", ee);
   3.247 -                            ok = false;
   3.248 -                            continue;
   3.249 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method has to be static", ee);
   3.250 +                            return false;
   3.251                          }
   3.252                          if (ee.getModifiers().contains(Modifier.PRIVATE)) {
   3.253 -                            error("@On method can't be private", ee);
   3.254 -                            ok = false;
   3.255 -                            continue;
   3.256 +                            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@On method can't be private", ee);
   3.257 +                            return false;
   3.258                          }
   3.259                          w.append("  OnEvent." + oc.event()).append(".of(").append(cnstnt(id)).
   3.260                              append(").perform(new OnDispatch(" + dispatchCnt + "));\n");
   3.261 @@ -473,7 +479,7 @@
   3.262              
   3.263  
   3.264          }
   3.265 -        return ok;
   3.266 +        return true;
   3.267      }
   3.268  
   3.269      @Override
   3.270 @@ -487,7 +493,8 @@
   3.271          
   3.272          Element cls = findClass(element);
   3.273          Page p = cls.getAnnotation(Page.class);
   3.274 -        String pkg = findPkgName(cls);
   3.275 +        PackageElement pe = (PackageElement) cls.getEnclosingElement();
   3.276 +        String pkg = pe.getQualifiedName().toString();
   3.277          ProcessPage pp;
   3.278          try {
   3.279              InputStream is = openStream(pkg, p.xhtml());
   3.280 @@ -497,7 +504,7 @@
   3.281              return Collections.emptyList();
   3.282          }
   3.283          
   3.284 -        List<Completion> cc = new ArrayList<>();
   3.285 +        List<Completion> cc = new ArrayList<Completion>();
   3.286          userText = userText.substring(1);
   3.287          for (String id : pp.ids()) {
   3.288              if (id.startsWith(userText)) {
   3.289 @@ -771,9 +778,9 @@
   3.290      }
   3.291  
   3.292      private boolean generateFunctions(
   3.293 -        Element clazz, StringWriter body, String className, 
   3.294 +        Element clazz, Writer body, String className, 
   3.295          List<? extends Element> enclosedElements, List<String> functions
   3.296 -    ) {
   3.297 +    ) throws IOException {
   3.298          for (Element m : enclosedElements) {
   3.299              if (m.getKind() != ElementKind.METHOD) {
   3.300                  continue;
   3.301 @@ -868,9 +875,9 @@
   3.302      }
   3.303      
   3.304      private boolean generateReceive(
   3.305 -        Element clazz, StringWriter body, String className, 
   3.306 +        Element clazz, Writer body, String className, 
   3.307          List<? extends Element> enclosedElements, List<String> functions
   3.308 -    ) {
   3.309 +    ) throws IOException {
   3.310          for (Element m : enclosedElements) {
   3.311              if (m.getKind() != ElementKind.METHOD) {
   3.312                  continue;
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PredefinedFields.java	Thu May 02 10:08:35 2013 +0200
     4.3 @@ -0,0 +1,65 @@
     4.4 +/**
     4.5 + * Back 2 Browser Bytecode Translator
     4.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, version 2 of the License.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU General Public License
    4.18 + * along with this program. Look for COPYING file in the top folder.
    4.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    4.20 + */
    4.21 +package org.apidesign.bck2brwsr.htmlpage;
    4.22 +
    4.23 +import java.io.IOException;
    4.24 +import java.io.Writer;
    4.25 +import java.util.HashMap;
    4.26 +import java.util.Map;
    4.27 +
    4.28 +/**
    4.29 + *
    4.30 + * @author Jan Horvath <jhorvath@netbeans.org>
    4.31 + */
    4.32 +public class PredefinedFields {
    4.33 +    
    4.34 +    private static final Map<String, String> IMPORTS = new HashMap<String, String>() {
    4.35 +        {
    4.36 +            put("canvas", "import org.apidesign.bck2brwsr.core.JavaScriptBody;");
    4.37 +        }
    4.38 +    };
    4.39 +    
    4.40 +    private static final Map<String, String> FIELDS = new HashMap<String, String>() {
    4.41 +        {
    4.42 +            put("canvas", 
    4.43 +                    "    @JavaScriptBody(\n" +
    4.44 +                    "            args = {\"el\"},\n" +
    4.45 +                    "            body = \"var e = window.document.getElementById(el._id());\\n\"\n" +
    4.46 +                    "            + \"return e.getContext('2d');\\n\")\n" +
    4.47 +                    "    private native static Object getContextImpl(Canvas el);\n" +
    4.48 +                    "    \n" +
    4.49 +                    "    public GraphicsContext getContext() {\n" +
    4.50 +                    "        return new GraphicsContext(getContextImpl(this));\n" +
    4.51 +                    "    }");
    4.52 +        }
    4.53 +    };
    4.54 +    
    4.55 +    static void appendImports(Writer w, String tag) throws IOException {
    4.56 +        String text = IMPORTS.get(tag.toLowerCase());
    4.57 +        if (text != null) {
    4.58 +            w.append(text).append("\n");
    4.59 +        }
    4.60 +    }
    4.61 +    
    4.62 +    static void appendFields(Writer w, String tag) throws IOException {
    4.63 +        String text = FIELDS.get(tag.toLowerCase());
    4.64 +        if (text != null) {
    4.65 +            w.append(text).append("\n");
    4.66 +        }
    4.67 +    }
    4.68 +}
     5.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Button.java	Thu May 02 09:18:22 2013 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,36 +0,0 @@
     5.4 -/**
     5.5 - * Back 2 Browser Bytecode Translator
     5.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     5.7 - *
     5.8 - * This program is free software: you can redistribute it and/or modify
     5.9 - * it under the terms of the GNU General Public License as published by
    5.10 - * the Free Software Foundation, version 2 of the License.
    5.11 - *
    5.12 - * This program is distributed in the hope that it will be useful,
    5.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 - * GNU General Public License for more details.
    5.16 - *
    5.17 - * You should have received a copy of the GNU General Public License
    5.18 - * along with this program. Look for COPYING file in the top folder.
    5.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    5.20 - */
    5.21 -package org.apidesign.bck2brwsr.htmlpage.api;
    5.22 -
    5.23 -/**
    5.24 - *
    5.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    5.26 - */
    5.27 -public final class Button extends Element {
    5.28 -    public Button(String id) {
    5.29 -        super(id);
    5.30 -    }
    5.31 -
    5.32 -    @Override
    5.33 -    void dontSubclass() {
    5.34 -    }
    5.35 -
    5.36 -    public void setDisabled(boolean state) {
    5.37 -        setAttribute(this, "disabled", state);
    5.38 -    }
    5.39 -}
     6.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java	Thu May 02 09:18:22 2013 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,64 +0,0 @@
     6.4 -/**
     6.5 - * Back 2 Browser Bytecode Translator
     6.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 - *
     6.8 - * This program is free software: you can redistribute it and/or modify
     6.9 - * it under the terms of the GNU General Public License as published by
    6.10 - * the Free Software Foundation, version 2 of the License.
    6.11 - *
    6.12 - * This program is distributed in the hope that it will be useful,
    6.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 - * GNU General Public License for more details.
    6.16 - *
    6.17 - * You should have received a copy of the GNU General Public License
    6.18 - * along with this program. Look for COPYING file in the top folder.
    6.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    6.20 - */
    6.21 -package org.apidesign.bck2brwsr.htmlpage.api;
    6.22 -
    6.23 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
    6.24 -import static org.apidesign.bck2brwsr.htmlpage.api.Element.getAttribute;
    6.25 -
    6.26 -/**
    6.27 - *
    6.28 - * @author Anton Epple <toni.epple@eppleton.de>
    6.29 - */
    6.30 -public class Canvas extends Element {
    6.31 -
    6.32 -    public Canvas(String id) {
    6.33 -        super(id);
    6.34 -    }
    6.35 -
    6.36 -    public void setHeight(int height) {
    6.37 -        setAttribute(this, "height", height);
    6.38 -    }
    6.39 -
    6.40 -    public int getHeight() {
    6.41 -       Object ret =  getAttribute(this, "height");
    6.42 -       return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE;
    6.43 -    }
    6.44 -    
    6.45 -    public void setWidth(int width) {
    6.46 -        setAttribute(this, "width", width);
    6.47 -    }
    6.48 -
    6.49 -    public int getWidth() {
    6.50 -       Object ret =  getAttribute(this, "width");
    6.51 -       return (ret instanceof Number) ? ((Number)ret).intValue(): Integer.MIN_VALUE;
    6.52 -    }
    6.53 -
    6.54 -    @JavaScriptBody(
    6.55 -            args = {"el"},
    6.56 -            body = "var e = window.document.getElementById(el._id());\n"
    6.57 -            + "return e.getContext('2d');\n")
    6.58 -    private native static Object getContextImpl(Canvas el);
    6.59 -
    6.60 -    public GraphicsContext getContext() {
    6.61 -        return new GraphicsContext(getContextImpl(this));
    6.62 -    }
    6.63 -
    6.64 -    @Override
    6.65 -    void dontSubclass() {
    6.66 -    }
    6.67 -}
     7.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Thu May 02 09:18:22 2013 +0200
     7.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java	Thu May 02 10:08:35 2013 +0200
     7.3 @@ -37,7 +37,13 @@
     7.4          return id;
     7.5      }
     7.6      
     7.7 -    abstract void dontSubclass();
     7.8 +    public String getText() {
     7.9 +        return (String)getAttribute("innerHTML");
    7.10 +    }
    7.11 +
    7.12 +    public void setText(String text) {
    7.13 +        setAttribute("innerHTML", text);
    7.14 +    }
    7.15      
    7.16      @JavaScriptBody(
    7.17          args={"el", "property", "value"},
     8.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Thu May 02 09:18:22 2013 +0200
     8.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Thu May 02 10:08:35 2013 +0200
     8.3 @@ -27,7 +27,7 @@
     8.4  
     8.5      Object context;
     8.6  
     8.7 -    GraphicsContext(Object contextImpl) {
     8.8 +    public GraphicsContext(Object contextImpl) {
     8.9          this.context = contextImpl;
    8.10      }
    8.11  
    8.12 @@ -113,15 +113,15 @@
    8.13      @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
    8.14      public native void scale(double x, double y);
    8.15  
    8.16 -    public void drawImage(Image image, double x, double y) {
    8.17 +    public void drawImage(Element image, double x, double y) {
    8.18          drawImageImpl(context, Element.getElementById(image), x, y);
    8.19      }
    8.20  
    8.21 -    public void drawImage(Image image, double x, double y, double width, double height) {
    8.22 +    public void drawImage(Element image, double x, double y, double width, double height) {
    8.23          drawImageImpl(context, Element.getElementById(image), x, y, width, height);
    8.24      }
    8.25  
    8.26 -    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
    8.27 +    public void drawImage(Element image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
    8.28          drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
    8.29      }
    8.30  
    8.31 @@ -319,12 +319,12 @@
    8.32      @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
    8.33      private  native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
    8.34  
    8.35 -    public Pattern createPattern(Image image, String repeat) {
    8.36 +    public Pattern createPattern(Element image, String repeat) {
    8.37          return new Pattern(createPatternImpl(context, image, repeat));
    8.38      }
    8.39  
    8.40      @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
    8.41 -    private static native Object createPatternImpl(Object context, Image image, String repeat);
    8.42 +    private static native Object createPatternImpl(Object context, Element image, String repeat);
    8.43  
    8.44      public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
    8.45          return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
     9.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Image.java	Thu May 02 09:18:22 2013 +0200
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,36 +0,0 @@
     9.4 -/**
     9.5 - * Back 2 Browser Bytecode Translator
     9.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     9.7 - *
     9.8 - * This program is free software: you can redistribute it and/or modify
     9.9 - * it under the terms of the GNU General Public License as published by
    9.10 - * the Free Software Foundation, version 2 of the License.
    9.11 - *
    9.12 - * This program is distributed in the hope that it will be useful,
    9.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    9.15 - * GNU General Public License for more details.
    9.16 - *
    9.17 - * You should have received a copy of the GNU General Public License
    9.18 - * along with this program. Look for COPYING file in the top folder.
    9.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
    9.20 - */
    9.21 -package org.apidesign.bck2brwsr.htmlpage.api;
    9.22 -
    9.23 -/**
    9.24 - *
    9.25 - * @author Anton Epple <toni.epple@eppleton.de>
    9.26 - */
    9.27 -public class Image extends Element{
    9.28 -
    9.29 -    public Image(String id) {
    9.30 -        super(id);
    9.31 -    }
    9.32 -
    9.33 -    
    9.34 -    
    9.35 -    @Override
    9.36 -    void dontSubclass() {
    9.37 -    }
    9.38 -    
    9.39 -}
    10.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Input.java	Thu May 02 09:18:22 2013 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,44 +0,0 @@
    10.4 -/**
    10.5 - * Back 2 Browser Bytecode Translator
    10.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    10.7 - *
    10.8 - * This program is free software: you can redistribute it and/or modify
    10.9 - * it under the terms of the GNU General Public License as published by
   10.10 - * the Free Software Foundation, version 2 of the License.
   10.11 - *
   10.12 - * This program is distributed in the hope that it will be useful,
   10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.15 - * GNU General Public License for more details.
   10.16 - *
   10.17 - * You should have received a copy of the GNU General Public License
   10.18 - * along with this program. Look for COPYING file in the top folder.
   10.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   10.20 - */
   10.21 -package org.apidesign.bck2brwsr.htmlpage.api;
   10.22 -
   10.23 -/**
   10.24 - *
   10.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   10.26 - */
   10.27 -public final class Input extends Element {
   10.28 -    public Input(String id) {
   10.29 -        super(id);
   10.30 -    }
   10.31 -
   10.32 -    @Override
   10.33 -    void dontSubclass() {
   10.34 -    }
   10.35 -    
   10.36 -    public void setAutocomplete(boolean state) {
   10.37 -        setAttribute(this, "autocomplete", state);
   10.38 -    }
   10.39 -    
   10.40 -    public final String getValue() {
   10.41 -        return (String)getAttribute(this, "value");
   10.42 -    }
   10.43 -    
   10.44 -    public final void setValue(String txt) {
   10.45 -        setAttribute(this, "value", txt);
   10.46 -    }
   10.47 -}
    11.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Title.java	Thu May 02 09:18:22 2013 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,36 +0,0 @@
    11.4 -/**
    11.5 - * Back 2 Browser Bytecode Translator
    11.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    11.7 - *
    11.8 - * This program is free software: you can redistribute it and/or modify
    11.9 - * it under the terms of the GNU General Public License as published by
   11.10 - * the Free Software Foundation, version 2 of the License.
   11.11 - *
   11.12 - * This program is distributed in the hope that it will be useful,
   11.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.15 - * GNU General Public License for more details.
   11.16 - *
   11.17 - * You should have received a copy of the GNU General Public License
   11.18 - * along with this program. Look for COPYING file in the top folder.
   11.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   11.20 - */
   11.21 -package org.apidesign.bck2brwsr.htmlpage.api;
   11.22 -
   11.23 -/**
   11.24 - *
   11.25 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   11.26 - */
   11.27 -public class Title extends Element {
   11.28 -    public Title(String id) {
   11.29 -        super(id);
   11.30 -    }
   11.31 -
   11.32 -    @Override
   11.33 -    void dontSubclass() {
   11.34 -    }
   11.35 -    
   11.36 -    public final void setText(String text) {
   11.37 -        setAttribute(this, "innerHTML", text);
   11.38 -    }
   11.39 -}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/ElementGeneratorTest.java	Thu May 02 10:08:35 2013 +0200
    12.3 @@ -0,0 +1,35 @@
    12.4 +/**
    12.5 + * Back 2 Browser Bytecode Translator
    12.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    12.7 + *
    12.8 + * This program is free software: you can redistribute it and/or modify
    12.9 + * it under the terms of the GNU General Public License as published by
   12.10 + * the Free Software Foundation, version 2 of the License.
   12.11 + *
   12.12 + * This program is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU General Public License
   12.18 + * along with this program. Look for COPYING file in the top folder.
   12.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   12.20 + */
   12.21 +package org.apidesign.bck2brwsr.htmlpage;
   12.22 +
   12.23 +import java.util.Map;
   12.24 +import static org.testng.Assert.*;
   12.25 +import org.testng.annotations.Test;
   12.26 +
   12.27 +/**
   12.28 + *
   12.29 + * @author Jan Horvath <jhorvath@netbeans.org>
   12.30 + */
   12.31 +public class ElementGeneratorTest {
   12.32 +    
   12.33 +    @Test public void testGetAttributes() {
   12.34 +        ElementGenerator gen = new ElementGenerator(null);
   12.35 +        Map<String, String> attrs = gen.getAttributes("input");
   12.36 +        assertEquals(attrs.get("width"), "Integer", "Expected type of width attribute is Integer");
   12.37 +    }
   12.38 +}
    13.1 --- a/javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/PageTest.java	Thu May 02 09:18:22 2013 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,53 +0,0 @@
    13.4 -/**
    13.5 - * Back 2 Browser Bytecode Translator
    13.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    13.7 - *
    13.8 - * This program is free software: you can redistribute it and/or modify
    13.9 - * it under the terms of the GNU General Public License as published by
   13.10 - * the Free Software Foundation, version 2 of the License.
   13.11 - *
   13.12 - * This program is distributed in the hope that it will be useful,
   13.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 - * GNU General Public License for more details.
   13.16 - *
   13.17 - * You should have received a copy of the GNU General Public License
   13.18 - * along with this program. Look for COPYING file in the top folder.
   13.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
   13.20 - */
   13.21 -package org.apidesign.bck2brwsr.htmlpage;
   13.22 -
   13.23 -import java.io.IOException;
   13.24 -import java.util.Locale;
   13.25 -import javax.tools.Diagnostic;
   13.26 -import javax.tools.JavaFileObject;
   13.27 -import static org.testng.Assert.*;
   13.28 -import org.testng.annotations.Test;
   13.29 -
   13.30 -/** Verify errors emitted by the processor.
   13.31 - *
   13.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
   13.33 - */
   13.34 -public class PageTest {
   13.35 -    @Test public void verifyWrongType() throws IOException {
   13.36 -        String html = "<html><body>"
   13.37 -            + "</body></html>";
   13.38 -        String code = "package x.y.z;\n"
   13.39 -            + "import org.apidesign.bck2brwsr.htmlpage.api.*;\n"
   13.40 -            + "@Page(xhtml=\"index.xhtml\", className=\"Model\", properties={\n"
   13.41 -            + "  @Property(name=\"prop\", type=Runnable.class)\n"
   13.42 -            + "})\n"
   13.43 -            + "class X {\n"
   13.44 -            + "}\n";
   13.45 -        
   13.46 -        Compile c = Compile.create(html, code);
   13.47 -        assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
   13.48 -        for (Diagnostic<? extends JavaFileObject> e : c.getErrors()) {
   13.49 -            String msg = e.getMessage(Locale.ENGLISH);
   13.50 -            if (!msg.contains("Runnable")) {
   13.51 -                fail("Should contain warning about Runnable: " + msg);
   13.52 -            }
   13.53 -        }
   13.54 -    }
   13.55 -    
   13.56 -}