1 19 20 package org.netbeans.modules.refactoring.java.plugins; 21 22 import com.sun.source.tree.*; 23 import com.sun.source.util.TreePath; 24 import com.sun.source.util.TreePathScanner; 25 import com.sun.source.util.Trees; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import javax.lang.model.element.*; 29 import javax.lang.model.util.Types; 30 import org.netbeans.api.java.source.TreeMaker; 31 import org.netbeans.api.java.source.WorkingCopy; 32 33 37 public class SearchVisitor extends TreePathScanner<Tree, Element> { 38 private Collection <TreePath> usages = new ArrayList <TreePath>(); 39 protected final WorkingCopy workingCopy; 40 protected final TreeMaker make; 41 42 public SearchVisitor(WorkingCopy workingCopy) { 43 super(); 44 this.workingCopy = workingCopy; 45 this.make = workingCopy.getTreeMaker(); 46 } 47 48 public Collection <TreePath> getUsages() { 49 return usages; 50 } 51 52 protected void addUsage(TreePath tp) { 53 assert tp != null; 54 usages.add(tp); 55 } 56 57 protected boolean isSubtype(TreePath t1, Element t2) { 58 Types types = workingCopy.getTypes(); 59 Trees trees = workingCopy.getTrees(); 60 return types.isSubtype(types.erasure(trees.getTypeMirror(t1)), types.erasure(t2.asType())); 61 } 62 } 63 | Popular Tags |