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

Side by Side Diff: pkg/analysis_services/lib/src/generated/status.dart

Issue 484733003: Import analysis_services.dart into analysis_server.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information.
7
8 library services.status;
9
10 import 'package:analyzer/src/generated/java_core.dart';
11 import 'package:analyzer/src/generated/ast.dart';
12 import 'package:analyzer/src/generated/element.dart';
13 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/source.dart';
15 import 'stubs.dart';
16
17 /**
18 * Outcome of a condition checking operation.
19 */
20 class RefactoringStatus {
21 /**
22 * @return the new [RefactoringStatus] with [RefactoringStatusSeverity#ERROR].
23 */
24 static RefactoringStatus createErrorStatus(String msg) {
25 RefactoringStatus status = new RefactoringStatus();
26 status.addError(msg);
27 return status;
28 }
29
30 /**
31 * @return the new [RefactoringStatus] with [RefactoringStatusSeverity#FATAL].
32 */
33 static RefactoringStatus createFatalErrorStatus(String msg, [RefactoringStatus Context context]) {
34 RefactoringStatus status = new RefactoringStatus();
35 status.addFatalError(msg, context);
36 return status;
37 }
38
39 /**
40 * @return the new [RefactoringStatus] with [RefactoringStatusSeverity#WARNING ].
41 */
42 static RefactoringStatus createWarningStatus(String msg) {
43 RefactoringStatus status = new RefactoringStatus();
44 status.addWarning(msg);
45 return status;
46 }
47
48 /**
49 * @return the [Enum] value with maximal ordinal.
50 */
51 static Enum _max(Enum a, Enum b) {
52 if (b.ordinal > a.ordinal) {
53 return b;
54 }
55 return a;
56 }
57
58 RefactoringStatusSeverity _severity = RefactoringStatusSeverity.OK;
59
60 final List<RefactoringStatusEntry> entries = [];
61
62 /**
63 * Adds a <code>ERROR</code> entry filled with the given message and status to this status.
64 */
65 void addError(String msg, [RefactoringStatusContext context]) {
66 _addEntry(new RefactoringStatusEntry(RefactoringStatusSeverity.ERROR, msg, c ontext));
67 }
68
69 /**
70 * Adds a <code>FATAL</code> entry filled with the given message and status to this status.
71 */
72 void addFatalError(String msg, [RefactoringStatusContext context]) {
73 _addEntry(new RefactoringStatusEntry(RefactoringStatusSeverity.FATAL, msg, c ontext));
74 }
75
76 /**
77 * Adds a <code>WARNING</code> entry filled with the given message and status to this status.
78 */
79 void addWarning(String msg, [RefactoringStatusContext context]) {
80 _addEntry(new RefactoringStatusEntry(RefactoringStatusSeverity.WARNING, msg, context));
81 }
82
83 /**
84 * @return the copy of this [RefactoringStatus] with [RefactoringStatusSeverit y#ERROR]
85 * replaced with [RefactoringStatusSeverity#FATAL].
86 */
87 RefactoringStatus escalateErrorToFatal() {
88 RefactoringStatus result = new RefactoringStatus();
89 for (RefactoringStatusEntry entry in entries) {
90 RefactoringStatusSeverity severity = entry.severity;
91 if (severity == RefactoringStatusSeverity.ERROR) {
92 severity = RefactoringStatusSeverity.FATAL;
93 }
94 result._addEntry(new RefactoringStatusEntry(severity, entry.message, entry .context));
95 }
96 return result;
97 }
98
99 /**
100 * @return the RefactoringStatusEntry with the highest severity, or <code>null </code> if no
101 * entries are present.
102 */
103 RefactoringStatusEntry get entryWithHighestSeverity {
104 if (entries.isEmpty) {
105 return null;
106 }
107 RefactoringStatusEntry result = entries[0];
108 for (RefactoringStatusEntry entry in entries) {
109 if (result.severity.ordinal < entry.severity.ordinal) {
110 result = entry;
111 }
112 }
113 return result;
114 }
115
116 /**
117 * @return the message from the [RefactoringStatusEntry] with highest severity ; may be
118 * <code>null</code> if not entries are present.
119 */
120 String get message {
121 RefactoringStatusEntry entry = entryWithHighestSeverity;
122 if (entry == null) {
123 return null;
124 }
125 return entry.message;
126 }
127
128 /**
129 * @return the current severity of the [RefactoringStatus].
130 */
131 RefactoringStatusSeverity get severity => _severity;
132
133 /**
134 * @return <code>true</code> if the current severity is <code>
135 * FATAL</code> or <code>ERROR</code>.
136 */
137 bool get hasError => _severity == RefactoringStatusSeverity.FATAL || _severity == RefactoringStatusSeverity.ERROR;
138
139 /**
140 * @return <code>true</code> if the current severity is <code>FATAL</code>.
141 */
142 bool get hasFatalError => _severity == RefactoringStatusSeverity.FATAL;
143
144 /**
145 * @return <code>true</code> if the current severity is <code>
146 * FATAL</code>, <code>ERROR</code>, <code>WARNING</code> or <code>INFO</code >.
147 */
148 bool get hasInfo => _severity == RefactoringStatusSeverity.FATAL || _severity == RefactoringStatusSeverity.ERROR || _severity == RefactoringStatusSeverity.WAR NING || _severity == RefactoringStatusSeverity.INFO;
149
150 /**
151 * @return <code>true</code> if the current severity is <code>
152 * FATAL</code>, <code>ERROR</code> or <code>WARNING</code>.
153 */
154 bool get hasWarning => _severity == RefactoringStatusSeverity.FATAL || _severi ty == RefactoringStatusSeverity.ERROR || _severity == RefactoringStatusSeverity. WARNING;
155
156 /**
157 * @return <code>true</code> if the severity is <code>OK</code>.
158 */
159 bool get isOK => _severity == RefactoringStatusSeverity.OK;
160
161 /**
162 * Merges the receiver and the parameter statuses. The resulting list of entri es in the receiver
163 * will contain entries from both. The resulting severity in the receiver will be the more severe
164 * of its current severity and the parameter's severity. Merging with <code>nu ll</code> is allowed
165 * - it has no effect.
166 */
167 void merge(RefactoringStatus other) {
168 if (other == null) {
169 return;
170 }
171 entries.addAll(other.entries);
172 _severity = _max(_severity, other.severity);
173 }
174
175 @override
176 String toString() {
177 JavaStringBuilder sb = new JavaStringBuilder();
178 sb.append("<").append(_severity.name);
179 if (!isOK) {
180 sb.append("\n");
181 for (RefactoringStatusEntry entry in entries) {
182 sb.append("\t").append(entry).append("\n");
183 }
184 }
185 sb.append(">");
186 return sb.toString();
187 }
188
189 /**
190 * Adds given [RefactoringStatusEntry] and updates [severity].
191 */
192 void _addEntry(RefactoringStatusEntry entry) {
193 entries.add(entry);
194 _severity = _max(_severity, entry.severity);
195 }
196 }
197
198 /**
199 * [RefactoringStatusContext] can be used to annotate a [RefactoringStatusEntry] with
200 * additional information typically presented in the user interface.
201 */
202 class RefactoringStatusContext {
203 /**
204 * @return the [RefactoringStatusContext] that corresponds to the given [Searc hMatch].
205 */
206 static RefactoringStatusContext create(SearchMatch match) {
207 Element enclosingElement = match.element;
208 return new RefactoringStatusContext(enclosingElement.context, enclosingEleme nt.source, match.sourceRange);
209 }
210
211 AnalysisContext _context;
212
213 Source _source;
214
215 SourceRange _range;
216
217 RefactoringStatusContext(AnalysisContext context, Source source, SourceRange r ange) {
218 this._context = context;
219 this._source = source;
220 this._range = range;
221 }
222
223 /**
224 * Creates a new [RefactoringStatusContext] which corresponds to the given [As tNode].
225 */
226 RefactoringStatusContext.forNode(AstNode node) {
227 CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit);
228 CompilationUnitElement unitElement = unit.element;
229 this._context = unitElement.context;
230 this._source = unitElement.source;
231 this._range = SourceRangeFactory.rangeNode(node);
232 }
233
234 /**
235 * Creates a new [RefactoringStatusContext] which corresponds to given locatio n in the
236 * [Source] of the given [CompilationUnit].
237 */
238 RefactoringStatusContext.forUnit(CompilationUnit unit, SourceRange range) {
239 CompilationUnitElement unitElement = unit.element;
240 this._context = unitElement.context;
241 this._source = unitElement.source;
242 this._range = range;
243 }
244
245 /**
246 * @return the [RefactoringStatusContext] which corresponds to the declaration of the given
247 * [Element].
248 */
249 RefactoringStatusContext.forElement(Element element) {
250 this._context = element.context;
251 this._source = element.source;
252 this._range = SourceRangeFactory.rangeElementName(element);
253 }
254
255 /**
256 * @return the [AnalysisContext] in which this status occurs.
257 */
258 AnalysisContext get context => _context;
259
260 /**
261 * @return the [SourceRange] with specific location where this status occurs.
262 */
263 SourceRange get range => _range;
264
265 /**
266 * @return the [Source] in which this status occurs.
267 */
268 Source get source => _source;
269
270 @override
271 String toString() {
272 JavaStringBuilder builder = new JavaStringBuilder();
273 builder.append("[source=");
274 builder.append(_source);
275 builder.append(", range=");
276 builder.append(_range);
277 builder.append("]");
278 return builder.toString();
279 }
280 }
281
282 /**
283 * An immutable object representing an entry in the list in [RefactoringStatus]. A refactoring
284 * status entry consists of a severity, a message and a context object.
285 */
286 class RefactoringStatusEntry {
287 /**
288 * The severity level.
289 */
290 final RefactoringStatusSeverity severity;
291
292 /**
293 * The message of the status entry.
294 */
295 final String message;
296
297 /**
298 * The [RefactoringStatusContext] which can be used to show more detailed info rmation
299 * regarding this status entry in the UI. May be `null` indicating that no con text is
300 * available.
301 */
302 RefactoringStatusContext _context;
303
304 RefactoringStatusEntry(this.severity, this.message, [RefactoringStatusContext ctx]) {
305 this._context = ctx;
306 }
307
308 /**
309 * @return the [RefactoringStatusContext] which can be used to show more detai led
310 * information regarding this status entry in the UI. The method may r eturn `null`
311 * indicating that no context is available.
312 */
313 RefactoringStatusContext get context => _context;
314
315 /**
316 * Returns whether the entry represents an error or not.
317 *
318 * @return <code>true</code> if (severity ==<code>RefactoringStatusSeverity.ER ROR</code>).
319 */
320 bool get isError => severity == RefactoringStatusSeverity.ERROR;
321
322 /**
323 * Returns whether the entry represents a fatal error or not.
324 *
325 * @return <code>true</code> if (severity ==<code>RefactoringStatusSeverity.FA TAL</code>)
326 */
327 bool get isFatalError => severity == RefactoringStatusSeverity.FATAL;
328
329 /**
330 * Returns whether the entry represents an information or not.
331 *
332 * @return <code>true</code> if (severity ==<code>RefactoringStatusSeverity.IN FO</code>).
333 */
334 bool get isInfo => severity == RefactoringStatusSeverity.INFO;
335
336 /**
337 * Returns whether the entry represents a warning or not.
338 *
339 * @return <code>true</code> if (severity ==<code>RefactoringStatusSeverity.WA RNING</code>).
340 */
341 bool get isWarning => severity == RefactoringStatusSeverity.WARNING;
342
343 @override
344 String toString() {
345 if (_context != null) {
346 return "${severity}: ${message}; Context: ${_context}";
347 } else {
348 return "${severity}: ${message}";
349 }
350 }
351 }
352
353 /**
354 * Severity of [RefactoringStatus].
355 */
356 class RefactoringStatusSeverity extends Enum<RefactoringStatusSeverity> {
357 static const RefactoringStatusSeverity OK = const RefactoringStatusSeverity('O K', 0);
358
359 static const RefactoringStatusSeverity INFO = const RefactoringStatusSeverity( 'INFO', 1);
360
361 static const RefactoringStatusSeverity WARNING = const RefactoringStatusSeveri ty('WARNING', 2);
362
363 static const RefactoringStatusSeverity ERROR = const RefactoringStatusSeverity ('ERROR', 3);
364
365 static const RefactoringStatusSeverity FATAL = const RefactoringStatusSeverity ('FATAL', 4);
366
367 static const List<RefactoringStatusSeverity> values = const [OK, INFO, WARNING , ERROR, FATAL];
368
369 const RefactoringStatusSeverity(String name, int ordinal) : super(name, ordina l);
370 }
OLDNEW
« no previous file with comments | « pkg/analysis_services/lib/src/generated/proposal.dart ('k') | pkg/analysis_services/lib/src/generated/stubs.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698