77
78 private final Names names;
79 private final Log log;
80 private final Symtab syms;
81 private final Resolve rs;
82 private final Operators operators;
83 private final Check chk;
84 private final Attr attr;
85 private TreeMaker make;
86 private DiagnosticPosition make_pos;
87 private final ClassWriter writer;
88 private final ConstFold cfolder;
89 private final Target target;
90 private final Source source;
91 private final TypeEnvs typeEnvs;
92 private final Name dollarAssertionsDisabled;
93 private final Name classDollar;
94 private final Name dollarCloseResource;
95 private final Types types;
96 private final boolean debugLower;
97 private final PkgInfo pkginfoOpt;
98
99 protected Lower(Context context) {
100 context.put(lowerKey, this);
101 names = Names.instance(context);
102 log = Log.instance(context);
103 syms = Symtab.instance(context);
104 rs = Resolve.instance(context);
105 operators = Operators.instance(context);
106 chk = Check.instance(context);
107 attr = Attr.instance(context);
108 make = TreeMaker.instance(context);
109 writer = ClassWriter.instance(context);
110 cfolder = ConstFold.instance(context);
111 target = Target.instance(context);
112 source = Source.instance(context);
113 typeEnvs = TypeEnvs.instance(context);
114 dollarAssertionsDisabled = names.
115 fromString(target.syntheticNameChar() + "assertionsDisabled");
116 classDollar = names.
117 fromString("class" + target.syntheticNameChar());
118 dollarCloseResource = names.
119 fromString(target.syntheticNameChar() + "closeResource");
120
121 types = Types.instance(context);
122 Options options = Options.instance(context);
123 debugLower = options.isSet("debuglower");
124 pkginfoOpt = PkgInfo.get(options);
125 }
126
127 /** The currently enclosing class.
128 */
129 ClassSymbol currentClass;
130
131 /** A queue of all translated classes.
132 */
133 ListBuffer<JCTree> translated;
134
135 /** Environment for symbol lookup, set by translateTopLevelClass.
136 */
137 Env<AttrContext> attrEnv;
138
139 /** A hash table mapping syntax trees to their ending source positions.
140 */
141 EndPosTable endPosTable;
142
143 /**************************************************************************
144 * Global mappings
1014 enterSynthetic(tree.pos(), accessor, accOwner.members());
1015 accessors[acode] = accessor;
1016 }
1017 return accessor;
1018 }
1019
1020 /** The qualifier to be used for accessing a symbol in an outer class.
1021 * This is either C.sym or C.this.sym, depending on whether or not
1022 * sym is static.
1023 * @param sym The accessed symbol.
1024 */
1025 JCExpression accessBase(DiagnosticPosition pos, Symbol sym) {
1026 return (sym.flags() & STATIC) != 0
1027 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner))
1028 : makeOwnerThis(pos, sym, true);
1029 }
1030
1031 /** Do we need an access method to reference private symbol?
1032 */
1033 boolean needsPrivateAccess(Symbol sym) {
1034 if ((sym.flags() & PRIVATE) == 0 || sym.owner == currentClass) {
1035 return false;
1036 } else if (sym.name == names.init && sym.owner.isLocal()) {
1037 // private constructor in local class: relax protection
1038 sym.flags_field &= ~PRIVATE;
1039 return false;
1040 } else {
1041 return true;
1042 }
1043 }
1044
1045 /** Do we need an access method to reference symbol in other package?
1046 */
1047 boolean needsProtectedAccess(Symbol sym, JCTree tree) {
1048 if ((sym.flags() & PROTECTED) == 0 ||
1049 sym.owner.owner == currentClass.owner || // fast special case
1050 sym.packge() == currentClass.packge())
1051 return false;
1052 if (!currentClass.isSubClass(sym.owner, types))
1053 return true;
1054 if ((sym.flags() & STATIC) != 0 ||
1055 !tree.hasTag(SELECT) ||
1056 TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
1057 return false;
1058 return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
1059 }
1060
1061 /** The class in which an access method for given symbol goes.
1062 * @param sym The access symbol
1063 * @param protAccess Is access to a protected symbol in another
1064 * package?
1065 */
1066 ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree) {
1067 if (protAccess) {
|
77
78 private final Names names;
79 private final Log log;
80 private final Symtab syms;
81 private final Resolve rs;
82 private final Operators operators;
83 private final Check chk;
84 private final Attr attr;
85 private TreeMaker make;
86 private DiagnosticPosition make_pos;
87 private final ClassWriter writer;
88 private final ConstFold cfolder;
89 private final Target target;
90 private final Source source;
91 private final TypeEnvs typeEnvs;
92 private final Name dollarAssertionsDisabled;
93 private final Name classDollar;
94 private final Name dollarCloseResource;
95 private final Types types;
96 private final boolean debugLower;
97 private final boolean disableProtectedAccessors; // experimental
98 private final PkgInfo pkginfoOpt;
99
100 protected Lower(Context context) {
101 context.put(lowerKey, this);
102 names = Names.instance(context);
103 log = Log.instance(context);
104 syms = Symtab.instance(context);
105 rs = Resolve.instance(context);
106 operators = Operators.instance(context);
107 chk = Check.instance(context);
108 attr = Attr.instance(context);
109 make = TreeMaker.instance(context);
110 writer = ClassWriter.instance(context);
111 cfolder = ConstFold.instance(context);
112 target = Target.instance(context);
113 source = Source.instance(context);
114 typeEnvs = TypeEnvs.instance(context);
115 dollarAssertionsDisabled = names.
116 fromString(target.syntheticNameChar() + "assertionsDisabled");
117 classDollar = names.
118 fromString("class" + target.syntheticNameChar());
119 dollarCloseResource = names.
120 fromString(target.syntheticNameChar() + "closeResource");
121
122 types = Types.instance(context);
123 Options options = Options.instance(context);
124 debugLower = options.isSet("debuglower");
125 pkginfoOpt = PkgInfo.get(options);
126 disableProtectedAccessors = options.isSet("disableProtectedAccessors");
127 }
128
129 /** The currently enclosing class.
130 */
131 ClassSymbol currentClass;
132
133 /** A queue of all translated classes.
134 */
135 ListBuffer<JCTree> translated;
136
137 /** Environment for symbol lookup, set by translateTopLevelClass.
138 */
139 Env<AttrContext> attrEnv;
140
141 /** A hash table mapping syntax trees to their ending source positions.
142 */
143 EndPosTable endPosTable;
144
145 /**************************************************************************
146 * Global mappings
1016 enterSynthetic(tree.pos(), accessor, accOwner.members());
1017 accessors[acode] = accessor;
1018 }
1019 return accessor;
1020 }
1021
1022 /** The qualifier to be used for accessing a symbol in an outer class.
1023 * This is either C.sym or C.this.sym, depending on whether or not
1024 * sym is static.
1025 * @param sym The accessed symbol.
1026 */
1027 JCExpression accessBase(DiagnosticPosition pos, Symbol sym) {
1028 return (sym.flags() & STATIC) != 0
1029 ? access(make.at(pos.getStartPosition()).QualIdent(sym.owner))
1030 : makeOwnerThis(pos, sym, true);
1031 }
1032
1033 /** Do we need an access method to reference private symbol?
1034 */
1035 boolean needsPrivateAccess(Symbol sym) {
1036 if (target.hasNestmateAccess()) {
1037 return false;
1038 }
1039 if ((sym.flags() & PRIVATE) == 0 || sym.owner == currentClass) {
1040 return false;
1041 } else if (sym.name == names.init && sym.owner.isLocal()) {
1042 // private constructor in local class: relax protection
1043 sym.flags_field &= ~PRIVATE;
1044 return false;
1045 } else {
1046 return true;
1047 }
1048 }
1049
1050 /** Do we need an access method to reference symbol in other package?
1051 */
1052 boolean needsProtectedAccess(Symbol sym, JCTree tree) {
1053 if (disableProtectedAccessors) return false;
1054 if ((sym.flags() & PROTECTED) == 0 ||
1055 sym.owner.owner == currentClass.owner || // fast special case
1056 sym.packge() == currentClass.packge())
1057 return false;
1058 if (!currentClass.isSubClass(sym.owner, types))
1059 return true;
1060 if ((sym.flags() & STATIC) != 0 ||
1061 !tree.hasTag(SELECT) ||
1062 TreeInfo.name(((JCFieldAccess) tree).selected) == names._super)
1063 return false;
1064 return !((JCFieldAccess) tree).selected.type.tsym.isSubClass(currentClass, types);
1065 }
1066
1067 /** The class in which an access method for given symbol goes.
1068 * @param sym The access symbol
1069 * @param protAccess Is access to a protected symbol in another
1070 * package?
1071 */
1072 ClassSymbol accessClass(Symbol sym, boolean protAccess, JCTree tree) {
1073 if (protAccess) {
|