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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 */ | 82 */ |
83 int _length = 0; | 83 int _length = 0; |
84 | 84 |
85 /** | 85 /** |
86 * A flag indicating whether this error can be shown to be a non-issue because | 86 * A flag indicating whether this error can be shown to be a non-issue because |
87 * of the result of type propagation. | 87 * of the result of type propagation. |
88 */ | 88 */ |
89 bool isStaticOnly = false; | 89 bool isStaticOnly = false; |
90 | 90 |
91 /** | 91 /** |
| 92 * Initialize a newly created analysis error. The error is associated with the |
| 93 * given [source] and is located at the given [offset] with the given |
| 94 * [length]. The error will have the given [errorCode] and the list of |
| 95 * [arguments] will be used to complete the message. |
| 96 */ |
| 97 AnalysisError(this.source, this.offset, int length, this.errorCode, |
| 98 [List<Object> arguments]) { |
| 99 this._length = length; |
| 100 this._message = formatList(errorCode.message, arguments); |
| 101 String correctionTemplate = errorCode.correction; |
| 102 if (correctionTemplate != null) { |
| 103 this._correction = formatList(correctionTemplate, arguments); |
| 104 } |
| 105 } |
| 106 |
| 107 /** |
92 * Initialize a newly created analysis error for the specified [source]. The | 108 * Initialize a newly created analysis error for the specified [source]. The |
93 * error will have the given [errorCode] and the list of [arguments] will be | 109 * error will have the given [errorCode] and the list of [arguments] will be |
94 * used to complete the message. The error has no location information. | 110 * used to complete the message. The error has no location information. |
95 */ | 111 */ |
96 AnalysisError.con1(this.source, this.errorCode, [List<Object> arguments]) { | 112 @deprecated // Use new AnalysisError(source, 0, 0, errorCode, arguments) |
97 this._message = formatList(errorCode.message, arguments); | 113 AnalysisError.con1(Source source, ErrorCode errorCode, |
98 } | 114 [List<Object> arguments]) |
| 115 : this(source, 0, 0, errorCode, arguments); |
99 | 116 |
100 /** | 117 /** |
101 * Initialize a newly created analysis error for the specified [source] at the | 118 * Initialize a newly created analysis error for the specified [source] at the |
102 * given [offset] with the given [length]. The error will have the given | 119 * given [offset] with the given [length]. The error will have the given |
103 * [errorCode] and the list of [arguments] will be used to complete the | 120 * [errorCode] and the list of [arguments] will be used to complete the |
104 * message. | 121 * message. |
105 */ | 122 */ |
106 AnalysisError.con2(this.source, this.offset, int length, this.errorCode, | 123 @deprecated // Use new AnalysisError(source, offset, length, errorCode, argume
nts) |
107 [List<Object> arguments]) { | 124 AnalysisError.con2(Source source, int offset, int length, ErrorCode errorCode, |
108 this._length = length; | 125 [List<Object> arguments]) |
109 this._message = formatList(errorCode.message, arguments); | 126 : this(source, offset, length, errorCode, arguments); |
110 String correctionTemplate = errorCode.correction; | |
111 if (correctionTemplate != null) { | |
112 this._correction = formatList(correctionTemplate, arguments); | |
113 } | |
114 } | |
115 | 127 |
116 /** | 128 /** |
117 * Return the template used to create the correction to be displayed for this | 129 * Return the template used to create the correction to be displayed for this |
118 * error, or `null` if there is no correction information for this error. The | 130 * error, or `null` if there is no correction information for this error. The |
119 * correction should indicate how the user can fix the error. | 131 * correction should indicate how the user can fix the error. |
120 */ | 132 */ |
121 String get correction => _correction; | 133 String get correction => _correction; |
122 | 134 |
123 @override | 135 @override |
124 int get hashCode { | 136 int get hashCode { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 * An [AnalysisError] that can have arbitrary properties associated with it. | 249 * An [AnalysisError] that can have arbitrary properties associated with it. |
238 */ | 250 */ |
239 class AnalysisErrorWithProperties extends AnalysisError { | 251 class AnalysisErrorWithProperties extends AnalysisError { |
240 /** | 252 /** |
241 * The properties associated with this error. | 253 * The properties associated with this error. |
242 */ | 254 */ |
243 HashMap<ErrorProperty, Object> _propertyMap = | 255 HashMap<ErrorProperty, Object> _propertyMap = |
244 new HashMap<ErrorProperty, Object>(); | 256 new HashMap<ErrorProperty, Object>(); |
245 | 257 |
246 /** | 258 /** |
| 259 * Initialize a newly created analysis error. The error is associated with the |
| 260 * given [source] and is located at the given [offset] with the given |
| 261 * [length]. The error will have the given [errorCode] and the list of |
| 262 * [arguments] will be used to complete the message. |
| 263 */ |
| 264 AnalysisErrorWithProperties( |
| 265 Source source, int offset, int length, ErrorCode errorCode, |
| 266 [List<Object> arguments]) |
| 267 : super(source, offset, length, errorCode, arguments); |
| 268 |
| 269 /** |
247 * Initialize a newly created analysis error for the specified [source]. The | 270 * Initialize a newly created analysis error for the specified [source]. The |
248 * error will have the given [errorCode] and the list of [arguments] will be | 271 * error will have the given [errorCode] and the list of [arguments] will be |
249 * used to complete the message. The error has no location information. | 272 * used to complete the message. The error has no location information. |
250 */ | 273 */ |
| 274 @deprecated // Use new AnalysisErrorWithProperties(source, 0, 0, errorCode, ar
guments) |
251 AnalysisErrorWithProperties.con1(Source source, ErrorCode errorCode, | 275 AnalysisErrorWithProperties.con1(Source source, ErrorCode errorCode, |
252 [List<Object> arguments]) | 276 [List<Object> arguments]) |
253 : super.con1(source, errorCode, arguments); | 277 : this(source, 0, 0, errorCode, arguments); |
254 | 278 |
255 /** | 279 /** |
256 * Initialize a newly created analysis error for the specified [source] at the | 280 * Initialize a newly created analysis error for the specified [source] at the |
257 * given [offset] with the given [length]. The error will have the given | 281 * given [offset] with the given [length]. The error will have the given |
258 * [errorCode] and the list of [arguments] will be used to complete the | 282 * [errorCode] and the list of [arguments] will be used to complete the |
259 * message. | 283 * message. |
260 */ | 284 */ |
| 285 @deprecated // Use new AnalysisErrorWithProperties(source, offset, length, err
orCode, arguments) |
261 AnalysisErrorWithProperties.con2( | 286 AnalysisErrorWithProperties.con2( |
262 Source source, int offset, int length, ErrorCode errorCode, | 287 Source source, int offset, int length, ErrorCode errorCode, |
263 [List<Object> arguments]) | 288 [List<Object> arguments]) |
264 : super.con2(source, offset, length, errorCode, arguments); | 289 : this(source, offset, length, errorCode, arguments); |
265 | 290 |
266 @override | 291 @override |
267 Object getProperty(ErrorProperty property) => _propertyMap[property]; | 292 Object getProperty(ErrorProperty property) => _propertyMap[property]; |
268 | 293 |
269 /** | 294 /** |
270 * Set the value of the given [property] to the given [value]. Using a value | 295 * Set the value of the given [property] to the given [value]. Using a value |
271 * of `null` will effectively remove the property from this error. | 296 * of `null` will effectively remove the property from this error. |
272 */ | 297 */ |
273 void setProperty(ErrorProperty property, Object value) { | 298 void setProperty(ErrorProperty property, Object value) { |
274 _propertyMap[property] = value; | 299 _propertyMap[property] = value; |
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 void set source(Source source) { | 2489 void set source(Source source) { |
2465 this._source = source == null ? _defaultSource : source; | 2490 this._source = source == null ? _defaultSource : source; |
2466 } | 2491 } |
2467 | 2492 |
2468 /** | 2493 /** |
2469 * Creates an error with properties with the given [errorCode] and | 2494 * Creates an error with properties with the given [errorCode] and |
2470 * [arguments]. The [node] is used to compute the location of the error. | 2495 * [arguments]. The [node] is used to compute the location of the error. |
2471 */ | 2496 */ |
2472 AnalysisErrorWithProperties newErrorWithProperties( | 2497 AnalysisErrorWithProperties newErrorWithProperties( |
2473 ErrorCode errorCode, AstNode node, List<Object> arguments) => | 2498 ErrorCode errorCode, AstNode node, List<Object> arguments) => |
2474 new AnalysisErrorWithProperties.con2( | 2499 new AnalysisErrorWithProperties( |
2475 _source, node.offset, node.length, errorCode, arguments); | 2500 _source, node.offset, node.length, errorCode, arguments); |
2476 | 2501 |
2477 /** | 2502 /** |
2478 * Report the given [error]. | 2503 * Report the given [error]. |
2479 */ | 2504 */ |
2480 void reportError(AnalysisError error) { | 2505 void reportError(AnalysisError error) { |
2481 _errorListener.onError(error); | 2506 _errorListener.onError(error); |
2482 } | 2507 } |
2483 | 2508 |
2484 /** | 2509 /** |
(...skipping 27 matching lines...) Expand all Loading... |
2512 reportErrorForOffset(errorCode, node.offset, node.length, arguments); | 2537 reportErrorForOffset(errorCode, node.offset, node.length, arguments); |
2513 } | 2538 } |
2514 | 2539 |
2515 /** | 2540 /** |
2516 * Report an error with the given [errorCode] and [arguments]. The location of | 2541 * Report an error with the given [errorCode] and [arguments]. The location of |
2517 * the error is specified by the given [offset] and [length]. | 2542 * the error is specified by the given [offset] and [length]. |
2518 */ | 2543 */ |
2519 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, | 2544 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, |
2520 [List<Object> arguments]) { | 2545 [List<Object> arguments]) { |
2521 _errorListener.onError( | 2546 _errorListener.onError( |
2522 new AnalysisError.con2(_source, offset, length, errorCode, arguments)); | 2547 new AnalysisError(_source, offset, length, errorCode, arguments)); |
2523 } | 2548 } |
2524 | 2549 |
2525 /** | 2550 /** |
2526 * Report an error with the given [errorCode] and [arguments]. The [token] is | 2551 * Report an error with the given [errorCode] and [arguments]. The [token] is |
2527 * used to compute the location of the error. | 2552 * used to compute the location of the error. |
2528 */ | 2553 */ |
2529 void reportErrorForToken(ErrorCode errorCode, Token token, | 2554 void reportErrorForToken(ErrorCode errorCode, Token token, |
2530 [List<Object> arguments]) { | 2555 [List<Object> arguments]) { |
2531 reportErrorForOffset(errorCode, token.offset, token.length, arguments); | 2556 reportErrorForOffset(errorCode, token.offset, token.length, arguments); |
2532 } | 2557 } |
(...skipping 2372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4905 * Initialize a newly created error code to have the given [name]. | 4930 * Initialize a newly created error code to have the given [name]. |
4906 */ | 4931 */ |
4907 const TodoCode(String name) : super(name, "{0}"); | 4932 const TodoCode(String name) : super(name, "{0}"); |
4908 | 4933 |
4909 @override | 4934 @override |
4910 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | 4935 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; |
4911 | 4936 |
4912 @override | 4937 @override |
4913 ErrorType get type => ErrorType.TODO; | 4938 ErrorType get type => ErrorType.TODO; |
4914 } | 4939 } |
OLD | NEW |