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

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

Issue 1167733004: Decide if unit without directives is a part or a library. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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.src.task.dart_work_manager; 5 library analyzer.src.task.dart_work_manager;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/cache.dart'; 9 import 'package:analyzer/src/context/cache.dart';
10 import 'package:analyzer/src/generated/engine.dart' 10 import 'package:analyzer/src/generated/engine.dart'
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 WorkOrderPriority getNextResultPriority() { 236 WorkOrderPriority getNextResultPriority() {
237 if (priorityResultQueue.isNotEmpty) { 237 if (priorityResultQueue.isNotEmpty) {
238 return WorkOrderPriority.PRIORITY; 238 return WorkOrderPriority.PRIORITY;
239 } 239 }
240 if (unknownSourceQueue.isNotEmpty || librarySourceQueue.isNotEmpty) { 240 if (unknownSourceQueue.isNotEmpty || librarySourceQueue.isNotEmpty) {
241 return WorkOrderPriority.NORMAL; 241 return WorkOrderPriority.NORMAL;
242 } 242 }
243 return WorkOrderPriority.NONE; 243 return WorkOrderPriority.NONE;
244 } 244 }
245 245
246 void unitIncrementallyResolved(Source librarySource, Source unitSource) {
247 librarySourceQueue.add(librarySource);
248 }
249
250 @override 246 @override
251 void resultsComputed( 247 void resultsComputed(
252 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) { 248 AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) {
253 // Organize sources. 249 // Organize sources.
254 if (_isDartSource(target)) { 250 if (_isDartSource(target)) {
255 SourceKind kind = outputs[SOURCE_KIND]; 251 SourceKind kind = outputs[SOURCE_KIND];
256 if (kind != null) { 252 if (kind != null) {
257 unknownSourceQueue.remove(target); 253 unknownSourceQueue.remove(target);
258 if (kind == SourceKind.LIBRARY && 254 if (kind == SourceKind.LIBRARY &&
259 context.shouldErrorsBeAnalyzed(target, null)) { 255 context.shouldErrorsBeAnalyzed(target, null)) {
260 librarySourceQueue.add(target); 256 librarySourceQueue.add(target);
261 } 257 }
262 } 258 }
263 } 259 }
264 // Update parts in libraries. 260 // Update parts in libraries.
265 if (_isDartSource(target)) { 261 if (_isDartSource(target)) {
266 Source library = target; 262 Source library = target;
267 List<Source> includedParts = outputs[INCLUDED_PARTS]; 263 List<Source> includedParts = outputs[INCLUDED_PARTS];
268 if (includedParts != null) { 264 if (includedParts != null) {
269 libraryPartsMap[library] = includedParts; 265 libraryPartsMap[library] = includedParts;
266 // update contanining libraries
270 for (Source part in includedParts) { 267 for (Source part in includedParts) {
271 List<Source> libraries = 268 List<Source> libraries =
272 partLibrariesMap.putIfAbsent(part, () => <Source>[]); 269 partLibrariesMap.putIfAbsent(part, () => <Source>[]);
273 if (!libraries.contains(library)) { 270 if (!libraries.contains(library)) {
274 libraries.add(library); 271 libraries.add(library);
275 } 272 }
276 } 273 }
274 // all of the "includedParts" are not libraries anymore
275 for (Source part in includedParts) {
276 unknownSourceQueue.remove(part);
277 librarySourceQueue.remove(part);
278 analysisCache.remove(new LibrarySpecificUnit(part, part));
279 CacheEntry partEntry = analysisCache.get(part);
280 if (partEntry != null) {
281 partEntry.setValue(SOURCE_KIND, SourceKind.PART, <TargetedResult>[
282 new TargetedResult(part, CONTENT),
283 new TargetedResult(target, CONTENT)
284 ]);
285 }
286 }
277 } 287 }
278 } 288 }
279 // Update notice. 289 // Update notice.
280 if (_isDartSource(target)) { 290 if (_isDartSource(target)) {
281 bool shouldSetErrors = false; 291 bool shouldSetErrors = false;
282 outputs.forEach((ResultDescriptor descriptor, value) { 292 outputs.forEach((ResultDescriptor descriptor, value) {
283 if (descriptor == PARSED_UNIT && value != null) { 293 if (descriptor == PARSED_UNIT && value != null) {
284 context.getNotice(target).parsedDartUnit = value; 294 context.getNotice(target).parsedDartUnit = value;
285 shouldSetErrors = true; 295 shouldSetErrors = true;
286 } 296 }
(...skipping 15 matching lines...) Expand all
302 shouldSetErrors = true; 312 shouldSetErrors = true;
303 } 313 }
304 }); 314 });
305 if (shouldSetErrors) { 315 if (shouldSetErrors) {
306 AnalysisErrorInfo info = getErrors(source); 316 AnalysisErrorInfo info = getErrors(source);
307 context.getNotice(source).setErrors(info.errors, info.lineInfo); 317 context.getNotice(source).setErrors(info.errors, info.lineInfo);
308 } 318 }
309 } 319 }
310 } 320 }
311 321
322 void unitIncrementallyResolved(Source librarySource, Source unitSource) {
323 librarySourceQueue.add(librarySource);
324 }
325
312 /** 326 /**
313 * Returns `true` if the given [result] of the given [target] needs 327 * Returns `true` if the given [result] of the given [target] needs
314 * computing, i.e. it is not in the valid and not in the error state. 328 * computing, i.e. it is not in the valid and not in the error state.
315 */ 329 */
316 bool _needsComputing(AnalysisTarget target, ResultDescriptor result) { 330 bool _needsComputing(AnalysisTarget target, ResultDescriptor result) {
317 CacheState state = analysisCache.getState(target, result); 331 CacheState state = analysisCache.getState(target, result);
318 return state != CacheState.VALID && state != CacheState.ERROR; 332 return state != CacheState.VALID && state != CacheState.ERROR;
319 } 333 }
320 334
321 /** 335 /**
322 * The given [library] source was changed or removed. 336 * The given [library] source was changed or removed.
323 * Update [libraryPartsMap] and [partLibrariesMap]. 337 * Update [libraryPartsMap] and [partLibrariesMap].
324 */ 338 */
325 void _onLibrarySourceChangedOrRemoved(Source library) { 339 void _onLibrarySourceChangedOrRemoved(Source library) {
326 List<Source> parts = libraryPartsMap.remove(library); 340 List<Source> parts = libraryPartsMap.remove(library);
327 if (parts != null) { 341 if (parts != null) {
328 for (Source part in parts) { 342 for (Source part in parts) {
329 List<Source> libraries = partLibrariesMap[part]; 343 List<Source> libraries = partLibrariesMap[part];
330 if (libraries != null) { 344 if (libraries != null) {
331 libraries.remove(library); 345 libraries.remove(library);
332 } 346 }
333 } 347 }
334 } 348 }
335 } 349 }
336 350
337 static bool _isDartSource(AnalysisTarget target) { 351 static bool _isDartSource(AnalysisTarget target) {
338 return target is Source && AnalysisEngine.isDartFileName(target.fullName); 352 return target is Source && AnalysisEngine.isDartFileName(target.fullName);
339 } 353 }
340 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698