< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/MemberEnter.java

Print this page

200 
201         if (types.isSignaturePolymorphic(m)) {
202             m.flags_field |= SIGNATURE_POLYMORPHIC;
203         }
204 
205         // Set m.params
206         ListBuffer<VarSymbol> params = new ListBuffer<>();
207         JCVariableDecl lastParam = null;
208         for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
209             JCVariableDecl param = lastParam = l.head;
210             params.append(Assert.checkNonNull(param.sym));
211         }
212         m.params = params.toList();
213 
214         // mark the method varargs, if necessary
215         if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
216             m.flags_field |= Flags.VARARGS;
217 
218         localEnv.info.scope.leave();
219         if (chk.checkUnique(tree.pos(), m, enclScope)) {
220         enclScope.enter(m);
221         }
222 
223         annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
224         // Visit the signature of the method. Note that
225         // TypeAnnotate doesn't descend into the body.
226         annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m, tree.pos());
227 
228         if (tree.defaultValue != null) {
229             m.defaultValue = annotate.unfinishedDefaultValue(); // set it to temporary sentinel for now
230             annotate.annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos());
231         }
232     }
233 
234     /** Create a fresh environment for method bodies.
235      *  @param tree     The method definition.
236      *  @param env      The environment current outside of the method definition.
237      */
238     Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
239         Env<AttrContext> localEnv =
240             env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym)));

270             deferredLintHandler.setPos(prevLintPos);
271         }
272 
273         if ((tree.mods.flags & VARARGS) != 0) {
274             //if we are entering a varargs parameter, we need to
275             //replace its type (a plain array type) with the more
276             //precise VarargsType --- we need to do it this way
277             //because varargs is represented in the tree as a
278             //modifier on the parameter declaration, and not as a
279             //distinct type of array node.
280             ArrayType atype = (ArrayType)tree.vartype.type;
281             tree.vartype.type = atype.makeVarargs();
282         }
283         WriteableScope enclScope = enter.enterScope(env);
284         Type vartype = tree.isImplicitlyTyped()
285                 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
286                 : tree.vartype.type;
287         VarSymbol v = new VarSymbol(0, tree.name, vartype, enclScope.owner);
288         v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
289         tree.sym = v;



290         if (tree.init != null) {
291             v.flags_field |= HASINIT;
292             if ((v.flags_field & FINAL) != 0 &&
293                 needsLazyConstValue(tree.init)) {
294                 Env<AttrContext> initEnv = getInitEnv(tree, env);
295                 initEnv.info.enclVar = v;
296                 v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
297             }
298         }
299         if (chk.checkUnique(tree.pos(), v, enclScope)) {
300             chk.checkTransparentVar(tree.pos(), v, enclScope);
301             enclScope.enter(v);
302         } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
303             // if this is a parameter or a field obtained from a record component, enter it
304             enclScope.enter(v);
305         }
306 
307         annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
308         if (!tree.isImplicitlyTyped()) {
309             annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v, tree.pos());
310         }
311 
312         v.pos = tree.pos;

200 
201         if (types.isSignaturePolymorphic(m)) {
202             m.flags_field |= SIGNATURE_POLYMORPHIC;
203         }
204 
205         // Set m.params
206         ListBuffer<VarSymbol> params = new ListBuffer<>();
207         JCVariableDecl lastParam = null;
208         for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
209             JCVariableDecl param = lastParam = l.head;
210             params.append(Assert.checkNonNull(param.sym));
211         }
212         m.params = params.toList();
213 
214         // mark the method varargs, if necessary
215         if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
216             m.flags_field |= Flags.VARARGS;
217 
218         localEnv.info.scope.leave();
219         if (chk.checkUnique(tree.pos(), m, enclScope)) {
220             enclScope.enter(m);
221         }
222 
223         annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
224         // Visit the signature of the method. Note that
225         // TypeAnnotate doesn't descend into the body.
226         annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m, tree.pos());
227 
228         if (tree.defaultValue != null) {
229             m.defaultValue = annotate.unfinishedDefaultValue(); // set it to temporary sentinel for now
230             annotate.annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos());
231         }
232     }
233 
234     /** Create a fresh environment for method bodies.
235      *  @param tree     The method definition.
236      *  @param env      The environment current outside of the method definition.
237      */
238     Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
239         Env<AttrContext> localEnv =
240             env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym)));

270             deferredLintHandler.setPos(prevLintPos);
271         }
272 
273         if ((tree.mods.flags & VARARGS) != 0) {
274             //if we are entering a varargs parameter, we need to
275             //replace its type (a plain array type) with the more
276             //precise VarargsType --- we need to do it this way
277             //because varargs is represented in the tree as a
278             //modifier on the parameter declaration, and not as a
279             //distinct type of array node.
280             ArrayType atype = (ArrayType)tree.vartype.type;
281             tree.vartype.type = atype.makeVarargs();
282         }
283         WriteableScope enclScope = enter.enterScope(env);
284         Type vartype = tree.isImplicitlyTyped()
285                 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
286                 : tree.vartype.type;
287         VarSymbol v = new VarSymbol(0, tree.name, vartype, enclScope.owner);
288         v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
289         tree.sym = v;
290         /* Don't want constant propagation/folding for instance fields of primitive classes,
291            as these can undergo updates via copy on write.
292         */
293         if (tree.init != null) {
294             v.flags_field |= HASINIT;
295             if ((v.flags_field & FINAL) != 0 && ((v.flags_field & STATIC) != 0 || !v.owner.isPrimitiveClass()) &&
296                 needsLazyConstValue(tree.init)) {
297                 Env<AttrContext> initEnv = getInitEnv(tree, env);
298                 initEnv.info.enclVar = v;
299                 v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
300             }
301         }
302         if (chk.checkUnique(tree.pos(), v, enclScope)) {
303             chk.checkTransparentVar(tree.pos(), v, enclScope);
304             enclScope.enter(v);
305         } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
306             // if this is a parameter or a field obtained from a record component, enter it
307             enclScope.enter(v);
308         }
309 
310         annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
311         if (!tree.isImplicitlyTyped()) {
312             annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v, tree.pos());
313         }
314 
315         v.pos = tree.pos;
< prev index next >