1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Sep 28 14:58:21 2012 +0200
1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Oct 03 08:19:44 2012 -0700
1.3 @@ -22,6 +22,9 @@
1.4 import java.util.ArrayList;
1.5 import java.util.Collection;
1.6 import java.util.List;
1.7 +import org.apidesign.bck2brwsr.core.ExtraJavaScript;
1.8 +import org.netbeans.modules.classfile.Annotation;
1.9 +import org.netbeans.modules.classfile.AnnotationComponent;
1.10 import static org.netbeans.modules.classfile.ByteCodes.*;
1.11 import org.netbeans.modules.classfile.CPClassInfo;
1.12 import org.netbeans.modules.classfile.CPEntry;
1.13 @@ -31,8 +34,10 @@
1.14 import org.netbeans.modules.classfile.ClassFile;
1.15 import org.netbeans.modules.classfile.ClassName;
1.16 import org.netbeans.modules.classfile.Code;
1.17 +import org.netbeans.modules.classfile.ElementValue;
1.18 import org.netbeans.modules.classfile.Method;
1.19 import org.netbeans.modules.classfile.Parameter;
1.20 +import org.netbeans.modules.classfile.PrimitiveElementValue;
1.21 import org.netbeans.modules.classfile.Variable;
1.22
1.23 /** Translator of the code inside class files to JavaScript.
1.24 @@ -62,14 +67,29 @@
1.25 * generated JavaScript code works properly. The names are in internal
1.26 * JVM form so String is <code>java/lang/String</code>. Can be <code>null</code>
1.27 * if one is not interested in knowing references
1.28 + * @param scripts write only collection with names of resources to read
1.29 + *
1.30 * @throws IOException if something goes wrong during read or write or translating
1.31 */
1.32
1.33 public static void compile(
1.34 InputStream classFile, Appendable out,
1.35 - Collection<? super String> references
1.36 + Collection<? super String> references,
1.37 + Collection<? super String> scripts
1.38 ) throws IOException {
1.39 ClassFile jc = new ClassFile(classFile, true);
1.40 + final ClassName extraAnn = ClassName.getClassName(ExtraJavaScript.class.getName().replace('.', '/'));
1.41 + Annotation a = jc.getAnnotation(extraAnn);
1.42 + if (a != null) {
1.43 + final ElementValue annVal = a.getComponent("resource").getValue();
1.44 + String res = ((PrimitiveElementValue)annVal).getValue().getValue().toString();
1.45 + scripts.add(res);
1.46 + final AnnotationComponent process = a.getComponent("processByteCode");
1.47 + if (process != null && "false".equals(process.getValue().toString())) {
1.48 + return;
1.49 + }
1.50 + }
1.51 +
1.52 ByteCodeToJavaScript compiler = new ByteCodeToJavaScript(
1.53 jc, out, references
1.54 );