001: package net.sourceforge.pmd.dcd.graph;
002:
003: import java.lang.reflect.Member;
004: import java.util.ArrayList;
005: import java.util.Collections;
006: import java.util.List;
007:
008: /**
009: * Represents a Class Member in a UsageGraph.
010: */
011: public abstract class MemberNode<S extends MemberNode<S, T>, T extends Member>
012: implements NodeVisitorAcceptor, Comparable<S> {
013: protected final ClassNode classNode;
014:
015: protected final String name;
016:
017: protected final String desc;
018:
019: private List<MemberNode> uses;
020:
021: private List<MemberNode> users;
022:
023: private Object decoration;
024:
025: public MemberNode(ClassNode classNode, String name, String desc) {
026: this .classNode = classNode;
027: this .name = name;
028: this .desc = desc;
029: }
030:
031: public Object accept(NodeVisitor visitor, Object data) {
032: visitor.visitUses(this , data);
033: visitor.visitUsers(this , data);
034: return data;
035: }
036:
037: public ClassNode getClassNode() {
038: return classNode;
039: }
040:
041: public String getName() {
042: return name;
043: }
044:
045: public String getDesc() {
046: return desc;
047: }
048:
049: public abstract T getMember();
050:
051: public void addUse(MemberNode use) {
052: if (uses == null) {
053: uses = new ArrayList<MemberNode>(1);
054: }
055: if (!uses.contains(use)) {
056: uses.add(use);
057: }
058: }
059:
060: public List<MemberNode> getUses() {
061: return uses != null ? uses : Collections
062: .<MemberNode> emptyList();
063: }
064:
065: public void addUser(MemberNode user) {
066: if (users == null) {
067: users = new ArrayList<MemberNode>(1);
068: }
069: if (!users.contains(user)) {
070: users.add(user);
071: }
072: }
073:
074: public List<MemberNode> getUsers() {
075: return users != null ? users : Collections
076: .<MemberNode> emptyList();
077: }
078:
079: public String toString() {
080: return name + " " + desc;
081: }
082:
083: public String toStringLong() {
084: return getMember().toString();
085: }
086:
087: public abstract boolean equals(Object that);
088:
089: public boolean equals(S that) {
090: return equals(that.name, that.desc);
091: }
092:
093: public boolean equals(String name, String desc) {
094: return this .name.equals(name) && this .desc.equals(desc);
095: }
096:
097: public int hashCode() {
098: return name.hashCode() + desc.hashCode();
099: }
100: }
|