Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2416 // | 2416 // |
| 2417 List<AnalysisError> errors = | 2417 List<AnalysisError> errors = |
| 2418 _filterIgnores(AnalysisError.mergeLists(errorLists)); | 2418 _filterIgnores(AnalysisError.mergeLists(errorLists)); |
| 2419 | 2419 |
| 2420 // | 2420 // |
| 2421 // Record outputs. | 2421 // Record outputs. |
| 2422 // | 2422 // |
| 2423 outputs[DART_ERRORS] = errors; | 2423 outputs[DART_ERRORS] = errors; |
| 2424 } | 2424 } |
| 2425 | 2425 |
| 2426 Token _advanceToLine(Token token, LineInfo lineInfo, int line) { | |
| 2427 while (lineInfo.getLocation(token.offset).lineNumber < line) { | |
|
Brian Wilkerson
2016/04/22 14:10:23
I don't have the code handy, but I think there's a
pquitslund
2016/04/22 16:18:47
Oh nice. Only one call to `lineInfo`. Good idea,
| |
| 2428 token = token.next; | |
| 2429 } | |
| 2430 return token; | |
| 2431 } | |
| 2432 | |
| 2426 List<AnalysisError> _filterIgnores(List<AnalysisError> errors) { | 2433 List<AnalysisError> _filterIgnores(List<AnalysisError> errors) { |
| 2427 if (errors.isEmpty) { | 2434 if (errors.isEmpty) { |
| 2428 return errors; | 2435 return errors; |
| 2429 } | 2436 } |
| 2430 | 2437 |
| 2431 List<AnalysisError> filtered = <AnalysisError>[]; | |
| 2432 | |
| 2433 // Sort errors. | 2438 // Sort errors. |
| 2434 errors.sort((AnalysisError e1, AnalysisError e2) => e1.offset - e2.offset); | 2439 errors.sort((AnalysisError e1, AnalysisError e2) => e1.offset - e2.offset); |
| 2435 | 2440 |
| 2436 CompilationUnit cu = getRequiredInput(PARSED_UNIT_INPUT); | 2441 CompilationUnit cu = getRequiredInput(PARSED_UNIT_INPUT); |
| 2437 Token token = cu.beginToken; | 2442 Token token = cu.beginToken; |
| 2438 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT); | 2443 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT); |
| 2439 | 2444 |
| 2440 int errorIndex = 0; | 2445 bool isIgnored(AnalysisError error) { |
| 2446 int errorLine = lineInfo.getLocation(error.offset).lineNumber; | |
| 2447 token = _advanceToLine(token, lineInfo, errorLine); | |
| 2441 | 2448 |
| 2442 // Step through tokens looking for comments. | 2449 //Check for leading comment. |
| 2443 while (errorIndex < errors.length && token.type != TokenType.EOF) { | |
| 2444 // Find leading comment. | |
| 2445 Token comments = token.precedingComments; | 2450 Token comments = token.precedingComments; |
| 2446 while (comments?.next != null) { | 2451 while (comments?.next != null) { |
| 2447 comments = comments.next; | 2452 comments = comments.next; |
| 2448 } | 2453 } |
| 2454 if (_isIgnoredBy(error, comments)) { | |
| 2455 return true; | |
| 2456 } | |
| 2449 | 2457 |
| 2450 // Normalize content. | 2458 //Check for trailing comment. |
| 2451 String comment = | 2459 Token nextLine = _advanceToLine(token, lineInfo, errorLine + 1); |
| 2452 comments?.lexeme?.toLowerCase()?.replaceAll(spacesRegExp, ''); | 2460 comments = nextLine.precedingComments; |
| 2453 | 2461 if (comments != null && nextLine.previous.type != TokenType.EOF) { |
| 2454 // Check for ignores. | 2462 int commentLine = lineInfo.getLocation(comments.offset).lineNumber; |
| 2455 if (comment != null && comment.startsWith(_normalizedIgnorePrefix)) { | 2463 int previousTokenLine = |
| 2456 int affectedLine = lineInfo.getLocation(token.offset).lineNumber; | 2464 lineInfo.getLocation(nextLine.previous.offset).lineNumber; |
| 2457 | 2465 if (commentLine == previousTokenLine) { |
|
Brian Wilkerson
2016/04/22 14:10:22
Don't we want to compare commentLine to the errorL
pquitslund
2016/04/22 16:18:47
Simpler, yes. Done.
| |
| 2458 // Process all affected errors. | 2466 return _isIgnoredBy(error, comments); |
| 2459 while (errorIndex < errors.length) { | |
| 2460 AnalysisError currentError = errors[errorIndex++]; | |
| 2461 int errorLine = lineInfo.getLocation(currentError.offset).lineNumber; | |
| 2462 if (errorLine < affectedLine) { | |
| 2463 filtered.add(currentError); | |
| 2464 } else if (errorLine == affectedLine) { | |
| 2465 // Check for an ignore. | |
| 2466 if (!_isIgnoredBy(currentError, comment)) { | |
| 2467 filtered.add(currentError); | |
| 2468 } | |
| 2469 } else { | |
| 2470 // Back up index and break. | |
| 2471 --errorIndex; | |
| 2472 break; | |
| 2473 } | |
| 2474 } | 2467 } |
| 2475 } | 2468 } |
| 2476 | 2469 |
| 2477 token = token.next; | 2470 return false; |
| 2478 } | 2471 } |
| 2479 | 2472 |
| 2480 // Add remaining errors. | 2473 return errors.where((AnalysisError e) => !isIgnored(e)).toList(); |
| 2481 if (errorIndex < errors.length) { | |
| 2482 filtered.addAll(errors.sublist(errorIndex)); | |
| 2483 } | |
| 2484 | |
| 2485 return filtered; | |
| 2486 } | 2474 } |
| 2487 | 2475 |
| 2488 bool _isIgnoredBy(AnalysisError error, String comment) => comment | 2476 bool _isIgnoredBy(AnalysisError error, Token comment) { |
| 2489 .substring(_normalizedIgnorePrefix.length) | 2477 //Normalize first. |
| 2490 .split(',') | 2478 String contents = |
| 2491 .contains(error.errorCode.name.toLowerCase()); | 2479 comment?.lexeme?.toLowerCase()?.replaceAll(spacesRegExp, ''); |
| 2480 if (contents == null || !contents.startsWith(_normalizedIgnorePrefix)) { | |
| 2481 return false; | |
| 2482 } | |
| 2483 return contents | |
| 2484 .substring(_normalizedIgnorePrefix.length) | |
| 2485 .split(',') | |
| 2486 .contains(error.errorCode.name.toLowerCase()); | |
| 2487 } | |
| 2492 | 2488 |
| 2493 /** | 2489 /** |
| 2494 * Return a map from the names of the inputs of this kind of task to the task | 2490 * Return a map from the names of the inputs of this kind of task to the task |
| 2495 * input descriptors describing those inputs for a task with the | 2491 * input descriptors describing those inputs for a task with the |
| 2496 * given [target]. | 2492 * given [target]. |
| 2497 */ | 2493 */ |
| 2498 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { | 2494 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
| 2499 Source source = target; | 2495 Source source = target; |
| 2500 Map<String, TaskInput> inputs = <String, TaskInput>{}; | 2496 Map<String, TaskInput> inputs = <String, TaskInput>{}; |
| 2501 inputs[LINE_INFO_INPUT] = LINE_INFO.of(source); | 2497 inputs[LINE_INFO_INPUT] = LINE_INFO.of(source); |
| (...skipping 3050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5552 | 5548 |
| 5553 @override | 5549 @override |
| 5554 bool moveNext() { | 5550 bool moveNext() { |
| 5555 if (_newSources.isEmpty) { | 5551 if (_newSources.isEmpty) { |
| 5556 return false; | 5552 return false; |
| 5557 } | 5553 } |
| 5558 currentTarget = _newSources.removeLast(); | 5554 currentTarget = _newSources.removeLast(); |
| 5559 return true; | 5555 return true; |
| 5560 } | 5556 } |
| 5561 } | 5557 } |
| OLD | NEW |