01: package net.sourceforge.pmd.dcd.graph;
02:
03: import java.util.List;
04:
05: /**
06: * Adapter class for easy implementation of a NodeVisitor. Subclasses
07: * need only override methods to add behavior, and call <code>super</code> to
08: * continue the visitation.
09: */
10: public class NodeVisitorAdapter implements NodeVisitor {
11:
12: public NodeVisitorAdapter() {
13: }
14:
15: public Object visit(UsageGraph usageGraph, Object data) {
16: return usageGraph.accept(this , data);
17: }
18:
19: public Object visit(ClassNode classNode, Object data) {
20: return classNode.accept(this , data);
21: }
22:
23: public Object visitFields(ClassNode classNode, Object data) {
24: for (FieldNode fieldNode : classNode.getFieldNodes()) {
25: visit(fieldNode, data);
26: }
27: return data;
28: }
29:
30: public Object visit(FieldNode fieldNode, Object data) {
31: return fieldNode.accept(this , data);
32: }
33:
34: public Object visitConstructors(ClassNode classNode, Object data) {
35: for (ConstructorNode constructorNode : classNode
36: .getConstructorNodes()) {
37: visit(constructorNode, data);
38: }
39: return data;
40: }
41:
42: public Object visit(ConstructorNode constructorNode, Object data) {
43: return constructorNode.accept(this , data);
44: }
45:
46: public Object visitMethods(ClassNode classNode, Object data) {
47: for (MethodNode methodNode : classNode.getMethodNodes()) {
48: visit(methodNode, data);
49: }
50: return data;
51: }
52:
53: public Object visit(MethodNode methodNode, Object data) {
54: return methodNode.accept(this , data);
55: }
56:
57: public Object visitUses(MemberNode memberNode, Object data) {
58: for (MemberNode use : (List<MemberNode>) memberNode.getUses()) {
59: this .visitUse(use, data);
60: }
61: return data;
62: }
63:
64: public Object visitUse(MemberNode memberNode, Object data) {
65: return data;
66: }
67:
68: public Object visitUsers(MemberNode memberNode, Object data) {
69: for (MemberNode user : (List<MemberNode>) memberNode.getUsers()) {
70: this .visitUser(user, data);
71: }
72: return data;
73: }
74:
75: public Object visitUser(MemberNode memberNode, Object data) {
76: return data;
77: }
78: }
|