dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java
branchjavac
changeset 1295 5b3ae17babdf
parent 579 942deef87200
child 1327 217ca48c5b80
     1.1 --- a/dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java	Fri Jan 25 10:25:30 2013 +0100
     1.2 +++ b/dew/src/main/java/org/apidesign/bck2brwsr/dew/Compile.java	Mon Sep 23 00:59:14 2013 +0200
     1.3 @@ -29,8 +29,6 @@
     1.4  import java.util.HashMap;
     1.5  import java.util.List;
     1.6  import java.util.Map;
     1.7 -import java.util.regex.Matcher;
     1.8 -import java.util.regex.Pattern;
     1.9  import javax.tools.Diagnostic;
    1.10  import javax.tools.DiagnosticListener;
    1.11  import javax.tools.FileObject;
    1.12 @@ -55,8 +53,8 @@
    1.13      private final String html;
    1.14  
    1.15      private Compile(String html, String code) throws IOException {
    1.16 -        this.pkg = findPkg(code);
    1.17 -        this.cls = findCls(code);
    1.18 +        this.pkg = find("package", ';', code);
    1.19 +        this.cls = find("class", ' ', code);
    1.20          this.html = html;
    1.21          classes = compile(html, code);
    1.22      }
    1.23 @@ -177,23 +175,20 @@
    1.24      public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
    1.25          errors.add(diagnostic);
    1.26      }
    1.27 -    private static String findPkg(String java) throws IOException {
    1.28 -        Pattern p = Pattern.compile("package\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}*;", Pattern.MULTILINE);
    1.29 -        Matcher m = p.matcher(java);
    1.30 -        if (!m.find()) {
    1.31 -            throw new IOException("Can't find package declaration in the java file");
    1.32 +    private static String find(String pref, char term, String java) throws IOException {
    1.33 +        int pkg = java.indexOf(pref);
    1.34 +        if (pkg != -1) {
    1.35 +            pkg += pref.length();
    1.36 +            while (Character.isWhitespace(java.charAt(pkg))) {
    1.37 +                pkg++;
    1.38 +            }
    1.39 +            int semicolon = java.indexOf(term, pkg);
    1.40 +            if (semicolon != -1) {
    1.41 +                String pkgName = java.substring(pkg, semicolon).trim();
    1.42 +                return pkgName;
    1.43 +            }
    1.44          }
    1.45 -        String pkg = m.group(1);
    1.46 -        return pkg;
    1.47 -    }
    1.48 -    private static String findCls(String java) throws IOException {
    1.49 -        Pattern p = Pattern.compile("class\\p{javaWhitespace}*([\\p{Alnum}\\.]+)\\p{javaWhitespace}", Pattern.MULTILINE);
    1.50 -        Matcher m = p.matcher(java);
    1.51 -        if (!m.find()) {
    1.52 -            throw new IOException("Can't find package declaration in the java file");
    1.53 -        }
    1.54 -        String cls = m.group(1);
    1.55 -        return cls;
    1.56 +        throw new IOException("Can't find " + pref + " declaration in the java file");
    1.57      }
    1.58  
    1.59      String getHtml() {