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

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

Issue 1702753003: LINE_INFO, TOKEN_STREAM access cleanup. (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
« no previous file with comments | « no previous file | no next file » | 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.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 2206 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 * A task that merges all of the errors for a single source into a single list 2217 * A task that merges all of the errors for a single source into a single list
2218 * of errors. 2218 * of errors.
2219 */ 2219 */
2220 class DartErrorsTask extends SourceBasedAnalysisTask { 2220 class DartErrorsTask extends SourceBasedAnalysisTask {
2221 /** 2221 /**
2222 * The task descriptor describing this kind of task. 2222 * The task descriptor describing this kind of task.
2223 */ 2223 */
2224 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask', 2224 static final TaskDescriptor DESCRIPTOR = new TaskDescriptor('DartErrorsTask',
2225 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]); 2225 createTask, buildInputs, <ResultDescriptor>[DART_ERRORS]);
2226 2226
2227 /**
2228 * The name of the [LINE_INFO_INPUT] input.
2229 */
2230 static const String LINE_INFO_INPUT = 'LINE_INFO_INPUT';
2231
2232 /**
2233 * The name of the [PARSED_UNIT_INPUT] input.
2234 */
2235 static const String PARSED_UNIT_INPUT = 'PARSED_UNIT_INPUT';
2236
2227 // Prefix for comments ignoring error codes. 2237 // Prefix for comments ignoring error codes.
2228 static const String _normalizedIgnorePrefix = '//#ignore:'; 2238 static const String _normalizedIgnorePrefix = '//#ignore:';
2229 2239
2230 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target) 2240 DartErrorsTask(InternalAnalysisContext context, AnalysisTarget target)
2231 : super(context, target); 2241 : super(context, target);
2232 2242
2233 @override 2243 @override
2234 TaskDescriptor get descriptor => DESCRIPTOR; 2244 TaskDescriptor get descriptor => DESCRIPTOR;
2235 2245
2236 @override 2246 @override
(...skipping 30 matching lines...) Expand all
2267 List<AnalysisError> _filterIgnores(List<AnalysisError> errors) { 2277 List<AnalysisError> _filterIgnores(List<AnalysisError> errors) {
2268 if (errors.isEmpty) { 2278 if (errors.isEmpty) {
2269 return errors; 2279 return errors;
2270 } 2280 }
2271 2281
2272 List<AnalysisError> filtered = <AnalysisError>[]; 2282 List<AnalysisError> filtered = <AnalysisError>[];
2273 2283
2274 // Sort errors. 2284 // Sort errors.
2275 errors.sort((AnalysisError e1, AnalysisError e2) => e1.offset - e2.offset); 2285 errors.sort((AnalysisError e1, AnalysisError e2) => e1.offset - e2.offset);
2276 2286
2277 Source source = target; 2287 CompilationUnit cu = getRequiredInput(PARSED_UNIT_INPUT);
2278 String contents = context.getContents(source).data; 2288 Token token = cu.beginToken;
2279 Scanner scanner = new Scanner(source, new CharSequenceReader(contents), 2289 LineInfo lineInfo = getRequiredInput(LINE_INFO_INPUT);
2280 AnalysisErrorListener.NULL_LISTENER);
2281
2282 // Scan.
2283 Token token = scanner.tokenize();
2284 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
2285 2290
2286 int errorIndex = 0; 2291 int errorIndex = 0;
2287 2292
2288 // Step through tokens looking for comments. 2293 // Step through tokens looking for comments.
2289 while (errorIndex < errors.length && token.type != TokenType.EOF) { 2294 while (errorIndex < errors.length && token.type != TokenType.EOF) {
2290 // Find leading comment. 2295 // Find leading comment.
2291 Token comments = token.precedingComments; 2296 Token comments = token.precedingComments;
2292 while (comments?.next != null) { 2297 while (comments?.next != null) {
2293 comments = comments.next; 2298 comments = comments.next;
2294 } 2299 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2337 .contains(error.errorCode.name.toLowerCase()); 2342 .contains(error.errorCode.name.toLowerCase());
2338 2343
2339 /** 2344 /**
2340 * Return a map from the names of the inputs of this kind of task to the task 2345 * Return a map from the names of the inputs of this kind of task to the task
2341 * input descriptors describing those inputs for a task with the 2346 * input descriptors describing those inputs for a task with the
2342 * given [target]. 2347 * given [target].
2343 */ 2348 */
2344 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 2349 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
2345 Source source = target; 2350 Source source = target;
2346 Map<String, TaskInput> inputs = <String, TaskInput>{}; 2351 Map<String, TaskInput> inputs = <String, TaskInput>{};
2352 inputs[LINE_INFO_INPUT] = LINE_INFO.of(source);
2353 inputs[PARSED_UNIT_INPUT] = PARSED_UNIT.of(source);
2347 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin; 2354 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
2348 // for Source 2355 // for Source
2349 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) { 2356 for (ResultDescriptor result in enginePlugin.dartErrorsForSource) {
2350 String inputName = result.name + '_input'; 2357 String inputName = result.name + '_input';
2351 inputs[inputName] = result.of(source); 2358 inputs[inputName] = result.of(source);
2352 } 2359 }
2353 // for LibrarySpecificUnit 2360 // for LibrarySpecificUnit
2354 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) { 2361 for (ResultDescriptor result in enginePlugin.dartErrorsForUnit) {
2355 String inputName = result.name + '_input'; 2362 String inputName = result.name + '_input';
2356 inputs[inputName] = 2363 inputs[inputName] =
(...skipping 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after
5374 5381
5375 @override 5382 @override
5376 bool moveNext() { 5383 bool moveNext() {
5377 if (_newSources.isEmpty) { 5384 if (_newSources.isEmpty) {
5378 return false; 5385 return false;
5379 } 5386 }
5380 currentTarget = _newSources.removeLast(); 5387 currentTarget = _newSources.removeLast();
5381 return true; 5388 return true;
5382 } 5389 }
5383 } 5390 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698