1 /**
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package net.sourceforge.pmd.dcd.graph;
5
6 import java.lang.ref.WeakReference;
7 import java.lang.reflect.Field;
8
9 import net.sourceforge.pmd.dcd.ClassLoaderUtil;
10
11 /**
12 * Represents a Class Field in a UsageGraph.
13 */
14 public class FieldNode extends MemberNode<FieldNode, Field> {
15
16 private WeakReference<Field> fieldReference;
17
18 public FieldNode(ClassNode classNode, String name, String desc) {
19 super(classNode, name, desc);
20 getMember();
21 }
22
23 public Field getMember() {
24 Field field = fieldReference == null ? null : fieldReference.get();
25 if (field == null) {
26 field = ClassLoaderUtil.getField(getClassNode().getType(), name);
27 this.fieldReference = new WeakReference<Field>(field);
28 }
29 return field;
30 }
31
32 public int compareTo(FieldNode that) {
33 return this.name.compareTo(that.name);
34 }
35
36 public boolean equals(Object obj) {
37 if (obj instanceof FieldNode) {
38 FieldNode that = (FieldNode)obj;
39 return super.equals(that);
40 }
41 return false;
42 }
43 }