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

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

Issue 1490233007: Remove the old task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@analyzer-breaking-0.27
Patch Set: Created 5 years 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/context/cache.dart ('k') | pkg/analyzer/lib/src/generated/constant.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.context.context; 5 library analyzer.src.context.context;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/instrumentation/instrumentation.dart'; 10 import 'package:analyzer/instrumentation/instrumentation.dart';
11 import 'package:analyzer/plugin/task.dart'; 11 import 'package:analyzer/plugin/task.dart';
12 import 'package:analyzer/source/embedder.dart'; 12 import 'package:analyzer/source/embedder.dart';
13 import 'package:analyzer/src/cancelable_future.dart'; 13 import 'package:analyzer/src/cancelable_future.dart';
14 import 'package:analyzer/src/context/cache.dart'; 14 import 'package:analyzer/src/context/cache.dart';
15 import 'package:analyzer/src/generated/ast.dart'; 15 import 'package:analyzer/src/generated/ast.dart';
16 import 'package:analyzer/src/generated/constant.dart'; 16 import 'package:analyzer/src/generated/constant.dart';
17 import 'package:analyzer/src/generated/element.dart'; 17 import 'package:analyzer/src/generated/element.dart';
18 import 'package:analyzer/src/generated/engine.dart' 18 import 'package:analyzer/src/generated/engine.dart';
19 hide
20 AnalysisCache,
21 CachePartition,
22 SdkCachePartition,
23 UniversalCachePartition,
24 WorkManager;
25 import 'package:analyzer/src/generated/error.dart'; 19 import 'package:analyzer/src/generated/error.dart';
26 import 'package:analyzer/src/generated/html.dart' as ht show HtmlUnit; 20 import 'package:analyzer/src/generated/html.dart' as ht show HtmlUnit;
27 import 'package:analyzer/src/generated/incremental_resolver.dart'; 21 import 'package:analyzer/src/generated/incremental_resolver.dart';
28 import 'package:analyzer/src/generated/java_core.dart'; 22 import 'package:analyzer/src/generated/java_core.dart';
29 import 'package:analyzer/src/generated/java_engine.dart'; 23 import 'package:analyzer/src/generated/java_engine.dart';
30 import 'package:analyzer/src/generated/resolver.dart'; 24 import 'package:analyzer/src/generated/resolver.dart';
31 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
32 import 'package:analyzer/src/generated/source.dart'; 26 import 'package:analyzer/src/generated/source.dart';
33 import 'package:analyzer/src/generated/utilities_collection.dart'; 27 import 'package:analyzer/src/generated/utilities_collection.dart';
34 import 'package:analyzer/src/task/dart.dart'; 28 import 'package:analyzer/src/task/dart.dart';
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 * A factory to override how the [ResolverVisitor] is created. 208 * A factory to override how the [ResolverVisitor] is created.
215 */ 209 */
216 ResolverVisitorFactory resolverVisitorFactory; 210 ResolverVisitorFactory resolverVisitorFactory;
217 211
218 /** 212 /**
219 * A factory to override how the [TypeResolverVisitor] is created. 213 * A factory to override how the [TypeResolverVisitor] is created.
220 */ 214 */
221 TypeResolverVisitorFactory typeResolverVisitorFactory; 215 TypeResolverVisitorFactory typeResolverVisitorFactory;
222 216
223 /** 217 /**
224 * A factory to override how [LibraryResolver] is created.
225 */
226 LibraryResolverFactory libraryResolverFactory;
227
228 /**
229 * Initialize a newly created analysis context. 218 * Initialize a newly created analysis context.
230 */ 219 */
231 AnalysisContextImpl() { 220 AnalysisContextImpl() {
232 _privatePartition = new UniversalCachePartition(this); 221 _privatePartition = new UniversalCachePartition(this);
233 _cache = createCacheFromSourceFactory(null); 222 _cache = createCacheFromSourceFactory(null);
234 _taskManager = AnalysisEngine.instance.taskManager; 223 _taskManager = AnalysisEngine.instance.taskManager;
235 for (WorkManagerFactory factory 224 for (WorkManagerFactory factory
236 in AnalysisEngine.instance.enginePlugin.workManagerFactories) { 225 in AnalysisEngine.instance.enginePlugin.workManagerFactories) {
237 WorkManager workManager = factory(this); 226 WorkManager workManager = factory(this);
238 if (workManager != null) { 227 if (workManager != null) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 while (iterator.moveNext()) { 436 while (iterator.moveNext()) {
448 AnalysisTarget target = iterator.key; 437 AnalysisTarget target = iterator.key;
449 if (target is Source) { 438 if (target is Source) {
450 _getSourcesNeedingProcessing( 439 _getSourcesNeedingProcessing(
451 target, iterator.value, false, hintsEnabled, lintsEnabled, sources); 440 target, iterator.value, false, hintsEnabled, lintsEnabled, sources);
452 } 441 }
453 } 442 }
454 return new List<Source>.from(sources); 443 return new List<Source>.from(sources);
455 } 444 }
456 445
457 @override
458 AnalysisContextStatistics get statistics {
459 AnalysisContextStatisticsImpl statistics =
460 new AnalysisContextStatisticsImpl();
461 // TODO(brianwilkerson) Implement this.
462 // visitCacheItems(statistics._internalPutCacheItem);
463 // statistics.partitionData = _cache.partitionData;
464 return statistics;
465 }
466
467 List<Source> get test_priorityOrder => _priorityOrder; 446 List<Source> get test_priorityOrder => _priorityOrder;
468 447
469 @override 448 @override
470 TypeProvider get typeProvider { 449 TypeProvider get typeProvider {
471 // Make sure a task didn't accidentally try to call back into the context 450 // Make sure a task didn't accidentally try to call back into the context
472 // to retrieve the type provider. 451 // to retrieve the type provider.
473 assert(!driver.isTaskRunning); 452 assert(!driver.isTaskRunning);
474 453
475 if (_typeProvider != null) { 454 if (_typeProvider != null) {
476 return _typeProvider; 455 return _typeProvider;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 */ 668 */
690 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 669 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
691 if (factory == null) { 670 if (factory == null) {
692 return new AnalysisCache(<CachePartition>[_privatePartition]); 671 return new AnalysisCache(<CachePartition>[_privatePartition]);
693 } 672 }
694 DartSdk sdk = factory.dartSdk; 673 DartSdk sdk = factory.dartSdk;
695 if (sdk == null) { 674 if (sdk == null) {
696 return new AnalysisCache(<CachePartition>[_privatePartition]); 675 return new AnalysisCache(<CachePartition>[_privatePartition]);
697 } 676 }
698 return new AnalysisCache(<CachePartition>[ 677 return new AnalysisCache(<CachePartition>[
699 AnalysisEngine.instance.partitionManager_new.forSdk(sdk), 678 AnalysisEngine.instance.partitionManager.forSdk(sdk),
700 _privatePartition 679 _privatePartition
701 ]); 680 ]);
702 } 681 }
703 682
704 @override 683 @override
705 void dispose() { 684 void dispose() {
706 _disposed = true; 685 _disposed = true;
707 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) { 686 for (List<PendingFuture> pendingFutures in _pendingFutureTargets.values) {
708 for (PendingFuture pendingFuture in pendingFutures) { 687 for (PendingFuture pendingFuture in pendingFutures) {
709 pendingFuture.forciblyComplete(); 688 pendingFuture.forciblyComplete();
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 void setConfigurationData(ResultDescriptor key, Object data) { 1220 void setConfigurationData(ResultDescriptor key, Object data) {
1242 _configurationData[key] = data; 1221 _configurationData[key] = data;
1243 } 1222 }
1244 1223
1245 @override 1224 @override
1246 void setContents(Source source, String contents) { 1225 void setContents(Source source, String contents) {
1247 _contentsChanged(source, contents, true); 1226 _contentsChanged(source, contents, true);
1248 } 1227 }
1249 1228
1250 @override 1229 @override
1251 bool shouldErrorsBeAnalyzed(Source source, Object entry) { 1230 bool shouldErrorsBeAnalyzed(Source source) {
1252 CacheEntry entry = analysisCache.get(source); 1231 CacheEntry entry = analysisCache.get(source);
1253 if (source.isInSystemLibrary) { 1232 if (source.isInSystemLibrary) {
1254 return _options.generateSdkErrors; 1233 return _options.generateSdkErrors;
1255 } else if (!entry.explicitlyAdded) { 1234 } else if (!entry.explicitlyAdded) {
1256 return _options.generateImplicitErrors; 1235 return _options.generateImplicitErrors;
1257 } else { 1236 } else {
1258 return true; 1237 return true;
1259 } 1238 }
1260 } 1239 }
1261 1240
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 buffer.writeln(source.fullName); 1303 buffer.writeln(source.fullName);
1325 } 1304 }
1326 _logInformation(buffer.toString()); 1305 _logInformation(buffer.toString());
1327 } 1306 }
1328 return changedSources.length > 0; 1307 return changedSources.length > 0;
1329 } 1308 }
1330 1309
1331 @deprecated 1310 @deprecated
1332 @override 1311 @override
1333 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, 1312 void visitCacheItems(void callback(Source source, SourceEntry dartEntry,
1334 DataDescriptor rowDesc, CacheState state)) { 1313 DataDescriptor rowDesc, CacheState state)) {}
1335 // TODO(brianwilkerson) Figure out where this is used and either remove it
1336 // or adjust the call sites to use CacheEntry's.
1337 // bool hintsEnabled = _options.hint;
1338 // bool lintsEnabled = _options.lint;
1339 // MapIterator<AnalysisTarget, cache.CacheEntry> iterator = _cache.iterator() ;
1340 // while (iterator.moveNext()) {
1341 // Source source = iterator.key;
1342 // cache.CacheEntry entry = iterator.value;
1343 // for (DataDescriptor descriptor in entry.descriptors) {
1344 // if (descriptor == DartEntry.SOURCE_KIND) {
1345 // // The source kind is always valid, so the state isn't interesting.
1346 // continue;
1347 // } else if (descriptor == DartEntry.CONTAINING_LIBRARIES) {
1348 // // The list of containing libraries is always valid, so the state
1349 // // isn't interesting.
1350 // continue;
1351 // } else if (descriptor == DartEntry.PUBLIC_NAMESPACE) {
1352 // // The public namespace isn't computed by performAnalysisTask()
1353 // // and therefore isn't interesting.
1354 // continue;
1355 // } else if (descriptor == HtmlEntry.HINTS) {
1356 // // We are not currently recording any hints related to HTML.
1357 // continue;
1358 // }
1359 // callback(
1360 // source, entry, descriptor, entry.getState(descriptor));
1361 // }
1362 // if (entry is DartEntry) {
1363 // // get library-specific values
1364 // List<Source> librarySources = getLibrariesContaining(source);
1365 // for (Source librarySource in librarySources) {
1366 // for (DataDescriptor descriptor in entry.libraryDescriptors) {
1367 // if (descriptor == DartEntry.BUILT_ELEMENT ||
1368 // descriptor == DartEntry.BUILT_UNIT) {
1369 // // These values are not currently being computed, so their state
1370 // // is not interesting.
1371 // continue;
1372 // } else if (!entry.explicitlyAdded &&
1373 // !_generateImplicitErrors &&
1374 // (descriptor == DartEntry.VERIFICATION_ERRORS ||
1375 // descriptor == DartEntry.HINTS ||
1376 // descriptor == DartEntry.LINTS)) {
1377 // continue;
1378 // } else if (source.isInSystemLibrary &&
1379 // !_generateSdkErrors &&
1380 // (descriptor == DartEntry.VERIFICATION_ERRORS ||
1381 // descriptor == DartEntry.HINTS ||
1382 // descriptor == DartEntry.LINTS)) {
1383 // continue;
1384 // } else if (!hintsEnabled && descriptor == DartEntry.HINTS) {
1385 // continue;
1386 // } else if (!lintsEnabled && descriptor == DartEntry.LINTS) {
1387 // continue;
1388 // }
1389 // callback(librarySource, entry, descriptor,
1390 // entry.getStateInLibrary(descriptor, librarySource));
1391 // }
1392 // }
1393 // }
1394 // }
1395 }
1396 1314
1397 @override 1315 @override
1398 void visitContentCache(ContentCacheVisitor visitor) { 1316 void visitContentCache(ContentCacheVisitor visitor) {
1399 _contentCache.accept(visitor); 1317 _contentCache.accept(visitor);
1400 } 1318 }
1401 1319
1402 /** 1320 /**
1403 * Add all of the sources contained in the given source [container] to the 1321 * Add all of the sources contained in the given source [container] to the
1404 * given list of [sources]. 1322 * given list of [sources].
1405 */ 1323 */
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 CacheEntry unitEntry = 1574 CacheEntry unitEntry =
1657 _cache.get(new LibrarySpecificUnit(librarySource, source)); 1575 _cache.get(new LibrarySpecificUnit(librarySource, source));
1658 state = unitEntry.getState(RESOLVED_UNIT); 1576 state = unitEntry.getState(RESOLVED_UNIT);
1659 if (state == CacheState.INVALID || 1577 if (state == CacheState.INVALID ||
1660 (isPriority && state == CacheState.FLUSHED)) { 1578 (isPriority && state == CacheState.FLUSHED)) {
1661 sources.add(source); 1579 sources.add(source);
1662 return; 1580 return;
1663 } else if (state == CacheState.ERROR) { 1581 } else if (state == CacheState.ERROR) {
1664 return; 1582 return;
1665 } 1583 }
1666 if (shouldErrorsBeAnalyzed(source, unitEntry)) { 1584 if (shouldErrorsBeAnalyzed(source)) {
1667 state = unitEntry.getState(VERIFY_ERRORS); 1585 state = unitEntry.getState(VERIFY_ERRORS);
1668 if (state == CacheState.INVALID || 1586 if (state == CacheState.INVALID ||
1669 (isPriority && state == CacheState.FLUSHED)) { 1587 (isPriority && state == CacheState.FLUSHED)) {
1670 sources.add(source); 1588 sources.add(source);
1671 return; 1589 return;
1672 } else if (state == CacheState.ERROR) { 1590 } else if (state == CacheState.ERROR) {
1673 return; 1591 return;
1674 } 1592 }
1675 if (hintsEnabled) { 1593 if (hintsEnabled) {
1676 state = unitEntry.getState(HINTS); 1594 state = unitEntry.getState(HINTS);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 CompilationUnit oldUnit = 1855 CompilationUnit oldUnit =
1938 getResolvedCompilationUnit2(unitSource, librarySource); 1856 getResolvedCompilationUnit2(unitSource, librarySource);
1939 if (oldUnit == null) { 1857 if (oldUnit == null) {
1940 return false; 1858 return false;
1941 } 1859 }
1942 // do resolution 1860 // do resolution
1943 Stopwatch perfCounter = new Stopwatch()..start(); 1861 Stopwatch perfCounter = new Stopwatch()..start();
1944 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver( 1862 PoorMansIncrementalResolver resolver = new PoorMansIncrementalResolver(
1945 typeProvider, 1863 typeProvider,
1946 unitSource, 1864 unitSource,
1947 null,
1948 sourceEntry, 1865 sourceEntry,
1949 unitEntry, 1866 unitEntry,
1950 oldUnit, 1867 oldUnit,
1951 analysisOptions.incrementalApi); 1868 analysisOptions.incrementalApi);
1952 bool success = resolver.resolve(newCode); 1869 bool success = resolver.resolve(newCode);
1953 AnalysisEngine.instance.instrumentationService.logPerformance( 1870 AnalysisEngine.instance.instrumentationService.logPerformance(
1954 AnalysisPerformanceKind.INCREMENTAL, 1871 AnalysisPerformanceKind.INCREMENTAL,
1955 perfCounter, 1872 perfCounter,
1956 'success=$success,context_id=$_id,code_length=${newCode.length}'); 1873 'success=$success,context_id=$_id,code_length=${newCode.length}');
1957 if (!success) { 1874 if (!success) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 @override 2070 @override
2154 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 2071 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
2155 if (factory == null) { 2072 if (factory == null) {
2156 return super.createCacheFromSourceFactory(factory); 2073 return super.createCacheFromSourceFactory(factory);
2157 } 2074 }
2158 DartSdk sdk = factory.dartSdk; 2075 DartSdk sdk = factory.dartSdk;
2159 if (sdk == null) { 2076 if (sdk == null) {
2160 throw new IllegalArgumentException( 2077 throw new IllegalArgumentException(
2161 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2078 "The source factory for an SDK analysis context must have a DartUriRes olver");
2162 } 2079 }
2163 return new AnalysisCache(<CachePartition>[ 2080 return new AnalysisCache(
2164 AnalysisEngine.instance.partitionManager_new.forSdk(sdk) 2081 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2165 ]);
2166 } 2082 }
2167 } 2083 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/context/cache.dart ('k') | pkg/analyzer/lib/src/generated/constant.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698