< 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);
224         // Visit the signature of the method. Note that
225         // TypeAnnotate doesn't descend into the body.
226         annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m);
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);
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)));

272             //because varargs is represented in the tree as a
273             //modifier on the parameter declaration, and not as a
274             //distinct type of array node.
275             ArrayType atype = (ArrayType)tree.vartype.type;
276             tree.vartype.type = atype.makeVarargs();
277         }
278         WriteableScope enclScope = enter.enterScope(env);
279         Type vartype = tree.isImplicitlyTyped()
280                 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
281                 : tree.vartype.type;
282         Name name = tree.name;
283         VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
284         v.flags_field = chk.checkFlags(tree.mods.flags, v, tree);
285         tree.sym = v;
286         if (tree.init != null) {
287             v.flags_field |= HASINIT;
288             if ((v.flags_field & FINAL) != 0 &&
289                 needsLazyConstValue(tree.init)) {
290                 Env<AttrContext> initEnv = getInitEnv(tree, env);
291                 initEnv.info.enclVar = v;


292                 v.setLazyConstValue(initEnv(tree, initEnv), env, attr, tree);
293             }
294         }
295 
296         if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
297             if (chk.checkUnique(tree.pos(), v, enclScope)) {
298                 chk.checkTransparentVar(tree.pos(), v, enclScope);
299                 enclScope.enter(v);
300             } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
301                 // if this is a parameter or a field obtained from a record component, enter it
302                 enclScope.enter(v);
303             }
304         }
305 
306         annotate.annotateLater(tree.mods.annotations, localEnv, v);
307         if (!tree.isImplicitlyTyped()) {
308             annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v);
309         }
310 
311         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);
224         // Visit the signature of the method. Note that
225         // TypeAnnotate doesn't descend into the body.
226         annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m);
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);
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)));

272             //because varargs is represented in the tree as a
273             //modifier on the parameter declaration, and not as a
274             //distinct type of array node.
275             ArrayType atype = (ArrayType)tree.vartype.type;
276             tree.vartype.type = atype.makeVarargs();
277         }
278         WriteableScope enclScope = enter.enterScope(env);
279         Type vartype = tree.isImplicitlyTyped()
280                 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
281                 : tree.vartype.type;
282         Name name = tree.name;
283         VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
284         v.flags_field = chk.checkFlags(tree.mods.flags, v, tree);
285         tree.sym = v;
286         if (tree.init != null) {
287             v.flags_field |= HASINIT;
288             if ((v.flags_field & FINAL) != 0 &&
289                 needsLazyConstValue(tree.init)) {
290                 Env<AttrContext> initEnv = getInitEnv(tree, env);
291                 initEnv.info.enclVar = v;
292                 initEnv = initEnv(tree, initEnv);
293                 initEnv.info.ctorPrologue = (v.owner.kind == TYP && v.owner.isValueClass() && !v.isStatic());
294                 v.setLazyConstValue(initEnv(tree, initEnv), env, attr, tree);
295             }
296         }
297 
298         if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
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 
308         annotate.annotateLater(tree.mods.annotations, localEnv, v);
309         if (!tree.isImplicitlyTyped()) {
310             annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v);
311         }
312 
313         v.pos = tree.pos;
< prev index next >