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

Side by Side Diff: pkg/analysis_server/lib/src/services/correction/status.dart

Issue 462403005: Move Location factories and RefactoringProblemSeverity.max into the generated classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rename to 'fromX'. 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
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 services.status; 5 library services.status;
6 6
7 import 'package:analysis_server/src/protocol2.dart' hide Element; 7 import 'package:analysis_server/src/protocol2.dart';
8 import 'package:analysis_server/src/services/correction/source_range.dart';
9 import 'package:analysis_server/src/services/search/search_engine.dart';
10 import 'package:analyzer/src/generated/ast.dart';
11 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/source.dart';
14 8
15 9
16 /** 10 /**
17 * Creates a new [Location].
18 */
19 Location createLocation(AnalysisContext context, Source source,
20 SourceRange range) {
21 int startLine = 0;
22 int startColumn = 0;
23 {
24 LineInfo lineInfo = context.getLineInfo(source);
25 if (lineInfo != null) {
26 LineInfo_Location offsetLocation = lineInfo.getLocation(range.offset);
27 startLine = offsetLocation.lineNumber;
28 startColumn = offsetLocation.columnNumber;
29 }
30 }
31 return new Location(
32 source.fullName,
33 range.offset,
34 range.length,
35 startLine,
36 startColumn);
37 }
38
39
40 /**
41 * Creates a new [Location] for the given [Element].
42 */
43 Location createLocation_forElement(Element element) {
44 AnalysisContext context = element.context;
45 Source source = element.source;
46 SourceRange range = rangeElementName(element);
47 return createLocation(context, source, range);
48 }
49
50
51 /**
52 * Creates a new [Location] for the given [SearchMatch].
53 */
54 Location createLocation_forMatch(SearchMatch match) {
55 Element enclosingElement = match.element;
56 return createLocation(
57 enclosingElement.context,
58 enclosingElement.source,
59 match.sourceRange);
60 }
61
62
63 /**
64 * Creates a new [Location] for the given [AstNode].
65 */
66 Location createLocation_forNode(AstNode node) {
67 CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit);
68 CompilationUnitElement unitElement = unit.element;
69 AnalysisContext context = unitElement.context;
70 Source source = unitElement.source;
71 SourceRange range = rangeNode(node);
72 return createLocation(context, source, range);
73 }
74
75
76 /**
77 * Creates a new [Location] for the given [CompilationUnit].
78 */
79 Location createLocation_forUnit(CompilationUnit unit, SourceRange range) {
80 CompilationUnitElement unitElement = unit.element;
81 AnalysisContext context = unitElement.context;
82 Source source = unitElement.source;
83 return createLocation(context, source, range);
84 }
85
86
87 RefactoringProblemSeverity _maxSeverity(RefactoringProblemSeverity a,
88 RefactoringProblemSeverity b) {
89 if (b == null) {
90 return a;
91 }
92 if (a == null) {
93 return b;
94 } else if (a == RefactoringProblemSeverity.INFO) {
95 return b;
96 } else if (a == RefactoringProblemSeverity.WARNING) {
97 if (b == RefactoringProblemSeverity.ERROR ||
98 b == RefactoringProblemSeverity.FATAL) {
99 return b;
100 }
101 } else if (a == RefactoringProblemSeverity.ERROR) {
102 if (b == RefactoringProblemSeverity.FATAL) {
103 return b;
104 }
105 }
106 return a;
107 }
108
109 /**
110 * An outcome of a condition checking operation. 11 * An outcome of a condition checking operation.
111 */ 12 */
112 class RefactoringStatus { 13 class RefactoringStatus {
113 /** 14 /**
114 * The current severity of this [RefactoringStatus] - the maximum of the 15 * The current severity of this [RefactoringStatus] - the maximum of the
115 * severities of its [entries]. 16 * severities of its [entries].
116 */ 17 */
117 RefactoringProblemSeverity _severity = null; 18 RefactoringProblemSeverity _severity = null;
118 19
119 /** 20 /**
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 * 137 *
237 * The resulting severity is the more severe of this and [other] severities. 138 * The resulting severity is the more severe of this and [other] severities.
238 * 139 *
239 * Merging with `null` is allowed - it has no effect. 140 * Merging with `null` is allowed - it has no effect.
240 */ 141 */
241 void addStatus(RefactoringStatus other) { 142 void addStatus(RefactoringStatus other) {
242 if (other == null) { 143 if (other == null) {
243 return; 144 return;
244 } 145 }
245 problems.addAll(other.problems); 146 problems.addAll(other.problems);
246 _severity = _maxSeverity(_severity, other.severity); 147 _severity = RefactoringProblemSeverity.max(_severity, other.severity);
247 } 148 }
248 149
249 /** 150 /**
250 * Adds a WARNING problem with the given message and location. 151 * Adds a WARNING problem with the given message and location.
251 */ 152 */
252 void addWarning(String msg, [Location location]) { 153 void addWarning(String msg, [Location location]) {
253 _addProblem( 154 _addProblem(
254 new RefactoringProblem( 155 new RefactoringProblem(
255 RefactoringProblemSeverity.WARNING, 156 RefactoringProblemSeverity.WARNING,
256 msg, 157 msg,
(...skipping 21 matching lines...) Expand all
278 return sb.toString(); 179 return sb.toString();
279 } 180 }
280 181
281 /** 182 /**
282 * Adds the given [RefactoringProblem] and updates [severity]. 183 * Adds the given [RefactoringProblem] and updates [severity].
283 */ 184 */
284 void _addProblem(RefactoringProblem problem) { 185 void _addProblem(RefactoringProblem problem) {
285 problems.add(problem); 186 problems.add(problem);
286 // update maximum severity 187 // update maximum severity
287 RefactoringProblemSeverity severity = problem.severity; 188 RefactoringProblemSeverity severity = problem.severity;
288 _severity = _maxSeverity(_severity, severity); 189 _severity = RefactoringProblemSeverity.max(_severity, severity);
289 } 190 }
290 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698