return null;
}
+ /**
+ * Returns field with given name (case is ignored). Or <code>null</code> if
+ * field is not found.
+ */
+ public FieldDescriptor getFieldIgnoreCase(final String fieldToSearch) {
+
+ for (final String fieldName : nameToFieldMap.keySet())
+ if (fieldToSearch.equalsIgnoreCase(fieldName))
+ return nameToFieldMap.get(fieldName);
+
+ return null;
+ }
+
@Override
public String getGraphId() {
final String result = "class_"
return result;
}
- public String getPackageName() {
-
- final int i = fullyQualifiedName.lastIndexOf('.');
-
- if (i == -1)
- return "";
-
- return fullyQualifiedName.substring(0, i).replace("[L", "");
- }
-
// public String getReadableName() {
//
// // do not print full class name for well known system classes
// return fullyQualifiedName;
// }
+ public String getPackageName() {
+
+ final int i = fullyQualifiedName.lastIndexOf('.');
+
+ if (i == -1)
+ return "";
+
+ return fullyQualifiedName.substring(0, i).replace("[L", "");
+ }
+
public String getParentClassesName() {
int i = fullyQualifiedName.lastIndexOf('.');
final String fullClassName = fullyQualifiedName.substring(i + 1);
return superClassColor;
}
+ /**
+ * Checks if class has field with given name (case is ignored). Returns
+ * <code>true</code> if such field is found.
+ */
+ public boolean hasFieldIgnoreCase(final String fieldToSearch) {
+
+ for (final String fieldName : nameToFieldMap.keySet())
+ if (fieldToSearch.equalsIgnoreCase(fieldName))
+ return true;
+
+ return false;
+ }
+
public void hide() {
isShown = false;
}
public String name;
private ClassDescriptor type;
- private ClassDescriptor parent;
+ private ClassDescriptor parentClass;
List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
public FieldDescriptor(final Field field, final ClassDescriptor parent,
final ClassGraph dump) {
- this.parent = parent;
+ parentClass = parent;
if (!field.getDeclaringClass().getName()
.equals(parent.fullyQualifiedName))
// main type
boolean showLink = type.areReferencesShown();
- if (type == parent)
+ if (type == parentClass)
showLink = false;
- if (parent.isEnum)
+ if (parentClass.isEnum)
showLink = false;
if (showLink)
final StringBuffer result = new StringBuffer();
result.append(" // " + name + "\n");
- if (parent.isEnum && (type == parent)) {
+ if (parentClass.isEnum && (type == parentClass)) {
result.append(" <TR><TD colspan=\"2\" PORT=\"" + name);
result.append("\" ALIGN=\"left\"><FONT POINT-SIZE=\"11.0\">");
result.append(name + "</FONT></TD></TR>\n");
@Override
public String getGraphId() {
- return parent.getGraphId() + ":" + name;
+ return parentClass.getGraphId() + ":" + name;
}
public int getOutsideVisibleReferencesCount() {
return 0;
}
+ public ClassDescriptor getType() {
+ return type;
+ }
+
@Override
public boolean isVisible() {
if (name.contains("$"))
return true;
}
+
}
\ No newline at end of file
import java.util.List;
public class MethodDescriptor implements GraphElement,
-Comparable<MethodDescriptor> {
+ Comparable<MethodDescriptor> {
/**
* This class corresponds to single method within a java class.
public String name;
public ClassDescriptor returnType;
- private final ClassDescriptor parent;
+ private final ClassDescriptor parentClass;
- List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
+ List<ClassDescriptor> argumentTypes = new ArrayList<ClassDescriptor>();
public MethodDescriptor(final Method method, final ClassDescriptor parent,
final ClassGraph dump) {
- this.parent = parent;
+ parentClass = parent;
name = method.getName();
final Class cl = (Class) t;
final ClassDescriptor classDescriptor = dump.addClass(cl);
classDescriptor.registerReference();
- typeArguments.add(classDescriptor);
+ argumentTypes.add(classDescriptor);
}
}
}
+ @Override
+ public int compareTo(final MethodDescriptor o) {
+
+ final int nameComparisonResult = name.compareTo(o.name);
+ if (nameComparisonResult != 0)
+ return nameComparisonResult;
+
+ return toString().compareTo(o.toString());
+ }
+
@Override
public String getDot() {
final StringBuffer result = new StringBuffer();
// describe associated types
- for (final ClassDescriptor classDescriptor : typeArguments)
+ for (final ClassDescriptor classDescriptor : argumentTypes)
if (classDescriptor.isVisible())
if (classDescriptor.areReferencesShown())
result.append(" " + getGraphId() + " -> "
@Override
public String getGraphId() {
- return parent.getGraphId() + ":" + name;
+ return parentClass.getGraphId() + ":" + name;
}
public String getMethodLabel() {
if (returnType.isVisible())
result++;
- for (final ClassDescriptor classDescriptor : typeArguments)
+ for (final ClassDescriptor classDescriptor : argumentTypes)
if (classDescriptor.isVisible())
result++;
@Override
public boolean isVisible() {
- if (Utils.isSystemMethod(name))
+ // hide common object methods
+ if (Utils.isCommonObjectMethod(name))
return false;
- if (parent.isEnum && Utils.isEnumMethod(name))
+ // hide common Enumeration methods
+ if (parentClass.isEnum && Utils.isEnumMethod(name))
return false;
- if (!(name.startsWith("get") || name.startsWith("set")))
- return true;
-
- final String upprCaseName = name.substring(3).toUpperCase();
-
- for (String parentField : parent.nameToFieldMap.keySet()) {
- parentField = parentField.toUpperCase();
-
- if (upprCaseName.equals(parentField))
+ // hide get/set methods for the field of the same name
+ if (name.startsWith("get") || name.startsWith("set"))
+ if (parentClass.hasFieldIgnoreCase(name.substring(3)))
return false;
+ // hide is methods for the boolean field of the same name
+ if (name.startsWith("is")) {
+ final FieldDescriptor field = parentClass.getFieldIgnoreCase(name
+ .substring(2));
+ if (field != null)
+ if ("boolean".equals(field.getType().fullyQualifiedName))
+ return false;
}
return true;
- }
-
- @Override
- public int compareTo(MethodDescriptor o) {
- int nameComparisonResult = name.compareTo(o.name);
- if (nameComparisonResult != 0)
- return nameComparisonResult;
-
- return toString().compareTo(o.toString());
}
}
private static final List<String> systemDataTypes = new ArrayList<String>();
- private static final List<String> systemMethods = new ArrayList<String>();
+ private static final List<String> commonObjectMethods = new ArrayList<String>();
private static final List<String> systemPackages = new ArrayList<String>();
initSystemDataTypes();
initDarkColors();
initLightColors();
- initSystemMethods();
+ initCommonObjectMethods();
initSystemPackages();
}
systemDataTypes.add("byte");
}
- public static void initSystemMethods() {
- systemMethods.add("wait");
- systemMethods.add("equals");
- systemMethods.add("toString");
- systemMethods.add("hashCode");
- systemMethods.add("notify");
- systemMethods.add("notifyAll");
- systemMethods.add("getClass");
+ public static void initCommonObjectMethods() {
+ commonObjectMethods.add("wait");
+ commonObjectMethods.add("equals");
+ commonObjectMethods.add("toString");
+ commonObjectMethods.add("hashCode");
+ commonObjectMethods.add("notify");
+ commonObjectMethods.add("notifyAll");
+ commonObjectMethods.add("getClass");
}
public static void initSystemPackages() {
return systemDataTypes.contains(name);
}
- public static boolean isSystemMethod(final String name) {
- return systemMethods.contains(name);
+ public static boolean isCommonObjectMethod(final String name) {
+ return commonObjectMethods.contains(name);
}
public static boolean isSystemPackage(final String name) {
--- /dev/null
+package eu.svjatoslav.inspector.java.structure.example;
+
+import eu.svjatoslav.inspector.java.structure.ClassGraph;
+import eu.svjatoslav.inspector.java.structure.example.structure.SampleClass;
+
+public class RenderDemoClasses {
+
+ public static void main(final String[] args) {
+ final ClassGraph graph = new ClassGraph();
+
+ graph.addClass(SampleClass.class);
+
+ graph.generateGraph("example");
+ }
+
+}
+++ /dev/null
-/*
- * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
-
-package eu.svjatoslav.inspector.java.structure.example;
-
-import eu.svjatoslav.inspector.java.structure.ClassGraph;
-import eu.svjatoslav.inspector.java.structure.example.structure.SampleClass;
-
-public class RenderExampleProject {
-
- public static void main(final String[] args) {
- final ClassGraph graph = new ClassGraph();
-
- graph.addClass(SampleClass.class);
-
- graph.generateGraph("example");
-
- }
-
-}