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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 engine.resolver.error_verifier; 5 library engine.resolver.error_verifier;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 10 import 'package:analyzer/src/generated/static_type_analyzer.dart';
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 foundError = true; 1193 foundError = true;
1194 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { 1194 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) {
1195 _errorReporter.reportErrorForNode( 1195 _errorReporter.reportErrorForNode(
1196 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS, 1196 CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS,
1197 fieldName, [fieldElement.displayName]); 1197 fieldName, [fieldElement.displayName]);
1198 foundError = true; 1198 foundError = true;
1199 } 1199 }
1200 } 1200 }
1201 } 1201 }
1202 } 1202 }
1203 // Prepare a list of not initialized fields.
1204 List<FieldElement> notInitFinalFields = <FieldElement>[];
1205 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
1206 if (state == INIT_STATE.NOT_INIT) {
1207 if (fieldElement.isFinal) {
1208 notInitFinalFields.add(fieldElement);
1209 }
1210 }
1211 });
1203 // Visit all of the states in the map to ensure that none were never 1212 // Visit all of the states in the map to ensure that none were never
1204 // initialized. 1213 // initialized.
1205 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) { 1214 fieldElementsMap.forEach((FieldElement fieldElement, INIT_STATE state) {
1206 if (state == INIT_STATE.NOT_INIT) { 1215 if (state == INIT_STATE.NOT_INIT) {
1207 if (fieldElement.isConst) { 1216 if (fieldElement.isConst) {
1208 _errorReporter.reportErrorForNode( 1217 _errorReporter.reportErrorForNode(
1209 CompileTimeErrorCode.CONST_NOT_INITIALIZED, node.returnType, 1218 CompileTimeErrorCode.CONST_NOT_INITIALIZED, node.returnType,
1210 [fieldElement.name]); 1219 [fieldElement.name]);
1211 foundError = true; 1220 foundError = true;
1212 } else if (fieldElement.isFinal) {
1213 _errorReporter.reportErrorForNode(
1214 StaticWarningCode.FINAL_NOT_INITIALIZED, node.returnType,
1215 [fieldElement.name]);
1216 foundError = true;
1217 } 1221 }
1218 } 1222 }
1219 }); 1223 });
1224 if (notInitFinalFields.isNotEmpty) {
1225 foundError = true;
1226 if (notInitFinalFields.length == 1) {
1227 _errorReporter.reportErrorForNode(
1228 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_1,
1229 node.returnType, [notInitFinalFields[0].name],
1230 <ErrorProperty, Object>{
1231 ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
1232 });
1233 } else if (notInitFinalFields.length == 2) {
1234 _errorReporter.reportErrorForNode(
1235 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_2,
1236 node.returnType, [
1237 notInitFinalFields[0].name,
1238 notInitFinalFields[1].name
1239 ], <ErrorProperty, Object>{
1240 ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
1241 });
1242 } else {
1243 _errorReporter.reportErrorForNode(
1244 StaticWarningCode.FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS,
1245 node.returnType, [
1246 notInitFinalFields[0].name,
1247 notInitFinalFields[1].name,
1248 notInitFinalFields.length - 2
1249 ], <ErrorProperty, Object>{
1250 ErrorProperty.NOT_INITIALIZED_FIELDS: notInitFinalFields
1251 });
1252 }
1253 }
1220 return foundError; 1254 return foundError;
1221 } 1255 }
1222 1256
1223 /** 1257 /**
1224 * This checks the passed executable element against override-error codes. 1258 * This checks the passed executable element against override-error codes.
1225 * 1259 *
1226 * @param executableElement a non-null [ExecutableElement] to evaluate 1260 * @param executableElement a non-null [ExecutableElement] to evaluate
1227 * @param overriddenExecutable the element that the executableElement is overr iding 1261 * @param overriddenExecutable the element that the executableElement is overr iding
1228 * @param parameters the parameters of the executable element 1262 * @param parameters the parameters of the executable element
1229 * @param errorNameTarget the node to report problems on 1263 * @param errorNameTarget the node to report problems on
(...skipping 4911 matching lines...) Expand 10 before | Expand all | Expand 10 after
6141 toCheck.add(type.element); 6175 toCheck.add(type.element);
6142 // type arguments 6176 // type arguments
6143 if (type is InterfaceType) { 6177 if (type is InterfaceType) {
6144 InterfaceType interfaceType = type; 6178 InterfaceType interfaceType = type;
6145 for (DartType typeArgument in interfaceType.typeArguments) { 6179 for (DartType typeArgument in interfaceType.typeArguments) {
6146 _addTypeToCheck(typeArgument); 6180 _addTypeToCheck(typeArgument);
6147 } 6181 }
6148 } 6182 }
6149 } 6183 }
6150 } 6184 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698