*/
private int incomingReferencesCount = 0;
+ private int extensionsCount = 0;
+
public ClassDescriptor(final Class<? extends Object> clazz,
final ClassGraph dump) {
classGraph = dump;
indexMethods(clazz);
- for (final Class interfaceClass : clazz.getInterfaces())
- interfaces.add(dump.addClass(interfaceClass));
+ for (final Class interfaceClass : clazz.getInterfaces()) {
+ final ClassDescriptor classDescriptor = dump
+ .addClass(interfaceClass);
+ classDescriptor.registerExtension();
+ interfaces.add(classDescriptor);
+ }
superClass = dump.addClass(clazz.getSuperclass());
+ if (superClass != null)
+ superClass.registerExtension();
+
}
public boolean areReferencesShown() {
public String getGraphId() {
final String result = "class_"
+ fullyQualifiedName.replace('.', '_').replace(";", "")
- .replace("[L", "").replace('$', '_');
+ .replace("[L", "").replace('$', '_');
return result;
}
return interfaceColor;
}
- public String getPackageName() {
+ private int getOutgoingReferencesCount() {
+ int result = 0;
- final int i = fullyQualifiedName.lastIndexOf('.');
+ // count method references
+ for (final MethodDescriptor methodDescriptor : methods)
+ result += methodDescriptor.getOutsideVisibleReferencesCount();
- if (i == -1)
- return "";
+ // count field references
+ for (final FieldDescriptor fieldDescriptor : nameToFieldMap.values())
+ result += fieldDescriptor.getOutsideVisibleReferencesCount();
- return fullyQualifiedName.substring(0, i).replace("[L", "");
+ // count implemented interfaces
+ for (final ClassDescriptor classDescriptor : interfaces)
+ if (classDescriptor.isVisible())
+ result++;
+
+ // count superclass
+ if (superClass != null)
+ if (superClass.isVisible())
+ result++;
+
+ return result;
}
- public String getParentClassesName() {
- int i = fullyQualifiedName.lastIndexOf('.');
- final String fullClassName = fullyQualifiedName.substring(i + 1);
+ public String getPackageName() {
+
+ final int i = fullyQualifiedName.lastIndexOf('.');
- i = fullClassName.lastIndexOf('$');
if (i == -1)
return "";
- final String parentClassesName = fullClassName.substring(0, i);
- return parentClassesName.replace('$', '.');
+
+ return fullyQualifiedName.substring(0, i).replace("[L", "");
}
// public String getReadableName() {
// return fullyQualifiedName;
// }
+ 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 getSuperClassColor() {
if (superClassColor == null)
superClassColor = Utils.getNextLightColor();
isShown = false;
}
- public boolean hideClassIfNoReferences() {
+ public void hideClassIfNoReferences() {
if (!isVisible())
- return false;
-
- int outgoingVisibleReferencesCount = 0;
-
- for (final MethodDescriptor methodDescriptor : methods)
- outgoingVisibleReferencesCount += methodDescriptor
- .getOutsideVisibleReferencesCount();
-
- for (final FieldDescriptor fieldDescriptor : nameToFieldMap.values())
- outgoingVisibleReferencesCount += fieldDescriptor
- .getOutsideVisibleReferencesCount();
+ return;
- final int totalReferencesCount = outgoingVisibleReferencesCount
- + incomingReferencesCount;
+ final int totalReferencesCount = getOutgoingReferencesCount()
+ + incomingReferencesCount + extensionsCount;
if (totalReferencesCount == 0) {
hide();
- return true;
+ return;
}
- return false;
+ return;
}
public void indexFields(final Field[] fields) {
return isShown;
}
+ /**
+ * Register event when another class is extending this one, or is
+ * implementing interface declared by this class.
+ */
+ public void registerExtension() {
+ extensionsCount++;
+ }
+
public void registerReference() {
incomingReferencesCount++;
}