ide/editor/src/main/java/org/apidesign/bck2brwsr/ide/editor/JsniCommentTokenizer.java
Igor's dejsni files and tests. Modified to compile.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.ide.editor;
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
23 public class JsniCommentTokenizer {
26 * Tokenize the contents of JSNI comment into the provided {@linkplain Sink}.
27 * @param in the contents of JSNI comment
28 * @param out the sink that consumes parsed tokens
30 public void process(final String in, final Sink out) {
31 final Matcher member = Pattern.compile("@([^:]+)::([a-zA-Z_$][a-zA-Z\\d_$]*)").matcher(in);
32 final Matcher signature = Pattern.compile("\\(([^\\)]*)\\)").matcher(in);
37 final int memberStart = member.start();
38 final int memberEnd = member.end();
39 if (memberStart > i) out.javascript(in.substring(i, memberStart));
41 final String clazz = member.group(1);
42 final String name = member.group(2);
44 if (in.charAt(memberEnd) == '(') {
45 if (!signature.find(memberEnd)) {
46 throw new IllegalStateException("Expected method signature");
48 assert signature.start() == memberEnd;
49 out.method(clazz, name, signature.group(1));
52 out.field(clazz, name);
56 out.javascript(in.substring(i, in.length()));
63 public static interface Sink {
64 void javascript(String s);
66 void method(String clazz, String method, String signature);
68 void field(String clazz, String field);