parse annotations
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / methods / JavaFile.java
index 400ff87..3dd5557 100644 (file)
@@ -22,6 +22,8 @@ public class JavaFile {
 
        StringBuffer contents = new StringBuffer();
 
+       public List<Clazz> classes = new ArrayList<Clazz>();
+
        public JavaFile(final File file) throws IOException, InvalidSyntaxException {
                this.file = file;
                parse();
@@ -33,6 +35,8 @@ public class JavaFile {
                readFile();
 
                final Tokenizer tokenizer = new Tokenizer(contents.toString());
+
+               // empty space
                tokenizer.addTerminator(" ", true);
                tokenizer.addTerminator("\t", true);
                tokenizer.addTerminator("\n", true);
@@ -47,11 +51,16 @@ public class JavaFile {
                tokenizer.addTerminator("<", false);
                tokenizer.addTerminator(">", false);
                tokenizer.addTerminator(",", false);
+               tokenizer.addTerminator("@", false);
+
+               // comments
+               tokenizer.addTerminator("//", "\n", true);
+               tokenizer.addTerminator("/*", "*/", true);
 
                final Modifiers modifiers = new Modifiers();
 
                while (true) {
-                       final TokenizerMatch match = tokenizer.getToken();
+                       final TokenizerMatch match = tokenizer.getNextToken();
                        if (match == null)
                                break;
 
@@ -74,6 +83,16 @@ public class JavaFile {
                                continue;
                        }
 
+                       if ("interface".equals(match.token)) {
+                               parseInterface(tokenizer);
+                               continue;
+                       }
+
+                       if ("@".equals(match.token)) {
+                               final Annotation annotation = new Annotation(tokenizer);
+                               continue;
+                       }
+
                        System.out.println("    " + modifiers.toString() + " "
                                        + match.token);
                        modifiers.reset();
@@ -85,9 +104,11 @@ public class JavaFile {
        private void parseClass(final Tokenizer tokenizer)
                        throws InvalidSyntaxException {
 
-               final TokenizerMatch match = tokenizer.getToken();
-               final Clazz clazz = new Clazz(packageName, match.token, tokenizer);
-               System.out.println(clazz.toString());
+               final TokenizerMatch match = tokenizer.getNextToken();
+               final Clazz clazz = new Clazz(packageName, match.token, tokenizer,
+                               false);
+               // System.out.println(clazz.toString());
+               classes.add(clazz);
 
        }
 
@@ -96,27 +117,36 @@ public class JavaFile {
 
                final Import imp = new Import();
 
-               final TokenizerMatch match = tokenizer.getToken();
+               final TokenizerMatch match = tokenizer.getNextToken();
 
                if (match.token.equals("static")) {
                        imp.isStatic = true;
-                       imp.path = tokenizer.getToken().token;
+                       imp.path = tokenizer.getNextToken().token;
                } else
                        imp.path = match.token;
 
                imports.add(imp);
 
-               tokenizer.expectToken(";");
+               tokenizer.expectNextToken(";");
+       }
+
+       private void parseInterface(final Tokenizer tokenizer)
+                       throws InvalidSyntaxException {
+
+               final TokenizerMatch match = tokenizer.getNextToken();
+               final Clazz clazz = new Clazz(packageName, match.token, tokenizer, true);
+               // System.out.println(clazz.toString());
+               classes.add(clazz);
        }
 
        private void parsePackage(final Tokenizer tokenizer)
                        throws InvalidSyntaxException {
 
-               final TokenizerMatch match = tokenizer.getToken();
+               final TokenizerMatch match = tokenizer.getNextToken();
 
                packageName = match.token;
 
-               tokenizer.expectToken(";");
+               tokenizer.expectNextToken(";");
        }
 
        private void readFile() throws FileNotFoundException, IOException {
@@ -140,7 +170,11 @@ public class JavaFile {
 
        public void skipUntilSemicolon(final Tokenizer tokenizer) {
                while (true) {
-                       final TokenizerMatch token = tokenizer.getToken();
+                       final TokenizerMatch token = tokenizer.getNextToken();
+
+                       if (token == null)
+                               return;
+
                        if (token.token.equals(";"))
                                return;
                }