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

Side by Side Diff: pkg/analyzer/lib/src/task/options.dart

Issue 1411253007: Extract 'computeLineStarts' utility. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Move into StringUtilities. Created 5 years, 1 month 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
« no previous file with comments | « pkg/analyzer/lib/src/task/html.dart ('k') | pkg/analyzer/test/generated/utilities_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.src.task.options; 5 library analyzer.src.task.options;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/plugin/options.dart'; 8 import 'package:analyzer/plugin/options.dart';
9 import 'package:analyzer/source/analysis_options_provider.dart'; 9 import 'package:analyzer/source/analysis_options_provider.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/generated/java_engine.dart';
11 import 'package:analyzer/src/generated/source.dart'; 12 import 'package:analyzer/src/generated/source.dart';
12 import 'package:analyzer/src/task/general.dart'; 13 import 'package:analyzer/src/task/general.dart';
13 import 'package:analyzer/task/general.dart'; 14 import 'package:analyzer/task/general.dart';
14 import 'package:analyzer/task/model.dart'; 15 import 'package:analyzer/task/model.dart';
15 import 'package:source_span/source_span.dart'; 16 import 'package:source_span/source_span.dart';
16 import 'package:yaml/yaml.dart'; 17 import 'package:yaml/yaml.dart';
17 18
18 /// The errors produced while parsing `.analysis_options` files. 19 /// The errors produced while parsing `.analysis_options` files.
19 /// 20 ///
20 /// The list will be empty if there were no errors, but will not be `null`. 21 /// The list will be empty if there were no errors, but will not be `null`.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 new OptionsFileValidator(source).validate(options); 89 new OptionsFileValidator(source).validate(options);
89 90
90 /// Return a map from the names of the inputs of this kind of task to the 91 /// Return a map from the names of the inputs of this kind of task to the
91 /// task input descriptors describing those inputs for a task with the 92 /// task input descriptors describing those inputs for a task with the
92 /// given [target]. 93 /// given [target].
93 static Map<String, TaskInput> buildInputs(Source source) => 94 static Map<String, TaskInput> buildInputs(Source source) =>
94 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)}; 95 <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
95 96
96 /// Compute [LineInfo] for the given [content]. 97 /// Compute [LineInfo] for the given [content].
97 static LineInfo computeLineInfo(String content) { 98 static LineInfo computeLineInfo(String content) {
98 List<int> lineStarts = <int>[0]; 99 List<int> lineStarts = StringUtilities.computeLineStarts(content);
99 int length = content.length;
100 int unit;
101 for (int index = 0; index < length; index++) {
102 unit = content.codeUnitAt(index);
103 // Special-case \r\n.
104 if (unit == 0x0D /* \r */) {
105 // Peek ahead to detect a following \n.
106 if ((index + 1 < length) && content.codeUnitAt(index + 1) == 0x0A) {
107 // Line start will get registered at next index at the \n.
108 } else {
109 lineStarts.add(index + 1);
110 }
111 }
112
113 if (unit == 0x0A) {
114 lineStarts.add(index + 1);
115 }
116 }
117 return new LineInfo(lineStarts); 100 return new LineInfo(lineStarts);
118 } 101 }
119 102
120 /// Create a task based on the given [target] in the given [context]. 103 /// Create a task based on the given [target] in the given [context].
121 static GenerateOptionsErrorsTask createTask( 104 static GenerateOptionsErrorsTask createTask(
122 AnalysisContext context, AnalysisTarget target) => 105 AnalysisContext context, AnalysisTarget target) =>
123 new GenerateOptionsErrorsTask(context, target); 106 new GenerateOptionsErrorsTask(context, target);
124 } 107 }
125 108
126 /// Validates `linter` top-level options. 109 /// Validates `linter` top-level options.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION, 152 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION,
170 k.span, 153 k.span,
171 [pluginName, k.value]); 154 [pluginName, k.value]);
172 } 155 }
173 } 156 }
174 //TODO(pq): consider an error if the node is not a Scalar. 157 //TODO(pq): consider an error if the node is not a Scalar.
175 }); 158 });
176 } 159 }
177 } 160 }
178 } 161 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/html.dart ('k') | pkg/analyzer/test/generated/utilities_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698