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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/driver.dart

Issue 2455843002: Several tests for AnalysisDriver and an elements.dart tweak. (Closed)
Patch Set: Created 4 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:convert'; 7 import 'dart:convert';
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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 _verifyApiSignatureOfChangedFile(path); 235 _verifyApiSignatureOfChangedFile(path);
236 // Repeat the processing loop. 236 // Repeat the processing loop.
237 _hasWork.notify(); 237 _hasWork.notify();
238 continue; 238 continue;
239 } 239 }
240 240
241 // Analyze a requested file. 241 // Analyze a requested file.
242 if (_requestedFiles.isNotEmpty) { 242 if (_requestedFiles.isNotEmpty) {
243 String path = _requestedFiles.keys.first; 243 String path = _requestedFiles.keys.first;
244 AnalysisResult result = _computeAnalysisResult(path, withUnit: true); 244 AnalysisResult result = _computeAnalysisResult(path, withUnit: true);
245 // Notify the completers.
245 _requestedFiles.remove(path).forEach((completer) { 246 _requestedFiles.remove(path).forEach((completer) {
246 completer.complete(result); 247 completer.complete(result);
247 }); 248 });
249 // Remove from to be analyzed and produce it now.
250 _filesToAnalyze.remove(path);
248 yield result; 251 yield result;
249 // Repeat the processing loop. 252 // Repeat the processing loop.
250 _hasWork.notify(); 253 _hasWork.notify();
251 continue; 254 continue;
252 } 255 }
253 256
254 // Analyze a priority file. 257 // Analyze a priority file.
255 if (_priorityFiles.isNotEmpty) { 258 if (_priorityFiles.isNotEmpty) {
256 bool analyzed = false; 259 bool analyzed = false;
257 for (String path in _priorityFiles) { 260 for (String path in _priorityFiles) {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 426
424 // We need the fully resolved unit, or the result is not cached. 427 // We need the fully resolved unit, or the result is not cached.
425 return _logger.run('Compute analysis result for $source', () { 428 return _logger.run('Compute analysis result for $source', () {
426 // Still no result, compute and store it. 429 // Still no result, compute and store it.
427 _File file = new _File.forResolution(this, source); 430 _File file = new _File.forResolution(this, source);
428 _LibraryContext libraryContext = _createLibraryContext(file); 431 _LibraryContext libraryContext = _createLibraryContext(file);
429 AnalysisContext analysisContext = _createAnalysisContext(libraryContext); 432 AnalysisContext analysisContext = _createAnalysisContext(libraryContext);
430 try { 433 try {
431 analysisContext.setContents(file.source, file.content); 434 analysisContext.setContents(file.source, file.content);
432 // TODO(scheglov) Add support for parts. 435 // TODO(scheglov) Add support for parts.
433 CompilationUnit resolvedUnit = 436 CompilationUnit resolvedUnit = withUnit
434 analysisContext.resolveCompilationUnit2(file.source, file.source); 437 ? analysisContext.resolveCompilationUnit2(file.source, file.source)
438 : null;
435 List<AnalysisError> errors = analysisContext.computeErrors(file.source); 439 List<AnalysisError> errors = analysisContext.computeErrors(file.source);
436 440
437 // Store the result into the cache. 441 // Store the result into the cache.
438 { 442 {
439 List<int> bytes = new AnalysisDriverResolvedUnitBuilder( 443 List<int> bytes = new AnalysisDriverResolvedUnitBuilder(
440 errors: errors 444 errors: errors
441 .map((error) => new AnalysisDriverUnitErrorBuilder( 445 .map((error) => new AnalysisDriverUnitErrorBuilder(
442 offset: error.offset, 446 offset: error.offset,
443 length: error.length, 447 length: error.length,
444 uniqueName: error.errorCode.uniqueName, 448 uniqueName: error.errorCode.uniqueName,
445 message: error.message, 449 message: error.message,
446 correction: error.correction)) 450 correction: error.correction))
447 .toList()) 451 .toList())
448 .toBuffer(); 452 .toBuffer();
449 String key = _getResolvedUnitKey(file); 453 String key = _getResolvedUnitKey(file);
450 _byteStore.put(key, bytes); 454 _byteStore.put(key, bytes);
451 } 455 }
452 456
453 // Return the full result. 457 // Return the result, full or partial.
454 _logger.writeln('Computed new analysis result.'); 458 _logger.writeln('Computed new analysis result.');
455 return new AnalysisResult(file.path, file.uri, file.content, 459 return new AnalysisResult(
456 file.contentHash, resolvedUnit, errors); 460 file.path,
461 file.uri,
462 withUnit ? file.content : null,
463 file.contentHash,
464 resolvedUnit,
465 errors);
457 } finally { 466 } finally {
458 analysisContext.dispose(); 467 analysisContext.dispose();
459 } 468 }
460 }); 469 });
461 } 470 }
462 471
463 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { 472 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) {
464 AnalysisContextImpl analysisContext = 473 AnalysisContextImpl analysisContext =
465 AnalysisEngine.instance.createAnalysisContext(); 474 AnalysisEngine.instance.createAnalysisContext();
466 475
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 await _completer.future; 1153 await _completer.future;
1145 _completer = new Completer<Null>(); 1154 _completer = new Completer<Null>();
1146 } 1155 }
1147 1156
1148 /** 1157 /**
1149 * Complete the [signal] future if it is not completed yet. It is safe to 1158 * Complete the [signal] future if it is not completed yet. It is safe to
1150 * call this method multiple times, but the [signal] will complete only once. 1159 * call this method multiple times, but the [signal] will complete only once.
1151 */ 1160 */
1152 void notify() { 1161 void notify() {
1153 if (!_completer.isCompleted) { 1162 if (!_completer.isCompleted) {
1154 _completer.complete(true); 1163 _completer.complete(null);
1155 } 1164 }
1156 } 1165 }
1157 } 1166 }
1158 1167
1159 /** 1168 /**
1160 * TODO(scheglov) document 1169 * TODO(scheglov) document
1161 */ 1170 */
1162 class _ReferencedUris { 1171 class _ReferencedUris {
1163 bool isLibrary = true; 1172 bool isLibrary = true;
1164 final List<String> imported = <String>[]; 1173 final List<String> imported = <String>[];
1165 final List<String> exported = <String>[]; 1174 final List<String> exported = <String>[];
1166 final List<String> parted = <String>[]; 1175 final List<String> parted = <String>[];
1167 1176
1168 factory _ReferencedUris(UnlinkedUnit unit) { 1177 factory _ReferencedUris(UnlinkedUnit unit) {
1169 _ReferencedUris referenced = new _ReferencedUris._(); 1178 _ReferencedUris referenced = new _ReferencedUris._();
1170 referenced.parted.addAll(unit.publicNamespace.parts); 1179 referenced.parted.addAll(unit.publicNamespace.parts);
1171 for (UnlinkedImport import in unit.imports) { 1180 for (UnlinkedImport import in unit.imports) {
1172 if (!import.isImplicit) { 1181 if (!import.isImplicit) {
1173 referenced.imported.add(import.uri); 1182 referenced.imported.add(import.uri);
1174 } 1183 }
1175 } 1184 }
1176 for (UnlinkedExportPublic export in unit.publicNamespace.exports) { 1185 for (UnlinkedExportPublic export in unit.publicNamespace.exports) {
1177 referenced.exported.add(export.uri); 1186 referenced.exported.add(export.uri);
1178 } 1187 }
1179 return referenced; 1188 return referenced;
1180 } 1189 }
1181 1190
1182 _ReferencedUris._(); 1191 _ReferencedUris._();
1183 } 1192 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | pkg/analyzer/test/src/dart/analysis/driver_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698