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

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2618923003: Update 'Add final field formal parameters' Quick Fix to support the new analysis driver. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/error/error.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/error_verifier.dart
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 91b072cf8238b31138601e2b4e988af54f301a4b..dff34027eadeec61808fa934d7b87999dd391743 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1659,28 +1659,24 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
});
if (notInitFinalFields.isNotEmpty) {
- AnalysisErrorWithProperties analysisError;
List<String> names = notInitFinalFields.map((item) => item.name).toList();
names.sort();
if (names.length == 1) {
- analysisError = _errorReporter.newErrorWithProperties(
+ _errorReporter.reportErrorForNode(
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1,
constructor.returnType,
names);
} else if (names.length == 2) {
- analysisError = _errorReporter.newErrorWithProperties(
+ _errorReporter.reportErrorForNode(
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2,
constructor.returnType,
names);
} else {
- analysisError = _errorReporter.newErrorWithProperties(
+ _errorReporter.reportErrorForNode(
StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS,
constructor.returnType,
[names[0], names[1], names.length - 2]);
}
- analysisError.setProperty(
- ErrorProperty.NOT_INITIALIZED_FIELDS, notInitFinalFields);
- _errorReporter.reportError(analysisError);
}
}
@@ -6655,6 +6651,45 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
/**
+ * Return [FieldElement]s that are declared in the [ClassDeclaration] with
+ * the given [constructor], but are not initialized.
+ */
+ static List<FieldElement> computeNotInitializedFields(
+ ConstructorDeclaration constructor) {
+ Set<FieldElement> fields = new Set<FieldElement>();
+ var classDeclaration = constructor.parent as ClassDeclaration;
+ for (ClassMember fieldDeclaration in classDeclaration.members) {
+ if (fieldDeclaration is FieldDeclaration) {
+ for (VariableDeclaration field in fieldDeclaration.fields.variables) {
+ if (field.initializer == null) {
+ fields.add(field.element);
+ }
+ }
+ }
+ }
+
+ List<FormalParameter> parameters = constructor.parameters?.parameters ?? [];
+ for (FormalParameter parameter in parameters) {
+ if (parameter is DefaultFormalParameter) {
+ parameter = (parameter as DefaultFormalParameter).parameter;
+ }
+ if (parameter is FieldFormalParameter) {
+ FieldFormalParameterElement element =
+ parameter.identifier.staticElement as FieldFormalParameterElement;
+ fields.remove(element.field);
+ }
+ }
+
+ for (ConstructorInitializer initializer in constructor.initializers) {
+ if (initializer is ConstructorFieldInitializer) {
+ fields.remove(initializer.fieldName.staticElement);
+ }
+ }
+
+ return fields.toList();
+ }
+
+ /**
* Return the static type of the given [expression] that is to be used for
* type analysis.
*/
« no previous file with comments | « pkg/analyzer/lib/error/error.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698