X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FClassGraph.java;h=7bae6f3179536676f42138ed3c3855d2af115e8f;hb=16ba5341215d24fdcfa07072d52cf87e5a4375ed;hp=6155876f07e31322106a0883b141a5b478d1be58;hpb=d9837ba577dd0c6d56c83326383f450e35764c90;p=javainspect.git diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java index 6155876..7bae6f3 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -35,19 +35,33 @@ public class ClassGraph { */ Map nameToClassMap = new HashMap(); - public Filter filter = new Filter(); + private Filter filter = new Filter(); public ClassGraph() { } - public ClassGraph(final Class clazz) { - addClass(clazz); + /** + * @param classes + * classes that shall be added to graph + */ + public ClassGraph(final Class... classes) { + for (final Class clazz : classes) + addClass(clazz); } - public ClassGraph(final Object root) { - addClass(root.getClass()); + /** + * @param objects + * objects that shall be added to graph + */ + public ClassGraph(final Object... objects) { + for (Object object : objects) + addClass(object.getClass()); } + /** + * @param clazz + * class that shall be added to graph + */ public ClassDescriptor addClass(final Class clazz) { if (clazz == null) @@ -61,10 +75,19 @@ public class ClassGraph { return new ClassDescriptor(clazz, this); } + /** + * @param object + * object that shall be added to graph + */ public ClassDescriptor addObject(final Object object) { return addClass(object.getClass()); } + /** + * @param path + * path to recursively scan for java source code could be + * relative to current project or absolute + */ public void addProject(final String path) { final ProjectScanner projectScanner = new ProjectScanner(new File(path)); for (final Clazz clazz : projectScanner.getAllClasses()) @@ -78,17 +101,34 @@ public class ClassGraph { } } - public void generateGraph(final String graphName) { - generateGraph(graphName, false); + /** + * @param resultFileName + * file name for the generated graph. Existing file with the same + * name will be overwritten. + */ + public void generateGraph(final String resultFileName) { + generateGraph(resultFileName, false); } - public void generateGraph(final String graphName, final boolean keepDotFile) { + /** + * @param resultFileName + * file name for the generated graph. File extension will be + * added automatically. Existing file with the same name will be + * overwritten. + * + * @param keepDotFile + * if set to true then intermediary GraphViz DOT + * file will be kept. + */ + + public void generateGraph(final String resultFileName, + final boolean keepDotFile) { final String desktopPath = CommonPathResolver.getDesktopDirectory() .getAbsolutePath() + "/"; - final String dotFilePath = desktopPath + graphName + ".dot"; - final String imageFilePath = desktopPath + graphName + ".png"; + final String dotFilePath = desktopPath + resultFileName + ".dot"; + final String imageFilePath = desktopPath + resultFileName + ".png"; System.out.println("Dot file path:" + dotFilePath); @@ -101,8 +141,8 @@ public class ClassGraph { // execute GraphViz to visualize graph try { Runtime.getRuntime() - .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o", - imageFilePath }).waitFor(); + .exec(new String[] { "dot", "-Tpng", dotFilePath, "-o", + imageFilePath }).waitFor(); } catch (final InterruptedException e) { } finally { } @@ -133,11 +173,22 @@ public class ClassGraph { return resultStr; } - public void hideClassesWithoutReferences() { + /** + * Hide orphaned class that have no references + */ + public void hideOrphanedClasses() { for (final ClassDescriptor classDescriptor : nameToClassMap.values()) classDescriptor.hideClassIfNoReferences(); } + public Filter getFilter() { + return filter; + } + + public void setFilter(Filter filter) { + this.filter = filter; + } + }