001: package net.sourceforge.pmd.dcd;
002:
003: import net.sourceforge.pmd.dcd.graph.ClassNode;
004: import net.sourceforge.pmd.dcd.graph.ConstructorNode;
005: import net.sourceforge.pmd.dcd.graph.FieldNode;
006: import net.sourceforge.pmd.dcd.graph.MemberNode;
007: import net.sourceforge.pmd.dcd.graph.MethodNode;
008: import net.sourceforge.pmd.dcd.graph.NodeVisitorAdapter;
009: import net.sourceforge.pmd.dcd.graph.UsageGraph;
010:
011: /**
012: * Dump a UsageGraph to System.out.
013: */
014: public class DumpNodeVisitor extends NodeVisitorAdapter {
015:
016: @Override
017: public Object visit(UsageGraph usageGraph, Object data) {
018: System.out.println("----------------------------------------");
019: super .visit(usageGraph, data);
020: System.out.println("----------------------------------------");
021: return data;
022: }
023:
024: @Override
025: public Object visit(ClassNode classNode, Object data) {
026: System.out
027: .println("Class: "
028: + ClassLoaderUtil.fromInternalForm(classNode
029: .getName()));
030: return super .visit(classNode, data);
031: }
032:
033: @Override
034: public Object visitFields(ClassNode classNode, Object data) {
035: System.out.println("\tFields ("
036: + classNode.getFieldNodes().size() + "):");
037: return super .visitFields(classNode, data);
038: }
039:
040: @Override
041: public Object visit(FieldNode fieldNode, Object data) {
042: printMember(fieldNode);
043: return super .visit(fieldNode, data);
044: }
045:
046: @Override
047: public Object visitConstructors(ClassNode classNode, Object data) {
048: System.out.println("\tConstructors ("
049: + classNode.getConstructorNodes().size() + "):");
050: return super .visitConstructors(classNode, data);
051: }
052:
053: @Override
054: public Object visit(ConstructorNode constructorNode, Object data) {
055: printMember(constructorNode);
056: return super .visit(constructorNode, data);
057: }
058:
059: @Override
060: public Object visitMethods(ClassNode classNode, Object data) {
061: System.out.println("\tMethods ("
062: + classNode.getMethodNodes().size() + "):");
063: return super .visitMethods(classNode, data);
064: }
065:
066: @Override
067: public Object visit(MethodNode methodNode, Object data) {
068: printMember(methodNode);
069: return super .visit(methodNode, data);
070: }
071:
072: @Override
073: public Object visitUses(MemberNode memberNode, Object data) {
074: if (Boolean.TRUE == data && !memberNode.getUses().isEmpty()) {
075: System.out.println("\t\t\tUses:");
076: }
077: return super .visitUses(memberNode, data);
078: }
079:
080: @Override
081: public Object visitUse(MemberNode use, Object data) {
082: if (Boolean.TRUE == data) {
083: System.out.println("\t\t\t\t" + use.toStringLong());
084: }
085: return super .visitUse(use, data);
086: }
087:
088: @Override
089: public Object visitUsers(MemberNode memberNode, Object data) {
090: if (Boolean.TRUE == data && !memberNode.getUsers().isEmpty()) {
091: System.out.println("\t\t\tUsers:");
092: }
093: return super .visitUsers(memberNode, data);
094: }
095:
096: @Override
097: public Object visitUser(MemberNode user, Object data) {
098: if (Boolean.TRUE == data) {
099: System.out.println("\t\t\t\t" + user.toStringLong());
100: }
101: return super .visitUser(user, data);
102: }
103:
104: protected void printMember(MemberNode memberNode) {
105: System.out.println("\t\t(" + memberNode.getUses().size() + ", "
106: + memberNode.getUsers().size() + ") "
107: + memberNode.toStringLong());
108: }
109: }
|