further restricted code visibility
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / FieldDescriptor.java
old mode 100644 (file)
new mode 100755 (executable)
index db5a112..7128c4e
@@ -1,10 +1,10 @@
 /*
  * JavaInspect - Utility to visualize java software
- * Copyright (C) 2013, 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 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,34 +15,31 @@ import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 
-public class FieldDescriptor implements GraphElement {
+/**
+ * This class corresponds to single field within a java class.
+ */
 
-       /**
-        * This class corresponds to single field within a java class.
-        */
+public class FieldDescriptor implements GraphElement {
 
-       public String name;
+       private String name;
        private ClassDescriptor type;
-       private ClassDescriptor parentClass;
-       List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
-
-       public FieldDescriptor(final Field field, final ClassDescriptor parent,
-                       final ClassGraph dump) {
+       private final ClassDescriptor parentClass;
+       private final List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
+       private boolean isInherited;
 
+       public FieldDescriptor(final ClassDescriptor parent) {
                parentClass = parent;
+       }
 
-               if (!field.getDeclaringClass().getName()
-                               .equals(parent.fullyQualifiedName))
-                       // if field is inherited, do not index it
-                       return;
-
-               // if (field.getType().isArray())
-               // System.out.println("field name: " + field.getName());
+       public void analyzeField(final Field field) {
 
-               parent.nameToFieldMap.put(field.getName(), this);
+               if (!field.getDeclaringClass().getName()
+                               .equals(parentClass.getFullyQualifiedName()))
+                       isInherited = true;
 
                name = field.getName();
-               type = dump.addClass(field.getType());
+               type = parentClass.getClassGraph().getOrCreateClassDescriptor(
+                               field.getType());
                type.registerReference();
 
                final Type genericType = field.getGenericType();
@@ -51,8 +48,8 @@ public class FieldDescriptor implements GraphElement {
                        for (final Type t : pt.getActualTypeArguments())
                                if (t instanceof Class) {
                                        final Class cl = (Class) t;
-                                       final ClassDescriptor genericTypeDescriptor = dump
-                                                       .addClass(cl);
+                                       final ClassDescriptor genericTypeDescriptor = parentClass
+                                                       .getClassGraph().getOrCreateClassDescriptor(cl);
                                        genericTypeDescriptor.registerReference();
                                        typeArguments.add(genericTypeDescriptor);
                                }
@@ -126,7 +123,7 @@ public class FieldDescriptor implements GraphElement {
                return parentClass.getGraphId() + ":" + name;
        }
 
-       public int getOutsideVisibleReferencesCount() {
+       protected int getOutsideVisibleReferencesCount() {
 
                if (!isVisible())
                        return 0;
@@ -138,12 +135,15 @@ public class FieldDescriptor implements GraphElement {
                return 0;
        }
 
-       public ClassDescriptor getType() {
+       protected ClassDescriptor getType() {
                return type;
        }
 
        @Override
        public boolean isVisible() {
+               if (isInherited)
+                       return false;
+
                if (name.contains("$"))
                        return false;