X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Finspector%2Fjava%2Fstructure%2FFieldDescriptor.java;h=d0a607b2c6134c29b13fb4994216e0c2ec41b0f7;hb=94b2a818903a8ec1579dce828b47076c53f435ab;hp=42ecfcf1a6973c668bbe44f786e6913311f5b358;hpb=16ba5341215d24fdcfa07072d52cf87e5a4375ed;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 old mode 100644 new mode 100755 index 42ecfcf..d0a607b --- a/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java +++ b/src/main/java/eu/svjatoslav/inspector/java/structure/FieldDescriptor.java @@ -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; @@ -22,27 +22,28 @@ public class FieldDescriptor implements GraphElement { */ public String name; - public ClassDescriptor type; - private ClassDescriptor parent; + private ClassDescriptor type; + private final ClassDescriptor parentClass; List typeArguments = new ArrayList(); - public FieldDescriptor(final Field field, final ClassDescriptor parent, - final ClassGraph dump) { + public boolean isInherited; - this.parent = parent; + public FieldDescriptor(final ClassDescriptor parent) { + parentClass = parent; + } + + public void analyzeField(final Field field) { if (!field.getDeclaringClass().getName() - .equals(parent.fullyQualifiedName)) - // if field is inherited, do not index it - return; + .equals(parentClass.classFullyQualifiedName)) + isInherited = true; // if (field.getType().isArray()) // System.out.println("field name: " + field.getName()); - parent.nameToFieldMap.put(field.getName(), this); - name = field.getName(); - type = dump.addClass(field.getType()); + type = parentClass.getClassGraph().getOrCreateClassDescriptor( + field.getType()); type.registerReference(); final Type genericType = field.getGenericType(); @@ -51,8 +52,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); } @@ -83,10 +84,10 @@ public class FieldDescriptor implements GraphElement { // main type boolean showLink = type.areReferencesShown(); - if (type == parent) + if (type == parentClass) showLink = false; - if (parent.isEnum) + if (parentClass.isEnum) showLink = false; if (showLink) @@ -106,7 +107,7 @@ public class FieldDescriptor implements GraphElement { final StringBuffer result = new StringBuffer(); result.append(" // " + name + "\n"); - if (parent.isEnum && (type == parent)) { + if (parentClass.isEnum && (type == parentClass)) { result.append(" "); result.append(name + "\n"); @@ -123,7 +124,7 @@ public class FieldDescriptor implements GraphElement { @Override public String getGraphId() { - return parent.getGraphId() + ":" + name; + return parentClass.getGraphId() + ":" + name; } public int getOutsideVisibleReferencesCount() { @@ -131,14 +132,22 @@ public class FieldDescriptor implements GraphElement { if (!isVisible()) return 0; - if (type.isVisible()) - return 1; + if (type != null) + if (type.isVisible()) + return 1; return 0; } + public ClassDescriptor getType() { + return type; + } + @Override public boolean isVisible() { + if (isInherited) + return false; + if (name.contains("$")) return false; @@ -147,4 +156,5 @@ public class FieldDescriptor implements GraphElement { return true; } + } \ No newline at end of file