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)));
276 tree.vartype.type = atype.makeVarargs();
277 }
278 WriteableScope enclScope = enter.enterScope(env);
279 Type vartype = switch (tree.declKind) {
280 case IMPLICIT -> tree.type;
281 case EXPLICIT -> tree.vartype.type;
282 case VAR -> tree.type != null ? tree.type
283 : env.info.scope.owner.kind == MTH ? Type.noType
284 : syms.errType;
285 };
286 Name name = tree.name;
287 VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
288 v.flags_field = chk.checkFlags(tree.mods.flags | tree.declKind.additionalSymbolFlags, 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), env, attr, tree);
297 }
298 }
299
300 if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
301 if (chk.checkUnique(tree.pos(), v, enclScope)) {
302 chk.checkTransparentVar(tree.pos(), v, enclScope);
303 enclScope.enter(v);
304 } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
305 // if this is a parameter or a field obtained from a record component, enter it
306 enclScope.enter(v);
307 }
308 }
309
310 annotate.annotateLater(tree.mods.annotations, localEnv, v);
311 if (!tree.isImplicitlyTyped()) {
312 annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v);
313 }
314
315 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)));
276 tree.vartype.type = atype.makeVarargs();
277 }
278 WriteableScope enclScope = enter.enterScope(env);
279 Type vartype = switch (tree.declKind) {
280 case IMPLICIT -> tree.type;
281 case EXPLICIT -> tree.vartype.type;
282 case VAR -> tree.type != null ? tree.type
283 : env.info.scope.owner.kind == MTH ? Type.noType
284 : syms.errType;
285 };
286 Name name = tree.name;
287 VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
288 v.flags_field = chk.checkFlags(tree.mods.flags | tree.declKind.additionalSymbolFlags, 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 initEnv = initEnv(tree, initEnv);
297 initEnv.info.ctorPrologue = (v.owner.kind == TYP && v.owner.isValueClass() && !v.isStatic());
298 v.setLazyConstValue(initEnv(tree, initEnv), env, attr, tree);
299 }
300 }
301
302 if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
303 if (chk.checkUnique(tree.pos(), v, enclScope)) {
304 chk.checkTransparentVar(tree.pos(), v, enclScope);
305 enclScope.enter(v);
306 } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
307 // if this is a parameter or a field obtained from a record component, enter it
308 enclScope.enter(v);
309 }
310 }
311
312 annotate.annotateLater(tree.mods.annotations, localEnv, v);
313 if (!tree.isImplicitlyTyped()) {
314 annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v);
315 }
316
317 v.pos = tree.pos;
|