Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: pkg/analyzer/lib/src/error/pending_error.dart

Issue 1977903002: Add support to the task model for the @required annotation (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove unused code Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/error.dart';
11 import 'package:analyzer/src/generated/source.dart';
12
13 /**
14 * A pending error is an analysis error that could not be reported at the time
15 * it was discovered because some piece of information might be missing. After
16 * the information has been computed, the pending error can be converted into a
17 * real error.
18 */
19 abstract class PendingError {
20 /**
21 * Create an analysis error based on the information in the pending error.
22 */
23 AnalysisError toAnalysisError();
24 }
25
26 /**
27 * A pending error used to compute either a [HintCode.MISSING_REQUIRED_PARAM] or
28 * [HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS] analysis error. These errors
29 * require that the value of the `@required` annotation be computed, which is
30 * not always true when the error is discovered.
31 */
32 class PendingMissingRequiredParameterError implements PendingError {
33 /**
34 * The source against which the error will be reported.
35 */
36 final Source source;
37
38 /**
39 * The name of the parameter that is required.
40 */
41 final String parameterName;
42
43 /**
44 * The offset of the name of the method / function at the invocation site.
45 */
46 final int offset;
47
48 /**
49 * The length of the name of the method / function at the invocation site.
50 */
51 final int length;
52
53 /**
54 * The `@required` annotation whose value is used to compose the error message .
55 */
56 final ElementAnnotation annotation;
57
58 /**
59 * Initialize a newly created pending error.
60 */
61 PendingMissingRequiredParameterError(
62 this.source, this.parameterName, AstNode node, this.annotation)
63 : offset = node.offset,
64 length = node.length;
65
66 @override
67 AnalysisError toAnalysisError() {
68 HintCode errorCode;
69 List<String> arguments;
70 DartObject constantValue = annotation.constantValue;
71 String reason = constantValue?.getField('reason')?.toStringValue();
72 if (reason != null) {
73 errorCode = HintCode.MISSING_REQUIRED_PARAM_WITH_DETAILS;
74 arguments = [parameterName, reason];
75 } else {
76 errorCode = HintCode.MISSING_REQUIRED_PARAM;
77 arguments = [parameterName];
78 }
79 return new AnalysisError(source, offset, length, errorCode, arguments);
80 }
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698