Chromium Code Reviews| 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 engine.error; | 5 library engine.error; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart' show AstNode; | 9 import 'ast.dart' show AstNode; |
| 10 import 'element.dart'; | 10 import 'element.dart'; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 * The properties associated with this error. | 229 * The properties associated with this error. |
| 230 */ | 230 */ |
| 231 HashMap<ErrorProperty, Object> _propertyMap = | 231 HashMap<ErrorProperty, Object> _propertyMap = |
| 232 new HashMap<ErrorProperty, Object>(); | 232 new HashMap<ErrorProperty, Object>(); |
| 233 | 233 |
| 234 /** | 234 /** |
| 235 * Initialize a newly created analysis error for the specified [source]. The | 235 * Initialize a newly created analysis error for the specified [source]. The |
| 236 * error will have the given [errorCode] and the list of [arguments] will be | 236 * error will have the given [errorCode] and the list of [arguments] will be |
| 237 * used to complete the message. The error has no location information. | 237 * used to complete the message. The error has no location information. |
| 238 */ | 238 */ |
| 239 AnalysisErrorWithProperties.con1( | 239 AnalysisErrorWithProperties.con1(Source source, ErrorCode errorCode, |
| 240 Source source, ErrorCode errorCode, [List<Object> arguments]) | 240 [List<Object> arguments]) |
| 241 : super.con1(source, errorCode, arguments); | 241 : super.con1(source, errorCode, arguments); |
| 242 | 242 |
| 243 /** | 243 /** |
| 244 * Initialize a newly created analysis error for the specified [source] at the | 244 * Initialize a newly created analysis error for the specified [source] at the |
| 245 * given [offset] with the given [length]. The error will have the given | 245 * given [offset] with the given [length]. The error will have the given |
| 246 * [errorCode] and the list of [arguments] will be used to complete the | 246 * [errorCode] and the list of [arguments] will be used to complete the |
| 247 * message. | 247 * message. |
| 248 */ | 248 */ |
| 249 AnalysisErrorWithProperties.con2(Source source, int offset, int length, | 249 AnalysisErrorWithProperties.con2( |
| 250 ErrorCode errorCode, [List<Object> arguments]) | 250 Source source, int offset, int length, ErrorCode errorCode, |
| 251 [List<Object> arguments]) | |
| 251 : super.con2(source, offset, length, errorCode, arguments); | 252 : super.con2(source, offset, length, errorCode, arguments); |
| 252 | 253 |
| 253 @override | 254 @override |
| 254 Object getProperty(ErrorProperty property) => _propertyMap[property]; | 255 Object getProperty(ErrorProperty property) => _propertyMap[property]; |
| 255 | 256 |
| 256 /** | 257 /** |
| 257 * Set the value of the given [property] to the given [value]. Using a value | 258 * Set the value of the given [property] to the given [value]. Using a value |
| 258 * of `null` will effectively remove the property from this error. | 259 * of `null` will effectively remove the property from this error. |
| 259 */ | 260 */ |
| 260 void setProperty(ErrorProperty property, Object value) { | 261 void setProperty(ErrorProperty property, Object value) { |
| (...skipping 2109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2370 * The unique name of this error code. | 2371 * The unique name of this error code. |
| 2371 */ | 2372 */ |
| 2372 String get uniqueName => "$runtimeType.$name"; | 2373 String get uniqueName => "$runtimeType.$name"; |
| 2373 } | 2374 } |
| 2374 | 2375 |
| 2375 /** | 2376 /** |
| 2376 * The properties that can be associated with an [AnalysisError]. | 2377 * The properties that can be associated with an [AnalysisError]. |
| 2377 */ | 2378 */ |
| 2378 class ErrorProperty extends Enum<ErrorProperty> { | 2379 class ErrorProperty extends Enum<ErrorProperty> { |
| 2379 /** | 2380 /** |
| 2381 * A property whose value is a list of [FieldElement]s that are final, but | |
| 2382 * not initialized by a constructor. | |
| 2383 */ | |
| 2384 static const ErrorProperty NOT_INITIALIZED_FIELDS = | |
| 2385 const ErrorProperty('NOT_INITIALIZED_FIELDS', 0); | |
| 2386 | |
| 2387 /** | |
| 2380 * A property whose value is the name of the library that is used by all | 2388 * A property whose value is the name of the library that is used by all |
| 2381 * of the "part of" directives, so should be used in the "library" directive. | 2389 * of the "part of" directives, so should be used in the "library" directive. |
| 2382 * Is `null` if there is no a single name used by all of the parts. | 2390 * Is `null` if there is no a single name used by all of the parts. |
| 2383 */ | 2391 */ |
| 2384 static const ErrorProperty PARTS_LIBRARY_NAME = | 2392 static const ErrorProperty PARTS_LIBRARY_NAME = |
| 2385 const ErrorProperty('PARTS_LIBRARY_NAME', 0); | 2393 const ErrorProperty('PARTS_LIBRARY_NAME', 1); |
| 2386 | 2394 |
| 2387 /** | 2395 /** |
| 2388 * A property whose value is a list of [ExecutableElement] that should | 2396 * A property whose value is a list of [ExecutableElement] that should |
| 2389 * be but are not implemented by a concrete class. | 2397 * be but are not implemented by a concrete class. |
| 2390 */ | 2398 */ |
| 2391 static const ErrorProperty UNIMPLEMENTED_METHODS = | 2399 static const ErrorProperty UNIMPLEMENTED_METHODS = |
| 2392 const ErrorProperty('UNIMPLEMENTED_METHODS', 1); | 2400 const ErrorProperty('UNIMPLEMENTED_METHODS', 2); |
| 2393 | 2401 |
| 2394 static const List<ErrorProperty> values = const [ | 2402 static const List<ErrorProperty> values = const [ |
| 2395 PARTS_LIBRARY_NAME, | 2403 PARTS_LIBRARY_NAME, |
| 2396 UNIMPLEMENTED_METHODS | 2404 UNIMPLEMENTED_METHODS |
| 2397 ]; | 2405 ]; |
| 2398 | 2406 |
| 2399 const ErrorProperty(String name, int ordinal) : super(name, ordinal); | 2407 const ErrorProperty(String name, int ordinal) : super(name, ordinal); |
| 2400 } | 2408 } |
| 2401 | 2409 |
| 2402 /** | 2410 /** |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2463 * Report an error with the given [errorCode] and [arguments]. The [element] | 2471 * Report an error with the given [errorCode] and [arguments]. The [element] |
| 2464 * is used to compute the location of the error. | 2472 * is used to compute the location of the error. |
| 2465 */ | 2473 */ |
| 2466 void reportErrorForElement( | 2474 void reportErrorForElement( |
| 2467 ErrorCode errorCode, Element element, List<Object> arguments) { | 2475 ErrorCode errorCode, Element element, List<Object> arguments) { |
| 2468 reportErrorForOffset( | 2476 reportErrorForOffset( |
| 2469 errorCode, element.nameOffset, element.displayName.length, arguments); | 2477 errorCode, element.nameOffset, element.displayName.length, arguments); |
| 2470 } | 2478 } |
| 2471 | 2479 |
| 2472 /** | 2480 /** |
| 2473 * Report an error with the given [errorCode] and [arguments]. The [node] is | 2481 * Report an error with the given [errorCode] and [arguments]. |
| 2474 * used to compute the location of the error. | 2482 * The [node] is used to compute the location of the error. |
| 2475 * | 2483 * |
| 2476 * If the arguments contain the names of two or more types, the method | 2484 * If the arguments contain the names of two or more types, the method |
| 2477 * [reportTypeErrorForNode] should be used and the types | 2485 * [reportTypeErrorForNode] should be used and the types |
| 2478 * themselves (rather than their names) should be passed as arguments. | 2486 * themselves (rather than their names) should be passed as arguments. |
| 2487 * | |
| 2488 * If optional [properties] are present, then [AnalysisErrorWithProperties] | |
| 2489 * is reported. | |
| 2479 */ | 2490 */ |
| 2480 void reportErrorForNode(ErrorCode errorCode, AstNode node, | 2491 void reportErrorForNode(ErrorCode errorCode, AstNode node, |
| 2481 [List<Object> arguments]) { | 2492 [List<Object> arguments, Map<ErrorProperty, Object> properties]) { |
| 2482 reportErrorForOffset(errorCode, node.offset, node.length, arguments); | 2493 reportErrorForOffset(errorCode, node.offset, node.length, arguments); |
|
Brian Wilkerson
2015/03/16 17:27:02
Add ", properties" to argument list?
| |
| 2483 } | 2494 } |
| 2484 | 2495 |
| 2485 /** | 2496 /** |
| 2486 * Report an error with the given [errorCode] and [arguments]. The location of | 2497 * Report an error with the given [errorCode] and [arguments]. The location of |
| 2487 * the error is specified by the given [offset] and [length]. | 2498 * the error is specified by the given [offset] and [length]. |
| 2499 * | |
| 2500 * If optional [properties] are present, then [AnalysisErrorWithProperties] | |
| 2501 * is reported. | |
| 2488 */ | 2502 */ |
| 2489 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, | 2503 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, |
| 2490 [List<Object> arguments]) { | 2504 [List<Object> arguments, Map<ErrorProperty, Object> properties]) { |
| 2491 _errorListener.onError( | 2505 if (properties != null && properties.isNotEmpty) { |
| 2492 new AnalysisError.con2(_source, offset, length, errorCode, arguments)); | 2506 AnalysisErrorWithProperties errorWithProperties = |
| 2507 new AnalysisErrorWithProperties.con2( | |
| 2508 _source, offset, length, errorCode, arguments); | |
| 2509 properties.forEach((property, value) { | |
| 2510 return errorWithProperties.setProperty(property, value); | |
|
Brian Wilkerson
2015/03/16 17:27:02
Remove "return ".
| |
| 2511 }); | |
| 2512 _errorListener.onError(errorWithProperties); | |
| 2513 } else { | |
| 2514 _errorListener.onError(new AnalysisError.con2( | |
| 2515 _source, offset, length, errorCode, arguments)); | |
| 2516 } | |
| 2493 } | 2517 } |
| 2494 | 2518 |
| 2495 /** | 2519 /** |
| 2496 * Report an error with the given [errorCode] and [arguments]. The [token] is | 2520 * Report an error with the given [errorCode] and [arguments]. The [token] is |
| 2497 * used to compute the location of the error. | 2521 * used to compute the location of the error. |
| 2498 */ | 2522 */ |
| 2499 void reportErrorForToken(ErrorCode errorCode, Token token, | 2523 void reportErrorForToken(ErrorCode errorCode, Token token, |
| 2500 [List<Object> arguments]) { | 2524 [List<Object> arguments]) { |
| 2501 reportErrorForOffset(errorCode, token.offset, token.length, arguments); | 2525 reportErrorForOffset(errorCode, token.offset, token.length, arguments); |
| 2502 } | 2526 } |
| (...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3921 */ | 3945 */ |
| 3922 static const StaticWarningCode FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE = | 3946 static const StaticWarningCode FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE = |
| 3923 const StaticWarningCode('FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE', | 3947 const StaticWarningCode('FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE', |
| 3924 "The parameter type '{0}' is incompatable with the field type '{1}'"); | 3948 "The parameter type '{0}' is incompatable with the field type '{1}'"); |
| 3925 | 3949 |
| 3926 /** | 3950 /** |
| 3927 * 5 Variables: It is a static warning if a library, static or local variable | 3951 * 5 Variables: It is a static warning if a library, static or local variable |
| 3928 * <i>v</i> is final and <i>v</i> is not initialized at its point of | 3952 * <i>v</i> is final and <i>v</i> is not initialized at its point of |
| 3929 * declaration. | 3953 * declaration. |
| 3930 * | 3954 * |
| 3955 * Parameters: | |
| 3956 * 0: the name of the uninitialized final variable | |
| 3957 */ | |
| 3958 static const StaticWarningCode FINAL_NOT_INITIALIZED = | |
| 3959 const StaticWarningCode('FINAL_NOT_INITIALIZED', | |
| 3960 "The final variable '{0}' must be initialized"); | |
| 3961 | |
| 3962 /** | |
| 3931 * 7.6.1 Generative Constructors: Each final instance variable <i>f</i> | 3963 * 7.6.1 Generative Constructors: Each final instance variable <i>f</i> |
| 3932 * declared in the immediately enclosing class must have an initializer in | 3964 * declared in the immediately enclosing class must have an initializer in |
| 3933 * <i>k</i>'s initializer list unless it has already been initialized by one | 3965 * <i>k</i>'s initializer list unless it has already been initialized by one |
| 3934 * of the following means: | 3966 * of the following means: |
| 3935 * * Initialization at the declaration of <i>f</i>. | 3967 * * Initialization at the declaration of <i>f</i>. |
| 3936 * * Initialization by means of an initializing formal of <i>k</i>. | 3968 * * Initialization by means of an initializing formal of <i>k</i>. |
| 3937 * or a static warning occurs. | 3969 * or a static warning occurs. |
| 3938 * | 3970 * |
| 3939 * Parameters: | 3971 * Parameters: |
| 3940 * 0: the name of the uninitialized final variable | 3972 * 0: the name of the uninitialized final variable |
| 3941 */ | 3973 */ |
| 3942 static const StaticWarningCode FINAL_NOT_INITIALIZED = | 3974 static const StaticWarningCode FINAL_NOT_INITIALIZED_CONSTRUCTOR_1 = |
| 3943 const StaticWarningCode('FINAL_NOT_INITIALIZED', | 3975 const StaticWarningCode('FINAL_NOT_INITIALIZED_CONSTRUCTOR_1', |
| 3944 "The final variable '{0}' must be initialized"); | 3976 "The final variable '{0}' must be initialized"); |
| 3945 | 3977 |
| 3946 /** | 3978 /** |
| 3979 * 7.6.1 Generative Constructors: Each final instance variable <i>f</i> | |
| 3980 * declared in the immediately enclosing class must have an initializer in | |
| 3981 * <i>k</i>'s initializer list unless it has already been initialized by one | |
| 3982 * of the following means: | |
| 3983 * * Initialization at the declaration of <i>f</i>. | |
| 3984 * * Initialization by means of an initializing formal of <i>k</i>. | |
| 3985 * or a static warning occurs. | |
| 3986 * | |
| 3987 * Parameters: | |
| 3988 * 0: the name of the uninitialized final variable | |
| 3989 * 1: the name of the uninitialized final variable | |
| 3990 */ | |
| 3991 static const StaticWarningCode FINAL_NOT_INITIALIZED_CONSTRUCTOR_2 = | |
| 3992 const StaticWarningCode('FINAL_NOT_INITIALIZED_CONSTRUCTOR_2', | |
| 3993 "The final variables '{0}' and '{1}' must be initialized"); | |
| 3994 | |
| 3995 /** | |
| 3996 * 7.6.1 Generative Constructors: Each final instance variable <i>f</i> | |
| 3997 * declared in the immediately enclosing class must have an initializer in | |
| 3998 * <i>k</i>'s initializer list unless it has already been initialized by one | |
| 3999 * of the following means: | |
| 4000 * * Initialization at the declaration of <i>f</i>. | |
| 4001 * * Initialization by means of an initializing formal of <i>k</i>. | |
| 4002 * or a static warning occurs. | |
| 4003 * | |
| 4004 * Parameters: | |
| 4005 * 0: the name of the uninitialized final variable | |
| 4006 * 1: the name of the uninitialized final variable | |
| 4007 * 2: the number of additional not initialized variables that aren't listed | |
| 4008 */ | |
| 4009 static const StaticWarningCode FINAL_NOT_INITIALIZED_CONSTRUCTOR_3_PLUS = | |
| 4010 const StaticWarningCode('FINAL_NOT_INITIALIZED_CONSTRUCTOR_3', | |
| 4011 "The final variables '{0}', '{1}' and '{2}' more must be initialized") ; | |
| 4012 | |
| 4013 /** | |
| 3947 * 15.5 Function Types: It is a static warning if a concrete class implements | 4014 * 15.5 Function Types: It is a static warning if a concrete class implements |
| 3948 * Function and does not have a concrete method named call(). | 4015 * Function and does not have a concrete method named call(). |
| 3949 */ | 4016 */ |
| 3950 static const StaticWarningCode FUNCTION_WITHOUT_CALL = const StaticWarningCode ( | 4017 static const StaticWarningCode FUNCTION_WITHOUT_CALL = const StaticWarningCode ( |
| 3951 'FUNCTION_WITHOUT_CALL', | 4018 'FUNCTION_WITHOUT_CALL', |
| 3952 "Concrete classes that implement Function must implement the method call() "); | 4019 "Concrete classes that implement Function must implement the method call() "); |
| 3953 | 4020 |
| 3954 /** | 4021 /** |
| 3955 * 14.1 Imports: It is a static warning to import two different libraries with | 4022 * 14.1 Imports: It is a static warning to import two different libraries with |
| 3956 * the same name. | 4023 * the same name. |
| (...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4808 * Initialize a newly created error code to have the given [name]. | 4875 * Initialize a newly created error code to have the given [name]. |
| 4809 */ | 4876 */ |
| 4810 const TodoCode(String name) : super(name, "{0}"); | 4877 const TodoCode(String name) : super(name, "{0}"); |
| 4811 | 4878 |
| 4812 @override | 4879 @override |
| 4813 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 4880 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
| 4814 | 4881 |
| 4815 @override | 4882 @override |
| 4816 ErrorType get type => ErrorType.TODO; | 4883 ErrorType get type => ErrorType.TODO; |
| 4817 } | 4884 } |
| OLD | NEW |