1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Feb 01 15:19:16 2013 +0100
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Tue Feb 05 08:27:42 2013 +0100
1.3 @@ -175,6 +175,7 @@
1.4 out.append("\n };");
1.5 }
1.6 out.append(prefix).append(mn).append(".access = " + m.getAccess()).append(";");
1.7 + out.append(prefix).append(mn).append(".cls = CLS;");
1.8 }
1.9 out.append("\n c.constructor = CLS;");
1.10 out.append("\n c.$instOf_").append(className).append(" = true;");
1.11 @@ -1605,7 +1606,7 @@
1.12 final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
1.13 class P extends AnnotationParser {
1.14 public P() {
1.15 - super(false);
1.16 + super(false, true);
1.17 }
1.18
1.19 int cnt;
1.20 @@ -1661,7 +1662,7 @@
1.21 final String[] values = new String[attrNames.length];
1.22 final boolean[] found = { false };
1.23 final String jvmType = "L" + className.replace('.', '/') + ";";
1.24 - AnnotationParser ap = new AnnotationParser(false) {
1.25 + AnnotationParser ap = new AnnotationParser(false, true) {
1.26 @Override
1.27 protected void visitAttr(String type, String attr, String at, String value) {
1.28 if (type.equals(jvmType)) {
1.29 @@ -1698,35 +1699,71 @@
1.30 return " = null;";
1.31 }
1.32
1.33 - private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
1.34 - AnnotationParser ap = new AnnotationParser(true) {
1.35 - int anno;
1.36 - int cnt;
1.37 + private void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
1.38 + AnnotationParser ap = new AnnotationParser(true, false) {
1.39 + int[] cnt = new int[32];
1.40 + int depth;
1.41
1.42 @Override
1.43 - protected void visitAnnotationStart(String type) throws IOException {
1.44 - if (anno++ > 0) {
1.45 + protected void visitAnnotationStart(String attrType, boolean top) throws IOException {
1.46 + final String slashType = attrType.substring(1, attrType.length() - 1);
1.47 + requireReference(slashType);
1.48 +
1.49 + if (cnt[depth]++ > 0) {
1.50 out.append(",");
1.51 }
1.52 - out.append('"').append(type).append("\" : {\n");
1.53 - cnt = 0;
1.54 + if (top) {
1.55 + out.append('"').append(attrType).append("\" : ");
1.56 + }
1.57 + out.append("{\n");
1.58 + cnt[++depth] = 0;
1.59 }
1.60
1.61 @Override
1.62 - protected void visitAnnotationEnd(String type) throws IOException {
1.63 + protected void visitAnnotationEnd(String type, boolean top) throws IOException {
1.64 out.append("\n}\n");
1.65 + depth--;
1.66 + }
1.67 +
1.68 + @Override
1.69 + protected void visitValueStart(String attrName, char type) throws IOException {
1.70 + if (cnt[depth]++ > 0) {
1.71 + out.append(",\n");
1.72 + }
1.73 + cnt[++depth] = 0;
1.74 + if (attrName != null) {
1.75 + out.append(attrName).append(" : ");
1.76 + }
1.77 + if (type == '[') {
1.78 + out.append("[");
1.79 + }
1.80 + }
1.81 +
1.82 + @Override
1.83 + protected void visitValueEnd(String attrName, char type) throws IOException {
1.84 + if (type == '[') {
1.85 + out.append("]");
1.86 + }
1.87 + depth--;
1.88 }
1.89
1.90 @Override
1.91 protected void visitAttr(String type, String attr, String attrType, String value)
1.92 throws IOException {
1.93 - if (attr == null) {
1.94 + if (attr == null && value == null) {
1.95 return;
1.96 }
1.97 - if (cnt++ > 0) {
1.98 - out.append(",\n");
1.99 - }
1.100 - out.append(attr).append("__").append(attrType).append(" : ").append(value);
1.101 + out.append(value);
1.102 + }
1.103 +
1.104 + @Override
1.105 + protected void visitEnumAttr(String type, String attr, String attrType, String value)
1.106 + throws IOException {
1.107 + final String slashType = attrType.substring(1, attrType.length() - 1);
1.108 + requireReference(slashType);
1.109 +
1.110 + out.append(accessClass(slashType.replace('/', '_')))
1.111 + .append("(false).constructor.").append(value);
1.112 }
1.113 };
1.114 ap.parse(data, cd);