-public class MethodDescriptor implements GraphElement {
-
- public String name;
- public ClassDescriptor returnType;
- private final ClassDescriptor parent;
-
- List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
-
- public MethodDescriptor(final Method method, final ClassDescriptor parent,
- final ClassGraph dump) {
-
- this.parent = parent;
-
- name = method.getName();
-
- if (!method.getDeclaringClass().getName()
- .equals(parent.fullyQualifiedName))
- // do not index inherited methods
- return;
-
- parent.methods.add(this);
-
- returnType = dump.addClass(method.getReturnType());
- returnType.registerReference();
-
- final Type genericType = method.getGenericReturnType();
- if (genericType instanceof ParameterizedType) {
- final ParameterizedType pt = (ParameterizedType) genericType;
- for (final Type t : pt.getActualTypeArguments())
- if (t instanceof Class) {
- final Class cl = (Class) t;
- final ClassDescriptor classDescriptor = dump.addClass(cl);
- classDescriptor.registerReference();
- typeArguments.add(classDescriptor);
- }
-
- }
-
- }
-
- @Override
- public String getDot() {
-
- if (!isVisible())
- return "";
-
- final StringBuffer result = new StringBuffer();
-
- // describe associated types
- for (final ClassDescriptor classDescriptor : typeArguments)
- if (classDescriptor.isVisible())
- if (classDescriptor.areReferencesShown())
- result.append(" " + getGraphId() + " -> "
- + classDescriptor.getGraphId() + "[label=\"" + name
- + "\", color=\"" + classDescriptor.getColor()
- + "\", style=\"dotted, bold\"];\n");
-
- if (!returnType.isVisible())
- return result.toString();
-
- // main type
- if (returnType.areReferencesShown())
- result.append(" " + getGraphId() + " -> "
- + returnType.getGraphId() + "[label=\"" + name + "\","
- + " color=\"" + returnType.getColor()
- + "\", style=\"dotted, bold\"];\n");
-
- return result.toString();
- }
+/**
+ * This class corresponds to single method within a java class.
+ */
+public class MethodDescriptor implements GraphElement,
+ Comparable<MethodDescriptor> {
+
+ private final String methodName;
+ private final ClassDescriptor parentClass;
+ private final List<ClassDescriptor> argumentTypes = new ArrayList<ClassDescriptor>();
+ private ClassDescriptor returnType;
+ private boolean isInherited;
+
+ public MethodDescriptor(final ClassDescriptor parent,
+ final String methodName) {
+ parentClass = parent;
+ this.methodName = methodName;
+ }
+
+ public void analyze(final Method method) {
+
+ if (!method.getDeclaringClass().getName()
+ .equals(parentClass.getFullyQualifiedName()))
+ isInherited = true;
+
+ returnType = parentClass.getClassGraph().getOrCreateClassDescriptor(
+ method.getReturnType());
+ returnType.registerReference();
+
+ final Type genericType = method.getGenericReturnType();
+ if (genericType instanceof ParameterizedType) {
+ final ParameterizedType pt = (ParameterizedType) genericType;
+ for (final Type t : pt.getActualTypeArguments())
+ if (t instanceof Class) {
+ final Class cl = (Class) t;
+ final ClassDescriptor classDescriptor = parentClass
+ .getClassGraph().getOrCreateClassDescriptor(cl);
+ classDescriptor.registerReference();
+ argumentTypes.add(classDescriptor);
+ }
+
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof MethodDescriptor)) return false;
+
+ MethodDescriptor that = (MethodDescriptor) o;