X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FMethodDescriptor.java;h=173ddc33d30e1adc5dbe6c67b09058a76872f2d6;hb=c508bf97e017675b49df989b7f5a64cbd31d9aa3;hp=89a492eaf2574850d02c41b83cdc00d323212ad0;hpb=ff4200b065c2eb7c8448fa060e7610ab57f6aec1;p=javainspect.git diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java old mode 100644 new mode 100755 index 89a492e..173ddc3 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java @@ -1,10 +1,10 @@ /* * JavaInspect - Utility to visualize java software - * Copyright (C) 2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * Copyright (C) 2013-2015, 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. + * modify it under the terms of version 3 of the GNU Lesser General Public License + * or later as published by the Free Software Foundation. */ package eu.svjatoslav.inspector.java.structure; @@ -15,34 +15,32 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +/** + * This class corresponds to single method within a java class. + */ public class MethodDescriptor implements GraphElement, Comparable { - /** - * This class corresponds to single method within a java class. - */ - - public String name; - public ClassDescriptor returnType; + private final String methodName; + private ClassDescriptor returnType; private final ClassDescriptor parentClass; + private final List argumentTypes = new ArrayList(); + private boolean isInherited; - List argumentTypes = new ArrayList(); - - public MethodDescriptor(final Method method, final ClassDescriptor parent, - final ClassGraph dump) { - + public MethodDescriptor(final ClassDescriptor parent, + final String methodName) { parentClass = parent; + this.methodName = methodName; + } - name = method.getName(); + public void analyze(final Method method) { if (!method.getDeclaringClass().getName() - .equals(parent.fullyQualifiedName)) - // do not index inherited methods - return; - - parent.methods.add(this); + .equals(parentClass.getFullyQualifiedName())) + isInherited = true; - returnType = dump.addClass(method.getReturnType()); + returnType = parentClass.getClassGraph().getOrCreateClassDescriptor( + method.getReturnType()); returnType.registerReference(); final Type genericType = method.getGenericReturnType(); @@ -51,7 +49,8 @@ public class MethodDescriptor implements GraphElement, for (final Type t : pt.getActualTypeArguments()) if (t instanceof Class) { final Class cl = (Class) t; - final ClassDescriptor classDescriptor = dump.addClass(cl); + final ClassDescriptor classDescriptor = parentClass + .getClassGraph().getOrCreateClassDescriptor(cl); classDescriptor.registerReference(); argumentTypes.add(classDescriptor); } @@ -62,7 +61,7 @@ public class MethodDescriptor implements GraphElement, @Override public int compareTo(final MethodDescriptor o) { - final int nameComparisonResult = name.compareTo(o.name); + final int nameComparisonResult = methodName.compareTo(o.methodName); if (nameComparisonResult != 0) return nameComparisonResult; @@ -82,8 +81,9 @@ public class MethodDescriptor implements GraphElement, if (classDescriptor.isVisible()) if (classDescriptor.areReferencesShown()) result.append(" " + getGraphId() + " -> " - + classDescriptor.getGraphId() + "[label=\"" + name - + "\", color=\"" + classDescriptor.getColor() + + classDescriptor.getGraphId() + "[label=\"" + + methodName + "\", color=\"" + + classDescriptor.getColor() + "\", style=\"dotted, bold\"];\n"); if (!returnType.isVisible()) @@ -92,8 +92,8 @@ public class MethodDescriptor implements GraphElement, // main type if (returnType.areReferencesShown()) result.append(" " + getGraphId() + " -> " - + returnType.getGraphId() + "[label=\"" + name + "\"," - + " color=\"" + returnType.getColor() + + returnType.getGraphId() + "[label=\"" + methodName + + "\"," + " color=\"" + returnType.getColor() + "\", style=\"dotted, bold\"];\n"); return result.toString(); @@ -106,7 +106,7 @@ public class MethodDescriptor implements GraphElement, final StringBuffer result = new StringBuffer(); - result.append(" // " + name + "\n"); + result.append(" // " + methodName + "\n"); result.append(" " + "" + returnType.getClassName(true) @@ -119,14 +119,14 @@ public class MethodDescriptor implements GraphElement, @Override public String getGraphId() { - return parentClass.getGraphId() + ":" + name; + return parentClass.getGraphId() + ":" + methodName; } - public String getMethodLabel() { - return name; + private String getMethodLabel() { + return methodName; } - public int getOutsideVisibleReferencesCount() { + protected int getOutsideVisibleReferencesCount() { int result = 0; if (returnType.isVisible()) @@ -142,25 +142,29 @@ public class MethodDescriptor implements GraphElement, @Override public boolean isVisible() { + // hide inherited methods + if (isInherited) + return false; + // hide common object methods - if (Utils.isCommonObjectMethod(name)) + if (Utils.isCommonObjectMethod(methodName)) return false; // hide common Enumeration methods - if (parentClass.isEnum && Utils.isEnumMethod(name)) + if (parentClass.isEnum && Utils.isEnumMethod(methodName)) return false; // hide get/set methods for the field of the same name - if (name.startsWith("get") || name.startsWith("set")) - if (parentClass.hasFieldIgnoreCase(name.substring(3))) + if (methodName.startsWith("get") || methodName.startsWith("set")) + if (parentClass.hasFieldIgnoreCase(methodName.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 (methodName.startsWith("is")) { + final FieldDescriptor field = parentClass + .getFieldIgnoreCase(methodName.substring(2)); if (field != null) - if ("boolean".equals(field.getType().fullyQualifiedName)) + if ("boolean".equals(field.getType().getFullyQualifiedName())) return false; }