View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.dcd;
5   
6   import net.sourceforge.pmd.dcd.graph.ClassNode;
7   import net.sourceforge.pmd.dcd.graph.ConstructorNode;
8   import net.sourceforge.pmd.dcd.graph.FieldNode;
9   import net.sourceforge.pmd.dcd.graph.MemberNode;
10  import net.sourceforge.pmd.dcd.graph.MethodNode;
11  import net.sourceforge.pmd.dcd.graph.NodeVisitorAdapter;
12  import net.sourceforge.pmd.dcd.graph.UsageGraph;
13  
14  /**
15   * Dump a UsageGraph to System.out.
16   */
17  public class DumpNodeVisitor extends NodeVisitorAdapter {
18  
19  	@Override
20  	public Object visit(UsageGraph usageGraph, Object data) {
21  		System.out.println("----------------------------------------");
22  		super.visit(usageGraph, data);
23  		System.out.println("----------------------------------------");
24  		return data;
25  	}
26  
27  	@Override
28  	public Object visit(ClassNode classNode, Object data) {
29  		System.out.println("Class: " + ClassLoaderUtil.fromInternalForm(classNode.getName()));
30  		return super.visit(classNode, data);
31  	}
32  
33  	@Override
34  	public Object visitFields(ClassNode classNode, Object data) {
35  		System.out.println("\tFields (" + classNode.getFieldNodes().size() + "):");
36  		return super.visitFields(classNode, data);
37  	}
38  
39  	@Override
40  	public Object visit(FieldNode fieldNode, Object data) {
41  		printMember(fieldNode);
42  		return super.visit(fieldNode, data);
43  	}
44  
45  	@Override
46  	public Object visitConstructors(ClassNode classNode, Object data) {
47  		System.out.println("\tConstructors (" + classNode.getConstructorNodes().size() + "):");
48  		return super.visitConstructors(classNode, data);
49  	}
50  
51  	@Override
52  	public Object visit(ConstructorNode constructorNode, Object data) {
53  		printMember(constructorNode);
54  		return super.visit(constructorNode, data);
55  	}
56  
57  	@Override
58  	public Object visitMethods(ClassNode classNode, Object data) {
59  		System.out.println("\tMethods (" + classNode.getMethodNodes().size() + "):");
60  		return super.visitMethods(classNode, data);
61  	}
62  
63  	@Override
64  	public Object visit(MethodNode methodNode, Object data) {
65  		printMember(methodNode);
66  		return super.visit(methodNode, data);
67  	}
68  
69  	@Override
70  	public Object visitUses(MemberNode memberNode, Object data) {
71  		if (Boolean.TRUE == data && !memberNode.getUses().isEmpty()) {
72  			System.out.println("\t\t\tUses:");
73  		}
74  		return super.visitUses(memberNode, data);
75  	}
76  
77  	@Override
78  	public Object visitUse(MemberNode use, Object data) {
79  		if (Boolean.TRUE == data) {
80  			System.out.println("\t\t\t\t" + use.toStringLong());
81  		}
82  		return super.visitUse(use, data);
83  	}
84  
85  	@Override
86  	public Object visitUsers(MemberNode memberNode, Object data) {
87  		if (Boolean.TRUE == data && !memberNode.getUsers().isEmpty()) {
88  			System.out.println("\t\t\tUsers:");
89  		}
90  		return super.visitUsers(memberNode, data);
91  	}
92  
93  	@Override
94  	public Object visitUser(MemberNode user, Object data) {
95  		if (Boolean.TRUE == data) {
96  			System.out.println("\t\t\t\t" + user.toStringLong());
97  		}
98  		return super.visitUser(user, data);
99  	}
100 
101 	protected void printMember(MemberNode memberNode) {
102 		System.out.println("\t\t(" + memberNode.getUses().size() + ", " + memberNode.getUsers().size() + ") "
103 				+ memberNode.toStringLong());
104 	}
105 }