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

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

Issue 2450183004: More tests and a few fixed for the driver. (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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Repeat the processing loop. 252 // Repeat the processing loop.
253 _hasWork.notify(); 253 _hasWork.notify();
254 continue; 254 continue;
255 } 255 }
256 256
257 // Analyze a priority file. 257 // Analyze a priority file.
258 if (_priorityFiles.isNotEmpty) { 258 if (_priorityFiles.isNotEmpty) {
259 bool analyzed = false; 259 bool analyzed = false;
260 for (String path in _priorityFiles) { 260 for (String path in _priorityFiles) {
261 if (_filesToAnalyze.remove(path)) { 261 if (_filesToAnalyze.remove(path)) {
262 analyzed = true;
262 AnalysisResult result = 263 AnalysisResult result =
263 _computeAnalysisResult(path, withUnit: true); 264 _computeAnalysisResult(path, withUnit: true);
264 yield result; 265 yield result;
265 break; 266 break;
266 } 267 }
267 } 268 }
268 // Repeat the processing loop. 269 // Repeat the processing loop.
269 if (analyzed) { 270 if (analyzed) {
270 _hasWork.notify(); 271 _hasWork.notify();
271 continue; 272 continue;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 * into the current file state prior to the next time the analysis state 325 * into the current file state prior to the next time the analysis state
325 * transitions to "idle". 326 * transitions to "idle".
326 * 327 *
327 * Invocation of this method will not prevent a [Future] returned from 328 * Invocation of this method will not prevent a [Future] returned from
328 * [getResult] from completing with a result, but the result is not 329 * [getResult] from completing with a result, but the result is not
329 * guaranteed to be consistent with the new current file state after this 330 * guaranteed to be consistent with the new current file state after this
330 * [changeFile] invocation. 331 * [changeFile] invocation.
331 */ 332 */
332 void changeFile(String path) { 333 void changeFile(String path) {
333 _changedFiles.add(path); 334 _changedFiles.add(path);
334 _filesToAnalyze.add(path); 335 if (_explicitFiles.contains(path)) {
336 _filesToAnalyze.add(path);
337 }
335 _transitionToAnalyzing(); 338 _transitionToAnalyzing();
336 _hasWork.notify(); 339 _hasWork.notify();
337 } 340 }
338 341
339 /** 342 /**
340 * Return the [Future] that completes with a [AnalysisResult] for the file 343 * Return the [Future] that completes with a [AnalysisResult] for the file
341 * with the given [path]. 344 * with the given [path].
342 * 345 *
343 * The [path] must be absolute and normalized. 346 * The [path] must be absolute and normalized.
344 * 347 *
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 errors); 468 errors);
466 } finally { 469 } finally {
467 analysisContext.dispose(); 470 analysisContext.dispose();
468 } 471 }
469 }); 472 });
470 } 473 }
471 474
472 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) { 475 AnalysisContext _createAnalysisContext(_LibraryContext libraryContext) {
473 AnalysisContextImpl analysisContext = 476 AnalysisContextImpl analysisContext =
474 AnalysisEngine.instance.createAnalysisContext(); 477 AnalysisEngine.instance.createAnalysisContext();
478 analysisContext.analysisOptions = _analysisOptions;
475 479
476 analysisContext.sourceFactory = 480 analysisContext.sourceFactory =
477 new SourceFactory((_sourceFactory as SourceFactoryImpl).resolvers); 481 new SourceFactory((_sourceFactory as SourceFactoryImpl).resolvers);
478 analysisContext.resultProvider = 482 analysisContext.resultProvider =
479 new InputPackagesResultProvider(analysisContext, libraryContext.store); 483 new InputPackagesResultProvider(analysisContext, libraryContext.store);
480 analysisContext 484 analysisContext
481 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source)); 485 .applyChanges(new ChangeSet()..addedSource(libraryContext.file.source));
482 return analysisContext; 486 return analysisContext;
483 } 487 }
484 488
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 if (contentHash == null) { 938 if (contentHash == null) {
935 _File file = new _File.forContent(driver, source); 939 _File file = new _File.forContent(driver, source);
936 contentHash = file.contentHash; 940 contentHash = file.contentHash;
937 } 941 }
938 // If we have the cached unlinked bundle, use it. 942 // If we have the cached unlinked bundle, use it.
939 { 943 {
940 String key = '$contentHash.unlinked'; 944 String key = '$contentHash.unlinked';
941 List<int> bytes = driver._byteStore.get(key); 945 List<int> bytes = driver._byteStore.get(key);
942 if (bytes != null) { 946 if (bytes != null) {
943 PackageBundle unlinked = new PackageBundle.fromBuffer(bytes); 947 PackageBundle unlinked = new PackageBundle.fromBuffer(bytes);
944 driver._fileApiSignatureMap[path] = unlinked.apiSignature; 948 _updateApiSignature(driver, path, unlinked.apiSignature);
945 return new _File._(driver, source, null, contentHash, unlinked, null); 949 return new _File._(driver, source, null, contentHash, unlinked, null);
946 } 950 }
947 } 951 }
948 // Otherwise, read the source, parse and build a new unlinked bundle. 952 // Otherwise, read the source, parse and build a new unlinked bundle.
949 return new _File.forResolution(driver, source); 953 return new _File.forResolution(driver, source);
950 } 954 }
951 955
952 factory _File.forResolution(AnalysisDriver driver, Source source) { 956 factory _File.forResolution(AnalysisDriver driver, Source source) {
953 _File file = new _File.forContent(driver, source); 957 _File file = new _File.forContent(driver, source);
954 String path = file.path; 958 String path = file.path;
(...skipping 10 matching lines...) Expand all
965 driver._logger.run('Create unlinked for $path', () { 969 driver._logger.run('Create unlinked for $path', () {
966 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit); 970 UnlinkedUnitBuilder unlinkedUnit = serializeAstUnlinked(unit);
967 PackageBundleAssembler assembler = new PackageBundleAssembler(); 971 PackageBundleAssembler assembler = new PackageBundleAssembler();
968 assembler.addUnlinkedUnitWithHash( 972 assembler.addUnlinkedUnitWithHash(
969 source.uri.toString(), unlinkedUnit, contentHash); 973 source.uri.toString(), unlinkedUnit, contentHash);
970 bytes = assembler.assemble().toBuffer(); 974 bytes = assembler.assemble().toBuffer();
971 driver._byteStore.put(key, bytes); 975 driver._byteStore.put(key, bytes);
972 }); 976 });
973 } 977 }
974 unlinked = new PackageBundle.fromBuffer(bytes); 978 unlinked = new PackageBundle.fromBuffer(bytes);
975 driver._fileApiSignatureMap[path] = unlinked.apiSignature; 979 _updateApiSignature(driver, path, unlinked.apiSignature);
976 } 980 }
977 // Return the full file. 981 // Return the full file.
978 return new _File._(driver, source, content, contentHash, unlinked, unit); 982 return new _File._(driver, source, content, contentHash, unlinked, unit);
979 } 983 }
980 984
981 _File._(this.driver, this.source, this.content, this.contentHash, 985 _File._(this.driver, this.source, this.content, this.contentHash,
982 this.unlinked, this.unit); 986 this.unlinked, this.unit);
983 987
984 String get path => source.fullName; 988 String get path => source.fullName;
985 989
(...skipping 28 matching lines...) Expand all
1014 scanner.scanGenericMethodComments = driver._analysisOptions.strongMode; 1018 scanner.scanGenericMethodComments = driver._analysisOptions.strongMode;
1015 Token token = scanner.tokenize(); 1019 Token token = scanner.tokenize();
1016 LineInfo lineInfo = new LineInfo(scanner.lineStarts); 1020 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
1017 1021
1018 Parser parser = new Parser(source, errorListener); 1022 Parser parser = new Parser(source, errorListener);
1019 parser.parseGenericMethodComments = driver._analysisOptions.strongMode; 1023 parser.parseGenericMethodComments = driver._analysisOptions.strongMode;
1020 CompilationUnit unit = parser.parseCompilationUnit(token); 1024 CompilationUnit unit = parser.parseCompilationUnit(token);
1021 unit.lineInfo = lineInfo; 1025 unit.lineInfo = lineInfo;
1022 return unit; 1026 return unit;
1023 } 1027 }
1028
1029 static void _updateApiSignature(
1030 AnalysisDriver driver, String path, String newSignature) {
1031 String oldSignature = driver._fileApiSignatureMap[path];
1032 if (oldSignature != null && oldSignature != newSignature) {
1033 driver._dependencySignatureMap.clear();
1034 }
1035 driver._fileApiSignatureMap[path] = newSignature;
1036 }
1024 } 1037 }
1025 1038
1026 /** 1039 /**
1027 * TODO(scheglov) document 1040 * TODO(scheglov) document
1028 */ 1041 */
1029 class _LibraryContext { 1042 class _LibraryContext {
1030 final _File file; 1043 final _File file;
1031 final _LibraryNode node; 1044 final _LibraryNode node;
1032 final SummaryDataStore store; 1045 final SummaryDataStore store;
1033 _LibraryContext(this.file, this.node, this.store); 1046 _LibraryContext(this.file, this.node, this.store);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 } 1196 }
1184 } 1197 }
1185 for (UnlinkedExportPublic export in unit.publicNamespace.exports) { 1198 for (UnlinkedExportPublic export in unit.publicNamespace.exports) {
1186 referenced.exported.add(export.uri); 1199 referenced.exported.add(export.uri);
1187 } 1200 }
1188 return referenced; 1201 return referenced;
1189 } 1202 }
1190 1203
1191 _ReferencedUris._(); 1204 _ReferencedUris._();
1192 } 1205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698