Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: pkg/analyzer/lib/src/dart/element/builder.dart

Issue 2800443002: Build elements for FieldFormalParameter(s) even for local functions. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/dart/element/builder_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.dart.element.builder; 5 library analyzer.src.dart.element.builder;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 _unitElement.setAnnotations(node.offset, annotations); 222 _unitElement.setAnnotations(node.offset, annotations);
223 return super.visitExportDirective(node); 223 return super.visitExportDirective(node);
224 } 224 }
225 225
226 @override 226 @override
227 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 227 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
228 return null; 228 return null;
229 } 229 }
230 230
231 @override 231 @override
232 Object visitFieldFormalParameter(FieldFormalParameter node) {
233 if (node.parent is! DefaultFormalParameter) {
234 SimpleIdentifier parameterName = node.identifier;
235 FieldFormalParameterElementImpl parameter =
236 new FieldFormalParameterElementImpl.forNode(parameterName);
237 _setCodeRange(parameter, node);
238 _setFieldParameterField(node, parameter);
239 parameter.isConst = node.isConst;
240 parameter.isExplicitlyCovariant = node.covariantKeyword != null;
241 parameter.isFinal = node.isFinal;
242 parameter.parameterKind = node.kind;
243 _currentHolder.addParameter(parameter);
244 parameterName.staticElement = parameter;
245 }
246 //
247 // The children of this parameter include any parameters defined on the type
248 // of this parameter.
249 //
250 ElementHolder holder = new ElementHolder();
251 _visitChildren(holder, node);
252 ParameterElementImpl element = node.element;
253 element.metadata = _createElementAnnotations(node.metadata);
254 element.parameters = holder.parameters;
255 element.typeParameters = holder.typeParameters;
256 holder.validate();
257 return null;
258 }
259
260 @override
261 Object visitFunctionDeclaration(FunctionDeclaration node) { 232 Object visitFunctionDeclaration(FunctionDeclaration node) {
262 FunctionExpression expression = node.functionExpression; 233 FunctionExpression expression = node.functionExpression;
263 if (expression != null) { 234 if (expression != null) {
264 ElementHolder holder = new ElementHolder(); 235 ElementHolder holder = new ElementHolder();
265 _visitChildren(holder, node); 236 _visitChildren(holder, node);
266 FunctionBody body = expression.body; 237 FunctionBody body = expression.body;
267 Token property = node.propertyKeyword; 238 Token property = node.propertyKeyword;
268 if (property == null) { 239 if (property == null) {
269 SimpleIdentifier functionName = node.name; 240 SimpleIdentifier functionName = node.name;
270 FunctionElementImpl element = 241 FunctionElementImpl element =
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 _currentHolder.addParameter(parameter); 1416 _currentHolder.addParameter(parameter);
1446 if (normalParameter is SimpleFormalParameterImpl) { 1417 if (normalParameter is SimpleFormalParameterImpl) {
1447 normalParameter.element = parameter; 1418 normalParameter.element = parameter;
1448 } 1419 }
1449 parameterName?.staticElement = parameter; 1420 parameterName?.staticElement = parameter;
1450 normalParameter.accept(this); 1421 normalParameter.accept(this);
1451 return null; 1422 return null;
1452 } 1423 }
1453 1424
1454 @override 1425 @override
1426 Object visitFieldFormalParameter(FieldFormalParameter node) {
Brian Wilkerson 2017/04/04 20:00:34 What's up with the sort order? This method shouldn
scheglov 2017/04/04 20:02:28 I moved it manually from one class (ApiElementBuil
Brian Wilkerson 2017/04/04 20:11:56 And unlike 'git diff', this tool doesn't provide t
1427 if (node.parent is! DefaultFormalParameter) {
1428 SimpleIdentifier parameterName = node.identifier;
1429 FieldFormalParameterElementImpl parameter =
1430 new FieldFormalParameterElementImpl.forNode(parameterName);
1431 _setCodeRange(parameter, node);
1432 _setFieldParameterField(node, parameter);
1433 parameter.isConst = node.isConst;
1434 parameter.isExplicitlyCovariant = node.covariantKeyword != null;
1435 parameter.isFinal = node.isFinal;
1436 parameter.parameterKind = node.kind;
1437 _currentHolder.addParameter(parameter);
1438 parameterName.staticElement = parameter;
1439 }
1440 //
1441 // The children of this parameter include any parameters defined on the type
1442 // of this parameter.
1443 //
1444 ElementHolder holder = new ElementHolder();
1445 _visitChildren(holder, node);
1446 ParameterElementImpl element = node.element;
1447 element.metadata = _createElementAnnotations(node.metadata);
1448 element.parameters = holder.parameters;
1449 element.typeParameters = holder.typeParameters;
1450 holder.validate();
1451 return null;
1452 }
1453
1454 @override
1455 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 1455 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
1456 if (node.parent is! DefaultFormalParameter) { 1456 if (node.parent is! DefaultFormalParameter) {
1457 SimpleIdentifier parameterName = node.identifier; 1457 SimpleIdentifier parameterName = node.identifier;
1458 ParameterElementImpl parameter = 1458 ParameterElementImpl parameter =
1459 new ParameterElementImpl.forNode(parameterName); 1459 new ParameterElementImpl.forNode(parameterName);
1460 _setCodeRange(parameter, node); 1460 _setCodeRange(parameter, node);
1461 parameter.isConst = node.isConst; 1461 parameter.isConst = node.isConst;
1462 parameter.isExplicitlyCovariant = node.covariantKeyword != null; 1462 parameter.isExplicitlyCovariant = node.covariantKeyword != null;
1463 parameter.isFinal = node.isFinal; 1463 parameter.isFinal = node.isFinal;
1464 parameter.parameterKind = node.kind; 1464 parameter.parameterKind = node.kind;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 return null; 1668 return null;
1669 } 1669 }
1670 1670
1671 /** 1671 /**
1672 * Return the lexical identifiers associated with the given [identifiers]. 1672 * Return the lexical identifiers associated with the given [identifiers].
1673 */ 1673 */
1674 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { 1674 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
1675 return identifiers.map((identifier) => identifier.name).toList(); 1675 return identifiers.map((identifier) => identifier.name).toList();
1676 } 1676 }
1677 } 1677 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/dart/element/builder_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698