Updated copyright info
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / FieldDescriptor.java
index b6de871..254b627 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013-2017, 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,24 +21,24 @@ import java.util.List;
 
 public class FieldDescriptor implements GraphElement {
 
-    private final ClassDescriptor parentClassDescriptior;
-    private final List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
+    private final ClassDescriptor parentClassDescriptor;
+    private final List<ClassDescriptor> typeArguments = new ArrayList<>();
     private String name;
     private ClassDescriptor type;
     private boolean isInherited;
 
     public FieldDescriptor(final ClassDescriptor parent) {
-        parentClassDescriptior = parent;
+        parentClassDescriptor = parent;
     }
 
     public void analyzeField(final Field field) {
 
         if (!field.getDeclaringClass().getName()
-                .equals(parentClassDescriptior.getFullyQualifiedName()))
+                .equals(parentClassDescriptor.getFullyQualifiedName()))
             isInherited = true;
 
         name = field.getName();
-        type = parentClassDescriptior.getClassGraph().getOrCreateClassDescriptor(
+        type = parentClassDescriptor.getClassGraph().getOrCreateClassDescriptor(
                 field.getType());
         type.registerReference();
 
@@ -48,7 +48,7 @@ public class FieldDescriptor implements GraphElement {
             for (final Type type : fieldParameterizedGenericType.getActualTypeArguments())
                 if (type instanceof Class) {
                     final Class aClass = (Class) type;
-                    final ClassDescriptor genericTypeDescriptor = parentClassDescriptior
+                    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 == parentClassDescriptior)
+        if (type == parentClassDescriptor)
             showLink = false;
 
-        if (parentClassDescriptior.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 (parentClassDescriptior.isEnum && (type == parentClassDescriptior)) {
+        if (parentClassDescriptor.isEnum && (type == parentClassDescriptor)) {
             result.append("        <TR><TD colspan=\"2\" PORT=\"" + name);
             result.append("\" ALIGN=\"left\"><FONT POINT-SIZE=\"11.0\">");
             result.append(name + "</FONT></TD></TR>\n");
         } else {
             result.append("        <TR><td ALIGN=\"right\">");
             result.append("<FONT POINT-SIZE=\"8.0\">");
-            result.append(type.getClassName(true) + "</FONT>");
+            result.append(describeType() + "</FONT>");
             result.append("</td><TD PORT=\"" + name);
             result.append("\" ALIGN=\"left\"><FONT POINT-SIZE=\"11.0\">");
             result.append(name + "</FONT></TD></TR>\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 parentClassDescriptior.getGraphId() + ":" + name;
+        return parentClassDescriptor.getGraphId() + ":" + name;
     }
 
     protected int getOutsideVisibleReferencesCount() {
@@ -151,4 +157,4 @@ public class FieldDescriptor implements GraphElement {
 
     }
 
-}
\ No newline at end of file
+}