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.dart.error.hint_codes; | 5 library analyzer.src.dart.error.hint_codes; |
6 | 6 |
7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
8 import 'package:analyzer/src/dart/element/element.dart'; | 8 import 'package:analyzer/src/dart/element/element.dart'; |
9 | 9 |
10 /** | 10 /** |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 "Duplicate import.", "Try removing all but one import of the library."); | 133 "Duplicate import.", "Try removing all but one import of the library."); |
134 | 134 |
135 /** | 135 /** |
136 * It is a bad practice for a source file in a package "lib" directory | 136 * It is a bad practice for a source file in a package "lib" directory |
137 * hierarchy to traverse outside that directory hierarchy. For example, a | 137 * hierarchy to traverse outside that directory hierarchy. For example, a |
138 * source file in the "lib" directory should not contain a directive such as | 138 * source file in the "lib" directory should not contain a directive such as |
139 * `import '../web/some.dart'` which references a file outside the lib | 139 * `import '../web/some.dart'` which references a file outside the lib |
140 * directory. | 140 * directory. |
141 */ | 141 */ |
142 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = | 142 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = |
143 const HintCode( | 143 const HintCode( |
144 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', | 144 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', |
145 "A file in the 'lib' directory shouldn't import a file outside the " | 145 "A file in the 'lib' directory shouldn't import a file outside the " |
146 "'lib' directory.", | 146 "'lib' directory.", |
147 "Try removing the import, or " | 147 "Try removing the import, or " |
148 "moving the imported file inside the 'lib' directory."); | 148 "moving the imported file inside the 'lib' directory."); |
149 | 149 |
150 /** | 150 /** |
151 * It is a bad practice for a source file ouside a package "lib" directory | 151 * It is a bad practice for a source file ouside a package "lib" directory |
152 * hierarchy to traverse into that directory hierarchy. For example, a source | 152 * hierarchy to traverse into that directory hierarchy. For example, a source |
153 * file in the "web" directory should not contain a directive such as | 153 * file in the "web" directory should not contain a directive such as |
154 * `import '../lib/some.dart'` which references a file inside the lib | 154 * `import '../lib/some.dart'` which references a file inside the lib |
155 * directory. | 155 * directory. |
156 */ | 156 */ |
157 static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = | 157 static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = |
158 const HintCode( | 158 const HintCode( |
159 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', | 159 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', |
160 "A file outside the 'lib' directory shouldn't reference a file " | 160 "A file outside the 'lib' directory shouldn't reference a file " |
161 "inside the 'lib' directory using a relative path.", | 161 "inside the 'lib' directory using a relative path.", |
162 "Try using a package: URI instead."); | 162 "Try using a package: URI instead."); |
163 | 163 |
164 /** | 164 /** |
165 * Deferred libraries shouldn't define a top level function 'loadLibrary'. | 165 * Deferred libraries shouldn't define a top level function 'loadLibrary'. |
166 */ | 166 */ |
167 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION = | 167 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION = |
168 const HintCode( | 168 const HintCode( |
169 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION', | 169 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION', |
170 "The library '{0}' defines a top-level function named 'loadLibrary' " | 170 "The library '{0}' defines a top-level function named 'loadLibrary' " |
171 "which is hidden by deferring this library.", | 171 "which is hidden by deferring this library.", |
172 "Try changing the import to not be deferred, or " | 172 "Try changing the import to not be deferred, or " |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 /** | 218 /** |
219 * Generic Method DEP: number of type parameters must match. | 219 * Generic Method DEP: number of type parameters must match. |
220 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> | 220 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> |
221 * | 221 * |
222 * Parameters: | 222 * Parameters: |
223 * 0: the number of type parameters in the method | 223 * 0: the number of type parameters in the method |
224 * 1: the number of type parameters in the overridden method | 224 * 1: the number of type parameters in the overridden method |
225 * 2: the name of the class where the overridden method is declared | 225 * 2: the name of the class where the overridden method is declared |
226 */ | 226 */ |
227 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS = | 227 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS = const HintCode
( |
228 const HintCode( | |
229 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS', | 228 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS', |
230 "The method has {0} type parameters, but it is overriding a method " | 229 "The method has {0} type parameters, but it is overriding a method " |
231 "with {1} type parameters from '{2}'.", | 230 "with {1} type parameters from '{2}'.", |
232 "Try changing the number of type parameters so that they are the same."); | 231 "Try changing the number of type parameters so that they are the same."); |
233 | 232 |
234 /** | 233 /** |
235 * Generic Method DEP: bounds of type parameters must be compatible. | 234 * Generic Method DEP: bounds of type parameters must be compatible. |
236 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> | 235 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> |
237 * | 236 * |
238 * Parameters: | 237 * Parameters: |
239 * 0: the type parameter name | 238 * 0: the type parameter name |
240 * 1: the type parameter bound | 239 * 1: the type parameter bound |
241 * 2: the overridden type parameter name | 240 * 2: the overridden type parameter name |
242 * 3: the overridden type parameter bound | 241 * 3: the overridden type parameter bound |
243 * 4: the name of the class where the overridden method is declared | 242 * 4: the name of the class where the overridden method is declared |
244 */ | 243 */ |
245 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND = | 244 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND = |
246 const HintCode( | 245 const HintCode( |
247 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND', | 246 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND', |
248 "The type parameter '{0}' extends '{1}', but that is stricter than " | 247 "The type parameter '{0}' extends '{1}', but that is stricter than " |
249 "'{2}' extends '{3}' in the overridden method from '{4}'.", | 248 "'{2}' extends '{3}' in the overridden method from '{4}'.", |
250 "Try changing the bounds on the type parameters so that they are compatibl
e."); | 249 "Try changing the bounds on the type parameters so that they are compa
tible."); |
251 | 250 |
252 /** | 251 /** |
253 * This hint is generated anywhere where a member annotated with `@protected` | 252 * This hint is generated anywhere where a member annotated with `@protected` |
254 * is used outside an instance member of a subclass. | 253 * is used outside an instance member of a subclass. |
255 * | 254 * |
256 * Parameters: | 255 * Parameters: |
257 * 0: the name of the member | 256 * 0: the name of the member |
258 * 1: the name of the defining class | 257 * 1: the name of the defining class |
259 */ | 258 */ |
260 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode( | 259 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode( |
261 'INVALID_USE_OF_PROTECTED_MEMBER', | 260 'INVALID_USE_OF_PROTECTED_MEMBER', |
262 "The member '{0}' can only be used within instance members of subclasses " | 261 "The member '{0}' can only be used within instance members of subclasses " |
263 "of '{1}'."); | 262 "of '{1}'."); |
264 | 263 |
265 /** | 264 /** |
266 * Hint for the `x is double` type checks. | 265 * Hint for the `x is double` type checks. |
267 */ | 266 */ |
268 static const HintCode IS_DOUBLE = const HintCode( | 267 static const HintCode IS_DOUBLE = const HintCode( |
269 'IS_DOUBLE', | 268 'IS_DOUBLE', |
270 "When compiled to JS, this test might return true when the left hand " | 269 "When compiled to JS, this test might return true when the left hand " |
271 "side is an int.", | 270 "side is an int.", |
272 "Try testing for 'num' instead."); | 271 "Try testing for 'num' instead."); |
273 | 272 |
274 /** | 273 /** |
275 * Hint for the `x is int` type checks. | 274 * Hint for the `x is int` type checks. |
276 */ | 275 */ |
277 static const HintCode IS_INT = const HintCode( | 276 static const HintCode IS_INT = const HintCode( |
278 'IS_INT', | 277 'IS_INT', |
279 "When compiled to JS, this test might return true when the left hand " | 278 "When compiled to JS, this test might return true when the left hand " |
280 "side is a double.", | 279 "side is a double.", |
281 "Try testing for 'num' instead."); | 280 "Try testing for 'num' instead."); |
282 | 281 |
283 /** | 282 /** |
284 * Hint for the `x is! double` type checks. | 283 * Hint for the `x is! double` type checks. |
285 */ | 284 */ |
286 static const HintCode IS_NOT_DOUBLE = const HintCode( | 285 static const HintCode IS_NOT_DOUBLE = const HintCode( |
287 'IS_NOT_DOUBLE', | 286 'IS_NOT_DOUBLE', |
288 "When compiled to JS, this test might return false when the left hand " | 287 "When compiled to JS, this test might return false when the left hand " |
289 "side is an int.", | 288 "side is an int.", |
290 "Try testing for 'num' instead."); | 289 "Try testing for 'num' instead."); |
291 | 290 |
292 /** | 291 /** |
293 * Hint for the `x is! int` type checks. | 292 * Hint for the `x is! int` type checks. |
294 */ | 293 */ |
295 static const HintCode IS_NOT_INT = const HintCode( | 294 static const HintCode IS_NOT_INT = const HintCode( |
296 'IS_NOT_INT', | 295 'IS_NOT_INT', |
297 "When compiled to JS, this test might return false when the left hand " | 296 "When compiled to JS, this test might return false when the left hand " |
298 "side is a double.", | 297 "side is a double.", |
299 "Try testing for 'num' instead."); | 298 "Try testing for 'num' instead."); |
300 | 299 |
301 /** | 300 /** |
302 * Generate a hint for an element that is annotated with `@JS(...)` whose | 301 * Generate a hint for an element that is annotated with `@JS(...)` whose |
303 * library declaration is not similarly annotated. | 302 * library declaration is not similarly annotated. |
304 */ | 303 */ |
305 static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode( | 304 static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode( |
306 'MISSING_JS_LIB_ANNOTATION', | 305 'MISSING_JS_LIB_ANNOTATION', |
307 "The @JS() annotation can only be used if it is also declared on the " | 306 "The @JS() annotation can only be used if it is also declared on the " |
308 "library directive.", | 307 "library directive.", |
309 "Try adding the annotation to the library directive."); | 308 "Try adding the annotation to the library directive."); |
310 | 309 |
311 /** | 310 /** |
312 * Generate a hint for a constructor, function or method invocation where a | 311 * Generate a hint for a constructor, function or method invocation where a |
313 * required parameter is missing. | 312 * required parameter is missing. |
314 * | 313 * |
315 * Parameters: | 314 * Parameters: |
316 * 0: the name of the parameter | 315 * 0: the name of the parameter |
317 */ | 316 */ |
318 static const HintCode MISSING_REQUIRED_PARAM = const HintCode( | 317 static const HintCode MISSING_REQUIRED_PARAM = const HintCode( |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 'UNNECESSARY_TYPE_CHECK_TRUE', | 544 'UNNECESSARY_TYPE_CHECK_TRUE', |
546 "Unnecessary type check, the result is always true.", | 545 "Unnecessary type check, the result is always true.", |
547 "Try correcting the type check, or removing the type check."); | 546 "Try correcting the type check, or removing the type check."); |
548 | 547 |
549 /** | 548 /** |
550 * Unused catch exception variables. | 549 * Unused catch exception variables. |
551 */ | 550 */ |
552 static const HintCode UNUSED_CATCH_CLAUSE = const HintCode( | 551 static const HintCode UNUSED_CATCH_CLAUSE = const HintCode( |
553 'UNUSED_CATCH_CLAUSE', | 552 'UNUSED_CATCH_CLAUSE', |
554 "The exception variable '{0}' isn't used, so the 'catch' clause can be rem
oved.", | 553 "The exception variable '{0}' isn't used, so the 'catch' clause can be rem
oved.", |
555 // TODO(brianwilkerson) Split this error code so that we can differentiate | 554 // TODO(brianwilkerson) Split this error code so that we can differentiate |
556 // between removing the catch clause and replacing the catch clause with | 555 // between removing the catch clause and replacing the catch clause with |
557 // an on clause. | 556 // an on clause. |
558 "Try removing the catch clause."); | 557 "Try removing the catch clause."); |
559 | 558 |
560 /** | 559 /** |
561 * Unused catch stack trace variables. | 560 * Unused catch stack trace variables. |
562 */ | 561 */ |
563 static const HintCode UNUSED_CATCH_STACK = const HintCode( | 562 static const HintCode UNUSED_CATCH_STACK = const HintCode( |
564 'UNUSED_CATCH_STACK', | 563 'UNUSED_CATCH_STACK', |
565 "The stack trace variable '{0}' isn't used and can be removed.", | 564 "The stack trace variable '{0}' isn't used and can be removed.", |
566 "Try removing the stack trace variable, or using it."); | 565 "Try removing the stack trace variable, or using it."); |
567 | 566 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 613 |
615 /** | 614 /** |
616 * It will be a static type warning if <i>m</i> is not a generic method with | 615 * It will be a static type warning if <i>m</i> is not a generic method with |
617 * exactly <i>n</i> type parameters. | 616 * exactly <i>n</i> type parameters. |
618 * | 617 * |
619 * Parameters: | 618 * Parameters: |
620 * 0: the name of the method being referenced (<i>G</i>) | 619 * 0: the name of the method being referenced (<i>G</i>) |
621 * 1: the number of type parameters that were declared | 620 * 1: the number of type parameters that were declared |
622 * 2: the number of type arguments provided | 621 * 2: the number of type arguments provided |
623 */ | 622 */ |
624 static const HintCode WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD = | 623 static const HintCode WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD = const HintCode( |
625 const HintCode( | |
626 'WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD', | 624 'WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD', |
627 "The method '{0}' is declared with {1} type parameters, " | 625 "The method '{0}' is declared with {1} type parameters, " |
628 "but {2} type arguments were given.", | 626 "but {2} type arguments were given.", |
629 "Try adjusting the number of type arguments."); | 627 "Try adjusting the number of type arguments."); |
630 | 628 |
631 /** | 629 /** |
632 * Initialize a newly created error code to have the given [name]. The message | 630 * Initialize a newly created error code to have the given [name]. The message |
633 * associated with the error will be created from the given [message] | 631 * associated with the error will be created from the given [message] |
634 * template. The correction associated with the error will be created from the | 632 * template. The correction associated with the error will be created from the |
635 * given [correction] template. | 633 * given [correction] template. |
636 */ | 634 */ |
637 const HintCode(String name, String message, [String correction]) | 635 const HintCode(String name, String message, [String correction]) |
638 : super(name, message, correction); | 636 : super(name, message, correction); |
639 | 637 |
640 @override | 638 @override |
641 ErrorSeverity get errorSeverity => ErrorType.HINT.severity; | 639 ErrorSeverity get errorSeverity => ErrorType.HINT.severity; |
642 | 640 |
643 @override | 641 @override |
644 ErrorType get type => ErrorType.HINT; | 642 ErrorType get type => ErrorType.HINT; |
645 } | 643 } |
OLD | NEW |