01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.refactor.method;
10:
11: import net.sourceforge.jrefactory.parser.ChildrenVisitor;
12: import net.sourceforge.jrefactory.ast.Node;
13: import net.sourceforge.jrefactory.ast.ASTBlockStatement;
14: import net.sourceforge.jrefactory.ast.ASTLocalVariableDeclaration;
15: import net.sourceforge.jrefactory.ast.ASTUnmodifiedClassDeclaration;
16: import net.sourceforge.jrefactory.ast.ASTUnmodifiedInterfaceDeclaration;
17: import net.sourceforge.jrefactory.ast.ASTVariableDeclarator;
18: import net.sourceforge.jrefactory.ast.ASTVariableDeclaratorId;
19: import org.acm.seguin.summary.VariableSummary;
20:
21: /**
22: * Finds the local variable declaration
23: *
24: *@author Chris Seguin
25: */
26: class FindLocalVariableDeclVisitor extends ChildrenVisitor {
27: private boolean found = false;
28:
29: /**
30: * Gets the Found attribute of the FindLocalVariableDeclVisitor object
31: *
32: *@return The Found value
33: */
34: public boolean isFound() {
35: return found;
36: }
37:
38: /**
39: * Visits a block node. Stops traversing the tree if we come to a new class.
40: *
41: *@param node Description of Parameter
42: *@param data Description of Parameter
43: *@return Description of the Returned Value
44: */
45: public Object visit(ASTBlockStatement node, Object data) {
46: Node child = node.jjtGetFirstChild();
47: if ((child instanceof ASTUnmodifiedClassDeclaration)
48: || (child instanceof ASTUnmodifiedInterfaceDeclaration)) {
49: return Boolean.FALSE;
50: }
51:
52: return super .visit(node, data);
53: }
54:
55: /**
56: * Determines if it is used here
57: *
58: *@param node Description of Parameter
59: *@param data Description of Parameter
60: *@return Description of the Returned Value
61: */
62: public Object visit(ASTLocalVariableDeclaration node, Object data) {
63: VariableSummary var = (VariableSummary) data;
64:
65: for (int ndx = 1; ndx < node.jjtGetNumChildren(); ndx++) {
66: ASTVariableDeclarator next = (ASTVariableDeclarator) node
67: .jjtGetChild(ndx);
68: ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) next
69: .jjtGetFirstChild();
70: if (id.getName().equals(var.getName())) {
71: found = true;
72: return Boolean.TRUE;
73: }
74: }
75:
76: return super.visit(node, data);
77: }
78: }
|