Merge with trunk arithmetic
authorLubomir Nerad <lubomir.nerad@oracle.com>
Fri, 15 Feb 2013 11:15:15 +0100
brancharithmetic
changeset 73480833f6829e6
parent 700 b9bf26ea0118
parent 733 25eba32a96cd
child 735 419d8802bcba
Merge with trunk
     1.1 --- a/benchmarks/matrix-multiplication/pom.xml	Thu Feb 07 17:41:41 2013 +0100
     1.2 +++ b/benchmarks/matrix-multiplication/pom.xml	Fri Feb 15 11:15:15 2013 +0100
     1.3 @@ -7,6 +7,11 @@
     1.4    <artifactId>matrix.multiplication</artifactId>
     1.5    <version>0.3-SNAPSHOT</version>
     1.6    <packaging>jar</packaging>
     1.7 +  <parent>
     1.8 +    <artifactId>benchmarks</artifactId>
     1.9 +    <groupId>org.apidesign.bck2brwsr</groupId>
    1.10 +    <version>0.3-SNAPSHOT</version>
    1.11 +  </parent>
    1.12  
    1.13    <name>Matrix multiplication</name>
    1.14  
    1.15 @@ -25,6 +30,14 @@
    1.16                 <target>1.7</target>
    1.17              </configuration>
    1.18            </plugin>
    1.19 +          <plugin>
    1.20 +              <groupId>org.apache.maven.plugins</groupId>
    1.21 +              <artifactId>maven-deploy-plugin</artifactId>
    1.22 +              <version>2.7</version>
    1.23 +              <configuration>
    1.24 +                  <skip>true</skip>
    1.25 +              </configuration>
    1.26 +          </plugin>      
    1.27        </plugins>
    1.28    </build>
    1.29    
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/JFXIssuesTest.java	Fri Feb 15 11:15:15 2013 +0100
     2.3 @@ -0,0 +1,46 @@
     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.compact.tck;
    2.22 +
    2.23 +import org.apidesign.bck2brwsr.vmtest.Compare;
    2.24 +import org.apidesign.bck2brwsr.vmtest.VMTest;
    2.25 +import org.testng.annotations.Factory;
    2.26 +
    2.27 +
    2.28 +public class JFXIssuesTest {
    2.29 +    private abstract class Application {
    2.30 +        public abstract int getID();
    2.31 +    }
    2.32 +    
    2.33 +    private class MyApplication extends Application {
    2.34 +
    2.35 +        @Override
    2.36 +        public int getID() {
    2.37 +            return 1;
    2.38 +        }
    2.39 +        
    2.40 +    } 
    2.41 +    
    2.42 +    @Compare public boolean isClassAssignable() {
    2.43 +        return Application.class.isAssignableFrom(MyApplication.class);
    2.44 +    }
    2.45 +    
    2.46 +    @Factory public static Object[] create() {
    2.47 +        return VMTest.create(JFXIssuesTest.class);
    2.48 +    }
    2.49 +}
     3.1 --- a/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java	Thu Feb 07 17:41:41 2013 +0100
     3.2 +++ b/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/ReaderTest.java	Fri Feb 15 11:15:15 2013 +0100
     3.3 @@ -20,6 +20,7 @@
     3.4  import java.io.ByteArrayInputStream;
     3.5  import java.io.IOException;
     3.6  import java.io.InputStreamReader;
     3.7 +import java.io.UnsupportedEncodingException;
     3.8  import java.util.Arrays;
     3.9  import org.apidesign.bck2brwsr.vmtest.Compare;
    3.10  import org.apidesign.bck2brwsr.vmtest.VMTest;
    3.11 @@ -50,8 +51,8 @@
    3.12          }
    3.13          return sb.toString().toString();
    3.14      }
    3.15 -    @Compare public String stringToBytes() {
    3.16 -        return Arrays.toString("Žluťoučký kůň".getBytes());
    3.17 +    @Compare public String stringToBytes() throws UnsupportedEncodingException {
    3.18 +        return Arrays.toString("\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("UTF-8"));
    3.19      }
    3.20      
    3.21      @Factory public static Object[] create() {
     4.1 --- a/emul/mini/src/main/java/java/lang/Class.java	Thu Feb 07 17:41:41 2013 +0100
     4.2 +++ b/emul/mini/src/main/java/java/lang/Class.java	Fri Feb 15 11:15:15 2013 +0100
     4.3 @@ -401,10 +401,15 @@
     4.4              return cmpType != null && getComponentType().isAssignableFrom(cmpType);
     4.5          }
     4.6          String prop = "$instOf_" + getName().replace('.', '_');
     4.7 -        return hasProperty(cls, prop);
     4.8 +        return hasCnstrProperty(cls, prop);
     4.9      }
    4.10  
    4.11 -
    4.12 +    @JavaScriptBody(args = { "who", "prop" }, body = 
    4.13 +        "if (who.cnstr.prototype[prop]) return true; else return false;"
    4.14 +    )
    4.15 +    private static native boolean hasCnstrProperty(Object who, String prop);
    4.16 +    
    4.17 +    
    4.18      /**
    4.19       * Determines if the specified {@code Class} object represents an
    4.20       * interface type.
     5.1 --- a/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Thu Feb 07 17:41:41 2013 +0100
     5.2 +++ b/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/lang/System.java	Fri Feb 15 11:15:15 2013 +0100
     5.3 @@ -45,7 +45,7 @@
     5.4      )
     5.5      public static native byte[] expandArray(byte[] arr, int expectedSize);
     5.6  
     5.7 -    @JavaScriptBody(args = {}, body = "return new Date().getMilliseconds();")
     5.8 +    @JavaScriptBody(args = {}, body = "return new Date().getTime();")
     5.9      public static native long currentTimeMillis();
    5.10      
    5.11      public static long nanoTime() {
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/ide/editor/pom.xml	Fri Feb 15 11:15:15 2013 +0100
     6.3 @@ -0,0 +1,198 @@
     6.4 +<?xml version="1.0" encoding="UTF-8"?>
     6.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     6.6 +    <modelVersion>4.0.0</modelVersion>
     6.7 +    <parent>
     6.8 +        <artifactId>ide</artifactId>
     6.9 +        <groupId>org.apidesign.bck2brwsr</groupId>
    6.10 +        <version>0.3-SNAPSHOT</version>
    6.11 +    </parent>
    6.12 +
    6.13 +    <groupId>org.apidesign.bck2brwsr.ide.editor</groupId>
    6.14 +    <artifactId>editor</artifactId>
    6.15 +    <version>0.3-SNAPSHOT</version>
    6.16 +    <packaging>nbm</packaging>
    6.17 +
    6.18 +    <name>Editor Support for Bck2Brwsr</name>
    6.19 +
    6.20 +    <properties>
    6.21 +        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    6.22 +        <netbeans.version>RELEASE72</netbeans.version>
    6.23 +        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    6.24 +    </properties>
    6.25 +
    6.26 +    <repositories>
    6.27 +        <!--
    6.28 +        Repository hosting NetBeans modules, especially APIs.
    6.29 +        Versions are based on IDE releases, e.g.: RELEASE691
    6.30 +        To create your own repository, use: nbm:populate-repository
    6.31 +        -->
    6.32 +        <repository>
    6.33 +            <id>netbeans</id>
    6.34 +            <name>NetBeans</name>
    6.35 +            <url>http://bits.netbeans.org/maven2/</url>
    6.36 +            <snapshots>
    6.37 +                <enabled>false</enabled>
    6.38 +            </snapshots>
    6.39 +        </repository>
    6.40 +    </repositories>
    6.41 +
    6.42 +    <dependencies>
    6.43 +        <dependency>
    6.44 +            <groupId>org.netbeans.api</groupId>
    6.45 +            <artifactId>org-netbeans-api-annotations-common</artifactId>
    6.46 +            <version>${netbeans.version}</version>
    6.47 +        </dependency>
    6.48 +        <dependency>
    6.49 +            <groupId>org.netbeans.api</groupId>
    6.50 +            <artifactId>org-netbeans-modules-java-source</artifactId>
    6.51 +            <version>${netbeans.version}</version>
    6.52 +        </dependency>
    6.53 +        <dependency>
    6.54 +            <groupId>org.netbeans.api</groupId>
    6.55 +            <artifactId>org-netbeans-libs-javacapi</artifactId>
    6.56 +            <version>${netbeans.version}</version>
    6.57 +        </dependency>
    6.58 +        <dependency>
    6.59 +            <groupId>org.netbeans.api</groupId>
    6.60 +            <artifactId>org-netbeans-spi-java-hints</artifactId>
    6.61 +            <version>${netbeans.version}</version>
    6.62 +        </dependency>
    6.63 +        <dependency>
    6.64 +            <groupId>org.netbeans.api</groupId>
    6.65 +            <artifactId>org-netbeans-modules-parsing-api</artifactId>
    6.66 +            <version>${netbeans.version}</version>
    6.67 +        </dependency>
    6.68 +        <dependency>
    6.69 +            <groupId>org.netbeans.api</groupId>
    6.70 +            <artifactId>org-netbeans-spi-editor-hints</artifactId>
    6.71 +            <version>${netbeans.version}</version>
    6.72 +        </dependency>
    6.73 +        <dependency>
    6.74 +            <groupId>org.netbeans.api</groupId>
    6.75 +            <artifactId>org-openide-util</artifactId>
    6.76 +            <version>${netbeans.version}</version>
    6.77 +        </dependency>
    6.78 +        <dependency>
    6.79 +            <groupId>org.netbeans.api</groupId>
    6.80 +            <artifactId>org-netbeans-modules-java-lexer</artifactId>
    6.81 +            <version>${netbeans.version}</version>
    6.82 +        </dependency>
    6.83 +        <dependency>
    6.84 +            <groupId>org.netbeans.api</groupId>
    6.85 +            <artifactId>org-netbeans-modules-lexer</artifactId>
    6.86 +            <version>${netbeans.version}</version>
    6.87 +        </dependency>
    6.88 +        <dependency>
    6.89 +            <groupId>org.apidesign.bck2brwsr</groupId>
    6.90 +            <artifactId>core</artifactId>
    6.91 +            <version>0.3-SNAPSHOT</version>
    6.92 +            <type>jar</type>
    6.93 +            <scope>test</scope>
    6.94 +        </dependency>
    6.95 +        <dependency>
    6.96 +            <groupId>org.netbeans.api</groupId>
    6.97 +            <artifactId>org-netbeans-modules-java-hints-test</artifactId>
    6.98 +            <version>${netbeans.version}</version>
    6.99 +            <scope>test</scope>
   6.100 +        </dependency>
   6.101 +        <dependency>
   6.102 +            <groupId>org.netbeans.api</groupId>
   6.103 +            <artifactId>org-netbeans-libs-junit4</artifactId>
   6.104 +            <version>${netbeans.version}</version>
   6.105 +            <scope>test</scope>
   6.106 +        </dependency>
   6.107 +        <dependency>
   6.108 +            <groupId>org.netbeans.modules</groupId>
   6.109 +            <artifactId>org-netbeans-lib-nbjavac</artifactId>
   6.110 +            <version>${netbeans.version}</version>
   6.111 +            <scope>test</scope>
   6.112 +        </dependency>
   6.113 +        <dependency>
   6.114 +            <groupId>org.testng</groupId>
   6.115 +            <artifactId>testng</artifactId>
   6.116 +            <scope>test</scope>
   6.117 +        </dependency>
   6.118 +    </dependencies>
   6.119 +
   6.120 +    <build>
   6.121 +        <plugins>
   6.122 +            <plugin>
   6.123 +                <groupId>org.codehaus.mojo</groupId>
   6.124 +                <artifactId>nbm-maven-plugin</artifactId>
   6.125 +                <version>3.8</version>
   6.126 +                <extensions>true</extensions>
   6.127 +            </plugin>
   6.128 +
   6.129 +            <plugin>
   6.130 +                <!-- NetBeans 6.9+ requires JDK 6 -->
   6.131 +                <groupId>org.apache.maven.plugins</groupId>
   6.132 +                <artifactId>maven-compiler-plugin</artifactId>
   6.133 +                <version>2.5.1</version>
   6.134 +                <configuration>
   6.135 +                    <source>1.6</source>
   6.136 +                    <target>1.6</target>
   6.137 +                    <compilerArguments>
   6.138 +                        <endorseddirs>${endorsed.dir}</endorseddirs>
   6.139 +                    </compilerArguments>
   6.140 +                </configuration>
   6.141 +            </plugin>
   6.142 +
   6.143 +            <plugin>
   6.144 +                <groupId>org.apache.maven.plugins</groupId>
   6.145 +                <artifactId>maven-jar-plugin</artifactId>
   6.146 +                <version>2.4</version>
   6.147 +                <configuration>
   6.148 +                    <!-- to have the jar plugin pickup the nbm generated manifest -->
   6.149 +                    <useDefaultManifestFile>true</useDefaultManifestFile>
   6.150 +                </configuration>
   6.151 +            </plugin>
   6.152 +
   6.153 +            <plugin>
   6.154 +                <groupId>org.apache.maven.plugins</groupId>
   6.155 +                <artifactId>maven-dependency-plugin</artifactId>
   6.156 +                <executions>
   6.157 +                    <execution>
   6.158 +                        <id>endorsed</id>
   6.159 +                        <phase>validate</phase>
   6.160 +                        <goals>
   6.161 +                            <goal>copy</goal>
   6.162 +                        </goals>
   6.163 +                    </execution>
   6.164 +                </executions>
   6.165 +                <configuration>
   6.166 +                    <outputDirectory>${endorsed.dir}</outputDirectory>
   6.167 +                    <silent>true</silent>
   6.168 +                    <artifactItems>
   6.169 +                        <artifactItem>
   6.170 +                            <groupId>org.netbeans.api</groupId>
   6.171 +                            <artifactId>org-netbeans-libs-javacapi</artifactId>
   6.172 +                            <version>${netbeans.version}</version>
   6.173 +                        </artifactItem>
   6.174 +                        <artifactItem>
   6.175 +                            <groupId>org.netbeans.external</groupId>
   6.176 +                            <artifactId>nb-javac-api</artifactId>
   6.177 +                            <version>${netbeans.version}</version>
   6.178 +                        </artifactItem>
   6.179 +                        <artifactItem>
   6.180 +                            <groupId>org.netbeans.modules</groupId>
   6.181 +                            <artifactId>org-netbeans-libs-javacimpl</artifactId>
   6.182 +                            <version>${netbeans.version}</version>
   6.183 +                        </artifactItem>
   6.184 +                        <artifactItem>
   6.185 +                            <groupId>org.netbeans.external</groupId>
   6.186 +                            <artifactId>nb-javac-impl</artifactId>
   6.187 +                            <version>${netbeans.version}</version>
   6.188 +                        </artifactItem>
   6.189 +                    </artifactItems>
   6.190 +                </configuration>
   6.191 +            </plugin>
   6.192 +            <plugin>
   6.193 +                <groupId>org.apache.maven.plugins</groupId>
   6.194 +                <artifactId>maven-surefire-plugin</artifactId>
   6.195 +                <configuration>
   6.196 +                    <argLine>-Djava.endorsed.dirs=${endorsed.dir}</argLine>
   6.197 +                </configuration>
   6.198 +            </plugin>
   6.199 +        </plugins>
   6.200 +    </build>
   6.201 +</project>
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java	Fri Feb 15 11:15:15 2013 +0100
     7.3 @@ -0,0 +1,80 @@
     7.4 +/**
     7.5 + * Back 2 Browser Bytecode Translator
     7.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     7.7 + *
     7.8 + * This program is free software: you can redistribute it and/or modify
     7.9 + * it under the terms of the GNU General Public License as published by
    7.10 + * the Free Software Foundation, version 2 of the License.
    7.11 + *
    7.12 + * This program is distributed in the hope that it will be useful,
    7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 + * GNU General Public License for more details.
    7.16 + *
    7.17 + * You should have received a copy of the GNU General Public License
    7.18 + * along with this program. Look for COPYING file in the top folder.
    7.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    7.20 + */
    7.21 +package org.apidesign.bck2brwsr.ide.editor;
    7.22 +
    7.23 +import java.lang.reflect.Method;
    7.24 +import java.util.HashMap;
    7.25 +import java.util.Map;
    7.26 +
    7.27 +/**
    7.28 + * JNI Helper.
    7.29 + * To facilitate lookup of methods by name and signature, instead of manually parsing signatures,
    7.30 + * constructs the map of all methods and uses Class.getName() to generate almost-correct signatures.
    7.31 + */
    7.32 +class JNIHelper {
    7.33 +
    7.34 +    static Method method(String clazz, String method, String signature) {
    7.35 +        final Map<String, Method> methods = methodMap(JNIHelper.clazz(clazz));
    7.36 +        return methods.get(methodKey(method, signature));
    7.37 +    }
    7.38 +
    7.39 +    static Class<?> clazz(String clazz) {
    7.40 +        try {
    7.41 +            return Class.forName(clazz);
    7.42 +        } catch (ClassNotFoundException e) {
    7.43 +            throw new IllegalArgumentException(e);
    7.44 +        }
    7.45 +    }
    7.46 +
    7.47 +    static Map<String, Method> methodMap(final Class<?> clazz) {
    7.48 +        final Map<String, Method> map = new HashMap<String, Method>();
    7.49 +        final Method[] methods = clazz.getDeclaredMethods();
    7.50 +        for (int i = 0; i < methods.length; i++) {
    7.51 +            final Method method = methods[i];
    7.52 +            map.put(methodKey(method.getName(), signature(method)), method);
    7.53 +        }
    7.54 +        return map;
    7.55 +    }
    7.56 +
    7.57 +    static String methodKey(String method, String signature) {
    7.58 +        return method + '@' + signature;
    7.59 +    }
    7.60 +
    7.61 +    static String signature(final Method method) {
    7.62 +        final Class<?>[] parameterTypes = method.getParameterTypes();
    7.63 +        final StringBuilder b = new StringBuilder();
    7.64 +        for (int j = 0; j < parameterTypes.length; j++) {
    7.65 +            b.append(signature(parameterTypes[j]));
    7.66 +        }
    7.67 +        return b.toString();
    7.68 +    }
    7.69 +
    7.70 +    static String signature(final Class<?> clazz) {
    7.71 +        if (clazz == boolean.class) return "Z";
    7.72 +        else if (clazz == byte.class) return "B";
    7.73 +        else if (clazz == char.class) return "C";
    7.74 +        else if (clazz == double.class) return "D";
    7.75 +        else if (clazz == float.class) return "F";
    7.76 +        else if (clazz == int.class) return "I";
    7.77 +        else if (clazz == long.class) return "J";
    7.78 +        else if (clazz == short.class) return "S";
    7.79 +        else if (clazz == void.class) return "V";
    7.80 +        else if (clazz.isArray()) return clazz.getName().replace('.','/');
    7.81 +        else return "L" + clazz.getName().replace('.','/') + ";";
    7.82 +    }
    7.83 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSEmbeddingProvider.java	Fri Feb 15 11:15:15 2013 +0100
     8.3 @@ -0,0 +1,188 @@
     8.4 +/**
     8.5 + * Back 2 Browser Bytecode Translator
     8.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 + *
     8.8 + * This program is free software: you can redistribute it and/or modify
     8.9 + * it under the terms of the GNU General Public License as published by
    8.10 + * the Free Software Foundation, version 2 of the License.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License
    8.18 + * along with this program. Look for COPYING file in the top folder.
    8.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
    8.20 + */
    8.21 +package org.apidesign.bck2brwsr.ide.editor;
    8.22 +
    8.23 +import com.sun.source.tree.AnnotationTree;
    8.24 +import com.sun.source.tree.AssignmentTree;
    8.25 +import com.sun.source.tree.CompilationUnitTree;
    8.26 +import com.sun.source.tree.ExpressionTree;
    8.27 +import com.sun.source.tree.LiteralTree;
    8.28 +import com.sun.source.tree.MethodTree;
    8.29 +import com.sun.source.util.SourcePositions;
    8.30 +import com.sun.source.util.TreePath;
    8.31 +import com.sun.source.util.TreePathScanner;
    8.32 +import com.sun.source.util.Trees;
    8.33 +import java.io.IOException;
    8.34 +import java.util.ArrayList;
    8.35 +import java.util.Collection;
    8.36 +import java.util.Collections;
    8.37 +import java.util.List;
    8.38 +import java.util.concurrent.atomic.AtomicBoolean;
    8.39 +import javax.lang.model.element.TypeElement;
    8.40 +import javax.swing.text.Document;
    8.41 +import org.netbeans.api.editor.mimelookup.MimeRegistration;
    8.42 +import org.netbeans.api.java.source.CompilationInfo;
    8.43 +import org.netbeans.api.java.source.JavaParserResultTask;
    8.44 +import org.netbeans.api.java.source.JavaSource;
    8.45 +import org.netbeans.api.lexer.Language;
    8.46 +import org.netbeans.api.lexer.TokenHierarchy;
    8.47 +import org.netbeans.api.lexer.TokenSequence;
    8.48 +import org.netbeans.modules.parsing.api.Snapshot;
    8.49 +import org.netbeans.modules.parsing.spi.Parser;
    8.50 +import org.netbeans.modules.parsing.spi.Scheduler;
    8.51 +import org.netbeans.modules.parsing.spi.SchedulerEvent;
    8.52 +import org.netbeans.modules.parsing.spi.SchedulerTask;
    8.53 +import org.netbeans.modules.parsing.spi.TaskFactory;
    8.54 +import org.openide.util.Exceptions;
    8.55 +
    8.56 +/**
    8.57 + *
    8.58 + * @author Tomas Zezula
    8.59 + */
    8.60 +public final class JSEmbeddingProvider extends JavaParserResultTask<Parser.Result> {
    8.61 +
    8.62 +    private static final int PRIORITY = 1000;
    8.63 +    private static final String JS_ANNOTATION = "org.apidesign.bck2brwsr.core.JavaScriptBody";  //NOI18N
    8.64 +    private static final String BODY = "body";                            //NOI18N
    8.65 +    private static final String JAVA_MIME_TYPE = "text/x-java";           //NOI18N
    8.66 +    private static final String JAVASCRIPT_MIME_TYPE = "text/javascript"; //NOI18N
    8.67 +    private final AtomicBoolean canceled = new AtomicBoolean();
    8.68 +
    8.69 +    private JSEmbeddingProvider() {
    8.70 +        super(JavaSource.Phase.ELEMENTS_RESOLVED);
    8.71 +    }
    8.72 +
    8.73 +    @Override
    8.74 +    public int getPriority() {
    8.75 +        return PRIORITY;
    8.76 +    }
    8.77 +
    8.78 +    @Override
    8.79 +    public void cancel() {
    8.80 +        canceled.set(true);
    8.81 +    }
    8.82 +
    8.83 +    @Override
    8.84 +    public Class<? extends Scheduler> getSchedulerClass() {
    8.85 +        return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER;
    8.86 +    }
    8.87 +
    8.88 +    @Override
    8.89 +    public void run(Parser.Result t, SchedulerEvent se) {
    8.90 +        canceled.set(false);
    8.91 +        final CompilationInfo ci = CompilationInfo.get(t);
    8.92 +        final CompilationUnitTree cu = ci.getCompilationUnit();
    8.93 +        final Trees trees = ci.getTrees();
    8.94 +        final SourcePositions sp = trees.getSourcePositions();
    8.95 +        final Finder f = new Finder(trees);
    8.96 +        final List<LiteralTree> result = new ArrayList<LiteralTree>();
    8.97 +        f.scan(cu, result);
    8.98 +        if (!result.isEmpty()) {
    8.99 +            try {
   8.100 +                final TokenHierarchy<Document> tk = TokenHierarchy.get(ci.getDocument());
   8.101 +                final Language<?> java = Language.find(JAVA_MIME_TYPE);
   8.102 +                final Language<?> javaScript = Language.find(JAVASCRIPT_MIME_TYPE);
   8.103 +                if (java != null && javaScript != null) {
   8.104 +                    final TokenSequence<?> seq = tk.tokenSequence(java);
   8.105 +                    if (seq != null) {
   8.106 +                        for (LiteralTree lt : result) {
   8.107 +                            final int start = (int) sp.getStartPosition(cu, lt);
   8.108 +                            final int end = (int) sp.getEndPosition(cu, lt);
   8.109 +                            seq.move(start);
   8.110 +                            while (seq.moveNext() && seq.offset() < end) {
   8.111 +                                seq.createEmbedding(javaScript, 1, 1, true);
   8.112 +                            }
   8.113 +                        }
   8.114 +                    }
   8.115 +                }
   8.116 +            } catch (IOException ioe) {
   8.117 +                Exceptions.printStackTrace(ioe);
   8.118 +            }
   8.119 +        }
   8.120 +    }
   8.121 +
   8.122 +
   8.123 +
   8.124 +
   8.125 +    private static final class Finder extends TreePathScanner<Void, List<? super LiteralTree>> {
   8.126 +
   8.127 +        private final Trees trees;
   8.128 +        private CompilationUnitTree cu;
   8.129 +        private boolean inEmbedding;
   8.130 +
   8.131 +        Finder(final Trees trees) {
   8.132 +            this.trees = trees;
   8.133 +        }
   8.134 +
   8.135 +        @Override
   8.136 +        public Void visitCompilationUnit(
   8.137 +                final CompilationUnitTree unit,
   8.138 +                final List p) {
   8.139 +            this.cu = unit;
   8.140 +            return super.visitCompilationUnit(unit, p);
   8.141 +        }
   8.142 +
   8.143 +
   8.144 +
   8.145 +        @Override
   8.146 +        public Void visitMethod(
   8.147 +                final MethodTree m,
   8.148 +                final List<? super LiteralTree> p) {
   8.149 +            for (AnnotationTree a : m.getModifiers().getAnnotations()) {
   8.150 +                final TypeElement ae = (TypeElement) trees.getElement(TreePath.getPath(cu, a.getAnnotationType()));
   8.151 +                if (ae != null && JS_ANNOTATION.contentEquals(ae.getQualifiedName())) {
   8.152 +                    final List<? extends ExpressionTree> args =  a.getArguments();
   8.153 +                    for (ExpressionTree kvp : args) {
   8.154 +                        if (kvp instanceof AssignmentTree) {
   8.155 +                            final AssignmentTree assignemt = (AssignmentTree) kvp;
   8.156 +                            if (BODY.equals(assignemt.getVariable().toString())) {
   8.157 +                                inEmbedding = true;
   8.158 +                                try {
   8.159 +                                    scan(assignemt.getExpression(), p);
   8.160 +                                } finally {
   8.161 +                                    inEmbedding = false;
   8.162 +                                }
   8.163 +                            }
   8.164 +                        }
   8.165 +                    }
   8.166 +                }
   8.167 +            }
   8.168 +            return null;
   8.169 +        }
   8.170 +
   8.171 +        @Override
   8.172 +        public Void visitLiteral(LiteralTree node, List<? super LiteralTree> p) {
   8.173 +            if (inEmbedding) {
   8.174 +                p.add(node);
   8.175 +            }
   8.176 +            return super.visitLiteral(node, p);
   8.177 +        }
   8.178 +
   8.179 +    }
   8.180 +
   8.181 +    @MimeRegistration(
   8.182 +            service = TaskFactory.class,
   8.183 +            mimeType = JAVA_MIME_TYPE)
   8.184 +    public static final class Factory extends TaskFactory {
   8.185 +        @Override
   8.186 +        public Collection<? extends SchedulerTask> create(Snapshot snpsht) {
   8.187 +            return Collections.singleton(new JSEmbeddingProvider());
   8.188 +        }
   8.189 +    }
   8.190 +
   8.191 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java	Fri Feb 15 11:15:15 2013 +0100
     9.3 @@ -0,0 +1,149 @@
     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.ide.editor;
    9.22 +
    9.23 +import com.sun.source.tree.AnnotationTree;
    9.24 +import com.sun.source.tree.ExpressionTree;
    9.25 +import com.sun.source.tree.LiteralTree;
    9.26 +import com.sun.source.tree.MethodTree;
    9.27 +import com.sun.source.tree.Tree.Kind;
    9.28 +import com.sun.source.tree.VariableTree;
    9.29 +import com.sun.source.util.TreePath;
    9.30 +import java.util.ArrayList;
    9.31 +import java.util.Arrays;
    9.32 +import java.util.Collections;
    9.33 +import java.util.List;
    9.34 +import org.netbeans.api.java.lexer.JavaTokenId;
    9.35 +import static org.netbeans.api.java.lexer.JavaTokenId.BLOCK_COMMENT;
    9.36 +import static org.netbeans.api.java.lexer.JavaTokenId.JAVADOC_COMMENT;
    9.37 +import static org.netbeans.api.java.lexer.JavaTokenId.LINE_COMMENT;
    9.38 +import static org.netbeans.api.java.lexer.JavaTokenId.WHITESPACE;
    9.39 +import org.netbeans.api.java.source.CompilationInfo;
    9.40 +import org.netbeans.api.java.source.TreeMaker;
    9.41 +import org.netbeans.api.lexer.Token;
    9.42 +import org.netbeans.api.lexer.TokenSequence;
    9.43 +import org.netbeans.spi.editor.hints.ErrorDescription;
    9.44 +import org.netbeans.spi.editor.hints.Fix;
    9.45 +import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
    9.46 +import org.netbeans.spi.java.hints.Hint;
    9.47 +import org.netbeans.spi.java.hints.HintContext;
    9.48 +import org.netbeans.spi.java.hints.JavaFix;
    9.49 +import org.netbeans.spi.java.hints.TriggerTreeKind;
    9.50 +import org.openide.util.NbBundle.Messages;
    9.51 +
    9.52 +@Hint(displayName = "#DN_JSNI2JavaScriptBody", description = "#DESC_JSNI2JavaScriptBody", category = "general")
    9.53 +@Messages({
    9.54 +    "DN_JSNI2JavaScriptBody=JSNI to @JavaScriptBody",
    9.55 +    "DESC_JSNI2JavaScriptBody=JSNI to @JavaScriptBody"
    9.56 +})
    9.57 +public class JSNI2JavaScriptBody {
    9.58 +
    9.59 +    @TriggerTreeKind(Kind.METHOD)
    9.60 +    @Messages("ERR_JSNI2JavaScriptBody=Can convert JSNI to @JavaScriptBody")
    9.61 +    public static ErrorDescription computeWarning(final HintContext ctx) {
    9.62 +        Token<JavaTokenId> token = findBlockToken(ctx.getInfo(), ctx.getPath(), ctx);
    9.63 +
    9.64 +        if (token == null) {
    9.65 +            return null;
    9.66 +        }
    9.67 +
    9.68 +        Fix fix = new FixImpl(ctx.getInfo(), ctx.getPath()).toEditorFix();
    9.69 +        return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_JSNI2JavaScriptBody(), fix);
    9.70 +    }
    9.71 +
    9.72 +    private static Token<JavaTokenId> findBlockToken(CompilationInfo info, TreePath path, HintContext ctx) {
    9.73 +        int end = (int) info.getTrees().getSourcePositions().getEndPosition(path.getCompilationUnit(), path.getLeaf());
    9.74 +        TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
    9.75 +
    9.76 +        if (ts == null) return null;
    9.77 +
    9.78 +        ts.move(end);
    9.79 +
    9.80 +        if ((ctx != null && ctx.isCanceled()) || !ts.movePrevious() || ts.token().id() != JavaTokenId.SEMICOLON) return null;
    9.81 +
    9.82 +        OUTER: while (ts.movePrevious()) {
    9.83 +            if (ctx != null && ctx.isCanceled()) return null;
    9.84 +
    9.85 +            switch (ts.token().id()) {
    9.86 +                case WHITESPACE: break;
    9.87 +                case LINE_COMMENT: break;
    9.88 +                case JAVADOC_COMMENT: break;
    9.89 +                case BLOCK_COMMENT:
    9.90 +                    final CharSequence tok = ts.token().text();
    9.91 +                    final int l = tok.length(); 
    9.92 +                    if (l > 4 
    9.93 +                        && tok.subSequence(0, 4).toString().equals("/*-{") // NOI18N
    9.94 +                        && tok.subSequence(l - 4, l).toString().equals("}-*/") // NOI18N
    9.95 +                    ) {
    9.96 +                        return ts.offsetToken();
    9.97 +                    }
    9.98 +                    break;
    9.99 +                default:
   9.100 +                    break OUTER;
   9.101 +            }
   9.102 +        }
   9.103 +
   9.104 +        return null;
   9.105 +    }
   9.106 +
   9.107 +    private static final class FixImpl extends JavaFix {
   9.108 +
   9.109 +        public FixImpl(CompilationInfo info, TreePath tp) {
   9.110 +            super(info, tp);
   9.111 +        }
   9.112 +
   9.113 +        @Override
   9.114 +        @Messages("FIX_JSNI2JavaScriptBody=Convert JSNI to @JavaScriptBody")
   9.115 +        protected String getText() {
   9.116 +            return Bundle.FIX_JSNI2JavaScriptBody();
   9.117 +        }
   9.118 +
   9.119 +        @Override
   9.120 +        protected void performRewrite(TransformationContext ctx) {
   9.121 +            Token<JavaTokenId> jsniComment = findBlockToken(ctx.getWorkingCopy(), ctx.getPath(), null);
   9.122 +
   9.123 +            if (jsniComment == null) {
   9.124 +                //XXX: warn?
   9.125 +                return ;
   9.126 +            }
   9.127 +            
   9.128 +            JsniCommentTokenizer tok = new JsniCommentTokenizer();
   9.129 +            ManglingSink ms = new ManglingSink();
   9.130 +            final CharSequence cmnt = jsniComment.text();
   9.131 +            tok.process(cmnt.subSequence(4, cmnt.length() - 4), ms);
   9.132 +
   9.133 +            TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
   9.134 +            MethodTree mt = (MethodTree) ctx.getPath().getLeaf();
   9.135 +            List<LiteralTree> params = new ArrayList<LiteralTree>();
   9.136 +
   9.137 +            for (VariableTree p : mt.getParameters()) {
   9.138 +                params.add(make.Literal(p.getName().toString()));
   9.139 +            }
   9.140 +
   9.141 +            AnnotationTree jsBody = make.Annotation(make.QualIdent("org.apidesign.bck2brwsr.core.JavaScriptBody"),
   9.142 +                Arrays.<ExpressionTree>asList(
   9.143 +                    make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.<ExpressionTree>emptyList(), params)),
   9.144 +                    make.Assignment(make.Identifier("body"), make.Literal(ms.out.toString()))
   9.145 +                )
   9.146 +            );
   9.147 +
   9.148 +
   9.149 +            ctx.getWorkingCopy().rewrite(mt.getModifiers(), make.addModifiersAnnotation(mt.getModifiers(), jsBody));
   9.150 +        }
   9.151 +    }
   9.152 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java	Fri Feb 15 11:15:15 2013 +0100
    10.3 @@ -0,0 +1,70 @@
    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.ide.editor;
   10.22 +
   10.23 +import java.util.regex.Matcher;
   10.24 +import java.util.regex.Pattern;
   10.25 +
   10.26 +final class JsniCommentTokenizer {
   10.27 +
   10.28 +    /**
   10.29 +     * Tokenize the contents of JSNI comment into the provided {@linkplain Sink}.
   10.30 +     * @param in the contents of JSNI comment
   10.31 +     * @param out the sink that consumes parsed tokens
   10.32 +     */
   10.33 +    public void process(final CharSequence in, final Sink out) {
   10.34 +        final Matcher member = Pattern.compile("@([^:]+)::([a-zA-Z_$][a-zA-Z\\d_$]*)").matcher(in);
   10.35 +        final Matcher signature = Pattern.compile("\\(([^\\)]*)\\)").matcher(in);
   10.36 +
   10.37 +        int i = 0;
   10.38 +        while (true) {
   10.39 +            if (member.find(i)) {
   10.40 +                final int memberStart = member.start();
   10.41 +                final int memberEnd = member.end();
   10.42 +                if (memberStart > i) out.javascript(in.subSequence(i, memberStart).toString());
   10.43 +
   10.44 +                final String clazz = member.group(1);
   10.45 +                final String name = member.group(2);
   10.46 +
   10.47 +                if (in.charAt(memberEnd) == '(') {
   10.48 +                    if (!signature.find(memberEnd)) {
   10.49 +                        throw new IllegalStateException("Expected method signature");
   10.50 +                    }
   10.51 +                    assert signature.start() == memberEnd;
   10.52 +                    out.method(clazz, name, signature.group(1));
   10.53 +                    i = signature.end();
   10.54 +                } else {
   10.55 +                    out.field(clazz, name);
   10.56 +                    i = memberEnd;
   10.57 +                }
   10.58 +            } else {
   10.59 +                out.javascript(in.subSequence(i, in.length()).toString());
   10.60 +                break;
   10.61 +            }
   10.62 +        }
   10.63 +    }
   10.64 +
   10.65 +
   10.66 +    static interface Sink {
   10.67 +        void javascript(String s);
   10.68 +
   10.69 +        void method(String clazz, String method, String signature);
   10.70 +
   10.71 +        void field(String clazz, String field);
   10.72 +    }
   10.73 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/ManglingSink.java	Fri Feb 15 11:15:15 2013 +0100
    11.3 @@ -0,0 +1,71 @@
    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.ide.editor;
   11.22 +
   11.23 +/**
   11.24 + * An implementation of {@linkplain JsniCommentTokenizer.Sink} that generates B2B
   11.25 + */
   11.26 +class ManglingSink implements JsniCommentTokenizer.Sink {
   11.27 +
   11.28 +    final StringBuilder out = new StringBuilder();
   11.29 +
   11.30 +    public void javascript(String s) {
   11.31 +        out.append(s);
   11.32 +    }
   11.33 +
   11.34 +    public void method(String clazz, String method, String signature) {
   11.35 +        out.append(mangle(clazz, method, signature));
   11.36 +    }
   11.37 +
   11.38 +    public void field(String clazz, String field) {
   11.39 +//        out.append(field);
   11.40 +        out.append('_').append(field).append('(').append(')');
   11.41 +    }
   11.42 +
   11.43 +
   11.44 +    @Override
   11.45 +    public String toString() {
   11.46 +        return out.toString();
   11.47 +    }
   11.48 +
   11.49 +
   11.50 +    static String mangle(String clazz, String method, String signature) {
   11.51 +        final StringBuilder builder = new StringBuilder();
   11.52 +        builder.append(method);
   11.53 +        builder.append("__");
   11.54 +        builder.append(mangle(JNIHelper.signature(JNIHelper.method(clazz, method, signature).getReturnType())));
   11.55 +        builder.append(mangle(signature));
   11.56 +        return builder.toString();
   11.57 +    }
   11.58 +
   11.59 +
   11.60 +    static String mangle(String txt) {
   11.61 +        final StringBuilder sb = new StringBuilder();
   11.62 +        for (int i = 0; i < txt.length(); i++) {
   11.63 +            final char ch = txt.charAt(i);
   11.64 +            switch (ch) {
   11.65 +                case '/': sb.append('_'); break;
   11.66 +                case '_': sb.append("_1"); break;
   11.67 +                case ';': sb.append("_2"); break;
   11.68 +                case '[': sb.append("_3"); break;
   11.69 +                default: sb.append(ch); break;
   11.70 +            }
   11.71 +        }
   11.72 +        return sb.toString();
   11.73 +    }
   11.74 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/ide/editor/src/main/nbm/manifest.mf	Fri Feb 15 11:15:15 2013 +0100
    12.3 @@ -0,0 +1,2 @@
    12.4 +Manifest-Version: 1.0
    12.5 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/hints/Bundle.properties
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/ide/editor/src/main/resources/org/netbeans/modules/jackpot30/test/hints/Bundle.properties	Fri Feb 15 11:15:15 2013 +0100
    13.3 @@ -0,0 +1,21 @@
    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 +
   13.22 +OpenIDE-Module-Name=Bck2Brwsr Editor Support
   13.23 +OpenIDE-Module-Short-Description=Provides hints, coloring, etc. for the bck2brwsr.apidesign.org project
   13.24 +OpenIDE-Module-Display-Category=Java
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java	Fri Feb 15 11:15:15 2013 +0100
    14.3 @@ -0,0 +1,84 @@
    14.4 +/**
    14.5 + * Back 2 Browser Bytecode Translator
    14.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    14.7 + *
    14.8 + * This program is free software: you can redistribute it and/or modify
    14.9 + * it under the terms of the GNU General Public License as published by
   14.10 + * the Free Software Foundation, version 2 of the License.
   14.11 + *
   14.12 + * This program is distributed in the hope that it will be useful,
   14.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.15 + * GNU General Public License for more details.
   14.16 + *
   14.17 + * You should have received a copy of the GNU General Public License
   14.18 + * along with this program. Look for COPYING file in the top folder.
   14.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   14.20 + */
   14.21 +package org.apidesign.bck2brwsr.ide.editor;
   14.22 +
   14.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   14.24 +import org.netbeans.modules.java.hints.test.api.HintTest;
   14.25 +import org.openide.filesystems.FileUtil;
   14.26 +import org.testng.annotations.Test;
   14.27 +
   14.28 +public class DejsniReaderTest {
   14.29 +
   14.30 +    @Test
   14.31 +    public void test1() throws Exception {
   14.32 +        String s = "class Test {\n" +
   14.33 +                "    /** javadoc */\n" +
   14.34 +                "    public native void test() /*-{\n" +
   14.35 +                "        // body\n" +
   14.36 +                "    }-*/;\n" +
   14.37 +                "}\n";
   14.38 +
   14.39 +        String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
   14.40 +              + "class Test {\n" +
   14.41 +                "\n" +
   14.42 +                "    /** javadoc */\n" +
   14.43 +                "    @JavaScriptBody(args = {}, body = \"\\n        // body\\n  \")\n" +
   14.44 +                "    public native void test();\n" +
   14.45 +                "}\n";
   14.46 +        
   14.47 +          HintTest.create()
   14.48 +                .input(s)
   14.49 +                .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
   14.50 +                .run(JSNI2JavaScriptBody.class)
   14.51 +                .findWarning("2:23-2:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
   14.52 +                .applyFix()
   14.53 +                .assertCompilable()
   14.54 +                .assertOutput(expected);
   14.55 +    }
   14.56 +
   14.57 +
   14.58 +    @Test
   14.59 +    public void test2() throws Exception {
   14.60 +        String s = "class Test {\n" +
   14.61 +                "    /** javadoc */\n" +
   14.62 +                "    @SuppressWarnings(\"unused\")\n" +
   14.63 +                "    // comment\n" +
   14.64 +                "    public native void test() /*-{\n" +
   14.65 +                "        // body\n" +
   14.66 +                "    }-*/;\n" +
   14.67 +                "}\n";
   14.68 +
   14.69 +        String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
   14.70 +              + "class Test {\n" +
   14.71 +                "\n" +
   14.72 +                "    /** javadoc */\n" +
   14.73 +                "    @SuppressWarnings(\"unused\")\n" +
   14.74 +                "    // comment\n" +
   14.75 +                "    @JavaScriptBody(args = {}, body = \"\\n        // body\\n  \")\n" +
   14.76 +                "    public native void test();\n" +
   14.77 +                "}\n";
   14.78 +          HintTest.create()
   14.79 +                .input(s)
   14.80 +                .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
   14.81 +                .run(JSNI2JavaScriptBody.class)
   14.82 +                .findWarning("4:23-4:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
   14.83 +                .applyFix()
   14.84 +                .assertCompilable()
   14.85 +                .assertOutput(expected);
   14.86 +    }
   14.87 +}
   14.88 \ No newline at end of file
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBodyTest.java	Fri Feb 15 11:15:15 2013 +0100
    15.3 @@ -0,0 +1,46 @@
    15.4 +/**
    15.5 + * Back 2 Browser Bytecode Translator
    15.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    15.7 + *
    15.8 + * This program is free software: you can redistribute it and/or modify
    15.9 + * it under the terms of the GNU General Public License as published by
   15.10 + * the Free Software Foundation, version 2 of the License.
   15.11 + *
   15.12 + * This program is distributed in the hope that it will be useful,
   15.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.15 + * GNU General Public License for more details.
   15.16 + *
   15.17 + * You should have received a copy of the GNU General Public License
   15.18 + * along with this program. Look for COPYING file in the top folder.
   15.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   15.20 + */
   15.21 +package org.apidesign.bck2brwsr.ide.editor;
   15.22 +
   15.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   15.24 +import org.netbeans.modules.java.hints.test.api.HintTest;
   15.25 +import org.openide.filesystems.FileUtil;
   15.26 +import org.testng.annotations.Test;
   15.27 +
   15.28 +public class JSNI2JavaScriptBodyTest {
   15.29 +
   15.30 +    @Test
   15.31 +    public void testFixWorking() throws Exception {
   15.32 +        HintTest.create()
   15.33 +                .input("package test;\n" +
   15.34 +                       "public class Test {\n" +
   15.35 +                       "    public native void run(int a) /*-{ this.a = a; }-*/;\n" +
   15.36 +                       "}\n")
   15.37 +                .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
   15.38 +                .run(JSNI2JavaScriptBody.class)
   15.39 +                .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
   15.40 +                .applyFix()
   15.41 +                .assertCompilable()
   15.42 +                .assertOutput("package test;\n" +
   15.43 +                              "import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" +
   15.44 +                              "public class Test {\n" +
   15.45 +                              "    @JavaScriptBody(args = {\"a\"}, body = \" this.a = a; \")\n" +
   15.46 +                              "    public native void run(int a);\n" +
   15.47 +                              "}\n");
   15.48 +    }
   15.49 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizerTest.java	Fri Feb 15 11:15:15 2013 +0100
    16.3 @@ -0,0 +1,154 @@
    16.4 +/**
    16.5 + * Back 2 Browser Bytecode Translator
    16.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    16.7 + *
    16.8 + * This program is free software: you can redistribute it and/or modify
    16.9 + * it under the terms of the GNU General Public License as published by
   16.10 + * the Free Software Foundation, version 2 of the License.
   16.11 + *
   16.12 + * This program is distributed in the hope that it will be useful,
   16.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.15 + * GNU General Public License for more details.
   16.16 + *
   16.17 + * You should have received a copy of the GNU General Public License
   16.18 + * along with this program. Look for COPYING file in the top folder.
   16.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   16.20 + */
   16.21 +package org.apidesign.bck2brwsr.ide.editor;
   16.22 +
   16.23 +import java.io.IOException;
   16.24 +import java.util.ArrayList;
   16.25 +import java.util.List;
   16.26 +import org.testng.Assert;
   16.27 +import org.testng.annotations.Test;
   16.28 +
   16.29 +public class JsniCommentTokenizerTest {
   16.30 +
   16.31 +    private static class MockSink implements JsniCommentTokenizer.Sink {
   16.32 +        final List<String> out = new ArrayList<String>();
   16.33 +
   16.34 +        public void javascript(String s) {
   16.35 +            out.add("J " + s);
   16.36 +        }
   16.37 +
   16.38 +        public void method(String clazz, String method, String signature) {
   16.39 +            out.add("M " + clazz + "|" + method + "|" + signature);
   16.40 +        }
   16.41 +
   16.42 +        public void field(String clazz, String field) {
   16.43 +            out.add("F " + clazz + "|" + field);
   16.44 +        }
   16.45 +    }
   16.46 +
   16.47 +
   16.48 +    @Test
   16.49 +    public void testProcess_nop() throws IOException {
   16.50 +        final String in = "foo bar";
   16.51 +        final List<String> expected = new ArrayList<String>();
   16.52 +        expected.add("J foo bar");
   16.53 +
   16.54 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
   16.55 +        final MockSink out = new MockSink();
   16.56 +        jsniCommentTokenizer.process(in, out);
   16.57 +
   16.58 +        Assert.assertEquals(expected, out.out);
   16.59 +    }
   16.60 +
   16.61 +    @Test
   16.62 +    public void testProcess_read_static_field() throws IOException {
   16.63 +        final String in = " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
   16.64 +        final List<String> expected = new ArrayList<String>();
   16.65 +        expected.add("J  ");
   16.66 +        expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
   16.67 +        expected.add("J  = val + \" and stuff\";");
   16.68 +
   16.69 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
   16.70 +        final MockSink out = new MockSink();
   16.71 +        jsniCommentTokenizer.process(in, out);
   16.72 +
   16.73 +        Assert.assertEquals(expected, out.out);
   16.74 +    }
   16.75 +
   16.76 +    @Test
   16.77 +    public void testProcess_write_instance_field() throws IOException {
   16.78 +        final String in = " x.@com.google.gwt.examples.JSNIExample::myInstanceField = val + \" and stuff\";";
   16.79 +        final List<String> expected = new ArrayList<String>();
   16.80 +        expected.add("J  x.");
   16.81 +        expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
   16.82 +        expected.add("J  = val + \" and stuff\";");
   16.83 +
   16.84 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
   16.85 +        final MockSink out = new MockSink();
   16.86 +        jsniCommentTokenizer.process(in, out);
   16.87 +
   16.88 +        Assert.assertEquals(expected, out.out);
   16.89 +    }
   16.90 +
   16.91 +    @Test
   16.92 +    public void testProcess_read_instance_field() throws IOException {
   16.93 +        final String in = " var val = this.@com.google.gwt.examples.JSNIExample::myInstanceField;";
   16.94 +        final List<String> expected = new ArrayList<String>();
   16.95 +        expected.add("J  var val = this.");
   16.96 +        expected.add("F com.google.gwt.examples.JSNIExample|myInstanceField");
   16.97 +        expected.add("J ;");
   16.98 +
   16.99 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
  16.100 +        final MockSink out = new MockSink();
  16.101 +        jsniCommentTokenizer.process(in, out);
  16.102 +
  16.103 +        Assert.assertEquals(expected, out.out);
  16.104 +    }
  16.105 +
  16.106 +
  16.107 +    @Test
  16.108 +    public void testProcess_static_method() throws IOException {
  16.109 +        final String in = " @com.google.gwt.examples.JSNIExample::staticFoo(Ljava/lang/String;)(s);";
  16.110 +        final List<String> expected = new ArrayList<String>();
  16.111 +        expected.add("J  ");
  16.112 +        expected.add("M com.google.gwt.examples.JSNIExample|staticFoo|Ljava/lang/String;");
  16.113 +        expected.add("J (s);");
  16.114 +
  16.115 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
  16.116 +        final MockSink out = new MockSink();
  16.117 +        jsniCommentTokenizer.process(in, out);
  16.118 +
  16.119 +        Assert.assertEquals(expected, out.out);
  16.120 +    }
  16.121 +
  16.122 +
  16.123 +    @Test
  16.124 +    public void testProcess_instance_method() throws IOException {
  16.125 +        final String in = " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);";
  16.126 +        final List<String> expected = new ArrayList<String>();
  16.127 +        expected.add("J  x.");
  16.128 +        expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
  16.129 +        expected.add("J (s);");
  16.130 +
  16.131 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
  16.132 +        final MockSink out = new MockSink();
  16.133 +        jsniCommentTokenizer.process(in, out);
  16.134 +
  16.135 +        Assert.assertEquals(expected, out.out);
  16.136 +    }
  16.137 +
  16.138 +
  16.139 +    @Test
  16.140 +    public void testProcess_multiline() throws IOException {
  16.141 +        final String in =
  16.142 +            " x.@com.google.gwt.examples.JSNIExample::instanceFoo(Ljava/lang/String;)(s);" +
  16.143 +            " @com.google.gwt.examples.JSNIExample::myStaticField = val + \" and stuff\";";
  16.144 +        final List<String> expected = new ArrayList<String>();
  16.145 +        expected.add("J  x.");
  16.146 +        expected.add("M com.google.gwt.examples.JSNIExample|instanceFoo|Ljava/lang/String;");
  16.147 +        expected.add("J (s); ");
  16.148 +        expected.add("F com.google.gwt.examples.JSNIExample|myStaticField");
  16.149 +        expected.add("J  = val + \" and stuff\";");
  16.150 +
  16.151 +        final JsniCommentTokenizer jsniCommentTokenizer = new JsniCommentTokenizer();
  16.152 +        final MockSink out = new MockSink();
  16.153 +        jsniCommentTokenizer.process(in, out);
  16.154 +
  16.155 +        Assert.assertEquals(expected, out.out);
  16.156 +    }
  16.157 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/ManglingSinkTest.java	Fri Feb 15 11:15:15 2013 +0100
    17.3 @@ -0,0 +1,58 @@
    17.4 +/**
    17.5 + * Back 2 Browser Bytecode Translator
    17.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    17.7 + *
    17.8 + * This program is free software: you can redistribute it and/or modify
    17.9 + * it under the terms of the GNU General Public License as published by
   17.10 + * the Free Software Foundation, version 2 of the License.
   17.11 + *
   17.12 + * This program is distributed in the hope that it will be useful,
   17.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.15 + * GNU General Public License for more details.
   17.16 + *
   17.17 + * You should have received a copy of the GNU General Public License
   17.18 + * along with this program. Look for COPYING file in the top folder.
   17.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   17.20 + */
   17.21 +package org.apidesign.bck2brwsr.ide.editor;
   17.22 +
   17.23 +import org.testng.Assert;
   17.24 +import org.testng.annotations.Test;
   17.25 +
   17.26 +
   17.27 +public class ManglingSinkTest {
   17.28 +
   17.29 +    @Test
   17.30 +    public void testMangle_1() {
   17.31 +        Assert.assertEquals(
   17.32 +                "binarySearch__I_3BIIB",
   17.33 +                ManglingSink.mangle("java.util.Arrays", "binarySearch", "[BIIB")
   17.34 +        );
   17.35 +    }
   17.36 +
   17.37 +    @Test
   17.38 +    public void testMangle_2() {
   17.39 +        Assert.assertEquals(
   17.40 +                "sort__V_3I",
   17.41 +                ManglingSink.mangle("java.util.Arrays", "sort", "[I")
   17.42 +        );
   17.43 +    }
   17.44 +
   17.45 +    @Test
   17.46 +    public void testMangle_3() {
   17.47 +        Assert.assertEquals(
   17.48 +                "binarySearch__I_3Ljava_lang_Object_2IILjava_lang_Object_2",
   17.49 +                ManglingSink.mangle("java.util.Arrays", "binarySearch", "[Ljava/lang/Object;IILjava/lang/Object;")
   17.50 +        );
   17.51 +    }
   17.52 +
   17.53 +
   17.54 +    @Test
   17.55 +    public void testField() {
   17.56 +        final ManglingSink manglingSink = new ManglingSink();
   17.57 +        manglingSink.field(null, "value");
   17.58 +
   17.59 +        Assert.assertEquals("_value()", manglingSink.toString());
   17.60 +    }
   17.61 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/ide/pom.xml	Fri Feb 15 11:15:15 2013 +0100
    18.3 @@ -0,0 +1,17 @@
    18.4 +<?xml version="1.0" encoding="UTF-8"?>
    18.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    18.6 +  <modelVersion>4.0.0</modelVersion>
    18.7 +  <parent>
    18.8 +    <artifactId>bck2brwsr</artifactId>
    18.9 +    <groupId>org.apidesign</groupId>
   18.10 +    <version>0.3-SNAPSHOT</version>
   18.11 +  </parent>
   18.12 +  <groupId>org.apidesign.bck2brwsr</groupId>
   18.13 +  <artifactId>ide</artifactId>
   18.14 +  <version>0.3-SNAPSHOT</version>
   18.15 +  <packaging>pom</packaging>
   18.16 +  <name>IDE Support</name>
   18.17 +  <modules>
   18.18 +    <module>editor</module>
   18.19 +  </modules>
   18.20 +</project>
    19.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Thu Feb 07 17:41:41 2013 +0100
    19.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java	Fri Feb 15 11:15:15 2013 +0100
    19.3 @@ -307,10 +307,10 @@
    19.4      public native double getGlobalAlpha();
    19.5  
    19.6      @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;")
    19.7 -    public native void setGlobalCompositeOperation(double alpha);
    19.8 +    public native void setGlobalCompositeOperation(String operation);
    19.9  
   19.10      @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
   19.11 -    public native double getGlobalCompositeOperation();
   19.12 +    public native String getGlobalCompositeOperation();
   19.13  
   19.14      public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
   19.15          return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
    20.1 --- a/javaquery/demo-calculator-dynamic/pom.xml	Thu Feb 07 17:41:41 2013 +0100
    20.2 +++ b/javaquery/demo-calculator-dynamic/pom.xml	Fri Feb 15 11:15:15 2013 +0100
    20.3 @@ -40,6 +40,14 @@
    20.4                 <target>1.7</target>
    20.5              </configuration>
    20.6           </plugin>
    20.7 +        <plugin>
    20.8 +           <groupId>org.apache.maven.plugins</groupId>
    20.9 +           <artifactId>maven-deploy-plugin</artifactId>
   20.10 +           <version>2.7</version>
   20.11 +           <configuration>
   20.12 +             <skip>true</skip>
   20.13 +           </configuration>
   20.14 +         </plugin>      
   20.15        </plugins>
   20.16    </build>
   20.17  
    21.1 --- a/javaquery/demo-calculator/pom.xml	Thu Feb 07 17:41:41 2013 +0100
    21.2 +++ b/javaquery/demo-calculator/pom.xml	Fri Feb 15 11:15:15 2013 +0100
    21.3 @@ -60,6 +60,14 @@
    21.4                      </execution>
    21.5                  </executions>                
    21.6              </plugin>      
    21.7 +        <plugin>
    21.8 +           <groupId>org.apache.maven.plugins</groupId>
    21.9 +           <artifactId>maven-deploy-plugin</artifactId>
   21.10 +           <version>2.7</version>
   21.11 +           <configuration>
   21.12 +             <skip>true</skip>
   21.13 +           </configuration>
   21.14 +         </plugin>      
   21.15        </plugins>
   21.16    </build>
   21.17  
    22.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Thu Feb 07 17:41:41 2013 +0100
    22.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Feb 15 11:15:15 2013 +0100
    22.3 @@ -285,10 +285,10 @@
    22.4              if (ch == '$' && params.length > 0) {
    22.5                  int cnt = is.read() - '0';
    22.6                  if (cnt == 'U' - '0') {
    22.7 -                    os.write(baseURL.getBytes());
    22.8 +                    os.write(baseURL.getBytes("UTF-8"));
    22.9                  }
   22.10                  if (cnt >= 0 && cnt < params.length) {
   22.11 -                    os.write(params[cnt].getBytes());
   22.12 +                    os.write(params[cnt].getBytes("UTF-8"));
   22.13                  }
   22.14              } else {
   22.15                  os.write(ch);
    23.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Thu Feb 07 17:41:41 2013 +0100
    23.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java	Fri Feb 15 11:15:15 2013 +0100
    23.3 @@ -37,7 +37,7 @@
    23.4  import org.apidesign.bck2brwsr.launcher.Launcher;
    23.5  
    23.6  /** Executes given HTML page in a browser. */
    23.7 -@Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY)
    23.8 +@Mojo(name="brwsr", defaultPhase=LifecyclePhase.NONE)
    23.9  public class BrswrMojo extends AbstractMojo {
   23.10      public BrswrMojo() {
   23.11      }
    24.1 --- a/mojo/src/main/resources/archetype-resources/pom.xml	Thu Feb 07 17:41:41 2013 +0100
    24.2 +++ b/mojo/src/main/resources/archetype-resources/pom.xml	Fri Feb 15 11:15:15 2013 +0100
    24.3 @@ -10,6 +10,32 @@
    24.4  
    24.5    <name>${artifactId}</name>
    24.6  
    24.7 +  <repositories>
    24.8 +      <repository>
    24.9 +          <id>java.net</id>
   24.10 +          <name>Java.net</name>
   24.11 +          <url>https://maven.java.net/content/repositories/snapshots/</url>
   24.12 +          <snapshots>
   24.13 +              <enabled>true</enabled>
   24.14 +          </snapshots>
   24.15 +      </repository>
   24.16 +      <repository>
   24.17 +          <id>netbeans</id>
   24.18 +          <name>NetBeans</name>
   24.19 +          <url>http://bits.netbeans.org/maven2/</url>
   24.20 +      </repository>
   24.21 +  </repositories>
   24.22 +  <pluginRepositories>
   24.23 +      <pluginRepository>
   24.24 +          <id>java.net</id>
   24.25 +          <name>Local Maven repository of releases</name>
   24.26 +          <url>https://maven.java.net/content/repositories/snapshots/</url>
   24.27 +          <snapshots>
   24.28 +              <enabled>true</enabled>
   24.29 +          </snapshots>
   24.30 +      </pluginRepository>
   24.31 +  </pluginRepositories>
   24.32 +
   24.33    <properties>
   24.34      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   24.35    </properties>
    25.1 --- a/pom.xml	Thu Feb 07 17:41:41 2013 +0100
    25.2 +++ b/pom.xml	Fri Feb 15 11:15:15 2013 +0100
    25.3 @@ -6,6 +6,11 @@
    25.4    <version>0.3-SNAPSHOT</version>
    25.5    <packaging>pom</packaging>
    25.6    <name>Back 2 Browser</name>
    25.7 +  <parent>
    25.8 +    <groupId>net.java</groupId>
    25.9 +    <artifactId>jvnet-parent</artifactId>
   25.10 +    <version>3</version>
   25.11 +  </parent>  
   25.12    <modules>
   25.13      <module>vm</module>
   25.14      <module>emul</module>
   25.15 @@ -17,6 +22,7 @@
   25.16      <module>benchmarks</module>
   25.17      <module>launcher</module>
   25.18      <module>vmtest</module>
   25.19 +    <module>ide</module>
   25.20    </modules>
   25.21    <licenses>
   25.22        <license>
   25.23 @@ -29,6 +35,11 @@
   25.24        <name>API Design</name>
   25.25        <url>http://apidesign.org</url>
   25.26    </organization>
   25.27 +  <scm>
   25.28 +      <connection>scm:hg:http://source.apidesign.org/hg/bck2brwsr</connection>
   25.29 +      <developerConnection>scm:hg:https://source.apidesign.org/hg/bck2brwsr</developerConnection>
   25.30 +      <url>http://source.apidesign.org/hg/bck2brwsr</url>
   25.31 +  </scm>
   25.32    <repositories>
   25.33        <repository>
   25.34            <id>netbeans</id>
    26.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Thu Feb 07 17:41:41 2013 +0100
    26.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Fri Feb 15 11:15:15 2013 +0100
    26.3 @@ -632,7 +632,7 @@
    26.4                      final int varIndx = wide ? readUShort(byteCodes, i++)
    26.5                                               : readUByte(byteCodes, i);
    26.6                      ++i;
    26.7 -                    final int incrBy = wide ? readIntArg(byteCodes, i++)
    26.8 +                    final int incrBy = wide ? readShort(byteCodes, i++)
    26.9                                              : byteCodes[i];
   26.10                      wide = false;
   26.11                      if (incrBy == 1) {
   26.12 @@ -1353,20 +1353,25 @@
   26.13          final int indxLo = byteCodes[offsetInstruction + 2];
   26.14          return (indxHi & 0xffffff00) | (indxLo & 0xff);
   26.15      }
   26.16 -    private int readInt4(byte[] byteCodes, int offsetInstruction) {
   26.17 -        final int d = byteCodes[offsetInstruction + 0] << 24;
   26.18 -        final int c = byteCodes[offsetInstruction + 1] << 16;
   26.19 -        final int b = byteCodes[offsetInstruction + 2] << 8;
   26.20 -        final int a = byteCodes[offsetInstruction + 3];
   26.21 +    private int readInt4(byte[] byteCodes, int offset) {
   26.22 +        final int d = byteCodes[offset + 0] << 24;
   26.23 +        final int c = byteCodes[offset + 1] << 16;
   26.24 +        final int b = byteCodes[offset + 2] << 8;
   26.25 +        final int a = byteCodes[offset + 3];
   26.26          return (d & 0xff000000) | (c & 0xff0000) | (b & 0xff00) | (a & 0xff);
   26.27      }
   26.28 -    private int readUByte(byte[] byteCodes, int offsetInstruction) {
   26.29 -        return byteCodes[offsetInstruction] & 0xff;
   26.30 +    private int readUByte(byte[] byteCodes, int offset) {
   26.31 +        return byteCodes[offset] & 0xff;
   26.32      }
   26.33  
   26.34 -    private int readUShort(byte[] byteCodes, int offsetInstruction) {
   26.35 -        return ((byteCodes[offsetInstruction] & 0xff) << 8)
   26.36 -                    | (byteCodes[offsetInstruction + 1] & 0xff);
   26.37 +    private int readUShort(byte[] byteCodes, int offset) {
   26.38 +        return ((byteCodes[offset] & 0xff) << 8)
   26.39 +                    | (byteCodes[offset + 1] & 0xff);
   26.40 +    }
   26.41 +
   26.42 +    private int readShort(byte[] byteCodes, int offset) {
   26.43 +        return (byteCodes[offset] << 8)
   26.44 +                    | (byteCodes[offset + 1] & 0xff);
   26.45      }
   26.46  
   26.47      private static void countArgs(String descriptor, char[] returnType, StringBuilder sig, StringBuilder cnt) {
    27.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Thu Feb 07 17:41:41 2013 +0100
    27.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java	Fri Feb 15 11:15:15 2013 +0100
    27.3 @@ -181,5 +181,11 @@
    27.4      ) throws Exception {
    27.5          StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
    27.6      }
    27.7 +    @Test public void isClassAssignable() throws Exception {
    27.8 +        assertExec("isAssignable works on subclasses", Classes.class, 
    27.9 +            "isClassAssignable__Z", 
   27.10 +            true
   27.11 +        );
   27.12 +    }
   27.13      
   27.14  }
    28.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Thu Feb 07 17:41:41 2013 +0100
    28.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java	Fri Feb 15 11:15:15 2013 +0100
    28.3 @@ -151,4 +151,20 @@
    28.4          Method m = StaticMethod.class.getMethod("sum", int.class, int.class);
    28.5          return (int) m.invoke(null, a, b);
    28.6      }
    28.7 +    
    28.8 +    private abstract class Application {
    28.9 +        public abstract int getID();
   28.10 +    }
   28.11 +
   28.12 +    private class MyApplication extends Application {
   28.13 +        @Override
   28.14 +        public int getID() {
   28.15 +            return 1;
   28.16 +        }
   28.17 +    }
   28.18 +
   28.19 +    public static boolean isClassAssignable() {
   28.20 +        return Application.class.isAssignableFrom(MyApplication.class);
   28.21 +    }
   28.22 +    
   28.23  }
    29.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Thu Feb 07 17:41:41 2013 +0100
    29.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Fri Feb 15 11:15:15 2013 +0100
    29.3 @@ -17,6 +17,8 @@
    29.4   */
    29.5  package org.apidesign.vm4brwsr;
    29.6  
    29.7 +import java.io.UnsupportedEncodingException;
    29.8 +
    29.9  /**
   29.10   *
   29.11   * @author Jaroslav Tulach <jtulach@netbeans.org>
   29.12 @@ -68,8 +70,8 @@
   29.13          return chars('a', (char)30, 'b') instanceof String;
   29.14      }
   29.15      
   29.16 -    public static String getBytes(String s) {
   29.17 -        byte[] arr = s.getBytes();
   29.18 +    public static String getBytes(String s) throws UnsupportedEncodingException {
   29.19 +        byte[] arr = s.getBytes("UTF-8");
   29.20          StringBuilder sb = new StringBuilder();
   29.21          for (int i = 0; i < arr.length; i++) {
   29.22              sb.append(arr[i]).append(" ");
    30.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Thu Feb 07 17:41:41 2013 +0100
    30.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Fri Feb 15 11:15:15 2013 +0100
    30.3 @@ -76,7 +76,7 @@
    30.4      }
    30.5  
    30.6      @Test public void getBytes() throws Exception {
    30.7 -        final String horse = "Žluťoučký kůň";
    30.8 +        final String horse = "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148";
    30.9          final String expected = StringSample.getBytes(horse);
   30.10          assertExec(
   30.11              "Bytes look simplar",
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/SystemTest.java	Fri Feb 15 11:15:15 2013 +0100
    31.3 @@ -0,0 +1,59 @@
    31.4 +/**
    31.5 + * Back 2 Browser Bytecode Translator
    31.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    31.7 + *
    31.8 + * This program is free software: you can redistribute it and/or modify
    31.9 + * it under the terms of the GNU General Public License as published by
   31.10 + * the Free Software Foundation, version 2 of the License.
   31.11 + *
   31.12 + * This program is distributed in the hope that it will be useful,
   31.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   31.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   31.15 + * GNU General Public License for more details.
   31.16 + *
   31.17 + * You should have received a copy of the GNU General Public License
   31.18 + * along with this program. Look for COPYING file in the top folder.
   31.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   31.20 + */
   31.21 +package org.apidesign.vm4brwsr;
   31.22 +
   31.23 +import javax.script.Invocable;
   31.24 +import org.testng.annotations.BeforeClass;
   31.25 +import static org.testng.Assert.*;
   31.26 +import org.testng.annotations.BeforeMethod;
   31.27 +import org.testng.annotations.Test;
   31.28 +
   31.29 +/**
   31.30 + *
   31.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   31.32 + */
   31.33 +public class SystemTest {
   31.34 +    @Test public void verifyJSTime() throws Exception {
   31.35 +        long now = System.currentTimeMillis();
   31.36 +        
   31.37 +        Object js = TestUtils.execCode(code, codeSeq, "Get js time", 
   31.38 +            org.apidesign.bck2brwsr.emul.lang.System.class, "currentTimeMillis__J",
   31.39 +            null
   31.40 +        );
   31.41 +        
   31.42 +        assertTrue(js instanceof Double, "Double " + js);
   31.43 +        long time = ((Double)js).longValue();
   31.44 +        
   31.45 +        long later = System.currentTimeMillis();
   31.46 +        
   31.47 +        assertTrue(now <= time, "Lower bound is OK: " + now + " <= " + time);
   31.48 +        assertTrue(time <= later, "Upper bound is OK: " + time + " <= " + later);
   31.49 +    }
   31.50 +    
   31.51 +    private static CharSequence codeSeq;
   31.52 +    private static Invocable code;
   31.53 +    
   31.54 +    @BeforeClass 
   31.55 +    public void compileTheCode() throws Exception {
   31.56 +        StringBuilder sb = new StringBuilder();
   31.57 +        code = StaticMethodTest.compileClass(sb, "org/apidesign/bck2brwsr/emul/lang/System");
   31.58 +        codeSeq = sb;
   31.59 +    }
   31.60 +    
   31.61 +}
   31.62 +
    32.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/TestUtils.java	Thu Feb 07 17:41:41 2013 +0100
    32.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/TestUtils.java	Fri Feb 15 11:15:15 2013 +0100
    32.3 @@ -40,7 +40,7 @@
    32.4          if (ret == null && expRes == null) {
    32.5              return null;
    32.6          }
    32.7 -        if (expRes.equals(ret)) {
    32.8 +        if (expRes != null && expRes.equals(ret)) {
    32.9              return null;
   32.10          }
   32.11          if (expRes instanceof Number) {
    33.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Thu Feb 07 17:41:41 2013 +0100
    33.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/CompareStringsTest.java	Fri Feb 15 11:15:15 2013 +0100
    33.3 @@ -134,7 +134,7 @@
    33.4  
    33.5      @Compare
    33.6      public int stringToBytesLenght() throws UnsupportedEncodingException {
    33.7 -        return "Žluťoučký kůň".getBytes("utf8").length;
    33.8 +        return "\u017dlu\u0165ou\u010dk\u00fd k\u016f\u0148".getBytes("utf8").length;
    33.9      }
   33.10  
   33.11      @Factory