added possibility to whitelist or blacklist classes of packages by wildcard pattern
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / ClassDescriptor.java
index c8a2773..fbd491b 100644 (file)
@@ -44,7 +44,9 @@ public class ClassDescriptor implements GraphElement {
 
        boolean isArray;
 
-       private final ClassGraph dump;
+       private boolean isShown = true;
+
+       private final ClassGraph classGraph;
 
        List<ClassDescriptor> interfaces = new ArrayList<ClassDescriptor>();
 
@@ -55,8 +57,9 @@ public class ClassDescriptor implements GraphElement {
         */
        private int referenceCount = 0;
 
-       public ClassDescriptor(final Class<? extends Object> clazz, final ClassGraph dump) {
-               this.dump = dump;
+       public ClassDescriptor(final Class<? extends Object> clazz,
+                       final ClassGraph dump) {
+               classGraph = dump;
 
                fullyQualifiedName = clazz.getName();
                dump.nameToClassMap.put(fullyQualifiedName, this);
@@ -185,8 +188,15 @@ public class ClassDescriptor implements GraphElement {
                result.append("    // class descriptor header\n");
                result.append("    <TR><TD colspan=\"2\" PORT=\"f0\">"
                                + "<FONT POINT-SIZE=\"8.0\" >" + getPackageName()
-                               + "</FONT><br/>" + "<FONT POINT-SIZE=\"25.0\"><B>"
-                               + getClassName(false) + "</B></FONT>" + "</TD></TR>\n");
+                               + "</FONT><br/>");
+
+               final String parentClassesName = getParentClassesName();
+               if (parentClassesName.length() > 0)
+                       result.append("<FONT POINT-SIZE=\"12.0\"><B>" + parentClassesName
+                                       + "</B></FONT><br/>\n");
+
+               result.append("<FONT POINT-SIZE=\"25.0\"><B>" + getClassName(false)
+                               + "</B></FONT>" + "</TD></TR>\n");
        }
 
        public List<FieldDescriptor> getAllFields() {
@@ -219,10 +229,12 @@ public class ClassDescriptor implements GraphElement {
        }
 
        public String getClassName(final boolean differentiateArray) {
+               // this is needed for nested classes
+               final String actualClassName = fullyQualifiedName.replace('$', '.');
 
-               final int i = fullyQualifiedName.lastIndexOf('.');
+               final int i = actualClassName.lastIndexOf('.');
 
-               String result = fullyQualifiedName.substring(i + 1);
+               String result = actualClassName.substring(i + 1);
 
                if (isArray)
                        result = result.substring(0, result.length() - 1);
@@ -231,6 +243,8 @@ public class ClassDescriptor implements GraphElement {
                        if (isArray)
                                result += " []";
 
+               // this is needed for nested classes
+               // result = result.replace('$', '.');
                return result;
        }
 
@@ -283,7 +297,7 @@ public class ClassDescriptor implements GraphElement {
        public String getGraphId() {
                final String result = "class_"
                                + fullyQualifiedName.replace('.', '_').replace(";", "")
-                                               .replace("[L", "");
+                                               .replace("[L", "").replace('$', '_');
                return result;
        }
 
@@ -304,6 +318,17 @@ public class ClassDescriptor implements GraphElement {
                return fullyQualifiedName.substring(0, i).replace("[L", "");
        }
 
+       public String getParentClassesName() {
+               int i = fullyQualifiedName.lastIndexOf('.');
+               final String fullClassName = fullyQualifiedName.substring(i + 1);
+
+               i = fullClassName.lastIndexOf('$');
+               if (i == -1)
+                       return "";
+               final String parentClassesName = fullClassName.substring(0, i);
+               return parentClassesName.replace('$', '.');
+       }
+
        // public String getReadableName() {
        //
        // // do not print full class name for well known system classes
@@ -325,13 +350,17 @@ public class ClassDescriptor implements GraphElement {
                return superClassColor;
        }
 
+       public void hide() {
+               isShown = false;
+       }
+
        public void indexFields(final Field[] fields) {
                for (final Field field : fields) {
                        if (nameToFieldMap.containsKey(field.getName()))
                                continue;
 
                        final FieldDescriptor fieldDescriptor = new FieldDescriptor(field,
-                                       this, dump);
+                                       this, classGraph);
 
                }
        }
@@ -340,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);
 
        }
 
@@ -353,7 +382,10 @@ public class ClassDescriptor implements GraphElement {
                if (Utils.isSystemPackage(fullyQualifiedName))
                        return false;
 
-               return true;
+               if (!classGraph.filter.isClassShown(fullyQualifiedName))
+                       return false;
+
+               return isShown;
        }
 
        public void registerReference() {