View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.dcd.graph;
    5
    6   import java.util.List;
    7
    8   /**
    9    * Adapter class for easy implementation of a NodeVisitor.  Subclasses
    10   * need only override methods to add behavior, and call <code>super</code> to
    11   * continue the visitation.
    12   */
    13  public class NodeVisitorAdapter implements NodeVisitor {
    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.getConstructorNodes()) {
    36  			visit(constructorNode, data);
    37  		}
    38  		return data;
    39  	}
    40
    41  	public Object visit(ConstructorNode constructorNode, Object data) {
    42  		return constructorNode.accept(this, data);
    43  	}
    44
    45  	public Object visitMethods(ClassNode classNode, Object data) {
    46  		for (MethodNode methodNode : classNode.getMethodNodes()) {
    47  			visit(methodNode, data);
    48  		}
    49  		return data;
    50  	}
    51
    52  	public Object visit(MethodNode methodNode, Object data) {
    53  		return methodNode.accept(this, data);
    54  	}
    55
    56  	public Object visitUses(MemberNode memberNode, Object data) {
    57  		for (MemberNode use : (List<MemberNode>)memberNode.getUses()) {
    58  			this.visitUse(use, data);
    59  		}
    60  		return data;
    61  	}
    62
    63  	public Object visitUse(MemberNode memberNode, Object data) {
    64  		return data;
    65  	}
    66
    67  	public Object visitUsers(MemberNode memberNode, Object data) {
    68  		for (MemberNode user : (List<MemberNode>)memberNode.getUsers()) {
    69  			this.visitUser(user, data);
    70  		}
    71  		return data;
    72  	}
    73
    74  	public Object visitUser(MemberNode memberNode, Object data) {
    75  		return data;
    76  	}
    77  }