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

Side by Side Diff: pkg/analyzer_cli/lib/src/analyzer_impl.dart

Issue 1720963003: Initial hermetic package analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer_cli.src.analyzer_impl; 5 library analyzer_cli.src.analyzer_impl;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // is because when the argument flags are constructed in BatchRunner and 217 // is because when the argument flags are constructed in BatchRunner and
218 // passed in from batch mode which removes the batch flag to prevent the 218 // passed in from batch mode which removes the batch flag to prevent the
219 // "cannot have the batch flag and source file" error message. 219 // "cannot have the batch flag and source file" error message.
220 StringSink sink = options.machineFormat ? errorSink : outSink; 220 StringSink sink = options.machineFormat ? errorSink : outSink;
221 221
222 // Print errors. 222 // Print errors.
223 ErrorFormatter formatter = new ErrorFormatter(sink, options, _processError); 223 ErrorFormatter formatter = new ErrorFormatter(sink, options, _processError);
224 formatter.formatErrors(errorInfos); 224 formatter.formatErrors(errorInfos);
225 } 225 }
226 226
227 /// Check various configuration options to get a desired severity for this 227 ProcessedSeverity _processError(AnalysisError error) =>
228 /// [error] (or `null` if it's to be suppressed). 228 processError(error, options, context);
229 ProcessedSeverity _processError(AnalysisError error) {
230 ErrorSeverity severity = computeSeverity(error, options, context);
231 bool isOverridden = false;
232
233 // First check for a filter.
234 if (severity == null) {
235 // Null severity means the error has been explicitly ignored.
236 return null;
237 } else {
238 isOverridden = true;
239 }
240
241 // If not overridden, some "natural" severities get globally filtered.
242 if (!isOverridden) {
243 // Check for global hint filtering.
244 if (severity == ErrorSeverity.INFO && options.disableHints) {
245 return null;
246 }
247
248 // Skip TODOs.
249 if (severity == ErrorType.TODO) {
250 return null;
251 }
252 }
253
254 return new ProcessedSeverity(severity, isOverridden);
255 }
256 229
257 LibraryElement _resolveLibrary() { 230 LibraryElement _resolveLibrary() {
258 return _resolveLibraryTag.makeCurrentWhile(() { 231 return _resolveLibraryTag.makeCurrentWhile(() {
259 return context.computeLibraryElement(librarySource); 232 return context.computeLibraryElement(librarySource);
260 }); 233 });
261 } 234 }
262 235
263 /// Compute the severity of the error; however: 236 /// Compute the severity of the error; however:
264 /// * if [options.enableTypeChecks] is false, then de-escalate checked-mode 237 /// * if [options.enableTypeChecks] is false, then de-escalate checked-mode
265 /// compile time errors to a severity of [ErrorSeverity.INFO]. 238 /// compile time errors to a severity of [ErrorSeverity.INFO].
(...skipping 30 matching lines...) Expand all
296 while (dir != null) { 269 while (dir != null) {
297 JavaFile packagesDir = new JavaFile.relative(dir, "packages"); 270 JavaFile packagesDir = new JavaFile.relative(dir, "packages");
298 if (packagesDir.exists()) { 271 if (packagesDir.exists()) {
299 return packagesDir; 272 return packagesDir;
300 } 273 }
301 dir = dir.getParentFile(); 274 dir = dir.getParentFile();
302 } 275 }
303 // Not found. 276 // Not found.
304 return null; 277 return null;
305 } 278 }
279
280 /// Check various configuration options to get a desired severity for this
281 /// [error] (or `null` if it's to be suppressed).
282 static ProcessedSeverity processError(AnalysisError error,
283 CommandLineOptions options, AnalysisContext context) {
284 ErrorSeverity severity = computeSeverity(error, options, context);
285 bool isOverridden = false;
286
287 // First check for a filter.
288 if (severity == null) {
289 // Null severity means the error has been explicitly ignored.
290 return null;
291 } else {
292 isOverridden = true;
293 }
294
295 // If not overridden, some "natural" severities get globally filtered.
296 if (!isOverridden) {
297 // Check for global hint filtering.
298 if (severity == ErrorSeverity.INFO && options.disableHints) {
299 return null;
300 }
301
302 // Skip TODOs.
303 if (severity == ErrorType.TODO) {
304 return null;
305 }
306 }
307
308 return new ProcessedSeverity(severity, isOverridden);
309 }
306 } 310 }
307 311
308 /// This [Logger] prints out information comments to [outSink] and error message s 312 /// This [Logger] prints out information comments to [outSink] and error message s
309 /// to [errorSink]. 313 /// to [errorSink].
310 class StdLogger extends Logger { 314 class StdLogger extends Logger {
311 StdLogger(); 315 StdLogger();
312 316
313 @override 317 @override
314 void logError(String message, [CaughtException exception]) { 318 void logError(String message, [CaughtException exception]) {
315 errorSink.writeln(message); 319 errorSink.writeln(message);
316 if (exception != null) { 320 if (exception != null) {
317 errorSink.writeln(exception); 321 errorSink.writeln(exception);
318 } 322 }
319 } 323 }
320 324
321 @override 325 @override
322 void logInformation(String message, [CaughtException exception]) { 326 void logInformation(String message, [CaughtException exception]) {
323 outSink.writeln(message); 327 outSink.writeln(message);
324 if (exception != null) { 328 if (exception != null) {
325 outSink.writeln(exception); 329 outSink.writeln(exception);
326 } 330 }
327 } 331 }
328 } 332 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/driver.dart » ('j') | pkg/analyzer_cli/lib/src/package_analyzer.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698