| OLD | NEW |
| 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 analyzer.src.generated.error; | 5 library analyzer.src.generated.error; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart' show AstNode; | 9 import 'package:analyzer/dart/ast/ast.dart' show AstNode; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| 11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
| 12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
| 13 import 'package:analyzer/source/error_processor.dart'; | 13 import 'package:analyzer/source/error_processor.dart'; |
| 14 import 'package:analyzer/src/dart/element/type.dart'; |
| 14 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; | 15 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; |
| 15 import 'package:analyzer/src/generated/generated/shared_messages.dart' | 16 import 'package:analyzer/src/generated/generated/shared_messages.dart' |
| 16 as shared_messages; | 17 as shared_messages; |
| 17 import 'package:analyzer/src/generated/java_core.dart'; | 18 import 'package:analyzer/src/generated/java_core.dart'; |
| 18 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 19 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 19 import 'package:analyzer/src/generated/source.dart'; | 20 import 'package:analyzer/src/generated/source.dart'; |
| 20 import 'package:analyzer/src/task/model.dart'; | 21 import 'package:analyzer/src/task/model.dart'; |
| 21 import 'package:analyzer/task/model.dart'; | 22 import 'package:analyzer/task/model.dart'; |
| 22 import 'package:source_span/source_span.dart'; | 23 import 'package:source_span/source_span.dart'; |
| 23 | 24 |
| (...skipping 3208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3232 } | 3233 } |
| 3233 | 3234 |
| 3234 /** | 3235 /** |
| 3235 * Given an array of [arguments] that is expected to contain two or more | 3236 * Given an array of [arguments] that is expected to contain two or more |
| 3236 * types, convert the types into strings by using the display names of the | 3237 * types, convert the types into strings by using the display names of the |
| 3237 * types, unless there are two or more types with the same names, in which | 3238 * types, unless there are two or more types with the same names, in which |
| 3238 * case the extended display names of the types will be used in order to | 3239 * case the extended display names of the types will be used in order to |
| 3239 * clarify the message. | 3240 * clarify the message. |
| 3240 */ | 3241 */ |
| 3241 void _convertTypeNames(List<Object> arguments) { | 3242 void _convertTypeNames(List<Object> arguments) { |
| 3243 String displayName(DartType type) { |
| 3244 if (type is FunctionType) { |
| 3245 String name = type.name; |
| 3246 if (name != null && name.length > 0) { |
| 3247 StringBuffer buffer = new StringBuffer(); |
| 3248 buffer.write(name); |
| 3249 (type as TypeImpl).appendTo(buffer); |
| 3250 return buffer.toString(); |
| 3251 } |
| 3252 } |
| 3253 return type.displayName; |
| 3254 } |
| 3242 if (_hasEqualTypeNames(arguments)) { | 3255 if (_hasEqualTypeNames(arguments)) { |
| 3243 int count = arguments.length; | 3256 int count = arguments.length; |
| 3244 for (int i = 0; i < count; i++) { | 3257 for (int i = 0; i < count; i++) { |
| 3245 Object argument = arguments[i]; | 3258 Object argument = arguments[i]; |
| 3246 if (argument is DartType) { | 3259 if (argument is DartType) { |
| 3247 DartType type = argument; | 3260 DartType type = argument; |
| 3248 Element element = type.element; | 3261 Element element = type.element; |
| 3249 if (element == null) { | 3262 if (element == null) { |
| 3250 arguments[i] = type.displayName; | 3263 arguments[i] = displayName(type); |
| 3251 } else { | 3264 } else { |
| 3252 arguments[i] = element.getExtendedDisplayName(type.displayName); | 3265 arguments[i] = element.getExtendedDisplayName(displayName(type)); |
| 3253 } | 3266 } |
| 3254 } | 3267 } |
| 3255 } | 3268 } |
| 3256 } else { | 3269 } else { |
| 3257 int count = arguments.length; | 3270 int count = arguments.length; |
| 3258 for (int i = 0; i < count; i++) { | 3271 for (int i = 0; i < count; i++) { |
| 3259 Object argument = arguments[i]; | 3272 Object argument = arguments[i]; |
| 3260 if (argument is DartType) { | 3273 if (argument is DartType) { |
| 3261 arguments[i] = argument.displayName; | 3274 arguments[i] = displayName(argument); |
| 3262 } | 3275 } |
| 3263 } | 3276 } |
| 3264 } | 3277 } |
| 3265 } | 3278 } |
| 3266 | 3279 |
| 3267 /** | 3280 /** |
| 3268 * Return `true` if the given array of [arguments] contains two or more types | 3281 * Return `true` if the given array of [arguments] contains two or more types |
| 3269 * with the same display name. | 3282 * with the same display name. |
| 3270 */ | 3283 */ |
| 3271 bool _hasEqualTypeNames(List<Object> arguments) { | 3284 bool _hasEqualTypeNames(List<Object> arguments) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3571 /** | 3584 /** |
| 3572 * Generate a hint for methods that override methods annotated `@mustCallSuper
` | 3585 * Generate a hint for methods that override methods annotated `@mustCallSuper
` |
| 3573 * that do not invoke the overridden super method. | 3586 * that do not invoke the overridden super method. |
| 3574 * | 3587 * |
| 3575 * Parameters: | 3588 * Parameters: |
| 3576 * 0: the name of the class declaring the overriden method | 3589 * 0: the name of the class declaring the overriden method |
| 3577 */ | 3590 */ |
| 3578 static const HintCode MUST_CALL_SUPER = const HintCode( | 3591 static const HintCode MUST_CALL_SUPER = const HintCode( |
| 3579 'MUST_CALL_SUPER', | 3592 'MUST_CALL_SUPER', |
| 3580 "This method overrides a method annotated as @mustCall super in '{0}', " | 3593 "This method overrides a method annotated as @mustCall super in '{0}', " |
| 3581 "but does invoke the overriden method"); | 3594 "but does invoke the overriden method"); |
| 3582 | 3595 |
| 3583 /** | 3596 /** |
| 3584 * A condition in a control flow statement could evaluate to `null` because it | 3597 * A condition in a control flow statement could evaluate to `null` because it |
| 3585 * uses the null-aware '?.' operator. | 3598 * uses the null-aware '?.' operator. |
| 3586 */ | 3599 */ |
| 3587 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode( | 3600 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode( |
| 3588 'NULL_AWARE_IN_CONDITION', | 3601 'NULL_AWARE_IN_CONDITION', |
| 3589 "The value of the '?.' operator can be 'null', which is not appropriate in
a condition", | 3602 "The value of the '?.' operator can be 'null', which is not appropriate in
a condition", |
| 3590 "Replace the '?.' with a '.', testing the left-hand side for null if neces
sary"); | 3603 "Replace the '?.' with a '.', testing the left-hand side for null if neces
sary"); |
| 3591 | 3604 |
| (...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4399 | 4412 |
| 4400 /** | 4413 /** |
| 4401 * 17.6.2 For-in. If the iterable expression does not implement Iterable, | 4414 * 17.6.2 For-in. If the iterable expression does not implement Iterable, |
| 4402 * this warning is reported. | 4415 * this warning is reported. |
| 4403 * | 4416 * |
| 4404 * Parameters: | 4417 * Parameters: |
| 4405 * 0: The type of the iterable expression. | 4418 * 0: The type of the iterable expression. |
| 4406 * 1: The sequence type -- Iterable for `for` or Stream for `await for`. | 4419 * 1: The sequence type -- Iterable for `for` or Stream for `await for`. |
| 4407 */ | 4420 */ |
| 4408 static const StaticTypeWarningCode FOR_IN_OF_INVALID_TYPE = | 4421 static const StaticTypeWarningCode FOR_IN_OF_INVALID_TYPE = |
| 4409 const StaticTypeWarningCode('FOR_IN_OF_INVALID_TYPE', | 4422 const StaticTypeWarningCode('FOR_IN_OF_INVALID_TYPE', |
| 4410 "The type '{0}' used in the 'for' loop must implement {1}"); | 4423 "The type '{0}' used in the 'for' loop must implement {1}"); |
| 4411 | 4424 |
| 4412 /** | 4425 /** |
| 4413 * 17.6.2 For-in. It the iterable expression does not implement Iterable with | 4426 * 17.6.2 For-in. It the iterable expression does not implement Iterable with |
| 4414 * a type argument that can be assigned to the for-in variable's type, this | 4427 * a type argument that can be assigned to the for-in variable's type, this |
| 4415 * warning is reported. | 4428 * warning is reported. |
| 4416 * | 4429 * |
| 4417 * Parameters: | 4430 * Parameters: |
| 4418 * 0: The type of the iterable expression. | 4431 * 0: The type of the iterable expression. |
| 4419 * 1: The sequence type -- Iterable for `for` or Stream for `await for`. | 4432 * 1: The sequence type -- Iterable for `for` or Stream for `await for`. |
| 4420 * 2: The loop variable type. | 4433 * 2: The loop variable type. |
| (...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5731 * Initialize a newly created error code to have the given [name]. | 5744 * Initialize a newly created error code to have the given [name]. |
| 5732 */ | 5745 */ |
| 5733 const TodoCode(String name) : super(name, "{0}"); | 5746 const TodoCode(String name) : super(name, "{0}"); |
| 5734 | 5747 |
| 5735 @override | 5748 @override |
| 5736 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 5749 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
| 5737 | 5750 |
| 5738 @override | 5751 @override |
| 5739 ErrorType get type => ErrorType.TODO; | 5752 ErrorType get type => ErrorType.TODO; |
| 5740 } | 5753 } |
| OLD | NEW |