1 11 package org.eclipse.jdt.internal.corext.dom.fragments; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.jdt.core.dom.ASTNode; 17 import org.eclipse.jdt.core.dom.Javadoc; 18 19 import org.eclipse.jdt.internal.corext.dom.GenericVisitor; 20 21 class ASTMatchingFragmentFinder extends GenericVisitor { 22 23 public static IASTFragment[] findMatchingFragments(ASTNode scope, ASTFragment toMatch) { 24 return new ASTMatchingFragmentFinder(toMatch).findMatches(scope); 25 } 26 27 private ASTFragment fFragmentToMatch; 28 private List fMatches= new ArrayList (); 29 30 private ASTMatchingFragmentFinder(ASTFragment toMatch) { 31 super(true); 32 fFragmentToMatch= toMatch; 33 } 34 private IASTFragment[] findMatches(ASTNode scope) { 35 fMatches.clear(); 36 scope.accept(this); 37 return getMatches(); 38 } 39 private IASTFragment[] getMatches() { 40 return (IASTFragment[]) fMatches.toArray(new IASTFragment[fMatches.size()]); 41 } 42 43 public boolean visit(Javadoc node) { 44 return false; 45 } 46 47 protected boolean visitNode(ASTNode node) { 48 IASTFragment[] localMatches= fFragmentToMatch.getMatchingFragmentsWithNode(node); 49 for(int i= 0; i < localMatches.length; i++) { 50 fMatches.add(localMatches[i]); 51 } 52 return true; 53 } 54 55 } 56 | Popular Tags |