X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FMethodDescriptor.java;h=456e728bd3f5889e9221a860433c5a1474da3844;hb=31e8e0b97c9f60f8820d708fa86c11d65f5445f3;hp=c3aeaf9dcbafce38bc0de34fe5f0b6b6d7252a13;hpb=39a8ba91a8541b26180cc3c3dcb99f5ff295785d;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 c3aeaf9..456e728 --- 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-2014, 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,18 +15,23 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; -public class MethodDescriptor implements GraphElement { +public class MethodDescriptor implements GraphElement, + Comparable { + + /** + * 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 typeArguments = new ArrayList(); + List argumentTypes = new ArrayList(); public MethodDescriptor(final Method method, final ClassDescriptor parent, final ClassGraph dump) { - this.parent = parent; + parentClass = parent; name = method.getName(); @@ -48,12 +53,22 @@ public class MethodDescriptor implements GraphElement { 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() { @@ -63,7 +78,7 @@ public class MethodDescriptor implements GraphElement { 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() + " -> " @@ -104,7 +119,7 @@ public class MethodDescriptor implements GraphElement { @Override public String getGraphId() { - return parent.getGraphId() + ":" + name; + return parentClass.getGraphId() + ":" + name; } public String getMethodLabel() { @@ -117,7 +132,7 @@ public class MethodDescriptor implements GraphElement { if (returnType.isVisible()) result++; - for (final ClassDescriptor classDescriptor : typeArguments) + for (final ClassDescriptor classDescriptor : argumentTypes) if (classDescriptor.isVisible()) result++; @@ -127,26 +142,30 @@ public class MethodDescriptor implements GraphElement { @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; + } }