1 19 20 package org.netbeans.api.java.source.query; 21 22 import java.util.ArrayList ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import javax.lang.model.element.Element; 26 import javax.lang.model.element.ElementKind; 27 import javax.lang.model.element.PackageElement; 28 import javax.lang.model.element.TypeElement; 29 30 39 public class ElementReferenceList<E> { 40 Element var; 41 PackageElement varPackage; 42 TypeElement varClass; 43 int usage; 44 List <E> refList; 45 46 public ElementReferenceList(Element var) { 47 this.var = var; 48 refList = new LinkedList <E>(); 49 varPackage = packageElement(var); 50 varClass = enclosingTypeElement(var); 51 usage = 0; 52 } 53 54 57 protected void addReference(E e, int flags) { 58 if (!refList.contains(e)) 59 refList.add(e); 60 usage |= flags; 61 } 62 63 69 public int getUsage() { 70 return usage; 71 } 72 73 76 public List <E> getReferences() { 77 return new ArrayList <E>(refList); 78 } 79 80 83 public Element getElement() { 84 return var; 85 } 86 87 90 protected TypeElement getTypeElement() { 91 return varClass; 92 } 93 94 97 protected PackageElement getPackageElement() { 98 return varPackage; 99 } 100 101 public int hashCode() { 102 return var.hashCode(); 103 } 104 105 public boolean equals(Object obj) { 106 return obj instanceof ElementReferenceList && 107 var == ((ElementReferenceList) obj).var; 108 } 109 110 private TypeElement enclosingTypeElement(Element element) { 111 Element e = element; 112 while (e != null && !(e instanceof TypeElement)) { 113 e = e.getEnclosingElement(); 114 } 115 return (TypeElement)e; 116 } 117 118 private PackageElement packageElement(Element element) { 119 Element e = element; 120 while (e.getKind() != ElementKind.PACKAGE) { 121 e = e.getEnclosingElement(); 122 } 123 return (PackageElement)e; 124 } 125 } 126 127 | Popular Tags |