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=7520d141e59025fdd93e43f6e86785b451975ecf;hp=cff1f8a77d055c1a0cbdf8df9646d7a6545e0a1c;hpb=cd718904f053ee6901e9b21d76a024ef646bb01c;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 index cff1f8a..173ddc3 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/MethodDescriptor.java @@ -1,7 +1,7 @@ /* * JavaInspect - Utility to visualize java software - * Copyright (C) 2013-2014, 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 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -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 methodName; - 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; + } - methodName = method.getName(); + public void analyze(final Method method) { if (!method.getDeclaringClass().getName() - .equals(parent.classFullyQualifiedName)) - // 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); } @@ -82,8 +81,9 @@ public class MethodDescriptor implements GraphElement, if (classDescriptor.isVisible()) if (classDescriptor.areReferencesShown()) result.append(" " + getGraphId() + " -> " - + classDescriptor.getGraphId() + "[label=\"" + methodName - + "\", 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=\"" + methodName + "\"," - + " color=\"" + returnType.getColor() + + returnType.getGraphId() + "[label=\"" + methodName + + "\"," + " color=\"" + returnType.getColor() + "\", style=\"dotted, bold\"];\n"); return result.toString(); @@ -122,11 +122,11 @@ public class MethodDescriptor implements GraphElement, return parentClass.getGraphId() + ":" + methodName; } - public String getMethodLabel() { + private String getMethodLabel() { return methodName; } - public int getOutsideVisibleReferencesCount() { + protected int getOutsideVisibleReferencesCount() { int result = 0; if (returnType.isVisible()) @@ -142,6 +142,10 @@ public class MethodDescriptor implements GraphElement, @Override public boolean isVisible() { + // hide inherited methods + if (isInherited) + return false; + // hide common object methods if (Utils.isCommonObjectMethod(methodName)) return false; @@ -157,10 +161,10 @@ public class MethodDescriptor implements GraphElement, // hide is methods for the boolean field of the same name if (methodName.startsWith("is")) { - final FieldDescriptor field = parentClass.getFieldIgnoreCase(methodName - .substring(2)); + final FieldDescriptor field = parentClass + .getFieldIgnoreCase(methodName.substring(2)); if (field != null) - if ("boolean".equals(field.getType().classFullyQualifiedName)) + if ("boolean".equals(field.getType().getFullyQualifiedName())) return false; }