|
4 | 4 |
|
5 | 5 | library fasta.codes; |
6 | 6 |
|
7 | | -import 'dart:convert' show JsonEncoder, json; |
8 | | - |
9 | 7 | import 'package:kernel/ast.dart' |
10 | 8 | show Constant, DartType, demangleMixinApplicationName; |
11 | 9 |
|
12 | | -import '../api_prototype/diagnostic_message.dart' show DiagnosticMessage; |
13 | | - |
14 | | -import '../scanner/token.dart' show Token; |
15 | | - |
16 | 10 | import 'kernel/type_labeler.dart'; |
17 | 11 |
|
18 | | -import 'severity.dart' show Severity; |
19 | | - |
20 | | -import 'resolve_input_uri.dart' show isWindows; |
21 | | - |
22 | | -import 'util/relativize.dart' as util show relativizeUri; |
23 | | - |
24 | | -part 'fasta_codes_generated.dart'; |
25 | | - |
26 | | -const int noLength = 1; |
27 | | - |
28 | | -class Code<T> { |
29 | | - final String name; |
30 | | - |
31 | | - /// The unique positive integer associated with this code, |
32 | | - /// or `-1` if none. This index is used when translating |
33 | | - /// this error to its corresponding Analyzer error. |
34 | | - final int index; |
35 | | - |
36 | | - final Template<T> template; |
37 | | - |
38 | | - final List<String> analyzerCodes; |
39 | | - |
40 | | - final Severity severity; |
41 | | - |
42 | | - const Code(this.name, this.template, |
43 | | - {int index, this.analyzerCodes, this.severity: Severity.error}) |
44 | | - : this.index = index ?? -1; |
45 | | - |
46 | | - String toString() => name; |
47 | | -} |
48 | | - |
49 | | -class Message { |
50 | | - final Code<dynamic> code; |
51 | | - |
52 | | - final String message; |
53 | | - |
54 | | - final String tip; |
55 | | - |
56 | | - final Map<String, dynamic> arguments; |
57 | | - |
58 | | - const Message(this.code, {this.message, this.tip, this.arguments}); |
59 | | - |
60 | | - LocatedMessage withLocation(Uri uri, int charOffset, int length) { |
61 | | - return new LocatedMessage(uri, charOffset, length, this); |
62 | | - } |
63 | | - |
64 | | - LocatedMessage withoutLocation() { |
65 | | - return new LocatedMessage(null, -1, noLength, this); |
66 | | - } |
67 | | - |
68 | | - String toString() { |
69 | | - return "Message[$code, $message, $tip, $arguments]"; |
70 | | - } |
71 | | -} |
72 | | - |
73 | | -class MessageCode extends Code<Null> implements Message { |
74 | | - final String message; |
75 | | - |
76 | | - final String tip; |
77 | | - |
78 | | - const MessageCode(String name, |
79 | | - {int index, |
80 | | - List<String> analyzerCodes, |
81 | | - Severity severity: Severity.error, |
82 | | - this.message, |
83 | | - this.tip}) |
84 | | - : super(name, null, |
85 | | - index: index, analyzerCodes: analyzerCodes, severity: severity); |
86 | | - |
87 | | - Map<String, dynamic> get arguments => const <String, dynamic>{}; |
88 | | - |
89 | | - Code<dynamic> get code => this; |
90 | | - |
91 | | - @override |
92 | | - LocatedMessage withLocation(Uri uri, int charOffset, int length) { |
93 | | - return new LocatedMessage(uri, charOffset, length, this); |
94 | | - } |
95 | | - |
96 | | - LocatedMessage withoutLocation() { |
97 | | - return new LocatedMessage(null, -1, noLength, this); |
98 | | - } |
99 | | -} |
100 | | - |
101 | | -class Template<T> { |
102 | | - final String messageTemplate; |
103 | | - |
104 | | - final String tipTemplate; |
105 | | - |
106 | | - final T withArguments; |
107 | | - |
108 | | - const Template({this.messageTemplate, this.tipTemplate, this.withArguments}); |
109 | | -} |
110 | | - |
111 | | -class LocatedMessage implements Comparable<LocatedMessage> { |
112 | | - final Uri uri; |
113 | | - |
114 | | - final int charOffset; |
115 | | - |
116 | | - final int length; |
117 | | - |
118 | | - final Message messageObject; |
119 | | - |
120 | | - const LocatedMessage( |
121 | | - this.uri, this.charOffset, this.length, this.messageObject); |
122 | | - |
123 | | - Code<dynamic> get code => messageObject.code; |
124 | | - |
125 | | - String get message => messageObject.message; |
126 | | - |
127 | | - String get tip => messageObject.tip; |
128 | | - |
129 | | - Map<String, dynamic> get arguments => messageObject.arguments; |
130 | | - |
131 | | - int compareTo(LocatedMessage other) { |
132 | | - int result = "${uri}".compareTo("${other.uri}"); |
133 | | - if (result != 0) return result; |
134 | | - result = charOffset.compareTo(other.charOffset); |
135 | | - if (result != 0) return result; |
136 | | - return message.compareTo(message); |
137 | | - } |
138 | | - |
139 | | - FormattedMessage withFormatting(String formatted, int line, int column, |
140 | | - Severity severity, List<FormattedMessage> relatedInformation) { |
141 | | - return new FormattedMessage( |
142 | | - this, formatted, line, column, severity, relatedInformation); |
143 | | - } |
144 | | -} |
145 | | - |
146 | | -class FormattedMessage implements DiagnosticMessage { |
147 | | - final LocatedMessage locatedMessage; |
148 | | - |
149 | | - final String formatted; |
150 | | - |
151 | | - final int line; |
152 | | - |
153 | | - final int column; |
154 | | - |
155 | | - @override |
156 | | - final Severity severity; |
157 | | - |
158 | | - final List<FormattedMessage> relatedInformation; |
159 | | - |
160 | | - const FormattedMessage(this.locatedMessage, this.formatted, this.line, |
161 | | - this.column, this.severity, this.relatedInformation); |
162 | | - |
163 | | - Code<dynamic> get code => locatedMessage.code; |
164 | | - |
165 | | - String get message => locatedMessage.message; |
166 | | - |
167 | | - String get tip => locatedMessage.tip; |
168 | | - |
169 | | - Map<String, dynamic> get arguments => locatedMessage.arguments; |
170 | | - |
171 | | - Uri get uri => locatedMessage.uri; |
172 | | - |
173 | | - int get charOffset => locatedMessage.charOffset; |
174 | | - |
175 | | - int get length => locatedMessage.length; |
176 | | - |
177 | | - @override |
178 | | - Iterable<String> get ansiFormatted sync* { |
179 | | - yield formatted; |
180 | | - if (relatedInformation != null) { |
181 | | - for (FormattedMessage m in relatedInformation) { |
182 | | - yield m.formatted; |
183 | | - } |
184 | | - } |
185 | | - } |
186 | | - |
187 | | - @override |
188 | | - Iterable<String> get plainTextFormatted { |
189 | | - // TODO(ahe): Implement this correctly. |
190 | | - return ansiFormatted; |
191 | | - } |
192 | | - |
193 | | - Map<String, Object> toJson() { |
194 | | - // This should be kept in sync with package:kernel/problems.md |
195 | | - return <String, Object>{ |
196 | | - "ansiFormatted": ansiFormatted.toList(), |
197 | | - "plainTextFormatted": plainTextFormatted.toList(), |
198 | | - "severity": severity.index, |
199 | | - "uri": uri.toString(), |
200 | | - }; |
201 | | - } |
202 | | - |
203 | | - String toJsonString() { |
204 | | - JsonEncoder encoder = new JsonEncoder.withIndent(" "); |
205 | | - return encoder.convert(this); |
206 | | - } |
207 | | -} |
208 | | - |
209 | | -class DiagnosticMessageFromJson implements DiagnosticMessage { |
210 | | - @override |
211 | | - final Iterable<String> ansiFormatted; |
212 | | - |
213 | | - @override |
214 | | - final Iterable<String> plainTextFormatted; |
215 | | - |
216 | | - @override |
217 | | - final Severity severity; |
218 | | - |
219 | | - final Uri uri; |
220 | | - |
221 | | - DiagnosticMessageFromJson( |
222 | | - this.ansiFormatted, this.plainTextFormatted, this.severity, this.uri); |
223 | | - |
224 | | - factory DiagnosticMessageFromJson.fromJson(String jsonString) { |
225 | | - Map<String, Object> decoded = json.decode(jsonString); |
226 | | - List<String> ansiFormatted = |
227 | | - new List<String>.from(decoded["ansiFormatted"]); |
228 | | - List<String> plainTextFormatted = |
229 | | - new List<String>.from(decoded["plainTextFormatted"]); |
230 | | - Severity severity = Severity.values[decoded["severity"]]; |
231 | | - Uri uri = Uri.parse(decoded["uri"]); |
232 | | - |
233 | | - return new DiagnosticMessageFromJson( |
234 | | - ansiFormatted, plainTextFormatted, severity, uri); |
235 | | - } |
236 | | - |
237 | | - Map<String, Object> toJson() { |
238 | | - // This should be kept in sync with package:kernel/problems.md |
239 | | - return <String, Object>{ |
240 | | - "ansiFormatted": ansiFormatted.toList(), |
241 | | - "plainTextFormatted": plainTextFormatted.toList(), |
242 | | - "severity": severity.index, |
243 | | - "uri": uri.toString(), |
244 | | - }; |
245 | | - } |
246 | | - |
247 | | - String toJsonString() { |
248 | | - JsonEncoder encoder = new JsonEncoder.withIndent(" "); |
249 | | - return encoder.convert(this); |
250 | | - } |
251 | | -} |
252 | | - |
253 | | -String relativizeUri(Uri uri) { |
254 | | - // We have this method here for two reasons: |
255 | | - // |
256 | | - // 1. It allows us to implement #uri message argument without using it |
257 | | - // (otherwise, we might get an `UNUSED_IMPORT` warning). |
258 | | - // |
259 | | - // 2. We can change `base` argument here if needed. |
260 | | - return uri == null ? null : util.relativizeUri(Uri.base, uri, isWindows); |
261 | | -} |
| 12 | +import 'fasta_codes_shared.dart' hide demangleMixinApplicationName; |
262 | 13 |
|
263 | | -typedef SummaryTemplate = Message Function(int, int, num, num, num); |
| 14 | +export 'fasta_codes_shared.dart' hide demangleMixinApplicationName; |
264 | 15 |
|
265 | | -String itemizeNames(List<String> names) { |
266 | | - StringBuffer buffer = new StringBuffer(); |
267 | | - for (int i = 0; i < names.length - 1; i++) { |
268 | | - buffer.write(" - "); |
269 | | - buffer.writeln(names[i]); |
270 | | - } |
271 | | - buffer.write(" - "); |
272 | | - buffer.write(names.last); |
273 | | - return "$buffer"; |
274 | | -} |
| 16 | +part 'fasta_codes_cfe_generated.dart'; |
0 commit comments