47 import javax.tools.JavaFileManager;
48 import javax.tools.JavaFileObject;
49
50 import com.sun.tools.javac.code.Kinds.Kind;
51 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
52 import com.sun.tools.javac.code.Type.*;
53 import com.sun.tools.javac.comp.Attr;
54 import com.sun.tools.javac.comp.AttrContext;
55 import com.sun.tools.javac.comp.Env;
56 import com.sun.tools.javac.jvm.*;
57 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
58 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
59 import com.sun.tools.javac.tree.JCTree.Tag;
60 import com.sun.tools.javac.util.*;
61 import com.sun.tools.javac.util.DefinedBy.Api;
62 import com.sun.tools.javac.util.Name;
63
64 import static com.sun.tools.javac.code.Flags.*;
65 import static com.sun.tools.javac.code.Kinds.*;
66 import static com.sun.tools.javac.code.Kinds.Kind.*;
67 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
68 import com.sun.tools.javac.code.Scope.WriteableScope;
69 import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
70 import static com.sun.tools.javac.code.TypeTag.CLASS;
71 import static com.sun.tools.javac.code.TypeTag.FORALL;
72 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
73 import static com.sun.tools.javac.jvm.ByteCodes.iadd;
74 import static com.sun.tools.javac.jvm.ByteCodes.ishll;
75 import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
76 import static com.sun.tools.javac.jvm.ByteCodes.lxor;
77 import static com.sun.tools.javac.jvm.ByteCodes.string_add;
78
79 /** Root class for Java symbols. It contains subclasses
80 * for specific sorts of symbols, such as variables, methods and operators,
81 * types, packages. Each subclass is represented as a static inner class
82 * inside Symbol.
83 *
84 * <p><b>This is NOT part of any supported API.
85 * If you write code that depends on this, you do so at your own risk.
86 * This code and its internal interfaces are subject to change or
87 * deletion without notice.</b>
88 */
89 public abstract class Symbol extends AnnoConstruct implements Element {
90
91 /** The kind of this symbol.
92 * @see Kinds
93 */
94 public Kind kind;
95
96 /** The flags of this symbol.
97 */
1171 public Symbol getEnclosingElement() {
1172 return modle != null && !modle.isNoModule() ? modle : null;
1173 }
1174
1175 @DefinedBy(Api.LANGUAGE_MODEL)
1176 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1177 return v.visitPackage(this, p);
1178 }
1179
1180 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1181 return v.visitPackageSymbol(this, p);
1182 }
1183
1184 /**Resets the Symbol into the state good for next round of annotation processing.*/
1185 public void reset() {
1186 metadata = null;
1187 }
1188
1189 }
1190
1191 /** A class for class symbols
1192 */
1193 public static class ClassSymbol extends TypeSymbol implements TypeElement {
1194
1195 /** a scope for all class members; variables, methods and inner classes
1196 * type parameters are not part of this scope
1197 */
1198 public WriteableScope members_field;
1199
1200 /** the fully qualified name of the class, i.e. pck.outer.inner.
1201 * null for anonymous classes
1202 */
1203 public Name fullname;
1204
1205 /** the fully qualified name of the class after converting to flat
1206 * representation, i.e. pck.outer$inner,
1207 * set externally for local and anonymous classes
1208 */
1209 public Name flatname;
1210
1614 // yet unevaluated initializer.
1615 Callable<?> eval = (Callable<?>)data;
1616 data = null; // to make sure we don't evaluate this twice.
1617 try {
1618 data = eval.call();
1619 } catch (Exception ex) {
1620 throw new AssertionError(ex);
1621 }
1622 }
1623 return data;
1624 }
1625
1626 public void setData(Object data) {
1627 Assert.check(!(data instanceof Env<?>), this);
1628 this.data = data;
1629 }
1630
1631 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1632 return v.visitVarSymbol(this, p);
1633 }
1634 }
1635
1636 /** A class for method symbols.
1637 */
1638 public static class MethodSymbol extends Symbol implements ExecutableElement {
1639
1640 /** The code of the method. */
1641 public Code code = null;
1642
1643 /** The extra (synthetic/mandated) parameters of the method. */
1644 public List<VarSymbol> extraParams = List.nil();
1645
1646 /** The captured local variables in an anonymous class */
1647 public List<VarSymbol> capturedLocals = List.nil();
1648
1649 /** The parameters of the method. */
1650 public List<VarSymbol> params = null;
1651
1652 /** For an annotation type element, its default value if any.
1653 * The value is null if none appeared in the method
|
47 import javax.tools.JavaFileManager;
48 import javax.tools.JavaFileObject;
49
50 import com.sun.tools.javac.code.Kinds.Kind;
51 import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
52 import com.sun.tools.javac.code.Type.*;
53 import com.sun.tools.javac.comp.Attr;
54 import com.sun.tools.javac.comp.AttrContext;
55 import com.sun.tools.javac.comp.Env;
56 import com.sun.tools.javac.jvm.*;
57 import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
58 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
59 import com.sun.tools.javac.tree.JCTree.Tag;
60 import com.sun.tools.javac.util.*;
61 import com.sun.tools.javac.util.DefinedBy.Api;
62 import com.sun.tools.javac.util.Name;
63
64 import static com.sun.tools.javac.code.Flags.*;
65 import static com.sun.tools.javac.code.Kinds.*;
66 import static com.sun.tools.javac.code.Kinds.Kind.*;
67 import com.sun.tools.javac.code.MissingInfoHandler;
68 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
69 import com.sun.tools.javac.code.Scope.WriteableScope;
70 import com.sun.tools.javac.code.Symbol;
71 import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.FIRSTASGOP;
72 import com.sun.tools.javac.code.Type;
73 import static com.sun.tools.javac.code.TypeTag.CLASS;
74 import static com.sun.tools.javac.code.TypeTag.FORALL;
75 import static com.sun.tools.javac.code.TypeTag.TYPEVAR;
76 import static com.sun.tools.javac.jvm.ByteCodes.iadd;
77 import static com.sun.tools.javac.jvm.ByteCodes.ishll;
78 import static com.sun.tools.javac.jvm.ByteCodes.lushrl;
79 import static com.sun.tools.javac.jvm.ByteCodes.lxor;
80 import static com.sun.tools.javac.jvm.ByteCodes.string_add;
81 import com.sun.tools.javac.util.Name;
82
83 /** Root class for Java symbols. It contains subclasses
84 * for specific sorts of symbols, such as variables, methods and operators,
85 * types, packages. Each subclass is represented as a static inner class
86 * inside Symbol.
87 *
88 * <p><b>This is NOT part of any supported API.
89 * If you write code that depends on this, you do so at your own risk.
90 * This code and its internal interfaces are subject to change or
91 * deletion without notice.</b>
92 */
93 public abstract class Symbol extends AnnoConstruct implements Element {
94
95 /** The kind of this symbol.
96 * @see Kinds
97 */
98 public Kind kind;
99
100 /** The flags of this symbol.
101 */
1175 public Symbol getEnclosingElement() {
1176 return modle != null && !modle.isNoModule() ? modle : null;
1177 }
1178
1179 @DefinedBy(Api.LANGUAGE_MODEL)
1180 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
1181 return v.visitPackage(this, p);
1182 }
1183
1184 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1185 return v.visitPackageSymbol(this, p);
1186 }
1187
1188 /**Resets the Symbol into the state good for next round of annotation processing.*/
1189 public void reset() {
1190 metadata = null;
1191 }
1192
1193 }
1194
1195 public static class RootPackageSymbol extends PackageSymbol {
1196 public final MissingInfoHandler missingInfoHandler;
1197
1198 public RootPackageSymbol(Name name, Symbol owner, MissingInfoHandler missingInfoHandler) {
1199 super(name, owner);
1200 this.missingInfoHandler = missingInfoHandler;
1201 }
1202
1203 }
1204
1205 /** A class for class symbols
1206 */
1207 public static class ClassSymbol extends TypeSymbol implements TypeElement {
1208
1209 /** a scope for all class members; variables, methods and inner classes
1210 * type parameters are not part of this scope
1211 */
1212 public WriteableScope members_field;
1213
1214 /** the fully qualified name of the class, i.e. pck.outer.inner.
1215 * null for anonymous classes
1216 */
1217 public Name fullname;
1218
1219 /** the fully qualified name of the class after converting to flat
1220 * representation, i.e. pck.outer$inner,
1221 * set externally for local and anonymous classes
1222 */
1223 public Name flatname;
1224
1628 // yet unevaluated initializer.
1629 Callable<?> eval = (Callable<?>)data;
1630 data = null; // to make sure we don't evaluate this twice.
1631 try {
1632 data = eval.call();
1633 } catch (Exception ex) {
1634 throw new AssertionError(ex);
1635 }
1636 }
1637 return data;
1638 }
1639
1640 public void setData(Object data) {
1641 Assert.check(!(data instanceof Env<?>), this);
1642 this.data = data;
1643 }
1644
1645 public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
1646 return v.visitVarSymbol(this, p);
1647 }
1648 }
1649
1650 public static class ParamSymbol extends VarSymbol {
1651 public ParamSymbol(long flags, Name name, Type type, Symbol owner) {
1652 super(flags, name, type, owner);
1653 }
1654
1655 @Override
1656 public Name getSimpleName() {
1657 if ((flags_field & NAME_FILLED) == 0) {
1658 flags_field |= NAME_FILLED;
1659 Symbol rootPack = this;
1660 while (rootPack != null && !(rootPack instanceof RootPackageSymbol)) {
1661 rootPack = rootPack.owner;
1662 }
1663 if (rootPack != null) {
1664 Name inferredName =
1665 ((RootPackageSymbol) rootPack).missingInfoHandler.getParameterName(this);
1666 if (inferredName != null) {
1667 this.name = inferredName;
1668 }
1669 }
1670 }
1671 return super.getSimpleName();
1672 }
1673
1674 }
1675
1676 /** A class for method symbols.
1677 */
1678 public static class MethodSymbol extends Symbol implements ExecutableElement {
1679
1680 /** The code of the method. */
1681 public Code code = null;
1682
1683 /** The extra (synthetic/mandated) parameters of the method. */
1684 public List<VarSymbol> extraParams = List.nil();
1685
1686 /** The captured local variables in an anonymous class */
1687 public List<VarSymbol> capturedLocals = List.nil();
1688
1689 /** The parameters of the method. */
1690 public List<VarSymbol> params = null;
1691
1692 /** For an annotation type element, its default value if any.
1693 * The value is null if none appeared in the method
|