1 19 20 package org.netbeans.api.java.source.query; 21 22 import org.netbeans.modules.java.source.engine.EngineEnvironment; 23 import com.sun.source.tree.*; 24 import com.sun.source.util.TreeScanner; 25 import javax.lang.model.element.Element; 26 import org.netbeans.modules.java.source.engine.ASTModel; 27 import org.netbeans.modules.java.source.engine.EngineEnvironment; 28 29 33 public class NodeScanner<R,P> extends TreeScanner<R,P> { 34 protected Element currentSym; 35 protected QueryEnvironment env; 36 ASTModel model; 37 38 42 public void init() { 43 } 44 45 49 public void attach(QueryEnvironment env) { 50 this.env = env; 51 this.model = ((EngineEnvironment)env).getModel(); 52 } 53 54 59 public void release() { 60 env = null; 61 model = null; 62 } 63 64 70 public void destroy() { 71 } 72 73 75 public R scan(Tree tree, P p) { 76 assert model != null : "NodeScanner not attached to CommandEnvironment"; 77 R r = null; 78 if(tree != null) { 79 Element sym = model.getElement(tree); 80 if (sym != null) { 81 Element oldSym = currentSym; 82 currentSym = sym; 83 r = tree.accept(this, p); 84 currentSym = oldSym; 85 } 86 else 87 r = tree.accept(this, p); 88 } 89 return r; 90 } 91 92 public Element getCurrentElement() { 93 return currentSym; 94 } 95 public void setCurrentElement(Element sym) { 96 currentSym = sym; 97 } 98 } 99 100 | Popular Tags |