1 package spoon.reflect.visitor; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import spoon.reflect.reference.CtReference; 7 8 12 13 public class ReferenceQueryVisitor<T extends CtReference> extends CtScanner { 14 ReferenceFilter<T> filter; 15 16 List <T> result = new ArrayList <T>(); 17 18 21 public ReferenceQueryVisitor(ReferenceFilter<T> filter) { 22 super(); 23 this.filter = filter; 24 } 25 26 29 public List <T> getResult() { 30 return result; 31 } 32 33 @SuppressWarnings ("unchecked") 34 @Override 35 public void scan(CtReference reference) { 36 if (reference == null) 37 return; 38 if (filter.getType().isAssignableFrom(reference.getClass())) { 39 if (filter.matches((T) reference)) { 40 result.add((T) reference); 41 } 42 } 43 super.scan(reference); 44 } 45 } | Popular Tags |