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

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

Issue 2663063004: Don't resolve FieldFormalParameter field if not in constructor. (Closed)
Patch Set: Created 3 years, 10 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/lib/src/dart/element/element.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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 224
225 @override 225 @override
226 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 226 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
227 return null; 227 return null;
228 } 228 }
229 229
230 @override 230 @override
231 Object visitFieldFormalParameter(FieldFormalParameter node) { 231 Object visitFieldFormalParameter(FieldFormalParameter node) {
232 if (node.parent is! DefaultFormalParameter) { 232 if (node.parent is! DefaultFormalParameter) {
233 SimpleIdentifier parameterName = node.identifier; 233 SimpleIdentifier parameterName = node.identifier;
234 FieldElement field =
235 _fieldMap == null ? null : _fieldMap[parameterName.name];
236 FieldFormalParameterElementImpl parameter = 234 FieldFormalParameterElementImpl parameter =
237 new FieldFormalParameterElementImpl.forNode(parameterName); 235 new FieldFormalParameterElementImpl.forNode(parameterName);
238 _setCodeRange(parameter, node); 236 _setCodeRange(parameter, node);
237 _setFieldParameterField(node, parameter);
239 parameter.isConst = node.isConst; 238 parameter.isConst = node.isConst;
240 parameter.isExplicitlyCovariant = node.covariantKeyword != null; 239 parameter.isExplicitlyCovariant = node.covariantKeyword != null;
241 parameter.isFinal = node.isFinal; 240 parameter.isFinal = node.isFinal;
242 parameter.parameterKind = node.kind; 241 parameter.parameterKind = node.kind;
243 if (field != null) {
244 parameter.field = field;
245 }
246 _currentHolder.addParameter(parameter); 242 _currentHolder.addParameter(parameter);
247 parameterName.staticElement = parameter; 243 parameterName.staticElement = parameter;
248 } 244 }
249 // 245 //
250 // The children of this parameter include any parameters defined on the type 246 // The children of this parameter include any parameters defined on the type
251 // of this parameter. 247 // of this parameter.
252 // 248 //
253 ElementHolder holder = new ElementHolder(); 249 ElementHolder holder = new ElementHolder();
254 _visitChildren(holder, node); 250 _visitChildren(holder, node);
255 ParameterElementImpl element = node.element; 251 ParameterElementImpl element = node.element;
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 typeParameters[i] as TypeParameterElementImpl; 723 typeParameters[i] as TypeParameterElementImpl;
728 TypeParameterTypeImpl typeParameterType = 724 TypeParameterTypeImpl typeParameterType =
729 new TypeParameterTypeImpl(typeParameter); 725 new TypeParameterTypeImpl(typeParameter);
730 typeParameter.type = typeParameterType; 726 typeParameter.type = typeParameterType;
731 typeArguments[i] = typeParameterType; 727 typeArguments[i] = typeParameterType;
732 } 728 }
733 return typeArguments; 729 return typeArguments;
734 } 730 }
735 731
736 @override 732 @override
737 void _setFieldParameterField(FieldFormalParameterElementImpl parameter) { 733 void _setFieldParameterField(
738 FieldElement field = _fieldMap == null ? null : _fieldMap[parameter.name]; 734 FormalParameter node, FieldFormalParameterElementImpl element) {
739 if (field != null) { 735 if (node.parent?.parent is ConstructorDeclaration) {
740 parameter.field = field; 736 FieldElement field = _fieldMap == null ? null : _fieldMap[element.name];
737 if (field != null) {
738 element.field = field;
739 }
741 } 740 }
742 } 741 }
743 } 742 }
744 743
745 /** 744 /**
746 * A `CompilationUnitBuilder` builds an element model for a single compilation 745 * A `CompilationUnitBuilder` builds an element model for a single compilation
747 * unit. 746 * unit.
748 */ 747 */
749 class CompilationUnitBuilder { 748 class CompilationUnitBuilder {
750 /** 749 /**
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 } 1381 }
1383 1382
1384 @override 1383 @override
1385 Object visitDefaultFormalParameter(DefaultFormalParameter node) { 1384 Object visitDefaultFormalParameter(DefaultFormalParameter node) {
1386 NormalFormalParameter normalParameter = node.parameter; 1385 NormalFormalParameter normalParameter = node.parameter;
1387 SimpleIdentifier parameterName = normalParameter.identifier; 1386 SimpleIdentifier parameterName = normalParameter.identifier;
1388 ParameterElementImpl parameter; 1387 ParameterElementImpl parameter;
1389 if (normalParameter is FieldFormalParameter) { 1388 if (normalParameter is FieldFormalParameter) {
1390 DefaultFieldFormalParameterElementImpl fieldParameter = 1389 DefaultFieldFormalParameterElementImpl fieldParameter =
1391 new DefaultFieldFormalParameterElementImpl.forNode(parameterName); 1390 new DefaultFieldFormalParameterElementImpl.forNode(parameterName);
1392 _setFieldParameterField(fieldParameter); 1391 _setFieldParameterField(node, fieldParameter);
1393 parameter = fieldParameter; 1392 parameter = fieldParameter;
1394 } else { 1393 } else {
1395 parameter = new DefaultParameterElementImpl.forNode(parameterName); 1394 parameter = new DefaultParameterElementImpl.forNode(parameterName);
1396 } 1395 }
1397 _setCodeRange(parameter, node); 1396 _setCodeRange(parameter, node);
1398 parameter.isConst = node.isConst; 1397 parameter.isConst = node.isConst;
1399 parameter.isExplicitlyCovariant = node.parameter.covariantKeyword != null; 1398 parameter.isExplicitlyCovariant = node.parameter.covariantKeyword != null;
1400 parameter.isFinal = node.isFinal; 1399 parameter.isFinal = node.isFinal;
1401 parameter.parameterKind = node.kind; 1400 parameter.parameterKind = node.kind;
1402 // visible range 1401 // visible range
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 } else if (parent is MethodDeclaration) { 1508 } else if (parent is MethodDeclaration) {
1510 return parent.body; 1509 return parent.body;
1511 } 1510 }
1512 return null; 1511 return null;
1513 } 1512 }
1514 1513
1515 void _setCodeRange(ElementImpl element, AstNode node) { 1514 void _setCodeRange(ElementImpl element, AstNode node) {
1516 element.setCodeRange(node.offset, node.length); 1515 element.setCodeRange(node.offset, node.length);
1517 } 1516 }
1518 1517
1519 void _setFieldParameterField(FieldFormalParameterElementImpl parameter) {} 1518 void _setFieldParameterField(
1519 FormalParameter node, FieldFormalParameterElementImpl element) {}
1520 1520
1521 /** 1521 /**
1522 * Sets the visible source range for formal parameter. 1522 * Sets the visible source range for formal parameter.
1523 */ 1523 */
1524 void _setParameterVisibleRange( 1524 void _setParameterVisibleRange(
1525 FormalParameter node, ParameterElementImpl element) { 1525 FormalParameter node, ParameterElementImpl element) {
1526 FunctionBody body = _getFunctionBody(node); 1526 FunctionBody body = _getFunctionBody(node);
1527 if (body is BlockFunctionBody || body is ExpressionFunctionBody) { 1527 if (body is BlockFunctionBody || body is ExpressionFunctionBody) {
1528 element.setVisibleRange(body.offset, body.length); 1528 element.setVisibleRange(body.offset, body.length);
1529 } 1529 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 return null; 1626 return null;
1627 } 1627 }
1628 1628
1629 /** 1629 /**
1630 * Return the lexical identifiers associated with the given [identifiers]. 1630 * Return the lexical identifiers associated with the given [identifiers].
1631 */ 1631 */
1632 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { 1632 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) {
1633 return identifiers.map((identifier) => identifier.name).toList(); 1633 return identifiers.map((identifier) => identifier.name).toList();
1634 } 1634 }
1635 } 1635 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698