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

Unified Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1413783005: `LineInfo` line-end detection fixes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Tests. Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/task/options.dart
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index 9f22f7f647aec59ebd23f567d3067a99073e2c09..5f8946efcfa074658218c01a7e31c2146f703319 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -81,7 +81,7 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
// Record outputs.
//
outputs[ANALYSIS_OPTIONS_ERRORS] = errors;
- outputs[LINE_INFO] = _computeLineInfo(content);
+ outputs[LINE_INFO] = computeLineInfo(content);
}
List<AnalysisError> _validate(Map<String, YamlNode> options) =>
@@ -93,21 +93,34 @@ class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
static Map<String, TaskInput> buildInputs(Source source) =>
<String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
- /// Create a task based on the given [target] in the given [context].
- static GenerateOptionsErrorsTask createTask(
- AnalysisContext context, AnalysisTarget target) =>
- new GenerateOptionsErrorsTask(context, target);
-
/// Compute [LineInfo] for the given [content].
- static LineInfo _computeLineInfo(String content) {
+ static LineInfo computeLineInfo(String content) {
List<int> lineStarts = <int>[0];
- for (int index = 0; index < content.length; index++) {
- if (content.codeUnitAt(index) == 0x0A) {
+ int length = content.length;
+ int unit;
+ for (int index = 0; index < length; index++) {
+ unit = content.codeUnitAt(index);
+ // Special-case \r\n.
+ if (unit == 0x0D /* \r */) {
+ // Peek ahead to detect a following \n.
+ if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) {
+ // Line start will get registered at next index at the \n.
+ } else {
+ lineStarts.add(index + 1);
+ }
+ }
+
+ if (unit == 0x0A) {
lineStarts.add(index + 1);
}
}
return new LineInfo(lineStarts);
}
+
+ /// Create a task based on the given [target] in the given [context].
+ static GenerateOptionsErrorsTask createTask(
+ AnalysisContext context, AnalysisTarget target) =>
+ new GenerateOptionsErrorsTask(context, target);
}
/// Validates `linter` top-level options.
« no previous file with comments | « pkg/analysis_server/test/integration/analysis/analysis_options_test.dart ('k') | pkg/analyzer/test/src/task/options_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698