44
55import 'package:analyzer/dart/ast/ast.dart' ;
66import 'package:analyzer/dart/ast/visitor.dart' ;
7- import 'package:analyzer/dart/element/element .dart' ;
7+ import 'package:analyzer/dart/element/element2 .dart' ;
88
99import '../analyzer.dart' ;
1010import '../extensions.dart' ;
@@ -32,14 +32,14 @@ Iterable<ConstructorFieldInitializer>
3232 ConstructorDeclaration node) =>
3333 node.initializers.whereType <ConstructorFieldInitializer >();
3434
35- Element ? _getLeftElement (AssignmentExpression assignment) =>
36- assignment.writeElement ? .canonicalElement ;
35+ Element2 ? _getLeftElement (AssignmentExpression assignment) =>
36+ assignment.writeElement2 ? .canonicalElement2 ;
3737
38- Iterable <Element ?> _getParameters (ConstructorDeclaration node) =>
39- node.parameters.parameters.map ((e) => e.declaredElement );
38+ Iterable <FormalParameterElement ?> _getParameters (ConstructorDeclaration node) =>
39+ node.parameters.parameters.map ((e) => e.declaredFragment ? .element );
4040
41- Element ? _getRightElement (AssignmentExpression assignment) =>
42- assignment.rightHandSide.canonicalElement ;
41+ Element2 ? _getRightElement (AssignmentExpression assignment) =>
42+ assignment.rightHandSide.canonicalElement2 ;
4343
4444class PreferInitializingFormals extends LintRule {
4545 PreferInitializingFormals ()
@@ -73,24 +73,24 @@ class _Visitor extends SimpleAstVisitor<void> {
7373 }
7474
7575 var parameters = _getParameters (node);
76- var parametersUsedOnce = < Element ? > {};
77- var parametersUsedMoreThanOnce = < Element ? > {};
76+ var parametersUsedOnce = < Element2 ? > {};
77+ var parametersUsedMoreThanOnce = < Element2 ? > {};
7878
7979 bool isAssignmentExpressionToLint (AssignmentExpression assignment) {
8080 var leftElement = _getLeftElement (assignment);
8181 var rightElement = _getRightElement (assignment);
8282 return leftElement != null &&
8383 rightElement != null &&
84- leftElement.name == rightElement.name &&
84+ leftElement.name3 == rightElement.name3 &&
8585 ! leftElement.isPrivate &&
86- leftElement is FieldElement &&
86+ leftElement is FieldElement2 &&
8787 ! leftElement.isSynthetic &&
88- leftElement.enclosingElement3 ==
89- node.declaredElement ? .enclosingElement3 &&
88+ leftElement.enclosingElement2 ==
89+ node.declaredFragment ? .element.enclosingElement2 &&
9090 parameters.contains (rightElement) &&
9191 (! parametersUsedMoreThanOnce.contains (rightElement) &&
92- ! (rightElement as ParameterElement ).isNamed ||
93- leftElement.name == rightElement.name );
92+ ! (rightElement as FormalParameterElement ).isNamed ||
93+ leftElement.name3 == rightElement.name3 );
9494 }
9595
9696 bool isConstructorFieldInitializerToLint (
@@ -101,28 +101,30 @@ class _Visitor extends SimpleAstVisitor<void> {
101101 if (fieldName.name != expression.name) {
102102 return false ;
103103 }
104- var staticElement = expression.staticElement ;
105- return staticElement is ParameterElement &&
106- ! (constructorFieldInitializer.fieldName.staticElement ? .isPrivate ??
104+ var staticElement = expression.element ;
105+ return staticElement is FormalParameterElement &&
106+ ! (constructorFieldInitializer.fieldName.element ? .isPrivate ??
107107 true ) &&
108108 parameters.contains (staticElement) &&
109- (! parametersUsedMoreThanOnce.contains (expression.staticElement ) &&
109+ (! parametersUsedMoreThanOnce.contains (expression.element ) &&
110110 ! staticElement.isNamed ||
111- (constructorFieldInitializer.fieldName.staticElement ? .name ==
112- expression.staticElement ? .name ));
111+ (constructorFieldInitializer.fieldName.element ? .name3 ==
112+ expression.element ? .name3 ));
113113 }
114114 return false ;
115115 }
116116
117- void processElement (Element ? element) {
117+ void processElement (Element2 ? element) {
118118 if (! parametersUsedOnce.add (element)) {
119119 parametersUsedMoreThanOnce.add (element);
120120 }
121121 }
122122
123- var parameterElements = node.parameters.parameterElements;
124- for (var parameter in parameterElements) {
125- if (parameter? .isInitializingFormal ?? false ) {
123+ for (var parameterFragment in node.parameters.parameterFragments) {
124+ if (parameterFragment == null ) continue ;
125+
126+ var parameter = parameterFragment.element;
127+ if (parameter.isInitializingFormal) {
126128 processElement (parameter);
127129 }
128130 }
@@ -137,8 +139,7 @@ class _Visitor extends SimpleAstVisitor<void> {
137139 var initializers = _getConstructorFieldInitializersInInitializers (node);
138140 for (var initializer in initializers) {
139141 if (isConstructorFieldInitializerToLint (initializer)) {
140- processElement (
141- (initializer.expression as SimpleIdentifier ).staticElement);
142+ processElement ((initializer.expression as SimpleIdentifier ).element);
142143 }
143144 }
144145
@@ -151,7 +152,7 @@ class _Visitor extends SimpleAstVisitor<void> {
151152
152153 for (var initializer in initializers) {
153154 if (isConstructorFieldInitializerToLint (initializer)) {
154- var name = initializer.fieldName.staticElement ! .name ! ;
155+ var name = initializer.fieldName.element ! .name3 ! ;
155156 rule.reportLint (initializer, arguments: [name]);
156157 }
157158 }
0 commit comments