1 19 20 package org.netbeans.api.java.source.query; 21 22 import com.sun.source.tree.Tree; 23 import javax.lang.model.element.Element; 24 import javax.lang.model.element.PackageElement; 25 import javax.lang.model.element.TypeElement; 26 27 30 public class SearchEntry implements Comparable <SearchEntry> { 31 public Query query; 32 public Tree tree; 33 private int pos; public Element sym; 35 public String className; 36 public String methName; 37 public String symName; 38 public String note; 39 public int flags; 40 41 public SearchEntry (Query q, Element e, Tree t, int pos) { 42 this(q, e, t, pos, null); 43 } 44 45 public SearchEntry (Query q, Element e, Tree t, int pos, String n) { 46 this(q, e, t, pos, n, 0); 47 } 48 49 public SearchEntry (Query q, Element e, Tree t, int pos, String n, int f) { 50 query = q; 51 flags = f; 52 sym = e; 53 tree = t; 54 this.pos = pos; 55 if(n != null && n.length()>0) note = n; 56 if(e==null) { className = "Unknown"; methName = "Unknown"; } 57 else if (e instanceof TypeElement) 58 className = classSymbolName(sym); 59 else { 60 while (e.getEnclosingElement() != null && 61 !(e.getEnclosingElement() instanceof TypeElement)) 62 e = e.getEnclosingElement(); 63 className = e.getEnclosingElement() == null ? "NULL PARENT" : classSymbolName(e); 64 methName = e.getSimpleName().toString(); 65 if(e!=sym) symName = sym.getSimpleName().toString(); 66 } 67 } 68 69 private String classSymbolName(Element e) { 70 if (e == null || e instanceof PackageElement) 71 return ""; 72 if (!(e instanceof TypeElement)) 73 return classSymbolName(e.getEnclosingElement()); 74 String owner = classSymbolName(e.getEnclosingElement()); 75 String name = e.getSimpleName().toString(); 76 if (name.length() == 0) 77 name = e.asType().toString(); 78 return owner.length() > 0 ? owner + '.' + name : name; 79 } 80 81 public int compareTo(SearchEntry oe) { 82 int ret = className.compareTo(oe.className); 83 if (ret == 0) 84 if ((methName == null || oe.methName == null || 85 (ret = methName.compareTo(oe.methName)) == 0) && 86 tree != null) 87 ret = pos - oe.pos; 88 return ret; 89 } 90 91 public String getSymName() { 92 return symName==null ? "" : symName; 93 } 94 95 public String getNote() { 96 return note==null ? "" : note; 97 } 98 99 public Element getElement() { 100 return this.sym; 101 } 102 } 103 | Popular Tags |