added possibility to whitelist or blacklist classes of packages by wildcard pattern
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 11 Jul 2013 18:50:21 +0000 (21:50 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 11 Jul 2013 18:50:21 +0000 (21:50 +0300)
src/main/java/eu/svjatoslav/inspector/java/structure/ClassDescriptor.java
src/main/java/eu/svjatoslav/inspector/java/structure/ClassGraph.java
src/main/java/eu/svjatoslav/inspector/java/structure/Filter.java [new file with mode: 0644]

index 41f92f3..fbd491b 100644 (file)
@@ -46,7 +46,7 @@ public class ClassDescriptor implements GraphElement {
 
        private boolean isShown = true;
 
-       private final ClassGraph dump;
+       private final ClassGraph classGraph;
 
        List<ClassDescriptor> interfaces = new ArrayList<ClassDescriptor>();
 
@@ -59,7 +59,7 @@ public class ClassDescriptor implements GraphElement {
 
        public ClassDescriptor(final Class<? extends Object> 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;
        }
 
index bda0882..b8f9c2c 100644 (file)
@@ -24,6 +24,8 @@ public class ClassGraph {
         */
        Map<String, ClassDescriptor> nameToClassMap = new HashMap<String, ClassDescriptor>();
 
+       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 (file)
index 0000000..72590f3
--- /dev/null
@@ -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<String> blacklistedClasses = new ArrayList<String>();
+
+       private static final List<String> whitelistedClasses = new ArrayList<String>();
+
+       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);
+       }
+
+}