01: package net.sourceforge.pmd.dcd.graph;
02:
03: import java.lang.ref.WeakReference;
04: import java.lang.reflect.Field;
05:
06: import net.sourceforge.pmd.dcd.ClassLoaderUtil;
07:
08: /**
09: * Represents a Class Field in a UsageGraph.
10: */
11: public class FieldNode extends MemberNode<FieldNode, Field> {
12:
13: private WeakReference<Field> fieldReference;
14:
15: public FieldNode(ClassNode classNode, String name, String desc) {
16: super (classNode, name, desc);
17: getMember();
18: }
19:
20: public Field getMember() {
21: Field field = fieldReference == null ? null : fieldReference
22: .get();
23: if (field == null) {
24: field = ClassLoaderUtil.getField(getClassNode().getType(),
25: name);
26: this .fieldReference = new WeakReference<Field>(field);
27: }
28: return field;
29: }
30:
31: public int compareTo(FieldNode that) {
32: return this .name.compareTo(that.name);
33: }
34:
35: public boolean equals(Object obj) {
36: if (obj instanceof FieldNode) {
37: FieldNode that = (FieldNode) obj;
38: return super .equals(that);
39: }
40: return false;
41: }
42: }
|