28 import java.lang.annotation.Annotation;
29 import java.lang.annotation.Inherited;
30 import java.util.Set;
31 import java.util.concurrent.Callable;
32
33 import javax.lang.model.element.*;
34 import javax.tools.JavaFileObject;
35
36 import com.sun.tools.javac.code.Type.*;
37 import com.sun.tools.javac.comp.Attr;
38 import com.sun.tools.javac.comp.AttrContext;
39 import com.sun.tools.javac.comp.Env;
40 import com.sun.tools.javac.jvm.*;
41 import com.sun.tools.javac.util.*;
42 import com.sun.tools.javac.util.Name;
43 import static com.sun.tools.javac.code.Flags.*;
44 import static com.sun.tools.javac.code.Kinds.*;
45 import static com.sun.tools.javac.code.TypeTag.CLASS;
46 import static com.sun.tools.javac.code.TypeTag.FORALL;
47 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
48 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
49
50 /** Root class for Java symbols. It contains subclasses
51 * for specific sorts of symbols, such as variables, methods and operators,
52 * types, packages. Each subclass is represented as a static inner class
53 * inside Symbol.
54 *
55 * <p><b>This is NOT part of any supported API.
56 * If you write code that depends on this, you do so at your own risk.
57 * This code and its internal interfaces are subject to change or
58 * deletion without notice.</b>
59 */
60 public abstract class Symbol extends AnnoConstruct implements Element {
61
62 /** The kind of this symbol.
63 * @see Kinds
64 */
65 public int kind;
66
67 /** The flags of this symbol.
68 */
189 initedMetadata().prepend(l);
190 }
191 }
192
193 public void resetAnnotations() {
194 initedMetadata().reset();
195 }
196
197 public void setAttributes(Symbol other) {
198 if (metadata != null || other.metadata != null) {
199 initedMetadata().setAttributes(other.metadata);
200 }
201 }
202
203 public void setDeclarationAttributes(List<Attribute.Compound> a) {
204 if (metadata != null || a.nonEmpty()) {
205 initedMetadata().setDeclarationAttributes(a);
206 }
207 }
208
209 public void setTypeAttributes(List<Attribute.TypeCompound> a) {
210 if (metadata != null || a.nonEmpty()) {
211 if (metadata == null)
212 metadata = new SymbolMetadata(this);
213 metadata.setTypeAttributes(a);
214 }
215 }
216
217 private SymbolMetadata initedMetadata() {
218 if (metadata == null)
219 metadata = new SymbolMetadata(this);
220 return metadata;
221 }
222
223 /** This method is intended for debugging only. */
224 public SymbolMetadata getMetadata() {
225 return metadata;
226 }
227
228 // </editor-fold>
1235 return ElementKind.ENUM_CONSTANT;
1236 } else if (owner.kind == TYP || owner.kind == ERR) {
1237 return ElementKind.FIELD;
1238 } else if (isResourceVariable()) {
1239 return ElementKind.RESOURCE_VARIABLE;
1240 } else {
1241 return ElementKind.LOCAL_VARIABLE;
1242 }
1243 }
1244
1245 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1246 return v.visitVariable(this, p);
1247 }
1248
1249 public Object getConstantValue() { // Mirror API
1250 return Constants.decode(getConstValue(), type);
1251 }
1252
1253 public void setLazyConstValue(final Env<AttrContext> env,
1254 final Attr attr,
1255 final JCVariableDecl variable)
1256 {
1257 setData(new Callable<Object>() {
1258 public Object call() {
1259 return attr.attribLazyConstantValue(env, variable, type);
1260 }
1261 });
1262 }
1263
1264 /**
1265 * The variable's constant value, if this is a constant.
1266 * Before the constant value is evaluated, it points to an
1267 * initializer environment. If this is not a constant, it can
1268 * be used for other stuff.
1269 */
1270 private Object data;
1271
1272 public boolean isExceptionParameter() {
1273 return data == ElementKind.EXCEPTION_PARAMETER;
1274 }
1275
1276 public boolean isResourceVariable() {
1277 return data == ElementKind.RESOURCE_VARIABLE;
1278 }
1279
|
28 import java.lang.annotation.Annotation;
29 import java.lang.annotation.Inherited;
30 import java.util.Set;
31 import java.util.concurrent.Callable;
32
33 import javax.lang.model.element.*;
34 import javax.tools.JavaFileObject;
35
36 import com.sun.tools.javac.code.Type.*;
37 import com.sun.tools.javac.comp.Attr;
38 import com.sun.tools.javac.comp.AttrContext;
39 import com.sun.tools.javac.comp.Env;
40 import com.sun.tools.javac.jvm.*;
41 import com.sun.tools.javac.util.*;
42 import com.sun.tools.javac.util.Name;
43 import static com.sun.tools.javac.code.Flags.*;
44 import static com.sun.tools.javac.code.Kinds.*;
45 import static com.sun.tools.javac.code.TypeTag.CLASS;
46 import static com.sun.tools.javac.code.TypeTag.FORALL;
47 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
48 import com.sun.tools.javac.tree.JCTree.*;
49
50 /** Root class for Java symbols. It contains subclasses
51 * for specific sorts of symbols, such as variables, methods and operators,
52 * types, packages. Each subclass is represented as a static inner class
53 * inside Symbol.
54 *
55 * <p><b>This is NOT part of any supported API.
56 * If you write code that depends on this, you do so at your own risk.
57 * This code and its internal interfaces are subject to change or
58 * deletion without notice.</b>
59 */
60 public abstract class Symbol extends AnnoConstruct implements Element {
61
62 /** The kind of this symbol.
63 * @see Kinds
64 */
65 public int kind;
66
67 /** The flags of this symbol.
68 */
189 initedMetadata().prepend(l);
190 }
191 }
192
193 public void resetAnnotations() {
194 initedMetadata().reset();
195 }
196
197 public void setAttributes(Symbol other) {
198 if (metadata != null || other.metadata != null) {
199 initedMetadata().setAttributes(other.metadata);
200 }
201 }
202
203 public void setDeclarationAttributes(List<Attribute.Compound> a) {
204 if (metadata != null || a.nonEmpty()) {
205 initedMetadata().setDeclarationAttributes(a);
206 }
207 }
208
209 public void appendDeclarationAttributes(List<Attribute.Compound> a) {
210 if (metadata != null || a.nonEmpty()) {
211 initedMetadata().append(a);
212 }
213 }
214
215 public void setTypeAttributes(List<Attribute.TypeCompound> a) {
216 if (metadata != null || a.nonEmpty()) {
217 if (metadata == null)
218 metadata = new SymbolMetadata(this);
219 metadata.setTypeAttributes(a);
220 }
221 }
222
223 private SymbolMetadata initedMetadata() {
224 if (metadata == null)
225 metadata = new SymbolMetadata(this);
226 return metadata;
227 }
228
229 /** This method is intended for debugging only. */
230 public SymbolMetadata getMetadata() {
231 return metadata;
232 }
233
234 // </editor-fold>
1241 return ElementKind.ENUM_CONSTANT;
1242 } else if (owner.kind == TYP || owner.kind == ERR) {
1243 return ElementKind.FIELD;
1244 } else if (isResourceVariable()) {
1245 return ElementKind.RESOURCE_VARIABLE;
1246 } else {
1247 return ElementKind.LOCAL_VARIABLE;
1248 }
1249 }
1250
1251 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1252 return v.visitVariable(this, p);
1253 }
1254
1255 public Object getConstantValue() { // Mirror API
1256 return Constants.decode(getConstValue(), type);
1257 }
1258
1259 public void setLazyConstValue(final Env<AttrContext> env,
1260 final Attr attr,
1261 final JCVariableDecl variable,
1262 final JCLambda currentLambda,
1263 final boolean speculative)
1264 {
1265 setData(new Callable<Object>() {
1266 public Object call() {
1267 return attr.attribLazyConstantValue(env, variable, type,
1268 currentLambda,
1269 speculative);
1270 }
1271 });
1272 }
1273
1274 /**
1275 * The variable's constant value, if this is a constant.
1276 * Before the constant value is evaluated, it points to an
1277 * initializer environment. If this is not a constant, it can
1278 * be used for other stuff.
1279 */
1280 private Object data;
1281
1282 public boolean isExceptionParameter() {
1283 return data == ElementKind.EXCEPTION_PARAMETER;
1284 }
1285
1286 public boolean isResourceVariable() {
1287 return data == ElementKind.RESOURCE_VARIABLE;
1288 }
1289
|