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

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

Issue 1776023002: Add AnalysisContext.onResultInvalidated(descriptor). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update Analysis Server. Created 4 years, 9 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.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/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 /** 187 /**
188 * The listeners that are to be notified when various analysis results are 188 * The listeners that are to be notified when various analysis results are
189 * produced in this context. 189 * produced in this context.
190 */ 190 */
191 List<AnalysisListener> _listeners = new List<AnalysisListener>(); 191 List<AnalysisListener> _listeners = new List<AnalysisListener>();
192 192
193 @override 193 @override
194 ResultProvider resultProvider; 194 ResultProvider resultProvider;
195 195
196 /** 196 /**
197 * The map of [ResultChangedEvent] controllers.
198 */
199 final Map<ResultDescriptor, StreamController<ResultChangedEvent>>
200 _resultChangedControllers =
201 <ResultDescriptor, StreamController<ResultChangedEvent>>{};
202
203 /**
197 * The most recently incrementally resolved source, or `null` when it was 204 * The most recently incrementally resolved source, or `null` when it was
198 * already validated, or the most recent change was not incrementally resolved . 205 * already validated, or the most recent change was not incrementally resolved .
199 */ 206 */
200 Source incrementalResolutionValidation_lastUnitSource; 207 Source incrementalResolutionValidation_lastUnitSource;
201 208
202 /** 209 /**
203 * The most recently incrementally resolved library source, or `null` when it 210 * The most recently incrementally resolved library source, or `null` when it
204 * was already validated, or the most recent change was not incrementally 211 * was already validated, or the most recent change was not incrementally
205 * resolved. 212 * resolved.
206 */ 213 */
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 * Create an analysis cache based on the given source [factory]. 682 * Create an analysis cache based on the given source [factory].
676 */ 683 */
677 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) { 684 AnalysisCache createCacheFromSourceFactory(SourceFactory factory) {
678 if (factory == null) { 685 if (factory == null) {
679 return new AnalysisCache(<CachePartition>[_privatePartition]); 686 return new AnalysisCache(<CachePartition>[_privatePartition]);
680 } 687 }
681 DartSdk sdk = factory.dartSdk; 688 DartSdk sdk = factory.dartSdk;
682 if (sdk == null) { 689 if (sdk == null) {
683 return new AnalysisCache(<CachePartition>[_privatePartition]); 690 return new AnalysisCache(<CachePartition>[_privatePartition]);
684 } 691 }
685 return new AnalysisCache(<CachePartition>[ 692 AnalysisCache cache = new AnalysisCache(<CachePartition>[
686 AnalysisEngine.instance.partitionManager.forSdk(sdk), 693 AnalysisEngine.instance.partitionManager.forSdk(sdk),
687 _privatePartition 694 _privatePartition
688 ]); 695 ]);
696 cache.onResultInvalidated.listen((InvalidatedResult event) {
697 StreamController<ResultChangedEvent> controller =
698 _resultChangedControllers[event.descriptor];
699 if (controller != null) {
700 controller.add(new ResultChangedEvent(
701 this, event.entry.target, event.descriptor, event.value, false));
702 }
703 });
704 return cache;
689 } 705 }
690 706
691 /** 707 /**
692 * Create a minimalistic mock dart:async library 708 * Create a minimalistic mock dart:async library
693 * to stand in for a real one if one does not exist 709 * to stand in for a real one if one does not exist
694 * facilitating creation a type provider without dart:async. 710 * facilitating creation a type provider without dart:async.
695 */ 711 */
696 LibraryElement createMockAsyncLib(LibraryElement coreLibrary) { 712 LibraryElement createMockAsyncLib(LibraryElement coreLibrary) {
697 InterfaceType objType = coreLibrary.getType('Object').type; 713 InterfaceType objType = coreLibrary.getType('Object').type;
698 714
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 1108
1093 @override 1109 @override
1094 bool isServerLibrary(Source librarySource) { 1110 bool isServerLibrary(Source librarySource) {
1095 CacheEntry entry = _cache.get(librarySource); 1111 CacheEntry entry = _cache.get(librarySource);
1096 return entry != null && 1112 return entry != null &&
1097 !_referencesDartHtml(librarySource) && 1113 !_referencesDartHtml(librarySource) &&
1098 entry.getValue(IS_LAUNCHABLE); 1114 entry.getValue(IS_LAUNCHABLE);
1099 } 1115 }
1100 1116
1101 @override 1117 @override
1102 Stream<ComputedResult> onResultComputed(ResultDescriptor descriptor) { 1118 Stream<ResultChangedEvent> onResultChanged(ResultDescriptor descriptor) {
1103 return driver.onResultComputed(descriptor); 1119 driver.onResultComputed(descriptor).listen((ResultChangedEvent event) {
1120 _resultChangedControllers[descriptor]?.add(event);
1121 });
1122 return _resultChangedControllers.putIfAbsent(descriptor, () {
1123 return new StreamController<ResultChangedEvent>.broadcast(sync: true);
1124 }).stream;
1104 } 1125 }
1105 1126
1106 @override 1127 @override
1128 @deprecated
1129 Stream<ComputedResult> onResultComputed(ResultDescriptor descriptor) {
1130 return onResultChanged(descriptor)
1131 .where((event) => event.wasComputed)
1132 .map((event) {
1133 return new ComputedResult(
1134 event.context, event.descriptor, event.target, event.value);
1135 });
1136 }
1137
1138 @override
1107 CompilationUnit parseCompilationUnit(Source source) { 1139 CompilationUnit parseCompilationUnit(Source source) {
1108 if (!AnalysisEngine.isDartFileName(source.shortName)) { 1140 if (!AnalysisEngine.isDartFileName(source.shortName)) {
1109 return null; 1141 return null;
1110 } 1142 }
1111 try { 1143 try {
1112 getContents(source); 1144 getContents(source);
1113 } catch (exception, stackTrace) { 1145 } catch (exception, stackTrace) {
1114 throw new AnalysisException('Could not get contents of $source', 1146 throw new AnalysisException('Could not get contents of $source',
1115 new CaughtException(exception, stackTrace)); 1147 new CaughtException(exception, stackTrace));
1116 } 1148 }
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 } 2178 }
2147 DartSdk sdk = factory.dartSdk; 2179 DartSdk sdk = factory.dartSdk;
2148 if (sdk == null) { 2180 if (sdk == null) {
2149 throw new IllegalArgumentException( 2181 throw new IllegalArgumentException(
2150 "The source factory for an SDK analysis context must have a DartUriRes olver"); 2182 "The source factory for an SDK analysis context must have a DartUriRes olver");
2151 } 2183 }
2152 return new AnalysisCache( 2184 return new AnalysisCache(
2153 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]); 2185 <CachePartition>[AnalysisEngine.instance.partitionManager.forSdk(sdk)]);
2154 } 2186 }
2155 } 2187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698