From: Svjatoslav Agejenko Date: Tue, 3 Mar 2015 18:18:41 +0000 (+0200) Subject: further API simplification X-Git-Tag: javainspect-1.5~14 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=javainspect.git;a=commitdiff_plain;h=300fb5791f0b79e43cfd2cd589c3ee7f35ac0c1c further API simplification --- diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java index e43fe8d..9f657d1 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java @@ -335,7 +335,7 @@ public class ClassDescriptor implements GraphElement { public String getGraphId() { final String result = "class_" + fullyQualifiedName.replace('.', '_').replace(";", "") - .replace("[L", "").replace('$', '_'); + .replace("[L", "").replace('$', '_'); return result; } @@ -471,7 +471,7 @@ public class ClassDescriptor implements GraphElement { if (Utils.isSystemPackage(fullyQualifiedName)) return false; - if (!getClassGraph().getFilter().isClassShown(fullyQualifiedName)) + if (!getClassGraph().isClassShown(fullyQualifiedName)) return false; if (isArray) 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 27eff03..cee1ee4 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -12,10 +12,13 @@ package eu.svjatoslav.inspector.java.structure; import java.io.File; import java.io.IOException; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import eu.svjatoslav.commons.file.CommonPathResolver; +import eu.svjatoslav.commons.string.WildCardMatcher; import eu.svjatoslav.inspector.java.methods.Clazz; import eu.svjatoslav.inspector.java.methods.ProjectScanner; @@ -26,7 +29,9 @@ public class ClassGraph { */ private final Map fullyQualifiedNameToClassMap = new HashMap(); - private final Filter filter = new Filter(); + private final List blacklistClassPatterns = new ArrayList(); + + private final List whitelistClassPatterns = new ArrayList(); public ClassGraph() { } @@ -69,6 +74,10 @@ public class ClassGraph { } } + public void blacklistClassPattern(final String pattern) { + blacklistClassPatterns.add(pattern); + } + /** * @param resultFileName * file name for the generated graph. Existing file with the same @@ -132,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 { } @@ -165,10 +174,6 @@ public class ClassGraph { return resultStr; } - public Filter getFilter() { - return filter; - } - /** * @param clazz * class that shall be added to graph @@ -205,4 +210,23 @@ public class ClassGraph { } + public boolean isClassShown(final String className) { + for (final String pattern : blacklistClassPatterns) + if (WildCardMatcher.match(className, pattern)) + return false; + + if (!whitelistClassPatterns.isEmpty()) { + for (final String pattern : whitelistClassPatterns) + if (WildCardMatcher.match(className, pattern)) + return true; + return false; + } + + return true; + } + + public void whitelistClassPattern(final String pattern) { + whitelistClassPatterns.add(pattern); + } + } diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java b/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java deleted file mode 100755 index 0519c36..0000000 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * JavaInspect - Utility to visualize java software - * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 3 of the GNU Lesser General Public License - * or later as published by the Free Software Foundation. - */ - -package eu.svjatoslav.inspector.java.structure; - -import java.util.ArrayList; -import java.util.List; - -import eu.svjatoslav.commons.string.WildCardMatcher; - -public class Filter { - - /** - * This class implements filter of classes that will be included or excluded - * from resulting graph. - * - * Filtering is done by lists of whitelist and blacklist patterns using - * wildcards. - * - * Filtering logic is such that if at least single whitelist entry is - * defined then every class that is not whitelisted is automatically - * excluded from graph. - * - * Otherwise every class in included in graph that is not blacklisted. - */ - - private final List blacklistClassPatterns = new ArrayList(); - - private final List whitelistClassPatterns = new ArrayList(); - - public void blacklistClassPattern(final String pattern) { - blacklistClassPatterns.add(pattern); - } - - public boolean isClassShown(final String className) { - for (final String pattern : blacklistClassPatterns) - if (WildCardMatcher.match(className, pattern)) - return false; - - if (!whitelistClassPatterns.isEmpty()) { - for (final String pattern : whitelistClassPatterns) - if (WildCardMatcher.match(className, pattern)) - return true; - return false; - } - - return true; - } - - public void whitelistClassPattern(final String pattern) { - whitelistClassPatterns.add(pattern); - } - -} diff --git a/src/test/java/eu/svjatoslav/inspector/java/structure/example/RenderJavaInspect.java b/src/test/java/eu/svjatoslav/inspector/java/structure/example/RenderJavaInspect.java index 7d9eb80..2bfd560 100755 --- a/src/test/java/eu/svjatoslav/inspector/java/structure/example/RenderJavaInspect.java +++ b/src/test/java/eu/svjatoslav/inspector/java/structure/example/RenderJavaInspect.java @@ -24,8 +24,7 @@ public class RenderJavaInspect { graph.addProject("."); // Blacklist example classes from being shown on the graph - graph.getFilter().blacklistClassPattern( - "eu.svjatoslav.inspector.java.structure.example.*"); + graph.blacklistClassPattern("eu.svjatoslav.inspector.java.structure.example.*"); // do not show single classes with no relationships on the graph graph.hideOrphanedClasses();