X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FFieldDescriptor.java;h=254b627ebb5b14088f1b5ad931f0f8f5fe00e6e4;hb=7d1259aea992843c47f29c932434a88ea9364f7e;hp=59f93fced7cc2ab864183832d7f406bf1a1e4ea9;hpb=c680c10ad9057106e23b149246abdd84b41775ee;p=javainspect.git diff --git a/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java b/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java index 59f93fc..254b627 100755 --- a/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java @@ -1,6 +1,6 @@ /* * JavaInspect - Utility to visualize java software - * Copyright (C) 2013-2015, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Copyright (C) 2013-2020, 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 @@ -21,35 +21,35 @@ import java.util.List; public class FieldDescriptor implements GraphElement { - private final ClassDescriptor parentClass; - private final List typeArguments = new ArrayList(); + private final ClassDescriptor parentClassDescriptor; + private final List typeArguments = new ArrayList<>(); private String name; private ClassDescriptor type; private boolean isInherited; public FieldDescriptor(final ClassDescriptor parent) { - parentClass = parent; + parentClassDescriptor = parent; } public void analyzeField(final Field field) { if (!field.getDeclaringClass().getName() - .equals(parentClass.getFullyQualifiedName())) + .equals(parentClassDescriptor.getFullyQualifiedName())) isInherited = true; name = field.getName(); - type = parentClass.getClassGraph().getOrCreateClassDescriptor( + type = parentClassDescriptor.getClassGraph().getOrCreateClassDescriptor( field.getType()); type.registerReference(); - final Type genericType = field.getGenericType(); - 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 genericTypeDescriptor = parentClass - .getClassGraph().getOrCreateClassDescriptor(cl); + final Type fieldGenericType = field.getGenericType(); + if (fieldGenericType instanceof ParameterizedType) { + final ParameterizedType fieldParameterizedGenericType = (ParameterizedType) fieldGenericType; + for (final Type type : fieldParameterizedGenericType.getActualTypeArguments()) + if (type instanceof Class) { + final Class aClass = (Class) type; + final ClassDescriptor genericTypeDescriptor = parentClassDescriptor + .getClassGraph().getOrCreateClassDescriptor(aClass); genericTypeDescriptor.registerReference(); typeArguments.add(genericTypeDescriptor); } @@ -63,7 +63,7 @@ public class FieldDescriptor implements GraphElement { if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); // describe associated types for (final ClassDescriptor classDescriptor : typeArguments) @@ -74,16 +74,17 @@ public class FieldDescriptor implements GraphElement { + "\", color=\"" + classDescriptor.getColor() + "\", style=\"bold\"];\n"); + if (type == null) return result.toString(); if (!type.isVisible()) return result.toString(); // main type boolean showLink = type.areReferencesShown(); - if (type == parentClass) + if (type == parentClassDescriptor) showLink = false; - if (parentClass.isEnum) + if (parentClassDescriptor.isEnum) showLink = false; if (showLink) @@ -100,17 +101,17 @@ public class FieldDescriptor implements GraphElement { if (!isVisible()) return ""; - final StringBuffer result = new StringBuffer(); + final StringBuilder result = new StringBuilder(); result.append(" // " + name + "\n"); - if (parentClass.isEnum && (type == parentClass)) { + if (parentClassDescriptor.isEnum && (type == parentClassDescriptor)) { result.append(" "); result.append(name + "\n"); } else { result.append(" "); result.append(""); - result.append(type.getClassName(true) + ""); + result.append(describeType() + ""); result.append(""); result.append(name + "\n"); @@ -118,9 +119,14 @@ public class FieldDescriptor implements GraphElement { return result.toString(); } + private String describeType() { + if (type == null) return "-null-"; + return type.getClassName(true); + } + @Override public String getGraphId() { - return parentClass.getGraphId() + ":" + name; + return parentClassDescriptor.getGraphId() + ":" + name; } protected int getOutsideVisibleReferencesCount() { @@ -151,4 +157,4 @@ public class FieldDescriptor implements GraphElement { } -} \ No newline at end of file +}