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

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

Issue 1591483002: Prepare for chaining resynthesizers from AC to SDK AC. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | pkg/analyzer/lib/src/generated/engine.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/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/instrumentation/instrumentation.dart'; 11 import 'package:analyzer/instrumentation/instrumentation.dart';
12 import 'package:analyzer/plugin/task.dart'; 12 import 'package:analyzer/plugin/task.dart';
13 import 'package:analyzer/source/embedder.dart'; 13 import 'package:analyzer/source/embedder.dart';
14 import 'package:analyzer/src/cancelable_future.dart'; 14 import 'package:analyzer/src/cancelable_future.dart';
15 import 'package:analyzer/src/context/cache.dart'; 15 import 'package:analyzer/src/context/cache.dart';
16 import 'package:analyzer/src/dart/element/element.dart'; 16 import 'package:analyzer/src/dart/element/element.dart';
17 import 'package:analyzer/src/generated/ast.dart'; 17 import 'package:analyzer/src/generated/ast.dart';
18 import 'package:analyzer/src/generated/constant.dart'; 18 import 'package:analyzer/src/generated/constant.dart';
19 import 'package:analyzer/src/generated/engine.dart'; 19 import 'package:analyzer/src/generated/engine.dart';
20 import 'package:analyzer/src/generated/error.dart'; 20 import 'package:analyzer/src/generated/error.dart';
21 import 'package:analyzer/src/generated/incremental_resolver.dart'; 21 import 'package:analyzer/src/generated/incremental_resolver.dart';
22 import 'package:analyzer/src/generated/java_core.dart'; 22 import 'package:analyzer/src/generated/java_core.dart';
23 import 'package:analyzer/src/generated/java_engine.dart'; 23 import 'package:analyzer/src/generated/java_engine.dart';
24 import 'package:analyzer/src/generated/resolver.dart'; 24 import 'package:analyzer/src/generated/resolver.dart';
25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk; 25 import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
26 import 'package:analyzer/src/generated/source.dart'; 26 import 'package:analyzer/src/generated/source.dart';
27 import 'package:analyzer/src/generated/utilities_collection.dart'; 27 import 'package:analyzer/src/generated/utilities_collection.dart';
28 import 'package:analyzer/src/summary/resynthesize.dart';
28 import 'package:analyzer/src/task/dart.dart'; 29 import 'package:analyzer/src/task/dart.dart';
29 import 'package:analyzer/src/task/dart_work_manager.dart'; 30 import 'package:analyzer/src/task/dart_work_manager.dart';
30 import 'package:analyzer/src/task/driver.dart'; 31 import 'package:analyzer/src/task/driver.dart';
31 import 'package:analyzer/src/task/incremental_element_builder.dart'; 32 import 'package:analyzer/src/task/incremental_element_builder.dart';
32 import 'package:analyzer/src/task/manager.dart'; 33 import 'package:analyzer/src/task/manager.dart';
33 import 'package:analyzer/task/dart.dart'; 34 import 'package:analyzer/task/dart.dart';
34 import 'package:analyzer/task/general.dart'; 35 import 'package:analyzer/task/general.dart';
35 import 'package:analyzer/task/html.dart'; 36 import 'package:analyzer/task/html.dart';
36 import 'package:analyzer/task/model.dart'; 37 import 'package:analyzer/task/model.dart';
37 import 'package:html/dom.dart' show Document; 38 import 'package:html/dom.dart' show Document;
38 39
39 /** 40 /**
40 * Type of callback functions used by PendingFuture. Functions of this type 41 * Type of callback functions used by PendingFuture. Functions of this type
41 * should perform a computation based on the data in [entry] and return it. If 42 * should perform a computation based on the data in [entry] and return it. If
42 * the computation can't be performed yet because more analysis is needed, 43 * the computation can't be performed yet because more analysis is needed,
43 * `null` should be returned. 44 * `null` should be returned.
44 * 45 *
45 * The function may also throw an exception, in which case the corresponding 46 * The function may also throw an exception, in which case the corresponding
46 * future will be completed with failure. 47 * future will be completed with failure.
47 * 48 *
48 * Because this function is called while the state of analysis is being updated, 49 * Because this function is called while the state of analysis is being updated,
49 * it should be free of side effects so that it doesn't cause reentrant changes 50 * it should be free of side effects so that it doesn't cause reentrant changes
50 * to the analysis state. 51 * to the analysis state.
51 */ 52 */
52 typedef T PendingFutureComputer<T>(CacheEntry entry); 53 typedef T PendingFutureComputer<T>(CacheEntry entry);
53 54
54 /** 55 /**
56 * Helper for [InternalAnalysisContext.aboutToComputeResult].
57 */
58 abstract class AboutToComputeResultHelper {
59 final InternalAnalysisContext context;
60
61 /**
62 * The [SummaryResynthesizer] of this context, maybe `null`.
63 */
64 SummaryResynthesizer resynthesizer;
65
66 AboutToComputeResultHelper(this.context);
67
68 /**
69 * This method is invoked by an [InternalAnalysisContext] when the state of
70 * the [result] of the [entry] is [CacheState.INVALID], so it is about to be
71 * computed.
72 *
73 * If the processor knows how to provide the value, it sets the value into
74 * the [entry] with all required dependencies, and returns `true`.
75 *
76 * Otherwise, it returns `false` to indicate that the result should be
77 * computed as usually.
78 */
79 bool compute(CacheEntry entry, ResultDescriptor result);
80 }
81
82 /**
55 * An [AnalysisContext] in which analysis can be performed. 83 * An [AnalysisContext] in which analysis can be performed.
56 */ 84 */
57 class AnalysisContextImpl implements InternalAnalysisContext { 85 class AnalysisContextImpl implements InternalAnalysisContext {
58 /** 86 /**
59 * The next context identifier. 87 * The next context identifier.
60 */ 88 */
61 static int _NEXT_ID = 0; 89 static int _NEXT_ID = 0;
62 90
63 /** 91 /**
64 * The unique identifier of this context. 92 * The unique identifier of this context.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 * not) being implicitly analyzed. 206 * not) being implicitly analyzed.
179 */ 207 */
180 StreamController<ImplicitAnalysisEvent> _implicitAnalysisEventsController; 208 StreamController<ImplicitAnalysisEvent> _implicitAnalysisEventsController;
181 209
182 /** 210 /**
183 * The listeners that are to be notified when various analysis results are 211 * The listeners that are to be notified when various analysis results are
184 * produced in this context. 212 * produced in this context.
185 */ 213 */
186 List<AnalysisListener> _listeners = new List<AnalysisListener>(); 214 List<AnalysisListener> _listeners = new List<AnalysisListener>();
187 215
216 @override
217 AboutToComputeResultHelper aboutToComputeResultHelper;
218
188 /** 219 /**
189 * The most recently incrementally resolved source, or `null` when it was 220 * The most recently incrementally resolved source, or `null` when it was
190 * already validated, or the most recent change was not incrementally resolved . 221 * already validated, or the most recent change was not incrementally resolved .
191 */ 222 */
192 Source incrementalResolutionValidation_lastUnitSource; 223 Source incrementalResolutionValidation_lastUnitSource;
193 224
194 /** 225 /**
195 * The most recently incrementally resolved library source, or `null` when it 226 * The most recently incrementally resolved library source, or `null` when it
196 * was already validated, or the most recent change was not incrementally 227 * was already validated, or the most recent change was not incrementally
197 * resolved. 228 * resolved.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 TypeSystem get typeSystem { 513 TypeSystem get typeSystem {
483 if (_typeSystem == null) { 514 if (_typeSystem == null) {
484 _typeSystem = TypeSystem.create(this); 515 _typeSystem = TypeSystem.create(this);
485 } 516 }
486 return _typeSystem; 517 return _typeSystem;
487 } 518 }
488 519
489 @override 520 @override
490 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { 521 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) {
491 return PerformanceStatistics.summary.makeCurrentWhile(() { 522 return PerformanceStatistics.summary.makeCurrentWhile(() {
492 AnalysisTarget target = entry.target; 523 // Use this helper if it is set.
493 // TYPE_PROVIDER 524 if (aboutToComputeResultHelper != null) {
494 if (target is AnalysisContextTarget && result == TYPE_PROVIDER) { 525 return aboutToComputeResultHelper.compute(entry, result);
Brian Wilkerson 2016/01/14 22:45:28 Shouldn't this fall through to check for results f
scheglov 2016/01/14 22:51:35 Ack. Thank you.
495 DartSdk dartSdk = sourceFactory.dartSdk; 526 }
496 if (dartSdk != null) { 527 // Ask the SDK.
497 AnalysisContext sdkContext = dartSdk.context; 528 DartSdk dartSdk = sourceFactory.dartSdk;
498 if (!identical(sdkContext, this) && 529 if (dartSdk != null) {
499 sdkContext is InternalAnalysisContext) { 530 AnalysisContext sdkContext = dartSdk.context;
500 return sdkContext.aboutToComputeResult(entry, result); 531 if (!identical(sdkContext, this) &&
501 } 532 sdkContext is InternalAnalysisContext) {
533 return sdkContext.aboutToComputeResult(entry, result);
502 } 534 }
503 } 535 }
504 // A result for a Source. 536 // Cannot provide the result.
505 Source source = target.source;
506 if (source != null) {
507 InternalAnalysisContext context = _cache.getContextFor(source);
508 if (!identical(context, this)) {
509 return context.aboutToComputeResult(entry, result);
510 }
511 }
512 return false; 537 return false;
513 }); 538 });
514 } 539 }
515 540
516 @override 541 @override
517 void addListener(AnalysisListener listener) { 542 void addListener(AnalysisListener listener) {
518 if (!_listeners.contains(listener)) { 543 if (!_listeners.contains(listener)) {
519 _listeners.add(listener); 544 _listeners.add(listener);
520 } 545 }
521 } 546 }
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 } 2058 }
2034 DartSdk sdk = factory.dartSdk; 2059 DartSdk sdk = factory.dartSdk;
2035 if (sdk == null) { 2060 if (sdk == null) {
2036 throw new IllegalArgumentException( 2061 throw new IllegalArgumentException(
2037 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2062 "The source factory for an SDK analysis context must have a DartUriRes olver");
2038 } 2063 }
2039 return new AnalysisCache( 2064 return new AnalysisCache(
2040 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2065 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2041 } 2066 }
2042 } 2067 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/engine.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698