From: Svjatoslav Agejenko Date: Thu, 11 Jul 2013 18:50:21 +0000 (+0300) Subject: added possibility to whitelist or blacklist classes of packages by wildcard pattern X-Git-Tag: javainspect-1.1~9 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=79db54fde2069b536c95e9da810efb27f2e4efb5;p=javainspect.git added possibility to whitelist or blacklist classes of packages by wildcard pattern --- 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 41f92f3..fbd491b 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java @@ -46,7 +46,7 @@ public class ClassDescriptor implements GraphElement { private boolean isShown = true; - private final ClassGraph dump; + private final ClassGraph classGraph; List interfaces = new ArrayList(); @@ -59,7 +59,7 @@ public class ClassDescriptor implements GraphElement { public ClassDescriptor(final Class clazz, final ClassGraph dump) { - this.dump = dump; + classGraph = dump; fullyQualifiedName = clazz.getName(); dump.nameToClassMap.put(fullyQualifiedName, this); @@ -360,7 +360,7 @@ public class ClassDescriptor implements GraphElement { continue; final FieldDescriptor fieldDescriptor = new FieldDescriptor(field, - this, dump); + this, classGraph); } } @@ -369,7 +369,7 @@ public class ClassDescriptor implements GraphElement { final Method[] methods = clazz.getMethods(); for (final Method method : methods) - new MethodDescriptor(method, this, dump); + new MethodDescriptor(method, this, classGraph); } @@ -382,6 +382,9 @@ public class ClassDescriptor implements GraphElement { if (Utils.isSystemPackage(fullyQualifiedName)) return false; + if (!classGraph.filter.isClassShown(fullyQualifiedName)) + return false; + return isShown; } 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 bda0882..b8f9c2c 100644 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java @@ -24,6 +24,8 @@ public class ClassGraph { */ Map nameToClassMap = new HashMap(); + public Filter filter = new Filter(); + public ClassGraph() { } diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java b/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java new file mode 100644 index 0000000..72590f3 --- /dev/null +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java @@ -0,0 +1,37 @@ +package eu.svjatoslav.inspector.java.structure; + +import java.util.ArrayList; +import java.util.List; + +import eu.svjatoslav.commons.string.WildCardMatcher; + +public class Filter { + + private static final List blacklistedClasses = new ArrayList(); + + private static final List whitelistedClasses = new ArrayList(); + + public void blacklistClassPattern(final String pattern) { + blacklistedClasses.add(pattern); + } + + public boolean isClassShown(final String className) { + for (final String pattern : blacklistedClasses) + if (WildCardMatcher.match(className, pattern)) + return false; + + if (!whitelistedClasses.isEmpty()) { + for (final String pattern : whitelistedClasses) + if (WildCardMatcher.match(className, pattern)) + return true; + return false; + } + + return true; + } + + public void whitelistClassPattern(final String pattern) { + whitelistedClasses.add(pattern); + } + +}