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(";");
126 mn = generateStaticMethod("\n c.", m, toInitilize);
128 mn = generateInstanceMethod("\n c.", m);
130 byte[] runAnno = m.findAnnotationData(false);
131 if (runAnno != null) {
132 out.append("\n c.").append(mn).append(".anno = {");
133 generateAnno(jc, out, runAnno);
137 out.append("\n c.constructor = CLS;");
138 out.append("\n c.$instOf_").append(className).append(" = true;");
139 for (String superInterface : jc.getSuperInterfaces()) {
140 out.append("\n c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
142 out.append("\n CLS.$class = java_lang_Class(true);");
143 out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
144 out.append("\n CLS.$class.superclass = sprcls;");
145 out.append("\n CLS.$class.cnstr = CLS;");
146 byte[] classAnno = jc.findAnnotationData(false);
147 if (classAnno != null) {
148 out.append("\n CLS.$class.anno = {");
149 generateAnno(jc, out, classAnno);
153 out.append("\n if (arguments.length === 0) {");
154 out.append("\n if (!(this instanceof CLS)) {");
155 out.append("\n return new CLS();");
157 for (FieldData v : jc.getFields()) {
158 byte[] onlyArr = v.findAnnotationData(true);
159 String[] only = findAnnotation(onlyArr, jc,
160 "org.apidesign.bck2brwsr.core.JavaScriptOnly",
164 if (only[0] != null && only[1] != null) {
165 out.append("\n p.").append(only[0]).append(" = ")
166 .append(only[1]).append(";");
171 out.append("\n this.fld_").
172 append(v.getName()).append(initField(v));
175 out.append("\n return this;");
177 out.append("\n return arguments[0] ? new CLS() : CLS.prototype;");
179 StringBuilder sb = new StringBuilder();
180 for (String init : toInitilize.toArray()) {
181 sb.append("\n").append(init).append("();");
183 return sb.toString();
185 private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
186 String jsb = javaScriptBody(prefix, m, true);
190 StringBuilder argsCnt = new StringBuilder();
191 final String mn = findMethodName(m, argsCnt);
192 out.append(prefix).append(mn).append(" = function");
193 if (mn.equals("class__V")) {
194 toInitilize.add(className(jc) + "(false)." + mn);
198 for (int index = 0, i = 0; i < argsCnt.length(); i++) {
200 out.append("arg").append(String.valueOf(index));
202 final String desc = null;// XXX findDescriptor(args.get(i).getDescriptor());
203 if (argsCnt.charAt(i) == '1') {
209 out.append(") {").append("\n");
210 final byte[] code = m.getCode();
212 int len = m.getMaxLocals();
213 for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
215 out.append("arg").append(String.valueOf(i)).append(";\n");
217 out.append(" var s = new Array();\n");
220 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
226 private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
227 String jsb = javaScriptBody(prefix, m, false);
231 StringBuilder argsCnt = new StringBuilder();
232 final String mn = findMethodName(m, argsCnt);
233 out.append(prefix).append(mn).append(" = function");
236 for (int index = 1, i = 0; i < argsCnt.length(); i++) {
238 out.append("arg").append(String.valueOf(index));
239 if (argsCnt.charAt(i) == '1') {
245 out.append(") {").append("\n");
246 final byte[] code = m.getCode();
248 int len = m.getMaxLocals();
249 for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
251 out.append("arg").append(String.valueOf(i + 1)).append(";\n");
253 out.append(";\n var s = new Array();\n");
256 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
262 private void produceCode(byte[] byteCodes) throws IOException {
263 out.append("\n var gt = 0;\n for(;;) switch(gt) {\n");
264 for (int i = 0; i < byteCodes.length; i++) {
266 out.append(" case " + i).append(": ");
267 final int c = readByte(byteCodes, i);
274 out.append("s.push(arg0);");
281 out.append("s.push(arg1);");
288 out.append("s.push(arg2);");
295 out.append("s.push(arg3);");
302 final int indx = readByte(byteCodes, ++i);
303 out.append("s.push(arg").append(indx + ");");
311 final int indx = readByte(byteCodes, ++i);
312 out.append("arg" + indx).append(" = s.pop();");
320 out.append("arg0 = s.pop();");
327 out.append("arg1 = s.pop();");
334 out.append("arg2 = s.pop();");
341 out.append("arg3 = s.pop();");
347 out.append("s.push(s.pop() + s.pop());");
353 out.append("{ var tmp = s.pop(); s.push(s.pop() - tmp); }");
359 out.append("s.push(s.pop() * s.pop());");
363 out.append("{ var tmp = s.pop(); s.push(Math.floor(s.pop() / tmp)); }");
367 out.append("{ var tmp = s.pop(); s.push(s.pop() / tmp); }");
373 out.append("{ var d = s.pop(); s.push(s.pop() % d); }");
377 out.append("s.push(s.pop() & s.pop());");
381 out.append("s.push(s.pop() | s.pop());");
385 out.append("s.push(s.pop() ^ s.pop());");
391 out.append("s.push(- s.pop());");
395 out.append("{ var v = s.pop(); s.push(s.pop() << v); }");
399 out.append("{ var v = s.pop(); s.push(s.pop() >> v); }");
403 out.append("{ var v = s.pop(); s.push(s.pop() >>> v); }");
406 final int varIndx = readByte(byteCodes, ++i);
407 final int incrBy = byteCodes[++i];
409 out.append("arg" + varIndx).append("++;");
411 out.append("arg" + varIndx).append(" += " + incrBy).append(";");
416 out.append("return;");
423 out.append("return s.pop();");
434 out.append("/* number conversion */");
440 out.append("s.push(Math.floor(s.pop()));");
445 out.append("/* number conversion */");
447 case opc_aconst_null:
448 out.append("s.push(null);");
451 out.append("s.push(-1);");
457 out.append("s.push(0);");
463 out.append("s.push(1);");
467 out.append("s.push(2);");
470 out.append("s.push(3);");
473 out.append("s.push(4);");
476 out.append("s.push(5);");
479 int indx = readByte(byteCodes, ++i);
480 String v = encodeConstant(indx);
481 out.append("s.push(").append(v).append(");");
486 int indx = readIntArg(byteCodes, i);
488 String v = encodeConstant(indx);
489 out.append("s.push(").append(v).append(");");
497 out.append("{ var delta = s.pop() - s.pop(); s.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
501 i = generateIf(byteCodes, i, "===");
504 i = generateIf(byteCodes, i, "!=");
506 case opc_if_icmpeq: {
507 i = generateIf(byteCodes, i, "==");
511 int indx = i + readIntArg(byteCodes, i);
512 out.append("if (s.pop() == 0) { gt = " + indx);
513 out.append("; continue; }");
518 int indx = i + readIntArg(byteCodes, i);
519 out.append("if (s.pop() != 0) { gt = " + indx);
520 out.append("; continue; }");
525 int indx = i + readIntArg(byteCodes, i);
526 out.append("if (s.pop() < 0) { gt = " + indx);
527 out.append("; continue; }");
532 int indx = i + readIntArg(byteCodes, i);
533 out.append("if (s.pop() <= 0) { gt = " + indx);
534 out.append("; continue; }");
539 int indx = i + readIntArg(byteCodes, i);
540 out.append("if (s.pop() > 0) { gt = " + indx);
541 out.append("; continue; }");
546 int indx = i + readIntArg(byteCodes, i);
547 out.append("if (s.pop() >= 0) { gt = " + indx);
548 out.append("; continue; }");
552 case opc_ifnonnull: {
553 int indx = i + readIntArg(byteCodes, i);
554 out.append("if (s.pop() !== null) { gt = " + indx);
555 out.append("; continue; }");
560 int indx = i + readIntArg(byteCodes, i);
561 out.append("if (s.pop() === null) { gt = " + indx);
562 out.append("; continue; }");
567 i = generateIf(byteCodes, i, "!=");
570 i = generateIf(byteCodes, i, ">");
573 i = generateIf(byteCodes, i, ">=");
576 i = generateIf(byteCodes, i, "<");
579 i = generateIf(byteCodes, i, "<=");
582 int indx = i + readIntArg(byteCodes, i);
583 out.append("gt = " + indx).append("; continue;");
587 case opc_lookupswitch: {
588 int table = i / 4 * 4 + 4;
589 int dflt = i + readInt4(byteCodes, table);
591 int n = readInt4(byteCodes, table);
593 out.append("switch (s.pop()) {\n");
595 int cnstnt = readInt4(byteCodes, table);
597 int offset = i + readInt4(byteCodes, table);
599 out.append(" case " + cnstnt).append(": gt = " + offset).append("; continue;\n");
601 out.append(" default: gt = " + dflt).append("; continue;\n}");
605 case opc_tableswitch: {
606 int table = i / 4 * 4 + 4;
607 int dflt = i + readInt4(byteCodes, table);
609 int low = readInt4(byteCodes, table);
611 int high = readInt4(byteCodes, table);
613 out.append("switch (s.pop()) {\n");
614 while (low <= high) {
615 int offset = i + readInt4(byteCodes, table);
617 out.append(" case " + low).append(": gt = " + offset).append("; continue;\n");
620 out.append(" default: gt = " + dflt).append("; continue;\n}");
624 case opc_invokeinterface: {
625 i = invokeVirtualMethod(byteCodes, i) + 2;
628 case opc_invokevirtual:
629 i = invokeVirtualMethod(byteCodes, i);
631 case opc_invokespecial:
632 i = invokeStaticMethod(byteCodes, i, false);
634 case opc_invokestatic:
635 i = invokeStaticMethod(byteCodes, i, true);
638 int indx = readIntArg(byteCodes, i);
639 String ci = jc.getClassName(indx);
640 out.append("s.push(new ");
641 out.append(ci.replace('/','_'));
648 int type = byteCodes[i++];
649 out.append("s.push(new Array(s.pop()).fillNulls());");
652 case opc_anewarray: {
653 i += 2; // skip type of array
654 out.append("s.push(new Array(s.pop()).fillNulls());");
657 case opc_multianewarray: {
659 int dim = readByte(byteCodes, ++i);
660 out.append("{ var a0 = new Array(s.pop()).fillNulls();");
661 for (int d = 1; d < dim; d++) {
662 out.append("\n var l" + d).append(" = s.pop();");
663 out.append("\n for (var i" + d).append (" = 0; i" + d).
664 append(" < a" + (d - 1)).
665 append(".length; i" + d).append("++) {");
666 out.append("\n var a" + d).
667 append (" = new Array(l" + d).append(").fillNulls();");
668 out.append("\n a" + (d - 1)).append("[i" + d).append("] = a" + d).
671 for (int d = 1; d < dim; d++) {
674 out.append("\ns.push(a0); }");
677 case opc_arraylength:
678 out.append("s.push(s.pop().length);");
688 out.append("{ var value = s.pop(); var indx = s.pop(); s.pop()[indx] = value; }");
699 out.append("{ var indx = s.pop(); s.push(s.pop()[indx]); }");
703 out.append("s.pop();");
705 out.append("s.pop();");
708 out.append("s.push(s[s.length - 1]);");
711 out.append("{ var v1 = s.pop(); var v2 = s.pop(); s.push(v1); s.push(v2); s.push(v1); }");
714 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); }");
717 out.append("s.push(" + byteCodes[++i] + ");");
720 out.append("s.push(" + readIntArg(byteCodes, i) + ");");
724 int indx = readIntArg(byteCodes, i);
725 String[] fi = jc.getFieldInfoName(indx);
726 out.append("s.push(s.pop().fld_").
727 append(fi[1]).append(");");
731 case opc_getstatic: {
732 int indx = readIntArg(byteCodes, i);
733 String[] fi = jc.getFieldInfoName(indx);
734 out.append("s.push(").append(fi[0].replace('/', '_'));
735 out.append('.').append(fi[1]).append(");");
740 case opc_putstatic: {
741 int indx = readIntArg(byteCodes, i);
742 String[] fi = jc.getFieldInfoName(indx);
743 out.append(fi[0].replace('/', '_'));
744 out.append('.').append(fi[1]).append(" = s.pop();");
750 int indx = readIntArg(byteCodes, i);
751 String[] fi = jc.getFieldInfoName(indx);
752 out.append("{ var v = s.pop(); s.pop().fld_")
753 .append(fi[1]).append(" = v; }");
757 case opc_checkcast: {
758 int indx = readIntArg(byteCodes, i);
759 final String type = jc.getClassName(indx);
760 if (!type.startsWith("[")) {
761 // no way to check arrays right now
762 out.append("if(s[s.length - 1].$instOf_")
763 .append(type.replace('/', '_'))
764 .append(" != 1) throw {};"); // XXX proper exception
769 case opc_instanceof: {
770 int indx = readIntArg(byteCodes, i);
771 final String type = jc.getClassName(indx);
772 out.append("s.push(s.pop().$instOf_")
773 .append(type.replace('/', '_'))
774 .append(" ? 1 : 0);");
779 out.append("{ var t = s.pop(); s = new Array(1); s[0] = t; throw t; }");
783 out.append("throw 'unknown bytecode " + c + "';");
788 for (int j = prev; j <= i; j++) {
790 final int cc = readByte(byteCodes, j);
791 out.append(Integer.toString(cc));
798 private int generateIf(byte[] byteCodes, int i, final String test) throws IOException {
799 int indx = i + readIntArg(byteCodes, i);
800 out.append("if (s.pop() ").append(test).append(" s.pop()) { gt = " + indx);
801 out.append("; continue; }");
805 private int readIntArg(byte[] byteCodes, int offsetInstruction) {
806 final int indxHi = byteCodes[offsetInstruction + 1] << 8;
807 final int indxLo = byteCodes[offsetInstruction + 2];
808 return (indxHi & 0xffffff00) | (indxLo & 0xff);
810 private int readInt4(byte[] byteCodes, int offsetInstruction) {
811 final int d = byteCodes[offsetInstruction + 0] << 24;
812 final int c = byteCodes[offsetInstruction + 1] << 16;
813 final int b = byteCodes[offsetInstruction + 2] << 8;
814 final int a = byteCodes[offsetInstruction + 3];
815 return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
817 private int readByte(byte[] byteCodes, int offsetInstruction) {
818 return (byteCodes[offsetInstruction] + 256) % 256;
821 private static void countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig, StringBuilder cnt) {
823 Boolean count = null;
824 boolean array = false;
826 int firstPos = sig.length();
827 while (i < descriptor.length()) {
828 char ch = descriptor.charAt(i++);
849 if (ch == 'J' || ch == 'D') {
855 hasReturnType[0] = true;
856 sig.insert(firstPos, ch);
858 sig.insert(firstPos, "_3");
865 hasReturnType[0] = false;
866 sig.insert(firstPos, 'V');
869 int next = descriptor.indexOf(';', i);
870 String realSig = mangleSig(descriptor, i - 1, next + 1);
878 sig.insert(firstPos, realSig);
880 sig.insert(firstPos, "_3");
882 hasReturnType[0] = true;
890 throw new IllegalStateException("Invalid char: " + ch);
895 private static String mangleSig(String txt, int first, int last) {
896 StringBuilder sb = new StringBuilder();
897 for (int i = first; i < last; i++) {
898 final char ch = txt.charAt(i);
900 case '/': sb.append('_'); break;
901 case '_': sb.append("_1"); break;
902 case ';': sb.append("_2"); break;
903 case '[': sb.append("_3"); break;
904 default: sb.append(ch); break;
907 return sb.toString();
910 private static String findMethodName(MethodData m, StringBuilder cnt) {
911 StringBuilder name = new StringBuilder();
912 if ("<init>".equals(m.getName())) { // NOI18N
913 name.append("cons"); // NOI18N
914 } else if ("<clinit>".equals(m.getName())) { // NOI18N
915 name.append("class"); // NOI18N
917 name.append(m.getName());
920 boolean hasReturn[] = { false };
921 countArgs(m.getInternalSig(), hasReturn, name, cnt);
922 return name.toString();
925 static String findMethodName(String[] mi, StringBuilder cnt, boolean[] hasReturn) {
926 StringBuilder name = new StringBuilder();
927 String descr = mi[2];//mi.getDescriptor();
929 if ("<init>".equals(nm)) { // NOI18N
930 name.append("cons"); // NOI18N
934 countArgs(descr, hasReturn, name, cnt);
935 return name.toString();
938 private int invokeStaticMethod(byte[] byteCodes, int i, boolean isStatic)
940 int methodIndex = readIntArg(byteCodes, i);
941 String[] mi = jc.getFieldInfoName(methodIndex);
942 boolean[] hasReturn = { false };
943 StringBuilder cnt = new StringBuilder();
944 String mn = findMethodName(mi, cnt, hasReturn);
946 for (int j = cnt.length() - 1; j >= 0; j--) {
947 out.append("var v" + j).append(" = s.pop(); ");
951 out.append("s.push(");
953 final String in = mi[0];
954 out.append(in.replace('/', '_'));
955 out.append("(false).");
960 out.append("s.pop()");
963 for (int j = 0; j < cnt.length(); j++) {
977 private int invokeVirtualMethod(byte[] byteCodes, int i)
979 int methodIndex = readIntArg(byteCodes, i);
980 String[] mi = jc.getFieldInfoName(methodIndex);
981 boolean[] hasReturn = { false };
982 StringBuilder cnt = new StringBuilder();
983 String mn = findMethodName(mi, cnt, hasReturn);
985 for (int j = cnt.length() - 1; j >= 0; j--) {
986 out.append("var v" + j).append(" = s.pop(); ");
988 out.append("var self = s.pop(); ");
990 out.append("s.push(");
996 for (int j = 0; j < cnt.length(); j++) {
1009 private void addReference(String cn) throws IOException {
1010 if (requireReference(cn)) {
1011 out.append(" /* needs ").append(cn).append(" */");
1015 private void outType(String d, StringBuilder out) {
1017 while (d.charAt(0) == '[') {
1021 if (d.charAt(0) == 'L') {
1022 assert d.charAt(d.length() - 1) == ';';
1023 out.append(d.replace('/', '_').substring(0, d.length() - 1));
1029 private String encodeConstant(int entryIndex) throws IOException {
1030 String[] classRef = { null };
1031 String s = jc.stringValue(entryIndex, classRef);
1032 if (classRef[0] != null) {
1033 addReference(classRef[0]);
1038 private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
1039 byte[] arr = m.findAnnotationData(true);
1043 final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
1044 class P extends AnnotationParser {
1050 String[] args = new String[30];
1054 protected void visitAttr(String type, String attr, String at, String value) {
1055 if (type.equals(jvmType)) {
1056 if ("body".equals(attr)) {
1058 } else if ("args".equals(attr)) {
1059 args[cnt++] = value;
1061 throw new IllegalArgumentException(attr);
1068 if (p.body == null) {
1071 StringBuilder cnt = new StringBuilder();
1072 final String mn = findMethodName(m, cnt);
1073 out.append(prefix).append(mn);
1074 out.append(" = function(");
1078 out.append(p.args[0]);
1085 for (int i = 0; i < cnt.length(); i++) {
1087 out.append(p.args[index]);
1091 out.append(") {").append("\n");
1093 out.append("\n}\n");
1096 private static String className(ClassData jc) {
1097 //return jc.getName().getInternalName().replace('/', '_');
1098 return jc.getClassName().replace('/', '_');
1101 private static String[] findAnnotation(
1102 byte[] arr, ClassData cd, final String className,
1103 final String... attrNames
1104 ) throws IOException {
1108 final String[] values = new String[attrNames.length];
1109 final boolean[] found = { false };
1110 final String jvmType = "L" + className.replace('.', '/') + ";";
1111 AnnotationParser ap = new AnnotationParser(false) {
1113 protected void visitAttr(String type, String attr, String at, String value) {
1114 if (type.equals(jvmType)) {
1116 for (int i = 0; i < attrNames.length; i++) {
1117 if (attrNames[i].equals(attr)) {
1126 return found[0] ? values : null;
1129 private CharSequence initField(FieldData v) {
1130 final String is = v.getInternalSig();
1131 if (is.length() == 1) {
1132 switch (is.charAt(0)) {
1138 case 'I': return " = 0;";
1140 case 'D': return " = 0.0;";
1142 throw new IllegalStateException(is);
1148 private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
1149 AnnotationParser ap = new AnnotationParser(true) {
1154 protected void visitAnnotationStart(String type) throws IOException {
1158 out.append('"').append(type).append("\" : {\n");
1163 protected void visitAnnotationEnd(String type) throws IOException {
1164 out.append("\n}\n");
1168 protected void visitAttr(String type, String attr, String attrType, String value)
1169 throws IOException {
1176 out.append(attr).append("__").append(attrType).append(" : ").append(value);