X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FMethodDescriptor.java;h=cff1f8a77d055c1a0cbdf8df9646d7a6545e0a1c;hb=cd718904f053ee6901e9b21d76a024ef646bb01c;hp=5e03b6b1b82e7cbaabe179e9b06a4c35dfcabf81;hpb=16ba5341215d24fdcfa07072d52cf87e5a4375ed;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 5e03b6b..cff1f8a --- 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; @@ -16,27 +16,27 @@ import java.util.ArrayList; import java.util.List; public class MethodDescriptor implements GraphElement, -Comparable { + Comparable { /** * This class corresponds to single method within a java class. */ - public String name; + public String methodName; 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(); + methodName = method.getName(); if (!method.getDeclaringClass().getName() - .equals(parent.fullyQualifiedName)) + .equals(parent.classFullyQualifiedName)) // do not index inherited methods return; @@ -53,12 +53,22 @@ Comparable { 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 = methodName.compareTo(o.methodName); + if (nameComparisonResult != 0) + return nameComparisonResult; + + return toString().compareTo(o.toString()); + } + @Override public String getDot() { @@ -68,11 +78,11 @@ Comparable { 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() + " -> " - + classDescriptor.getGraphId() + "[label=\"" + name + + classDescriptor.getGraphId() + "[label=\"" + methodName + "\", color=\"" + classDescriptor.getColor() + "\", style=\"dotted, bold\"];\n"); @@ -82,7 +92,7 @@ Comparable { // main type if (returnType.areReferencesShown()) result.append(" " + getGraphId() + " -> " - + returnType.getGraphId() + "[label=\"" + name + "\"," + + returnType.getGraphId() + "[label=\"" + methodName + "\"," + " color=\"" + returnType.getColor() + "\", style=\"dotted, bold\"];\n"); @@ -96,7 +106,7 @@ Comparable { final StringBuffer result = new StringBuffer(); - result.append(" // " + name + "\n"); + result.append(" // " + methodName + "\n"); result.append(" " + "" + returnType.getClassName(true) @@ -109,11 +119,11 @@ Comparable { @Override public String getGraphId() { - return parent.getGraphId() + ":" + name; + return parentClass.getGraphId() + ":" + methodName; } public String getMethodLabel() { - return name; + return methodName; } public int getOutsideVisibleReferencesCount() { @@ -122,7 +132,7 @@ Comparable { if (returnType.isVisible()) result++; - for (final ClassDescriptor classDescriptor : typeArguments) + for (final ClassDescriptor classDescriptor : argumentTypes) if (classDescriptor.isVisible()) result++; @@ -132,36 +142,30 @@ Comparable { @Override public boolean isVisible() { - if (Utils.isSystemMethod(name)) + // hide common object methods + if (Utils.isCommonObjectMethod(methodName)) return false; - if (parent.isEnum && Utils.isEnumMethod(name)) + // hide common Enumeration methods + if (parentClass.isEnum && Utils.isEnumMethod(methodName)) 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 (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 (methodName.startsWith("is")) { + final FieldDescriptor field = parentClass.getFieldIgnoreCase(methodName + .substring(2)); + if (field != null) + if ("boolean".equals(field.getType().classFullyQualifiedName)) + 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()); } }