1.1 --- a/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java Wed Feb 13 12:08:00 2013 +0100
1.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JNIHelper.java Wed Feb 13 12:45:02 2013 +0100
1.3 @@ -26,7 +26,7 @@
1.4 * To facilitate lookup of methods by name and signature, instead of manually parsing signatures,
1.5 * constructs the map of all methods and uses Class.getName() to generate almost-correct signatures.
1.6 */
1.7 -public class JNIHelper {
1.8 +class JNIHelper {
1.9
1.10 static Method method(String clazz, String method, String signature) {
1.11 final Map<String, Method> methods = methodMap(JNIHelper.clazz(clazz));
2.1 --- a/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java Wed Feb 13 12:08:00 2013 +0100
2.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JSNI2JavaScriptBody.java Wed Feb 13 12:45:02 2013 +0100
2.3 @@ -55,8 +55,6 @@
2.4 })
2.5 public class JSNI2JavaScriptBody {
2.6
2.7 - private static final Pattern JSNIPattern = Pattern.compile("/\\*-\\{(.*)}-\\*/");
2.8 -
2.9 @TriggerTreeKind(Kind.METHOD)
2.10 @Messages("ERR_JSNI2JavaScriptBody=Can convert JSNI to @JavaScriptBody")
2.11 public static ErrorDescription computeWarning(final HintContext ctx) {
2.12 @@ -88,7 +86,12 @@
2.13 case LINE_COMMENT: break;
2.14 case JAVADOC_COMMENT: break;
2.15 case BLOCK_COMMENT:
2.16 - if (JSNIPattern.matcher(ts.token().text()).matches()) {
2.17 + final CharSequence tok = ts.token().text();
2.18 + final int l = tok.length();
2.19 + if (l > 4
2.20 + && tok.subSequence(0, 4).toString().equals("/*-{") // NOI18N
2.21 + && tok.subSequence(l - 4, l).toString().equals("}-*/") // NOI18N
2.22 + ) {
2.23 return ts.offsetToken();
2.24 }
2.25 break;
2.26 @@ -120,25 +123,24 @@
2.27 //XXX: warn?
2.28 return ;
2.29 }
2.30 -
2.31 - Matcher m = JSNIPattern.matcher(jsniComment.text());
2.32 -
2.33 - if (!m.matches()) return ; //XXX: warn?
2.34 +
2.35 + JsniCommentTokenizer tok = new JsniCommentTokenizer();
2.36 + ManglingSink ms = new ManglingSink();
2.37 + final CharSequence cmnt = jsniComment.text();
2.38 + tok.process(cmnt.subSequence(4, cmnt.length() - 4), ms);
2.39
2.40 TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
2.41 MethodTree mt = (MethodTree) ctx.getPath().getLeaf();
2.42 List<LiteralTree> params = new ArrayList<LiteralTree>();
2.43
2.44 - params.add(make.Literal("this"));
2.45 -
2.46 for (VariableTree p : mt.getParameters()) {
2.47 params.add(make.Literal(p.getName().toString()));
2.48 }
2.49
2.50 AnnotationTree jsBody = make.Annotation(make.QualIdent("org.apidesign.bck2brwsr.core.JavaScriptBody"),
2.51 Arrays.<ExpressionTree>asList(
2.52 - make.Assignment(make.Identifier("body"), make.Literal(m.group(1))),
2.53 - make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.<ExpressionTree>emptyList(), params))
2.54 + make.Assignment(make.Identifier("args"), make.NewArray(null, Collections.<ExpressionTree>emptyList(), params)),
2.55 + make.Assignment(make.Identifier("body"), make.Literal(ms.out.toString()))
2.56 )
2.57 );
2.58
3.1 --- a/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java Wed Feb 13 12:08:00 2013 +0100
3.2 +++ b/ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java Wed Feb 13 12:45:02 2013 +0100
3.3 @@ -20,14 +20,14 @@
3.4 import java.util.regex.Matcher;
3.5 import java.util.regex.Pattern;
3.6
3.7 -public class JsniCommentTokenizer {
3.8 +final class JsniCommentTokenizer {
3.9
3.10 /**
3.11 * Tokenize the contents of JSNI comment into the provided {@linkplain Sink}.
3.12 * @param in the contents of JSNI comment
3.13 * @param out the sink that consumes parsed tokens
3.14 */
3.15 - public void process(final String in, final Sink out) {
3.16 + public void process(final CharSequence in, final Sink out) {
3.17 final Matcher member = Pattern.compile("@([^:]+)::([a-zA-Z_$][a-zA-Z\\d_$]*)").matcher(in);
3.18 final Matcher signature = Pattern.compile("\\(([^\\)]*)\\)").matcher(in);
3.19
3.20 @@ -36,7 +36,7 @@
3.21 if (member.find(i)) {
3.22 final int memberStart = member.start();
3.23 final int memberEnd = member.end();
3.24 - if (memberStart > i) out.javascript(in.substring(i, memberStart));
3.25 + if (memberStart > i) out.javascript(in.subSequence(i, memberStart).toString());
3.26
3.27 final String clazz = member.group(1);
3.28 final String name = member.group(2);
3.29 @@ -53,14 +53,14 @@
3.30 i = memberEnd;
3.31 }
3.32 } else {
3.33 - out.javascript(in.substring(i, in.length()));
3.34 + out.javascript(in.subSequence(i, in.length()).toString());
3.35 break;
3.36 }
3.37 }
3.38 }
3.39
3.40
3.41 - public static interface Sink {
3.42 + static interface Sink {
3.43 void javascript(String s);
3.44
3.45 void method(String clazz, String method, String signature);
4.1 --- a/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java Wed Feb 13 12:08:00 2013 +0100
4.2 +++ b/ide/editor/src/test/java/org/apidesign/bck2brwsr/ide/editor/DejsniReaderTest.java Wed Feb 13 12:45:02 2013 +0100
4.3 @@ -33,10 +33,11 @@
4.4 " }-*/;\n" +
4.5 "}\n";
4.6
4.7 - String expected = "class Test {\n" +
4.8 + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
4.9 + + "class Test {\n" +
4.10 "\n" +
4.11 " /** javadoc */\n" +
4.12 - " @org.apidesign.bck2brwsr.core.JavaScriptBody(args = { }, body = \"\\n // body\\n \")\n" +
4.13 + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" +
4.14 " public native void test();\n" +
4.15 "}\n";
4.16
4.17 @@ -44,7 +45,7 @@
4.18 .input(s)
4.19 .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
4.20 .run(JSNI2JavaScriptBody.class)
4.21 - .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
4.22 + .findWarning("2:23-2:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
4.23 .applyFix()
4.24 .assertCompilable()
4.25 .assertOutput(expected);
4.26 @@ -62,18 +63,20 @@
4.27 " }-*/;\n" +
4.28 "}\n";
4.29
4.30 - String expected = "class Test {\n" +
4.31 + String expected = " import org.apidesign.bck2brwsr.core.JavaScriptBody;\n"
4.32 + + "class Test {\n" +
4.33 "\n" +
4.34 " /** javadoc */\n" +
4.35 " @SuppressWarnings(\"unused\")\n" +
4.36 - " @org.apidesign.bck2brwsr.core.JavaScriptBody(args = { }, body = \"\\n // body\\n \")\n" +
4.37 + " // comment\n" +
4.38 + " @JavaScriptBody(args = {}, body = \"\\n // body\\n \")\n" +
4.39 " public native void test();\n" +
4.40 "}\n";
4.41 HintTest.create()
4.42 .input(s)
4.43 .classpath(FileUtil.getArchiveRoot(JavaScriptBody.class.getProtectionDomain().getCodeSource().getLocation()))
4.44 .run(JSNI2JavaScriptBody.class)
4.45 - .findWarning("2:23-2:26:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
4.46 + .findWarning("4:23-4:27:verifier:" + Bundle.ERR_JSNI2JavaScriptBody())
4.47 .applyFix()
4.48 .assertCompilable()
4.49 .assertOutput(expected);