/*
* 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;
public class FieldDescriptor implements GraphElement {
+ /**
+ * This class corresponds to single field within a java class.
+ */
+
public String name;
- public ClassDescriptor type;
- private ClassDescriptor parent;
+ private ClassDescriptor type;
+ private final ClassDescriptor parentClass;
List<ClassDescriptor> typeArguments = new ArrayList<ClassDescriptor>();
- public FieldDescriptor(final Field field, final ClassDescriptor parent,
- final ClassGraph dump) {
+ public boolean isInherited;
+
+ public FieldDescriptor(final ClassDescriptor parent) {
+ parentClass = parent;
+ }
- this.parent = 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.getFullyQualifiedName()))
+ 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();
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);
}
// main type
boolean showLink = type.areReferencesShown();
- if (type == parent)
+ if (type == parentClass)
showLink = false;
- if (parent.isEnum)
+ if (parentClass.isEnum)
showLink = false;
if (showLink)
final StringBuffer result = new StringBuffer();
result.append(" // " + name + "\n");
- if (parent.isEnum && (type == parent)) {
+ if (parentClass.isEnum && (type == parentClass)) {
result.append(" <TR><TD colspan=\"2\" PORT=\"" + name);
result.append("\" ALIGN=\"left\"><FONT POINT-SIZE=\"11.0\">");
result.append(name + "</FONT></TD></TR>\n");
@Override
public String getGraphId() {
- return parent.getGraphId() + ":" + name;
+ return parentClass.getGraphId() + ":" + name;
}
public int getOutsideVisibleReferencesCount() {
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;
return true;
}
+
}
\ No newline at end of file