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

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

Issue 1004793003: Add NOT_INITIALIZED_FIELDS property for FINAL_NOT_INITIALIZED_CONSTRUCTOR_X. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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
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 e50f9dcee4579ab5067b96af00a81a6efa73a424..d4bcc301fc9d57616f9cca5db50812b5b98fc17b 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1200,6 +1200,15 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
}
}
}
+ // Prepare a list of not initialized fields.
+ List<FieldElement> notInitFinalFields = <FieldElement>[];
+ fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
+ if (state == INIT_STATE.NOT_INIT) {
+ if (fieldElement.isFinal) {
+ notInitFinalFields.add(fieldElement);
+ }
+ }
+ });
// Visit all of the states in the map to ensure that none were never
// initialized.
fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
@@ -1209,14 +1218,39 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
CompileTimeErrorCode.CONST_NOT_INITIALIZED, node.returnType,
[fieldElement.name]);
foundError = true;
- } else if (fieldElement.isFinal) {
- _errorReporter.reportErrorForNode(
- StaticWarningCode.FINAL_NOT_INITIALIZED, node.returnType,
- [fieldElement.name]);
- foundError = true;
}
}
});
+ if (notInitFinalFields.isNotEmpty) {
+ foundError = true;
+ if (notInitFinalFields.length == 1) {
+ _errorReporter.reportErrorForNode(
+ StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1,
+ node.returnType, [notInitFinalFields[0].name],
+ <ErrorProperty, Object>{
+ ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
+ });
+ } else if (notInitFinalFields.length == 2) {
+ _errorReporter.reportErrorForNode(
+ StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2,
+ node.returnType, [
+ notInitFinalFields[0].name,
+ notInitFinalFields[1].name
+ ], <ErrorProperty, Object>{
+ ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
+ });
+ } else {
+ _errorReporter.reportErrorForNode(
+ StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS,
+ node.returnType, [
+ notInitFinalFields[0].name,
+ notInitFinalFields[1].name,
+ notInitFinalFields.length - 2
+ ], <ErrorProperty, Object>{
+ ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
+ });
+ }
+ }
return foundError;
}

Powered by Google App Engine
This is Rietveld 408576698