1 package spoon.reflect.visitor; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import spoon.reflect.Factory; 7 import spoon.reflect.declaration.CtElement; 8 import spoon.reflect.declaration.CtPackage; 9 import spoon.reflect.reference.CtReference; 10 11 18 public abstract class Query extends CtScanner { 19 20 private Query() { 21 } 22 23 35 public static <E extends CtElement> List <E> getElements(Factory factory, 36 Filter<E> filter) { 37 List <E> e = new ArrayList <E>(); 38 for (CtPackage p : factory.Package().getAllRoots()) { 39 e.addAll(getElements(p, filter)); 40 } 41 return e; 42 } 43 44 54 public static <E extends CtElement> List <E> getElements( 55 CtElement rootElement, Filter<E> filter) { 56 QueryVisitor<E> visitor = new QueryVisitor<E>(filter); 57 visitor.scan(rootElement); 58 return visitor.getResult(); 59 } 60 61 71 public static <T extends CtReference> List <T> getReferences( 72 CtElement rootElement, ReferenceFilter<T> filter) { 73 ReferenceQueryVisitor<T> visitor = new ReferenceQueryVisitor<T>(filter); 74 visitor.scan(rootElement); 75 return visitor.getResult(); 76 } 77 78 90 public static <R extends CtReference> List <R> getReferences( 91 Factory factory, ReferenceFilter<R> filter) { 92 List <R> r = new ArrayList <R>(); 93 for (CtPackage p : factory.Package().getAllRoots()) { 94 r.addAll(getReferences(p, filter)); 95 } 96 return r; 97 } 98 99 } | Popular Tags |