--- /dev/null
+package eu.svjatoslav.inspector.java.methods;
+
+import eu.svjatoslav.inspector.tokenizer.InvalidSyntaxException;
+import eu.svjatoslav.inspector.tokenizer.Tokenizer;
+import eu.svjatoslav.inspector.tokenizer.TokenizerMatch;
+
+public class Annotation {
+
+ private String name;
+
+ public Annotation(final Tokenizer tokenizer) throws InvalidSyntaxException {
+
+ name = tokenizer.getNextToken().token;
+
+ if (!tokenizer.probeNextToken("("))
+ return;
+
+ int depth = 1;
+
+ while (true) {
+ final TokenizerMatch token = tokenizer.getNextToken();
+
+ if ("(".equals(token.token))
+ depth++;
+ if (")".equals(token.token))
+ depth--;
+
+ if (depth == 0)
+ return;
+ }
+
+ }
+
+}
}
}
+ public String getFullName() {
+ return packageName + "." + className;
+ }
+
public void parseClassBody(final Tokenizer tokenizer) {
tokenizer.skipUntilDataEnd();
}
StringBuffer contents = new StringBuffer();
+ public List<Clazz> classes = new ArrayList<Clazz>();
+
public JavaFile(final File file) throws IOException, InvalidSyntaxException {
this.file = file;
parse();
tokenizer.addTerminator("<", false);
tokenizer.addTerminator(">", false);
tokenizer.addTerminator(",", false);
+ tokenizer.addTerminator("@", false);
// comments
tokenizer.addTerminator("//", "\n", true);
continue;
}
+ if ("@".equals(match.token)) {
+ final Annotation annotation = new Annotation(tokenizer);
+ continue;
+ }
+
System.out.println(" " + modifiers.toString() + " "
+ match.token);
modifiers.reset();
final TokenizerMatch match = tokenizer.getNextToken();
final Clazz clazz = new Clazz(packageName, match.token, tokenizer,
false);
- System.out.println(clazz.toString());
+ // System.out.println(clazz.toString());
+ classes.add(clazz);
+
}
private void parseImport(final Tokenizer tokenizer)
final TokenizerMatch match = tokenizer.getNextToken();
final Clazz clazz = new Clazz(packageName, match.token, tokenizer, true);
- System.out.println(clazz.toString());
+ // System.out.println(clazz.toString());
+ classes.add(clazz);
}
private void parsePackage(final Tokenizer tokenizer)
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import eu.svjatoslav.commons.file.FilePathParser;
private final File scanPath;
Map<File, Project> projects = new HashMap<File, Project>();
+ public List<JavaFile> javaFiles = new ArrayList<JavaFile>();
public ProjectScanner(final File projectPath) {
scanPath = projectPath;
parse();
}
+ public List<Clazz> getAllClasses() {
+ final List<Clazz> result = new ArrayList<Clazz>();
+
+ for (final JavaFile file : javaFiles)
+ for (final Clazz clazz : file.classes)
+ result.add(clazz);
+
+ return result;
+ }
+
public void parse() {
if (!scanPath.exists())
if ("java".equalsIgnoreCase(fileExtension))
try {
final JavaFile javaFile = new JavaFile(file);
+ javaFiles.add(javaFile);
} catch (final IOException e) {
System.out.println("Error parsing file: " + file.toString()
+ ": " + e.toString());
import java.util.Map;
import eu.svjatoslav.commons.file.CommonPathResolver;
+import eu.svjatoslav.inspector.java.methods.Clazz;
+import eu.svjatoslav.inspector.java.methods.ProjectScanner;
public class ClassGraph {
return addClass(object.getClass());
}
+ public void addProject(final String path) {
+ final ProjectScanner projectScanner = new ProjectScanner(new File(path));
+ for (final Clazz clazz : projectScanner.getAllClasses())
+ try {
+ System.out.println("Class full name: " + clazz.getFullName());
+ final Class c = this.getClass().forName(clazz.getFullName());
+ addClass(c);
+ } catch (final Exception exception) {
+ System.out.println("cannot add class: "
+ + exception.getMessage());
+ }
+ }
+
public void generateGraph(final String graphName) {
generateGraph(graphName, false);
}