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

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 1480433002: Add support for assert statements with messages to the analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
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:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; 10 import 'package:analyzer/src/generated/static_type_analyzer.dart';
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 */ 259 */
260 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT; 260 List<InterfaceType> _DISALLOWED_TYPES_TO_EXTEND_OR_IMPLEMENT;
261 261
262 /** 262 /**
263 * If `true`, mixins are allowed to inherit from types other than Object, and 263 * If `true`, mixins are allowed to inherit from types other than Object, and
264 * are allowed to reference `super`. 264 * are allowed to reference `super`.
265 */ 265 */
266 final bool enableSuperMixins; 266 final bool enableSuperMixins;
267 267
268 /** 268 /**
269 * If `true`, asserts are allowed to take a second argument representing the
270 * assertion failure message (see DEP 37).
271 */
272 final bool enableAssertMessage;
273
274 /**
269 * Initialize a newly created error verifier. 275 * Initialize a newly created error verifier.
270 */ 276 */
271 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, 277 ErrorVerifier(
272 this._inheritanceManager, this.enableSuperMixins) { 278 this._errorReporter,
279 this._currentLibrary,
280 this._typeProvider,
281 this._inheritanceManager,
282 this.enableSuperMixins,
283 this.enableAssertMessage) {
273 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; 284 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary;
274 this._hasExtUri = _currentLibrary.hasExtUri; 285 this._hasExtUri = _currentLibrary.hasExtUri;
275 _isEnclosingConstructorConst = false; 286 _isEnclosingConstructorConst = false;
276 _isInCatchClause = false; 287 _isInCatchClause = false;
277 _isInStaticVariableDeclaration = false; 288 _isInStaticVariableDeclaration = false;
278 _isInInstanceVariableDeclaration = false; 289 _isInInstanceVariableDeclaration = false;
279 _isInInstanceVariableInitializer = false; 290 _isInInstanceVariableInitializer = false;
280 _isInConstructorInitializer = false; 291 _isInConstructorInitializer = false;
281 _isInStaticMethod = false; 292 _isInStaticMethod = false;
282 _boolType = _typeProvider.boolType; 293 _boolType = _typeProvider.boolType;
(...skipping 16 matching lines...) Expand all
299 310
300 @override 311 @override
301 Object visitAsExpression(AsExpression node) { 312 Object visitAsExpression(AsExpression node) {
302 _checkForTypeAnnotationDeferredClass(node.type); 313 _checkForTypeAnnotationDeferredClass(node.type);
303 return super.visitAsExpression(node); 314 return super.visitAsExpression(node);
304 } 315 }
305 316
306 @override 317 @override
307 Object visitAssertStatement(AssertStatement node) { 318 Object visitAssertStatement(AssertStatement node) {
308 _checkForNonBoolExpression(node); 319 _checkForNonBoolExpression(node);
320 _checkAssertMessage(node);
309 return super.visitAssertStatement(node); 321 return super.visitAssertStatement(node);
310 } 322 }
311 323
312 @override 324 @override
313 Object visitAssignmentExpression(AssignmentExpression node) { 325 Object visitAssignmentExpression(AssignmentExpression node) {
314 sc.TokenType operatorType = node.operator.type; 326 sc.TokenType operatorType = node.operator.type;
315 Expression lhs = node.leftHandSide; 327 Expression lhs = node.leftHandSide;
316 Expression rhs = node.rightHandSide; 328 Expression rhs = node.rightHandSide;
317 if (operatorType == sc.TokenType.EQ || 329 if (operatorType == sc.TokenType.EQ ||
318 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) { 330 operatorType == sc.TokenType.QUESTION_QUESTION_EQ) {
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; 1122 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR;
1111 } else { 1123 } else {
1112 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; 1124 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR;
1113 } 1125 }
1114 _errorReporter.reportErrorForNode(errorCode, node); 1126 _errorReporter.reportErrorForNode(errorCode, node);
1115 } 1127 }
1116 return super.visitYieldStatement(node); 1128 return super.visitYieldStatement(node);
1117 } 1129 }
1118 1130
1119 /** 1131 /**
1132 * If the given assert [statement] specifies a message, verify that support
1133 * for assertions with messages is enabled.
1134 */
1135 void _checkAssertMessage(AssertStatement statement) {
1136 Expression expression = statement.message;
1137 if (expression != null && !enableAssertMessage) {
1138 _errorReporter.reportErrorForNode(
1139 CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression);
1140 return;
1141 }
1142 }
1143
1144 /**
1120 * Verify that the given list of [typeArguments] contains exactly two 1145 * Verify that the given list of [typeArguments] contains exactly two
1121 * elements. 1146 * elements.
1122 * 1147 *
1123 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. 1148 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS].
1124 */ 1149 */
1125 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) { 1150 bool _checkExpectedTwoMapTypeArguments(TypeArgumentList typeArguments) {
1126 // check number of type arguments 1151 // check number of type arguments
1127 int num = typeArguments.arguments.length; 1152 int num = typeArguments.arguments.length;
1128 if (num == 2) { 1153 if (num == 2) {
1129 return false; 1154 return false;
(...skipping 4947 matching lines...) Expand 10 before | Expand all | Expand 10 after
6077 toCheck.add(type.element); 6102 toCheck.add(type.element);
6078 // type arguments 6103 // type arguments
6079 if (type is InterfaceType) { 6104 if (type is InterfaceType) {
6080 InterfaceType interfaceType = type; 6105 InterfaceType interfaceType = type;
6081 for (DartType typeArgument in interfaceType.typeArguments) { 6106 for (DartType typeArgument in interfaceType.typeArguments) {
6082 _addTypeToCheck(typeArgument); 6107 _addTypeToCheck(typeArgument);
6083 } 6108 }
6084 } 6109 }
6085 } 6110 }
6086 } 6111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698