1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ide/editor/pom.xml Wed Feb 13 11:12:55 2013 +0100
1.3 @@ -0,0 +1,188 @@
1.4 +<?xml version="1.0" encoding="UTF-8"?>
1.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">
1.6 + <modelVersion>4.0.0</modelVersion>
1.7 + <parent>
1.8 + <artifactId>ide</artifactId>
1.9 + <groupId>org.apidesign.bck2brwsr</groupId>
1.10 + <version>0.3-SNAPSHOT</version>
1.11 + </parent>
1.12 +
1.13 + <groupId>org.apidesign.bck2brwsr.ide.editor</groupId>
1.14 + <artifactId>editor</artifactId>
1.15 + <version>0.3-SNAPSHOT</version>
1.16 + <packaging>nbm</packaging>
1.17 +
1.18 + <name>Editor Support for Bck2Brwsr</name>
1.19 +
1.20 + <properties>
1.21 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1.22 + <netbeans.version>RELEASE72</netbeans.version>
1.23 + <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
1.24 + </properties>
1.25 +
1.26 + <repositories>
1.27 + <!--
1.28 + Repository hosting NetBeans modules, especially APIs.
1.29 + Versions are based on IDE releases, e.g.: RELEASE691
1.30 + To create your own repository, use: nbm:populate-repository
1.31 + -->
1.32 + <repository>
1.33 + <id>netbeans</id>
1.34 + <name>NetBeans</name>
1.35 + <url>http://bits.netbeans.org/maven2/</url>
1.36 + <snapshots>
1.37 + <enabled>false</enabled>
1.38 + </snapshots>
1.39 + </repository>
1.40 + </repositories>
1.41 +
1.42 + <dependencies>
1.43 + <dependency>
1.44 + <groupId>org.netbeans.api</groupId>
1.45 + <artifactId>org-netbeans-api-annotations-common</artifactId>
1.46 + <version>${netbeans.version}</version>
1.47 + </dependency>
1.48 + <dependency>
1.49 + <groupId>org.netbeans.api</groupId>
1.50 + <artifactId>org-netbeans-modules-java-source</artifactId>
1.51 + <version>${netbeans.version}</version>
1.52 + </dependency>
1.53 + <dependency>
1.54 + <groupId>org.netbeans.api</groupId>
1.55 + <artifactId>org-netbeans-libs-javacapi</artifactId>
1.56 + <version>${netbeans.version}</version>
1.57 + </dependency>
1.58 + <dependency>
1.59 + <groupId>org.netbeans.api</groupId>
1.60 + <artifactId>org-netbeans-spi-java-hints</artifactId>
1.61 + <version>${netbeans.version}</version>
1.62 + </dependency>
1.63 + <dependency>
1.64 + <groupId>org.netbeans.api</groupId>
1.65 + <artifactId>org-netbeans-spi-editor-hints</artifactId>
1.66 + <version>${netbeans.version}</version>
1.67 + </dependency>
1.68 + <dependency>
1.69 + <groupId>org.netbeans.api</groupId>
1.70 + <artifactId>org-openide-util</artifactId>
1.71 + <version>${netbeans.version}</version>
1.72 + </dependency>
1.73 + <dependency>
1.74 + <groupId>org.netbeans.api</groupId>
1.75 + <artifactId>org-netbeans-modules-java-lexer</artifactId>
1.76 + <version>${netbeans.version}</version>
1.77 + </dependency>
1.78 + <dependency>
1.79 + <groupId>org.netbeans.api</groupId>
1.80 + <artifactId>org-netbeans-modules-lexer</artifactId>
1.81 + <version>${netbeans.version}</version>
1.82 + </dependency>
1.83 + <dependency>
1.84 + <groupId>org.apidesign.bck2brwsr</groupId>
1.85 + <artifactId>core</artifactId>
1.86 + <version>0.3-SNAPSHOT</version>
1.87 + <type>jar</type>
1.88 + <scope>test</scope>
1.89 + </dependency>
1.90 + <dependency>
1.91 + <groupId>org.netbeans.api</groupId>
1.92 + <artifactId>org-netbeans-modules-java-hints-test</artifactId>
1.93 + <version>${netbeans.version}</version>
1.94 + <scope>test</scope>
1.95 + </dependency>
1.96 + <dependency>
1.97 + <groupId>org.netbeans.api</groupId>
1.98 + <artifactId>org-netbeans-libs-junit4</artifactId>
1.99 + <version>${netbeans.version}</version>
1.100 + <scope>test</scope>
1.101 + </dependency>
1.102 + <dependency>
1.103 + <groupId>org.netbeans.modules</groupId>
1.104 + <artifactId>org-netbeans-lib-nbjavac</artifactId>
1.105 + <version>${netbeans.version}</version>
1.106 + <scope>test</scope>
1.107 + </dependency>
1.108 + </dependencies>
1.109 +
1.110 + <build>
1.111 + <plugins>
1.112 + <plugin>
1.113 + <groupId>org.codehaus.mojo</groupId>
1.114 + <artifactId>nbm-maven-plugin</artifactId>
1.115 + <version>3.8</version>
1.116 + <extensions>true</extensions>
1.117 + </plugin>
1.118 +
1.119 + <plugin>
1.120 + <!-- NetBeans 6.9+ requires JDK 6 -->
1.121 + <groupId>org.apache.maven.plugins</groupId>
1.122 + <artifactId>maven-compiler-plugin</artifactId>
1.123 + <version>2.5.1</version>
1.124 + <configuration>
1.125 + <source>1.6</source>
1.126 + <target>1.6</target>
1.127 + <compilerArguments>
1.128 + <endorseddirs>${endorsed.dir}</endorseddirs>
1.129 + </compilerArguments>
1.130 + </configuration>
1.131 + </plugin>
1.132 +
1.133 + <plugin>
1.134 + <groupId>org.apache.maven.plugins</groupId>
1.135 + <artifactId>maven-jar-plugin</artifactId>
1.136 + <version>2.4</version>
1.137 + <configuration>
1.138 + <!-- to have the jar plugin pickup the nbm generated manifest -->
1.139 + <useDefaultManifestFile>true</useDefaultManifestFile>
1.140 + </configuration>
1.141 + </plugin>
1.142 +
1.143 + <plugin>
1.144 + <groupId>org.apache.maven.plugins</groupId>
1.145 + <artifactId>maven-dependency-plugin</artifactId>
1.146 + <executions>
1.147 + <execution>
1.148 + <id>endorsed</id>
1.149 + <phase>validate</phase>
1.150 + <goals>
1.151 + <goal>copy</goal>
1.152 + </goals>
1.153 + </execution>
1.154 + </executions>
1.155 + <configuration>
1.156 + <outputDirectory>${endorsed.dir}</outputDirectory>
1.157 + <silent>true</silent>
1.158 + <artifactItems>
1.159 + <artifactItem>
1.160 + <groupId>org.netbeans.api</groupId>
1.161 + <artifactId>org-netbeans-libs-javacapi</artifactId>
1.162 + <version>${netbeans.version}</version>
1.163 + </artifactItem>
1.164 + <artifactItem>
1.165 + <groupId>org.netbeans.external</groupId>
1.166 + <artifactId>nb-javac-api</artifactId>
1.167 + <version>${netbeans.version}</version>
1.168 + </artifactItem>
1.169 + <artifactItem>
1.170 + <groupId>org.netbeans.modules</groupId>
1.171 + <artifactId>org-netbeans-libs-javacimpl</artifactId>
1.172 + <version>${netbeans.version}</version>
1.173 + </artifactItem>
1.174 + <artifactItem>
1.175 + <groupId>org.netbeans.external</groupId>
1.176 + <artifactId>nb-javac-impl</artifactId>
1.177 + <version>${netbeans.version}</version>
1.178 + </artifactItem>
1.179 + </artifactItems>
1.180 + </configuration>
1.181 + </plugin>
1.182 + <plugin>
1.183 + <groupId>org.apache.maven.plugins</groupId>
1.184 + <artifactId>maven-surefire-plugin</artifactId>
1.185 + <configuration>
1.186 + <argLine>-Djava.endorsed.dirs=${endorsed.dir}</argLine>
1.187 + </configuration>
1.188 + </plugin>
1.189 + </plugins>
1.190 + </build>
1.191 +</project>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java Wed Feb 13 11:12:55 2013 +0100
2.3 @@ -0,0 +1,149 @@
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.ide.editor;
2.22 +
2.23 +import com.sun.source.tree.AnnotationTree;
2.24 +import com.sun.source.tree.ExpressionTree;
2.25 +import com.sun.source.tree.LiteralTree;
2.26 +import com.sun.source.tree.MethodTree;
2.27 +import com.sun.source.tree.Tree.Kind;
2.28 +import com.sun.source.tree.VariableTree;
2.29 +import com.sun.source.util.TreePath;
2.30 +import java.util.ArrayList;
2.31 +import java.util.Arrays;
2.32 +import java.util.Collections;
2.33 +import java.util.List;
2.34 +import java.util.regex.Matcher;
2.35 +import java.util.regex.Pattern;
2.36 +import org.netbeans.api.java.lexer.JavaTokenId;
2.37 +import static org.netbeans.api.java.lexer.JavaTokenId.BLOCK_COMMENT;
2.38 +import static org.netbeans.api.java.lexer.JavaTokenId.JAVADOC_COMMENT;
2.39 +import static org.netbeans.api.java.lexer.JavaTokenId.LINE_COMMENT;
2.40 +import static org.netbeans.api.java.lexer.JavaTokenId.WHITESPACE;
2.41 +import org.netbeans.api.java.source.CompilationInfo;
2.42 +import org.netbeans.api.java.source.TreeMaker;
2.43 +import org.netbeans.api.lexer.Token;
2.44 +import org.netbeans.api.lexer.TokenSequence;
2.45 +import org.netbeans.spi.editor.hints.ErrorDescription;
2.46 +import org.netbeans.spi.editor.hints.Fix;
2.47 +import org.netbeans.spi.java.hints.ErrorDescriptionFactory;
2.48 +import org.netbeans.spi.java.hints.Hint;
2.49 +import org.netbeans.spi.java.hints.HintContext;
2.50 +import org.netbeans.spi.java.hints.JavaFix;
2.51 +import org.netbeans.spi.java.hints.TriggerTreeKind;
2.52 +import org.openide.util.NbBundle.Messages;
2.53 +
2.54 +@Hint(displayName = "#DN_JSNI2JavaScriptBody", description = "#DESC_JSNI2JavaScriptBody", category = "general")
2.55 +@Messages({
2.56 + "DN_JSNI2JavaScriptBody=JSNI to @JavaScriptBody",
2.57 + "DESC_JSNI2JavaScriptBody=JSNI to @JavaScriptBody"
2.58 +})
2.59 +public class JSNI2JavaScriptBody {
2.60 +
2.61 + private static final Pattern JSNIPattern = Pattern.compile("/\\*-\\{(.*)}-\\*/");
2.62 +
2.63 + @TriggerTreeKind(Kind.METHOD)
2.64 + @Messages("ERR_JSNI2JavaScriptBody=Can convert JSNI to @JavaScriptBody")
2.65 + public static ErrorDescription computeWarning(final HintContext ctx) {
2.66 + Token<JavaTokenId> token = findBlockToken(ctx.getInfo(), ctx.getPath(), ctx);
2.67 +
2.68 + if (token == null) {
2.69 + return null;
2.70 + }
2.71 +
2.72 + Fix fix = new FixImpl(ctx.getInfo(), ctx.getPath()).toEditorFix();
2.73 + return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_JSNI2JavaScriptBody(), fix);
2.74 + }
2.75 +
2.76 + private static Token<JavaTokenId> findBlockToken(CompilationInfo info, TreePath path, HintContext ctx) {
2.77 + int end = (int) info.getTrees().getSourcePositions().getEndPosition(path.getCompilationUnit(), path.getLeaf());
2.78 + TokenSequence<JavaTokenId> ts = info.getTokenHierarchy().tokenSequence(JavaTokenId.language());
2.79 +
2.80 + if (ts == null) return null;
2.81 +
2.82 + ts.move(end);
2.83 +
2.84 + if ((ctx != null && ctx.isCanceled()) || !ts.movePrevious() || ts.token().id() != JavaTokenId.SEMICOLON) return null;
2.85 +
2.86 + OUTER: while (ts.movePrevious()) {
2.87 + if (ctx != null && ctx.isCanceled()) return null;
2.88 +
2.89 + switch (ts.token().id()) {
2.90 + case WHITESPACE: break;
2.91 + case LINE_COMMENT: break;
2.92 + case JAVADOC_COMMENT: break;
2.93 + case BLOCK_COMMENT:
2.94 + if (JSNIPattern.matcher(ts.token().text()).matches()) {
2.95 + return ts.offsetToken();
2.96 + }
2.97 + break;
2.98 + default:
2.99 + break OUTER;
2.100 + }
2.101 + }
2.102 +
2.103 + return null;
2.104 + }
2.105 +
2.106 + private static final class FixImpl extends JavaFix {
2.107 +
2.108 + public FixImpl(CompilationInfo info, TreePath tp) {
2.109 + super(info, tp);
2.110 + }
2.111 +
2.112 + @Override
2.113 + @Messages("FIX_JSNI2JavaScriptBody=Convert JSNI to @JavaScriptBody")
2.114 + protected String getText() {
2.115 + return Bundle.FIX_JSNI2JavaScriptBody();
2.116 + }
2.117 +
2.118 + @Override
2.119 + protected void performRewrite(TransformationContext ctx) {
2.120 + Token<JavaTokenId> jsniComment = findBlockToken(ctx.getWorkingCopy(), ctx.getPath(), null);
2.121 +
2.122 + if (jsniComment == null) {
2.123 + //XXX: warn?
2.124 + return ;
2.125 + }
2.126 +
2.127 + Matcher m = JSNIPattern.matcher(jsniComment.text());
2.128 +
2.129 + if (!m.matches()) return ; //XXX: warn?
2.130 +
2.131 + TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
2.132 + MethodTree mt = (MethodTree) ctx.getPath().getLeaf();
2.133 + List<LiteralTree> params = new ArrayList<LiteralTree>();
2.134 +
2.135 + params.add(make.Literal("this"));
2.136 +
2.137 + for (VariableTree p : mt.getParameters()) {
2.138 + params.add(make.Literal(p.getName().toString()));
2.139 + }
2.140 +
2.141 + AnnotationTree jsBody = make.Annotation(make.QualIdent("org.apidesign.bck2brwsr.core.JavaScriptBody"),
2.142 + Arrays.<ExpressionTree>asList(
2.143 + make.Assignment(make.Identifier("body"), make.Literal(m.group(1))),
2.144 + make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.<ExpressionTree>emptyList(), params))
2.145 + )
2.146 + );
2.147 +
2.148 +
2.149 + ctx.getWorkingCopy().rewrite(mt.getModifiers(), make.addModifiersAnnotation(mt.getModifiers(), jsBody));
2.150 + }
2.151 + }
2.152 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/ide/editor/src/main/nbm/manifest.mf Wed Feb 13 11:12:55 2013 +0100
3.3 @@ -0,0 +1,2 @@
3.4 +Manifest-Version: 1.0
3.5 +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/test/hints/Bundle.properties
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/ide/editor/src/main/resources/org/netbeans/modules/jackpot30/test/hints/Bundle.properties Wed Feb 13 11:12:55 2013 +0100
4.3 @@ -0,0 +1,21 @@
4.4 +#
4.5 +# Back 2 Browser Bytecode Translator
4.6 +# Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.7 +#
4.8 +# This program is free software: you can redistribute it and/or modify
4.9 +# it under the terms of the GNU General Public License as published by
4.10 +# the Free Software Foundation, version 2 of the License.
4.11 +#
4.12 +# This program is distributed in the hope that it will be useful,
4.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
4.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.15 +# GNU General Public License for more details.
4.16 +#
4.17 +# You should have received a copy of the GNU General Public License
4.18 +# along with this program. Look for COPYING file in the top folder.
4.19 +# If not, see http://opensource.org/licenses/GPL-2.0.
4.20 +#
4.21 +
4.22 +OpenIDE-Module-Name=Bck2Brwsr Editor Support
4.23 +OpenIDE-Module-Short-Description=Provides hints, coloring, etc. for the bck2brwsr.apidesign.org project
4.24 +OpenIDE-Module-Display-Category=Java
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBodyTest.java Wed Feb 13 11:12:55 2013 +0100
5.3 @@ -0,0 +1,46 @@
5.4 +/**
5.5 + * Back 2 Browser Bytecode Translator
5.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5.7 + *
5.8 + * This program is free software: you can redistribute it and/or modify
5.9 + * it under the terms of the GNU General Public License as published by
5.10 + * the Free Software Foundation, version 2 of the License.
5.11 + *
5.12 + * This program is distributed in the hope that it will be useful,
5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.15 + * GNU General Public License for more details.
5.16 + *
5.17 + * You should have received a copy of the GNU General Public License
5.18 + * along with this program. Look for COPYING file in the top folder.
5.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
5.20 + */
5.21 +package org.apidesign.bck2brwsr.ide.editor;
5.22 +
5.23 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
5.24 +import org.junit.Test;
5.25 +import org.netbeans.modules.java.hints.test.api.HintTest;
5.26 +import org.openide.filesystems.FileUtil;
5.27 +
5.28 +public class JSNI2JavaScriptBodyTest {
5.29 +
5.30 + @Test
5.31 + public void testFixWorking() throws Exception {
5.32 + HintTest.create()
5.33 + .input("package test;\n" +
5.34 + "public class Test {\n" +
5.35 + " public native void run(int a) /*-{ this.a = a; }-*/;\n" +
5.36 + "}\n")
5.37 + .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
5.38 + .run(JSNI2JavaScriptBody.class)
5.39 + .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
5.40 + .applyFix()
5.41 + .assertCompilable()
5.42 + .assertOutput("package test;\n" +
5.43 + "import org.apidesign.bck2brwsr.core.JavaScriptBody;\n" +
5.44 + "public class Test {\n" +
5.45 + " @JavaScriptBody(body = \" this.a = a; \", args = {\"this\", \"a\"})\n" +
5.46 + " public native void run(int a);\n" +
5.47 + "}\n");
5.48 + }
5.49 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/ide/pom.xml Wed Feb 13 11:12:55 2013 +0100
6.3 @@ -0,0 +1,17 @@
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>bck2brwsr</artifactId>
6.9 + <groupId>org.apidesign</groupId>
6.10 + <version>0.3-SNAPSHOT</version>
6.11 + </parent>
6.12 + <groupId>org.apidesign.bck2brwsr</groupId>
6.13 + <artifactId>ide</artifactId>
6.14 + <version>0.3-SNAPSHOT</version>
6.15 + <packaging>pom</packaging>
6.16 + <name>IDE Support</name>
6.17 + <modules>
6.18 + <module>editor</module>
6.19 + </modules>
6.20 +</project>
7.1 --- a/pom.xml Tue Feb 12 12:07:55 2013 +0100
7.2 +++ b/pom.xml Wed Feb 13 11:12:55 2013 +0100
7.3 @@ -17,6 +17,7 @@
7.4 <module>benchmarks</module>
7.5 <module>launcher</module>
7.6 <module>vmtest</module>
7.7 + <module>ide</module>
7.8 </modules>
7.9 <licenses>
7.10 <license>