| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library analyzer.src.error.pending_error; |
| 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/src/error/codes.dart'; |
| 11 import 'package:analyzer/src/generated/constant.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; |
| 13 |
| 14 /** |
| 15 * A pending error is an analysis error that could not be reported at the time |
| 16 * it was discovered because some piece of information might be missing. After |
| 17 * the information has been computed, the pending error can be converted into a |
| 18 * real error. |
| 19 */ |
| 20 abstract class PendingError { |
| 21 /** |
| 22 * Create an analysis error based on the information in the pending error. |
| 23 */ |
| 24 AnalysisError toAnalysisError(); |
| 25 } |
| 26 |
| 27 /** |
| 28 * A pending error used to compute either a [HintCode.MISSING_REQUIRED_PARAM] or |
| 29 * [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS] analysis error. These errors |
| 30 * require that the value of the `@required` annotation be computed, which is |
| 31 * not always true when the error is discovered. |
| 32 */ |
| 33 class PendingMissingRequiredParameterError implements PendingError { |
| 34 /** |
| 35 * The source against which the error will be reported. |
| 36 */ |
| 37 final Source source; |
| 38 |
| 39 /** |
| 40 * The name of the parameter that is required. |
| 41 */ |
| 42 final String parameterName; |
| 43 |
| 44 /** |
| 45 * The offset of the name of the method / function at the invocation site. |
| 46 */ |
| 47 final int offset; |
| 48 |
| 49 /** |
| 50 * The length of the name of the method / function at the invocation site. |
| 51 */ |
| 52 final int length; |
| 53 |
| 54 /** |
| 55 * The `@required` annotation whose value is used to compose the error message
. |
| 56 */ |
| 57 final ElementAnnotation annotation; |
| 58 |
| 59 /** |
| 60 * Initialize a newly created pending error. |
| 61 */ |
| 62 PendingMissingRequiredParameterError( |
| 63 this.source, this.parameterName, AstNode node, this.annotation) |
| 64 : offset = node.offset, |
| 65 length = node.length; |
| 66 |
| 67 @override |
| 68 AnalysisError toAnalysisError() { |
| 69 HintCode errorCode; |
| 70 List<String> arguments; |
| 71 DartObject constantValue = annotation.constantValue; |
| 72 String reason = constantValue?.getField('reason')?.toStringValue(); |
| 73 if (reason != null) { |
| 74 errorCode = HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS; |
| 75 arguments = [parameterName, reason]; |
| 76 } else { |
| 77 errorCode = HintCode.MISSING_REQUIRED_PARAM; |
| 78 arguments = [parameterName]; |
| 79 } |
| 80 return new AnalysisError(source, offset, length, errorCode, arguments); |
| 81 } |
| 82 } |
| OLD | NEW |