src/share/classes/com/sun/tools/javac/code/Symbol.java

changeset 1802
8fb68f73d4b1
parent 1709
bae8387d16aa
child 1820
6b48ebae2569
equal deleted inserted replaced
1801:775a51e3276f 1802:8fb68f73d4b1
30 30
31 import javax.lang.model.element.*; 31 import javax.lang.model.element.*;
32 import javax.tools.JavaFileObject; 32 import javax.tools.JavaFileObject;
33 33
34 import com.sun.tools.javac.code.Type.*; 34 import com.sun.tools.javac.code.Type.*;
35 import com.sun.tools.javac.comp.Annotate;
35 import com.sun.tools.javac.comp.Attr; 36 import com.sun.tools.javac.comp.Attr;
36 import com.sun.tools.javac.comp.AttrContext; 37 import com.sun.tools.javac.comp.AttrContext;
37 import com.sun.tools.javac.comp.Env; 38 import com.sun.tools.javac.comp.Env;
38 import com.sun.tools.javac.jvm.*; 39 import com.sun.tools.javac.jvm.*;
39 import com.sun.tools.javac.model.*; 40 import com.sun.tools.javac.model.*;
72 * Flags of class symbols should be accessed through the accessor 73 * Flags of class symbols should be accessed through the accessor
73 * method to make sure that the class symbol is loaded. 74 * method to make sure that the class symbol is loaded.
74 */ 75 */
75 public long flags() { return flags_field; } 76 public long flags() { return flags_field; }
76 77
78 /** The name of this symbol in Utf8 representation.
79 */
80 public Name name;
81
82 /** The type of this symbol.
83 */
84 public Type type;
85
86 /** The owner of this symbol.
87 */
88 public Symbol owner;
89
90 /** The completer of this symbol.
91 */
92 public Completer completer;
93
94 /** A cache for the type erasure of this symbol.
95 */
96 public Type erasure_field;
97
98 // <editor-fold defaultstate="collapsed" desc="annotations">
99
77 /** The attributes of this symbol are contained in this 100 /** The attributes of this symbol are contained in this
78 * Annotations. The Annotations instance is NOT immutable. 101 * Annotations. The Annotations instance is NOT immutable.
79 */ 102 */
80 public final Annotations annotations = new Annotations(this); 103 protected Annotations annotations;
81 104
82 /** An accessor method for the attributes of this symbol. 105 /** An accessor method for the attributes of this symbol.
83 * Attributes of class symbols should be accessed through the accessor 106 * Attributes of class symbols should be accessed through the accessor
84 * method to make sure that the class symbol is loaded. 107 * method to make sure that the class symbol is loaded.
85 */ 108 */
86 public List<Attribute.Compound> getRawAttributes() { 109 public List<Attribute.Compound> getRawAttributes() {
87 return annotations.getDeclarationAttributes(); 110 return (annotations == null)
111 ? List.<Attribute.Compound>nil()
112 : annotations.getDeclarationAttributes();
88 } 113 }
89 114
90 /** An accessor method for the type attributes of this symbol. 115 /** An accessor method for the type attributes of this symbol.
91 * Attributes of class symbols should be accessed through the accessor 116 * Attributes of class symbols should be accessed through the accessor
92 * method to make sure that the class symbol is loaded. 117 * method to make sure that the class symbol is loaded.
93 */ 118 */
94 public List<Attribute.TypeCompound> getRawTypeAttributes() { 119 public List<Attribute.TypeCompound> getRawTypeAttributes() {
95 return annotations.getTypeAttributes(); 120 return (annotations == null)
121 ? List.<Attribute.TypeCompound>nil()
122 : annotations.getTypeAttributes();
96 } 123 }
97 124
98 /** Fetch a particular annotation from a symbol. */ 125 /** Fetch a particular annotation from a symbol. */
99 public Attribute.Compound attribute(Symbol anno) { 126 public Attribute.Compound attribute(Symbol anno) {
100 for (Attribute.Compound a : getRawAttributes()) { 127 for (Attribute.Compound a : getRawAttributes()) {
101 if (a.type.tsym == anno) return a; 128 if (a.type.tsym == anno) return a;
102 } 129 }
103 return null; 130 return null;
104 } 131 }
105 132
106 /** The name of this symbol in Utf8 representation. 133 public boolean annotationsPendingCompletion() {
107 */ 134 return annotations == null ? false : annotations.pendingCompletion();
108 public Name name; 135 }
109 136
110 /** The type of this symbol. 137 public void appendAttributes(List<Attribute.Compound> l) {
111 */ 138 if (l.nonEmpty()) {
112 public Type type; 139 initedAnnos().append(l);
113 140 }
114 /** The owner of this symbol. 141 }
115 */ 142
116 public Symbol owner; 143 public void appendClassInitTypeAttributes(List<Attribute.TypeCompound> l) {
117 144 if (l.nonEmpty()) {
118 /** The completer of this symbol. 145 initedAnnos().appendClassInitTypeAttributes(l);
119 */ 146 }
120 public Completer completer; 147 }
121 148
122 /** A cache for the type erasure of this symbol. 149 public void appendInitTypeAttributes(List<Attribute.TypeCompound> l) {
123 */ 150 if (l.nonEmpty()) {
124 public Type erasure_field; 151 initedAnnos().appendInitTypeAttributes(l);
152 }
153 }
154
155 public void appendTypeAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.TypeCompound> ctx) {
156 initedAnnos().appendTypeAttributesWithCompletion(ctx);
157 }
158
159 public void appendUniqueTypeAttributes(List<Attribute.TypeCompound> l) {
160 if (l.nonEmpty()) {
161 initedAnnos().appendUniqueTypes(l);
162 }
163 }
164
165 public List<Attribute.TypeCompound> getClassInitTypeAttributes() {
166 return (annotations == null)
167 ? List.<Attribute.TypeCompound>nil()
168 : annotations.getClassInitTypeAttributes();
169 }
170
171 public List<Attribute.TypeCompound> getInitTypeAttributes() {
172 return (annotations == null)
173 ? List.<Attribute.TypeCompound>nil()
174 : annotations.getInitTypeAttributes();
175 }
176
177 public List<Attribute.Compound> getDeclarationAttributes() {
178 return (annotations == null)
179 ? List.<Attribute.Compound>nil()
180 : annotations.getDeclarationAttributes();
181 }
182
183 public boolean hasAnnotations() {
184 return (annotations != null && !annotations.isEmpty());
185 }
186
187 public boolean hasTypeAnnotations() {
188 return (annotations != null && !annotations.isTypesEmpty());
189 }
190
191 public void prependAttributes(List<Attribute.Compound> l) {
192 if (l.nonEmpty()) {
193 initedAnnos().prepend(l);
194 }
195 }
196
197 public void resetAnnotations() {
198 initedAnnos().reset();
199 }
200
201 public void setAttributes(Symbol other) {
202 if (annotations != null || other.annotations != null) {
203 initedAnnos().setAttributes(other.annotations);
204 }
205 }
206
207 public void setDeclarationAttributes(List<Attribute.Compound> a) {
208 if (annotations != null || a.nonEmpty()) {
209 initedAnnos().setDeclarationAttributes(a);
210 }
211 }
212
213 public void setDeclarationAttributesWithCompletion(final Annotate.AnnotateRepeatedContext<Attribute.Compound> ctx) {
214 initedAnnos().setDeclarationAttributesWithCompletion(ctx);
215 }
216
217 public void setTypeAttributes(List<Attribute.TypeCompound> a) {
218 if (annotations != null || a.nonEmpty()) {
219 if (annotations == null)
220 annotations = new Annotations(this);
221 annotations.setTypeAttributes(a);
222 }
223 }
224
225 private Annotations initedAnnos() {
226 if (annotations == null)
227 annotations = new Annotations(this);
228 return annotations;
229 }
230
231 /** This method is intended for debugging only. */
232 public Annotations getAnnotations() {
233 return annotations;
234 }
235
236 // </editor-fold>
125 237
126 /** Construct a symbol with given kind, flags, name, type and owner. 238 /** Construct a symbol with given kind, flags, name, type and owner.
127 */ 239 */
128 public Symbol(int kind, long flags, Name name, Type type, Symbol owner) { 240 public Symbol(int kind, long flags, Name name, Type type, Symbol owner) {
129 this.kind = kind; 241 this.kind = kind;
203 t.getThrownTypes(), 315 t.getThrownTypes(),
204 t.tsym); 316 t.tsym);
205 } else { 317 } else {
206 return t; 318 return t;
207 } 319 }
320 }
321
322 public boolean isDeprecated() {
323 return (flags_field & DEPRECATED) != 0;
208 } 324 }
209 325
210 public boolean isStatic() { 326 public boolean isStatic() {
211 return 327 return
212 (flags() & STATIC) != 0 || 328 (flags() & STATIC) != 0 ||
724 } 840 }
725 return super.getRawAttributes(); 841 return super.getRawAttributes();
726 } 842 }
727 843
728 private void mergeAttributes() { 844 private void mergeAttributes() {
729 if (annotations.isEmpty() && 845 if (annotations == null &&
730 !package_info.annotations.isEmpty()) { 846 package_info.annotations != null) {
847 annotations = new Annotations(this);
731 annotations.setAttributes(package_info.annotations); 848 annotations.setAttributes(package_info.annotations);
732 } 849 }
733 } 850 }
734 851
735 /** A package "exists" if a type or package that exists has 852 /** A package "exists" if a type or package that exists has

mercurial