207
208 if (types.isSignaturePolymorphic(m)) {
209 m.flags_field |= SIGNATURE_POLYMORPHIC;
210 }
211
212 // Set m.params
213 ListBuffer<VarSymbol> params = new ListBuffer<>();
214 JCVariableDecl lastParam = null;
215 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
216 JCVariableDecl param = lastParam = l.head;
217 params.append(Assert.checkNonNull(param.sym));
218 }
219 m.params = params.toList();
220
221 // mark the method varargs, if necessary
222 if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
223 m.flags_field |= Flags.VARARGS;
224
225 localEnv.info.scope.leave();
226 if (chk.checkUnique(tree.pos(), m, enclScope)) {
227 enclScope.enter(m);
228 }
229
230 annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
231 // Visit the signature of the method. Note that
232 // TypeAnnotate doesn't descend into the body.
233 annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m, tree.pos());
234
235 if (tree.defaultValue != null) {
236 m.defaultValue = annotate.unfinishedDefaultValue(); // set it to temporary sentinel for now
237 annotate.annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos());
238 }
239 }
240
241 /** Create a fresh environment for method bodies.
242 * @param tree The method definition.
243 * @param env The environment current outside of the method definition.
244 */
245 Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
246 Env<AttrContext> localEnv =
247 env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym)));
284 //because varargs is represented in the tree as a
285 //modifier on the parameter declaration, and not as a
286 //distinct type of array node.
287 ArrayType atype = (ArrayType)tree.vartype.type;
288 tree.vartype.type = atype.makeVarargs();
289 }
290 WriteableScope enclScope = enter.enterScope(env);
291 Type vartype = tree.isImplicitlyTyped()
292 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
293 : tree.vartype.type;
294 Name name = tree.name;
295 VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
296 v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
297 tree.sym = v;
298 if (tree.init != null) {
299 v.flags_field |= HASINIT;
300 if ((v.flags_field & FINAL) != 0 &&
301 needsLazyConstValue(tree.init)) {
302 Env<AttrContext> initEnv = getInitEnv(tree, env);
303 initEnv.info.enclVar = v;
304 v.setLazyConstValue(initEnv(tree, initEnv), attr, tree);
305 }
306 }
307
308 if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
309 if (chk.checkUnique(tree.pos(), v, enclScope)) {
310 chk.checkTransparentVar(tree.pos(), v, enclScope);
311 enclScope.enter(v);
312 } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
313 // if this is a parameter or a field obtained from a record component, enter it
314 enclScope.enter(v);
315 }
316 }
317
318 annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
319 if (!tree.isImplicitlyTyped()) {
320 annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v, tree.pos());
321 }
322
323 v.pos = tree.pos;
324 }
|
207
208 if (types.isSignaturePolymorphic(m)) {
209 m.flags_field |= SIGNATURE_POLYMORPHIC;
210 }
211
212 // Set m.params
213 ListBuffer<VarSymbol> params = new ListBuffer<>();
214 JCVariableDecl lastParam = null;
215 for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
216 JCVariableDecl param = lastParam = l.head;
217 params.append(Assert.checkNonNull(param.sym));
218 }
219 m.params = params.toList();
220
221 // mark the method varargs, if necessary
222 if (lastParam != null && (lastParam.mods.flags & Flags.VARARGS) != 0)
223 m.flags_field |= Flags.VARARGS;
224
225 localEnv.info.scope.leave();
226 if (chk.checkUnique(tree.pos(), m, enclScope)) {
227 enclScope.enter(m);
228 }
229
230 annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos());
231 // Visit the signature of the method. Note that
232 // TypeAnnotate doesn't descend into the body.
233 annotate.queueScanTreeAndTypeAnnotate(tree, localEnv, m, tree.pos());
234
235 if (tree.defaultValue != null) {
236 m.defaultValue = annotate.unfinishedDefaultValue(); // set it to temporary sentinel for now
237 annotate.annotateDefaultValueLater(tree.defaultValue, localEnv, m, tree.pos());
238 }
239 }
240
241 /** Create a fresh environment for method bodies.
242 * @param tree The method definition.
243 * @param env The environment current outside of the method definition.
244 */
245 Env<AttrContext> methodEnv(JCMethodDecl tree, Env<AttrContext> env) {
246 Env<AttrContext> localEnv =
247 env.dup(tree, env.info.dup(env.info.scope.dupUnshared(tree.sym)));
284 //because varargs is represented in the tree as a
285 //modifier on the parameter declaration, and not as a
286 //distinct type of array node.
287 ArrayType atype = (ArrayType)tree.vartype.type;
288 tree.vartype.type = atype.makeVarargs();
289 }
290 WriteableScope enclScope = enter.enterScope(env);
291 Type vartype = tree.isImplicitlyTyped()
292 ? env.info.scope.owner.kind == MTH ? Type.noType : syms.errType
293 : tree.vartype.type;
294 Name name = tree.name;
295 VarSymbol v = new VarSymbol(0, name, vartype, enclScope.owner);
296 v.flags_field = chk.checkFlags(tree.pos(), tree.mods.flags, v, tree);
297 tree.sym = v;
298 if (tree.init != null) {
299 v.flags_field |= HASINIT;
300 if ((v.flags_field & FINAL) != 0 &&
301 needsLazyConstValue(tree.init)) {
302 Env<AttrContext> initEnv = getInitEnv(tree, env);
303 initEnv.info.enclVar = v;
304 initEnv = initEnv(tree, initEnv);
305 initEnv.info.ctorPrologue = (v.owner.kind == TYP && v.owner.isValueClass() && !v.isStatic());
306 v.setLazyConstValue(initEnv, attr, tree);
307 }
308 }
309
310 if(!(Feature.UNNAMED_VARIABLES.allowedInSource(source) && tree.sym.isUnnamedVariable())) {
311 if (chk.checkUnique(tree.pos(), v, enclScope)) {
312 chk.checkTransparentVar(tree.pos(), v, enclScope);
313 enclScope.enter(v);
314 } else if (v.owner.kind == MTH || (v.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0) {
315 // if this is a parameter or a field obtained from a record component, enter it
316 enclScope.enter(v);
317 }
318 }
319
320 annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos());
321 if (!tree.isImplicitlyTyped()) {
322 annotate.queueScanTreeAndTypeAnnotate(tree.vartype, localEnv, v, tree.pos());
323 }
324
325 v.pos = tree.pos;
326 }
|