2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import org.apidesign.javap.AnnotationParser;
23 import org.apidesign.javap.ClassData;
24 import org.apidesign.javap.FieldData;
25 import org.apidesign.javap.MethodData;
26 import static org.apidesign.javap.RuntimeConstants.*;
28 /** Translator of the code inside class files to JavaScript.
30 * @author Jaroslav Tulach <jtulach@netbeans.org>
32 public abstract class ByteCodeToJavaScript {
34 private final Appendable out;
36 protected ByteCodeToJavaScript(Appendable out) {
40 /* Collects additional required resources.
42 * @param internalClassName classes that were referenced and should be loaded in order the
43 * generated JavaScript code works properly. The names are in internal
44 * JVM form so String is <code>java/lang/String</code>.
46 protected abstract boolean requireReference(String internalClassName);
49 * @param resourcePath name of resources to read
51 protected abstract void requireScript(String resourcePath);
53 /** Allows subclasses to redefine what field a function representing a
54 * class gets assigned. By default it returns the suggested name followed
55 * by <code>" = "</code>;
57 * @param className suggested name of the class
59 protected String assignClass(String className) {
60 return className + " = ";
64 * Converts a given class file to a JavaScript version.
66 * @param classFile input stream with code of the .class file
67 * @return the initialization code for this class, if any. Otherwise <code>null</code>
69 * @throws IOException if something goes wrong during read or write or translating
72 public String compile(InputStream classFile) throws IOException {
73 this.jc = new ClassData(classFile);
74 byte[] arrData = jc.findAnnotationData(true);
75 String[] arr = findAnnotation(arrData, jc,
76 "org.apidesign.bck2brwsr.core.ExtraJavaScript",
77 "resource", "processByteCode"
80 requireScript(arr[0]);
81 if ("0".equals(arr[1])) {
85 String[] proto = findAnnotation(arrData, jc,
86 "org.apidesign.bck2brwsr.core.JavaScriptPrototype",
87 "container", "prototype"
89 StringArray toInitilize = new StringArray();
90 final String className = className(jc);
91 out.append("\n\n").append(assignClass(className));
92 out.append("function CLS() {");
93 out.append("\n if (!CLS.prototype.$instOf_").append(className).append(") {");
94 for (FieldData v : jc.getFields()) {
96 out.append("\n CLS.").append(v.getName()).append(initField(v));
100 String sc = jc.getSuperClassName(); // with _
101 out.append("\n var pp = ").
102 append(sc.replace('/', '_')).append("(true);");
103 out.append("\n var p = CLS.prototype = pp;");
104 out.append("\n var c = p;");
105 out.append("\n var sprcls = pp.constructor.$class;");
107 out.append("\n var p = CLS.prototype = ").append(proto[1]).append(";");
108 out.append("\n var c = ").append(proto[0]).append(";");
109 out.append("\n var sprcls = null;");
111 for (MethodData m : jc.getMethods()) {
112 byte[] onlyArr = m.findAnnotationData(true);
113 String[] only = findAnnotation(onlyArr, jc,
114 "org.apidesign.bck2brwsr.core.JavaScriptOnly",
118 if (only[0] != null && only[1] != null) {
119 out.append("\n p.").append(only[0]).append(" = ")
120 .append(only[1]).append(";");
125 generateStaticMethod("\n c.", m, toInitilize);
127 generateInstanceMethod("\n c.", m);
130 out.append("\n c.constructor = CLS;");
131 out.append("\n c.$instOf_").append(className).append(" = true;");
132 for (String superInterface : jc.getSuperInterfaces()) {
133 out.append("\n c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
135 out.append("\n CLS.$class = java_lang_Class(true);");
136 out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
137 out.append("\n CLS.$class.superclass = sprcls;");
138 out.append("\n CLS.$class.cnstr = CLS;");
139 byte[] classAnno = jc.findAnnotationData(false);
140 if (classAnno != null) {
141 out.append("\n CLS.$class.anno = {");
142 generateAnno(jc, out, classAnno);
146 out.append("\n if (arguments.length === 0) {");
147 out.append("\n if (!(this instanceof CLS)) {");
148 out.append("\n return new CLS();");
150 for (FieldData v : jc.getFields()) {
151 byte[] onlyArr = v.findAnnotationData(true);
152 String[] only = findAnnotation(onlyArr, jc,
153 "org.apidesign.bck2brwsr.core.JavaScriptOnly",
157 if (only[0] != null && only[1] != null) {
158 out.append("\n p.").append(only[0]).append(" = ")
159 .append(only[1]).append(";");
164 out.append("\n this.fld_").
165 append(v.getName()).append(initField(v));
168 out.append("\n return this;");
170 out.append("\n return arguments[0] ? new CLS() : CLS.prototype;");
172 StringBuilder sb = new StringBuilder();
173 for (String init : toInitilize.toArray()) {
174 sb.append("\n").append(init).append("();");
176 return sb.toString();
178 private void generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
179 if (javaScriptBody(prefix, m, true)) {
182 StringBuilder argsCnt = new StringBuilder();
183 final String mn = findMethodName(m, argsCnt);
184 out.append(prefix).append(mn).append(" = function");
185 if (mn.equals("class__V")) {
186 toInitilize.add(className(jc) + "(false)." + mn);
190 for (int index = 0, i = 0; i < argsCnt.length(); i++) {
192 out.append("arg").append(String.valueOf(index));
194 final String desc = null;// XXX findDescriptor(args.get(i).getDescriptor());
195 if (argsCnt.charAt(i) == '1') {
201 out.append(") {").append("\n");
202 final byte[] code = m.getCode();
204 int len = m.getMaxLocals();
205 for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
207 out.append("arg").append(String.valueOf(i)).append(";\n");
209 out.append(" var s = new Array();\n");
212 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
217 private void generateInstanceMethod(String prefix, MethodData m) throws IOException {
218 if (javaScriptBody(prefix, m, false)) {
221 StringBuilder argsCnt = new StringBuilder();
222 final String mn = findMethodName(m, argsCnt);
223 out.append(prefix).append(mn).append(" = function");
226 for (int index = 1, i = 0; i < argsCnt.length(); i++) {
228 out.append("arg").append(String.valueOf(index));
229 if (argsCnt.charAt(i) == '1') {
235 out.append(") {").append("\n");
236 final byte[] code = m.getCode();
238 int len = m.getMaxLocals();
239 for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
241 out.append("arg").append(String.valueOf(i + 1)).append(";\n");
243 out.append(";\n var s = new Array();\n");
246 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
251 private void produceCode(byte[] byteCodes) throws IOException {
252 out.append("\n var gt = 0;\n for(;;) switch(gt) {\n");
253 for (int i = 0; i < byteCodes.length; i++) {
255 out.append(" case " + i).append(": ");
256 final int c = readByte(byteCodes, i);
263 out.append("s.push(arg0);");
270 out.append("s.push(arg1);");
277 out.append("s.push(arg2);");
284 out.append("s.push(arg3);");
291 final int indx = readByte(byteCodes, ++i);
292 out.append("s.push(arg").append(indx + ");");
300 final int indx = readByte(byteCodes, ++i);
301 out.append("arg" + indx).append(" = s.pop();");
309 out.append("arg0 = s.pop();");
316 out.append("arg1 = s.pop();");
323 out.append("arg2 = s.pop();");
330 out.append("arg3 = s.pop();");
336 out.append("s.push(s.pop() + s.pop());");
342 out.append("{ var tmp = s.pop(); s.push(s.pop() - tmp); }");
348 out.append("s.push(s.pop() * s.pop());");
352 out.append("{ var tmp = s.pop(); s.push(Math.floor(s.pop() / tmp)); }");
356 out.append("{ var tmp = s.pop(); s.push(s.pop() / tmp); }");
362 out.append("{ var d = s.pop(); s.push(s.pop() % d); }");
366 out.append("s.push(s.pop() & s.pop());");
370 out.append("s.push(s.pop() | s.pop());");
374 out.append("s.push(s.pop() ^ s.pop());");
380 out.append("s.push(- s.pop());");
384 out.append("{ var v = s.pop(); s.push(s.pop() << v); }");
388 out.append("{ var v = s.pop(); s.push(s.pop() >> v); }");
392 out.append("{ var v = s.pop(); s.push(s.pop() >>> v); }");
395 final int varIndx = readByte(byteCodes, ++i);
396 final int incrBy = byteCodes[++i];
398 out.append("arg" + varIndx).append("++;");
400 out.append("arg" + varIndx).append(" += " + incrBy).append(";");
405 out.append("return;");
412 out.append("return s.pop();");
423 out.append("/* number conversion */");
429 out.append("s.push(Math.floor(s.pop()));");
434 out.append("/* number conversion */");
436 case opc_aconst_null:
437 out.append("s.push(null);");
440 out.append("s.push(-1);");
446 out.append("s.push(0);");
452 out.append("s.push(1);");
456 out.append("s.push(2);");
459 out.append("s.push(3);");
462 out.append("s.push(4);");
465 out.append("s.push(5);");
468 int indx = readByte(byteCodes, ++i);
469 String v = encodeConstant(indx);
470 out.append("s.push(").append(v).append(");");
475 int indx = readIntArg(byteCodes, i);
477 String v = encodeConstant(indx);
478 out.append("s.push(").append(v).append(");");
486 out.append("{ var delta = s.pop() - s.pop(); s.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
490 i = generateIf(byteCodes, i, "===");
493 i = generateIf(byteCodes, i, "!=");
495 case opc_if_icmpeq: {
496 i = generateIf(byteCodes, i, "==");
500 int indx = i + readIntArg(byteCodes, i);
501 out.append("if (s.pop() == 0) { gt = " + indx);
502 out.append("; continue; }");
507 int indx = i + readIntArg(byteCodes, i);
508 out.append("if (s.pop() != 0) { gt = " + indx);
509 out.append("; continue; }");
514 int indx = i + readIntArg(byteCodes, i);
515 out.append("if (s.pop() < 0) { gt = " + indx);
516 out.append("; continue; }");
521 int indx = i + readIntArg(byteCodes, i);
522 out.append("if (s.pop() <= 0) { gt = " + indx);
523 out.append("; continue; }");
528 int indx = i + readIntArg(byteCodes, i);
529 out.append("if (s.pop() > 0) { gt = " + indx);
530 out.append("; continue; }");
535 int indx = i + readIntArg(byteCodes, i);
536 out.append("if (s.pop() >= 0) { gt = " + indx);
537 out.append("; continue; }");
541 case opc_ifnonnull: {
542 int indx = i + readIntArg(byteCodes, i);
543 out.append("if (s.pop() !== null) { gt = " + indx);
544 out.append("; continue; }");
549 int indx = i + readIntArg(byteCodes, i);
550 out.append("if (s.pop() === null) { gt = " + indx);
551 out.append("; continue; }");
556 i = generateIf(byteCodes, i, "!=");
559 i = generateIf(byteCodes, i, ">");
562 i = generateIf(byteCodes, i, ">=");
565 i = generateIf(byteCodes, i, "<");
568 i = generateIf(byteCodes, i, "<=");
571 int indx = i + readIntArg(byteCodes, i);
572 out.append("gt = " + indx).append("; continue;");
576 case opc_lookupswitch: {
577 int table = i / 4 * 4 + 4;
578 int dflt = i + readInt4(byteCodes, table);
580 int n = readInt4(byteCodes, table);
582 out.append("switch (s.pop()) {\n");
584 int cnstnt = readInt4(byteCodes, table);
586 int offset = i + readInt4(byteCodes, table);
588 out.append(" case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
590 out.append(" default: gt = " + dflt).append("; continue;\n}");
594 case opc_tableswitch: {
595 int table = i / 4 * 4 + 4;
596 int dflt = i + readInt4(byteCodes, table);
598 int low = readInt4(byteCodes, table);
600 int high = readInt4(byteCodes, table);
602 out.append("switch (s.pop()) {\n");
603 while (low <= high) {
604 int offset = i + readInt4(byteCodes, table);
606 out.append(" case " + low).append(": gt = " + offset).append("; continue;\n");
609 out.append(" default: gt = " + dflt).append("; continue;\n}");
613 case opc_invokeinterface: {
614 i = invokeVirtualMethod(byteCodes, i) + 2;
617 case opc_invokevirtual:
618 i = invokeVirtualMethod(byteCodes, i);
620 case opc_invokespecial:
621 i = invokeStaticMethod(byteCodes, i, false);
623 case opc_invokestatic:
624 i = invokeStaticMethod(byteCodes, i, true);
627 int indx = readIntArg(byteCodes, i);
628 String ci = jc.getClassName(indx);
629 out.append("s.push(new ");
630 out.append(ci.replace('/','_'));
637 int type = byteCodes[i++];
638 out.append("s.push(new Array(s.pop()).fillNulls());");
641 case opc_anewarray: {
642 i += 2; // skip type of array
643 out.append("s.push(new Array(s.pop()).fillNulls());");
646 case opc_multianewarray: {
648 int dim = readByte(byteCodes, ++i);
649 out.append("{ var a0 = new Array(s.pop()).fillNulls();");
650 for (int d = 1; d < dim; d++) {
651 out.append("\n var l" + d).append(" = s.pop();");
652 out.append("\n for (var i" + d).append (" = 0; i" + d).
653 append(" < a" + (d - 1)).
654 append(".length; i" + d).append("++) {");
655 out.append("\n var a" + d).
656 append (" = new Array(l" + d).append(").fillNulls();");
657 out.append("\n a" + (d - 1)).append("[i" + d).append("] = a" + d).
660 for (int d = 1; d < dim; d++) {
663 out.append("\ns.push(a0); }");
666 case opc_arraylength:
667 out.append("s.push(s.pop().length);");
677 out.append("{ var value = s.pop(); var indx = s.pop(); s.pop()[indx] = value; }");
688 out.append("{ var indx = s.pop(); s.push(s.pop()[indx]); }");
692 out.append("s.pop();");
694 out.append("s.pop();");
697 out.append("s.push(s[s.length - 1]);");
700 out.append("{ var v1 = s.pop(); var v2 = s.pop(); s.push(v1); s.push(v2); s.push(v1); }");
703 out.append("{ var v1 = s.pop(); var v2 = s.pop(); var v3 = s.pop(); s.push(v1); s.push(v3); s.push(v2); s.push(v1); }");
706 out.append("s.push(" + byteCodes[++i] + ");");
709 out.append("s.push(" + readIntArg(byteCodes, i) + ");");
713 int indx = readIntArg(byteCodes, i);
714 String[] fi = jc.getFieldInfoName(indx);
715 out.append("s.push(s.pop().fld_").
716 append(fi[1]).append(");");
720 case opc_getstatic: {
721 int indx = readIntArg(byteCodes, i);
722 String[] fi = jc.getFieldInfoName(indx);
723 out.append("s.push(").append(fi[0].replace('/', '_'));
724 out.append('.').append(fi[1]).append(");");
729 case opc_putstatic: {
730 int indx = readIntArg(byteCodes, i);
731 String[] fi = jc.getFieldInfoName(indx);
732 out.append(fi[0].replace('/', '_'));
733 out.append('.').append(fi[1]).append(" = s.pop();");
739 int indx = readIntArg(byteCodes, i);
740 String[] fi = jc.getFieldInfoName(indx);
741 out.append("{ var v = s.pop(); s.pop().fld_")
742 .append(fi[1]).append(" = v; }");
746 case opc_checkcast: {
747 int indx = readIntArg(byteCodes, i);
748 final String type = jc.getClassName(indx);
749 if (!type.startsWith("[")) {
750 // no way to check arrays right now
751 out.append("if(s[s.length - 1].$instOf_")
752 .append(type.replace('/', '_'))
753 .append(" != 1) throw {};"); // XXX proper exception
758 case opc_instanceof: {
759 int indx = readIntArg(byteCodes, i);
760 final String type = jc.getClassName(indx);
761 out.append("s.push(s.pop().$instOf_")
762 .append(type.replace('/', '_'))
763 .append(" ? 1 : 0);");
768 out.append("{ var t = s.pop(); s = new Array(1); s[0] = t; throw t; }");
772 out.append("throw 'unknown bytecode " + c + "';");
777 for (int j = prev; j <= i; j++) {
779 final int cc = readByte(byteCodes, j);
780 out.append(Integer.toString(cc));
787 private int generateIf(byte[] byteCodes, int i, final String test) throws IOException {
788 int indx = i + readIntArg(byteCodes, i);
789 out.append("if (s.pop() ").append(test).append(" s.pop()) { gt = " + indx);
790 out.append("; continue; }");
794 private int readIntArg(byte[] byteCodes, int offsetInstruction) {
795 final int indxHi = byteCodes[offsetInstruction + 1] << 8;
796 final int indxLo = byteCodes[offsetInstruction + 2];
797 return (indxHi & 0xffffff00) | (indxLo & 0xff);
799 private int readInt4(byte[] byteCodes, int offsetInstruction) {
800 final int d = byteCodes[offsetInstruction + 0] << 24;
801 final int c = byteCodes[offsetInstruction + 1] << 16;
802 final int b = byteCodes[offsetInstruction + 2] << 8;
803 final int a = byteCodes[offsetInstruction + 3];
804 return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
806 private int readByte(byte[] byteCodes, int offsetInstruction) {
807 return (byteCodes[offsetInstruction] + 256) % 256;
810 private static void countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig, StringBuilder cnt) {
812 Boolean count = null;
813 boolean array = false;
815 int firstPos = sig.length();
816 while (i < descriptor.length()) {
817 char ch = descriptor.charAt(i++);
838 if (ch == 'J' || ch == 'D') {
844 hasReturnType[0] = true;
845 sig.insert(firstPos, ch);
847 sig.insert(firstPos, "_3");
854 hasReturnType[0] = false;
855 sig.insert(firstPos, 'V');
858 int next = descriptor.indexOf(';', i);
859 String realSig = mangleSig(descriptor, i - 1, next + 1);
867 sig.insert(firstPos, realSig);
869 sig.insert(firstPos, "_3");
871 hasReturnType[0] = true;
879 throw new IllegalStateException("Invalid char: " + ch);
884 private static String mangleSig(String txt, int first, int last) {
885 StringBuilder sb = new StringBuilder();
886 for (int i = first; i < last; i++) {
887 final char ch = txt.charAt(i);
889 case '/': sb.append('_'); break;
890 case '_': sb.append("_1"); break;
891 case ';': sb.append("_2"); break;
892 case '[': sb.append("_3"); break;
893 default: sb.append(ch); break;
896 return sb.toString();
899 private static String findMethodName(MethodData m, StringBuilder cnt) {
900 StringBuilder name = new StringBuilder();
901 if ("<init>".equals(m.getName())) { // NOI18N
902 name.append("cons"); // NOI18N
903 } else if ("<clinit>".equals(m.getName())) { // NOI18N
904 name.append("class"); // NOI18N
906 name.append(m.getName());
909 boolean hasReturn[] = { false };
910 countArgs(m.getInternalSig(), hasReturn, name, cnt);
911 return name.toString();
914 static String findMethodName(String[] mi, StringBuilder cnt, boolean[] hasReturn) {
915 StringBuilder name = new StringBuilder();
916 String descr = mi[2];//mi.getDescriptor();
918 if ("<init>".equals(nm)) { // NOI18N
919 name.append("cons"); // NOI18N
923 countArgs(descr, hasReturn, name, cnt);
924 return name.toString();
927 private int invokeStaticMethod(byte[] byteCodes, int i, boolean isStatic)
929 int methodIndex = readIntArg(byteCodes, i);
930 String[] mi = jc.getFieldInfoName(methodIndex);
931 boolean[] hasReturn = { false };
932 StringBuilder cnt = new StringBuilder();
933 String mn = findMethodName(mi, cnt, hasReturn);
935 for (int j = cnt.length() - 1; j >= 0; j--) {
936 out.append("var v" + j).append(" = s.pop(); ");
940 out.append("s.push(");
942 final String in = mi[0];
943 out.append(in.replace('/', '_'));
944 out.append("(false).");
949 out.append("s.pop()");
952 for (int j = 0; j < cnt.length(); j++) {
966 private int invokeVirtualMethod(byte[] byteCodes, int i)
968 int methodIndex = readIntArg(byteCodes, i);
969 String[] mi = jc.getFieldInfoName(methodIndex);
970 boolean[] hasReturn = { false };
971 StringBuilder cnt = new StringBuilder();
972 String mn = findMethodName(mi, cnt, hasReturn);
974 for (int j = cnt.length() - 1; j >= 0; j--) {
975 out.append("var v" + j).append(" = s.pop(); ");
977 out.append("var self = s.pop(); ");
979 out.append("s.push(");
985 for (int j = 0; j < cnt.length(); j++) {
998 private void addReference(String cn) throws IOException {
999 if (requireReference(cn)) {
1000 out.append(" /* needs ").append(cn).append(" */");
1004 private void outType(String d, StringBuilder out) {
1006 while (d.charAt(0) == '[') {
1010 if (d.charAt(0) == 'L') {
1011 assert d.charAt(d.length() - 1) == ';';
1012 out.append(d.replace('/', '_').substring(0, d.length() - 1));
1018 private String encodeConstant(int entryIndex) throws IOException {
1019 String[] classRef = { null };
1020 String s = jc.stringValue(entryIndex, classRef);
1021 if (classRef[0] != null) {
1022 addReference(classRef[0]);
1027 private boolean javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
1028 byte[] arr = m.findAnnotationData(true);
1032 final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
1033 class P extends AnnotationParser {
1039 String[] args = new String[30];
1043 protected void visitAttr(String type, String attr, String at, String value) {
1044 if (type.equals(jvmType)) {
1045 if ("body".equals(attr)) {
1047 } else if ("args".equals(attr)) {
1048 args[cnt++] = value;
1050 throw new IllegalArgumentException(attr);
1057 if (p.body == null) {
1060 StringBuilder cnt = new StringBuilder();
1061 out.append(prefix).append(findMethodName(m, cnt));
1062 out.append(" = function(");
1066 out.append(p.args[0]);
1073 for (int i = 0; i < cnt.length(); i++) {
1075 out.append(p.args[index]);
1079 out.append(") {").append("\n");
1081 out.append("\n}\n");
1084 private static String className(ClassData jc) {
1085 //return jc.getName().getInternalName().replace('/', '_');
1086 return jc.getClassName().replace('/', '_');
1089 private static String[] findAnnotation(
1090 byte[] arr, ClassData cd, final String className,
1091 final String... attrNames
1092 ) throws IOException {
1096 final String[] values = new String[attrNames.length];
1097 final boolean[] found = { false };
1098 final String jvmType = "L" + className.replace('.', '/') + ";";
1099 AnnotationParser ap = new AnnotationParser(false) {
1101 protected void visitAttr(String type, String attr, String at, String value) {
1102 if (type.equals(jvmType)) {
1104 for (int i = 0; i < attrNames.length; i++) {
1105 if (attrNames[i].equals(attr)) {
1114 return found[0] ? values : null;
1117 private CharSequence initField(FieldData v) {
1118 final String is = v.getInternalSig();
1119 if (is.length() == 1) {
1120 switch (is.charAt(0)) {
1126 case 'I': return " = 0;";
1128 case 'D': return " = 0.0;";
1130 throw new IllegalStateException(is);
1136 private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
1137 AnnotationParser ap = new AnnotationParser(true) {
1142 protected void visitAnnotationStart(String type) throws IOException {
1146 out.append('"').append(type).append("\" : {\n");
1151 protected void visitAnnotationEnd(String type) throws IOException {
1152 out.append("\n}\n");
1156 protected void visitAttr(String type, String attr, String attrType, String value)
1157 throws IOException {
1161 out.append(attr).append("__").append(attrType).append(" : ").append(value);