1 11 package org.eclipse.jdt.internal.corext.refactoring.code; 12 import java.util.ArrayList ; 13 import java.util.List ; 14 15 import org.eclipse.jdt.core.dom.ASTNode; 16 import org.eclipse.jdt.core.dom.SimpleName; 17 import org.eclipse.jdt.core.dom.SingleVariableDeclaration; 18 import org.eclipse.jdt.core.dom.TypeDeclarationStatement; 19 import org.eclipse.jdt.core.dom.VariableDeclarationFragment; 20 import org.eclipse.jdt.core.dom.VariableDeclarationStatement; 21 22 import org.eclipse.jdt.internal.corext.dom.GenericVisitor; 23 import org.eclipse.jdt.internal.corext.dom.Selection; 24 25 class NameCollector extends GenericVisitor { 26 private List names= new ArrayList (); 27 private Selection fSelection; 28 public NameCollector(ASTNode node) { 29 fSelection= Selection.createFromStartLength(node.getStartPosition(), node.getLength()); 30 } 31 protected boolean visitNode(ASTNode node) { 32 if (node.getStartPosition() > fSelection.getInclusiveEnd()) 33 return true; 34 if (fSelection.coveredBy(node)) 35 return true; 36 return false; 37 } 38 public boolean visit(SimpleName node) { 39 names.add(node.getIdentifier()); 40 return super.visit(node); 41 } 42 public boolean visit(VariableDeclarationStatement node) { 43 return true; 44 } 45 public boolean visit(VariableDeclarationFragment node) { 46 boolean result= super.visit(node); 47 if (!result) 48 names.add(node.getName().getIdentifier()); 49 return result; 50 } 51 public boolean visit(SingleVariableDeclaration node) { 52 boolean result= super.visit(node); 53 if (!result) 54 names.add(node.getName().getIdentifier()); 55 return result; 56 } 57 public boolean visit(TypeDeclarationStatement node) { 58 names.add(node.getDeclaration().getName().getIdentifier()); 59 return false; 60 } 61 62 List getNames() { 63 return names; 64 } 65 } 66 | Popular Tags |