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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1124053003: Use AbstractContextTest for AnalysisContextImplTest. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/test/src/context/abstract_context.dart ('k') | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 test.src.context.context_test; 5 library test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/src/cancelable_future.dart'; 9 import 'package:analyzer/src/cancelable_future.dart';
10 import 'package:analyzer/src/context/cache.dart'; 10 import 'package:analyzer/src/context/cache.dart';
(...skipping 13 matching lines...) Expand all
24 AnalysisOptionsImpl, 24 AnalysisOptionsImpl,
25 AnalysisResult, 25 AnalysisResult,
26 CacheState, 26 CacheState,
27 ChangeNotice, 27 ChangeNotice,
28 ChangeSet, 28 ChangeSet,
29 IncrementalAnalysisCache, 29 IncrementalAnalysisCache,
30 TimestampedData; 30 TimestampedData;
31 import 'package:analyzer/src/generated/error.dart'; 31 import 'package:analyzer/src/generated/error.dart';
32 import 'package:analyzer/src/generated/html.dart' as ht; 32 import 'package:analyzer/src/generated/html.dart' as ht;
33 import 'package:analyzer/src/generated/java_engine.dart'; 33 import 'package:analyzer/src/generated/java_engine.dart';
34 import 'package:analyzer/src/generated/java_engine_io.dart';
35 import 'package:analyzer/src/generated/resolver.dart'; 34 import 'package:analyzer/src/generated/resolver.dart';
36 import 'package:analyzer/src/generated/scanner.dart'; 35 import 'package:analyzer/src/generated/scanner.dart';
37 import 'package:analyzer/src/generated/sdk.dart';
38 import 'package:analyzer/src/generated/sdk_io.dart';
39 import 'package:analyzer/src/generated/source.dart'; 36 import 'package:analyzer/src/generated/source.dart';
40 import 'package:analyzer/src/generated/source_io.dart';
41 import 'package:analyzer/src/plugin/engine_plugin.dart';
42 import 'package:analyzer/task/dart.dart'; 37 import 'package:analyzer/task/dart.dart';
43 import 'package:plugin/manager.dart';
44 import 'package:unittest/unittest.dart'; 38 import 'package:unittest/unittest.dart';
45 import 'package:watcher/src/utils.dart'; 39 import 'package:watcher/src/utils.dart';
46 40
47 import '../../generated/engine_test.dart'; 41 import '../../generated/engine_test.dart';
48 import '../../generated/test_support.dart'; 42 import '../../generated/test_support.dart';
49 import '../../reflective_tests.dart'; 43 import '../../reflective_tests.dart';
50 import '../mock_sdk.dart'; 44 import 'abstract_context.dart';
51 45
52 main() { 46 main() {
53 groupSep = ' | '; 47 groupSep = ' | ';
54 runReflectiveTests(AnalysisContextImplTest); 48 runReflectiveTests(AnalysisContextImplTest);
55 } 49 }
56 50
57 contextWithCore() {
58 return new AnalysisContextForTests();
59 }
60
61 /**
62 * An analysis context that has a fake SDK that is much smaller and faster for
63 * testing purposes.
64 */
65 class AnalysisContextForTests extends AnalysisContextImpl {
66 AnalysisContextForTests() {
67 DartSdk sdk = new MockSdk();
68 SourceFactory sourceFactory =
69 new SourceFactory([new DartUriResolver(sdk), new FileUriResolver()]);
70 this.sourceFactory = sourceFactory;
71 }
72
73 @override
74 void set analysisOptions(AnalysisOptions options) {
75 AnalysisOptions currentOptions = analysisOptions;
76 bool needsRecompute = currentOptions.analyzeFunctionBodiesPredicate !=
77 options.analyzeFunctionBodiesPredicate ||
78 currentOptions.generateImplicitErrors !=
79 options.generateImplicitErrors ||
80 currentOptions.generateSdkErrors != options.generateSdkErrors ||
81 currentOptions.dart2jsHint != options.dart2jsHint ||
82 (currentOptions.hint && !options.hint) ||
83 currentOptions.preserveComments != options.preserveComments ||
84 currentOptions.enableNullAwareOperators !=
85 options.enableNullAwareOperators ||
86 currentOptions.enableStrictCallChecks != options.enableStrictCallChecks;
87 if (needsRecompute) {
88 fail(
89 "Cannot set options that cause the sources to be reanalyzed in a test context");
90 }
91 super.analysisOptions = options;
92 }
93
94 @override
95 LibraryResolverFactory get libraryResolverFactory => null;
96
97 @override
98 bool exists(Source source) =>
99 super.exists(source) || sourceFactory.dartSdk.context.exists(source);
100
101 @override
102 TimestampedData<String> getContents(Source source) {
103 if (source.isInSystemLibrary) {
104 return sourceFactory.dartSdk.context.getContents(source);
105 }
106 return super.getContents(source);
107 }
108
109 @override
110 int getModificationStamp(Source source) {
111 if (source.isInSystemLibrary) {
112 return sourceFactory.dartSdk.context.getModificationStamp(source);
113 }
114 return super.getModificationStamp(source);
115 }
116
117 // /**
118 // * Set the analysis options, even if they would force re-analysis. This meth od should only be
119 // * invoked before the fake SDK is initialized.
120 // *
121 // * @param options the analysis options to be set
122 // */
123 // void _internalSetAnalysisOptions(AnalysisOptions options) {
124 // super.analysisOptions = options;
125 // }
126 }
127
128 @reflectiveTest 51 @reflectiveTest
129 class AnalysisContextImplTest extends EngineTestCase { 52 class AnalysisContextImplTest extends AbstractContextTest {
130 /**
131 * An analysis context whose source factory is [sourceFactory].
132 */
133 AnalysisContextImpl _context;
134
135 /**
136 * The source factory associated with the analysis [context].
137 */
138 SourceFactory _sourceFactory;
139
140 void fail_applyChanges_empty() { 53 void fail_applyChanges_empty() {
141 _context.applyChanges(new ChangeSet()); 54 context.applyChanges(new ChangeSet());
142 expect(_context.performAnalysisTask().changeNotices, isNull); 55 expect(context.performAnalysisTask().changeNotices, isNull);
143 // This test appears to be flaky. If it is named "test_" it fails, if it's 56 // This test appears to be flaky. If it is named "test_" it fails, if it's
144 // named "fail_" it doesn't fail. I'm guessing that it's dependent on 57 // named "fail_" it doesn't fail. I'm guessing that it's dependent on
145 // whether some other test is run. 58 // whether some other test is run.
146 fail('Should have failed'); 59 fail('Should have failed');
147 } 60 }
148 61
149 void fail_applyChanges_overriddenSource() { 62 void fail_applyChanges_overriddenSource() {
150 // Note: addSource adds the source to the contentCache. 63 // Note: addSource adds the source to the contentCache.
151 Source source = _addSource("/test.dart", "library test;"); 64 Source source = addSource("/test.dart", "library test;");
152 _context.computeErrors(source); 65 context.computeErrors(source);
153 while (!_context.sourcesNeedingProcessing.isEmpty) { 66 while (!context.sourcesNeedingProcessing.isEmpty) {
154 _context.performAnalysisTask(); 67 context.performAnalysisTask();
155 } 68 }
156 // Adding the source as a changedSource should have no effect since 69 // Adding the source as a changedSource should have no effect since
157 // it is already overridden in the content cache. 70 // it is already overridden in the content cache.
158 ChangeSet changeSet = new ChangeSet(); 71 ChangeSet changeSet = new ChangeSet();
159 changeSet.changedSource(source); 72 changeSet.changedSource(source);
160 _context.applyChanges(changeSet); 73 context.applyChanges(changeSet);
161 expect(_context.sourcesNeedingProcessing, hasLength(0)); 74 expect(context.sourcesNeedingProcessing, hasLength(0));
162 } 75 }
163 76
164 Future fail_applyChanges_remove() { 77 Future fail_applyChanges_remove() {
165 _context = contextWithCore();
166 SourcesChangedListener listener = new SourcesChangedListener(); 78 SourcesChangedListener listener = new SourcesChangedListener();
167 _context.onSourcesChanged.listen(listener.onData); 79 context.onSourcesChanged.listen(listener.onData);
168 _sourceFactory = _context.sourceFactory;
169 String libAContents = r''' 80 String libAContents = r'''
170 library libA; 81 library libA;
171 import 'libB.dart';'''; 82 import 'libB.dart';''';
172 Source libA = _addSource("/libA.dart", libAContents); 83 Source libA = addSource("/libA.dart", libAContents);
173 String libBContents = "library libB;"; 84 String libBContents = "library libB;";
174 Source libB = _addSource("/libB.dart", libBContents); 85 Source libB = addSource("/libB.dart", libBContents);
175 LibraryElement libAElement = _context.computeLibraryElement(libA); 86 LibraryElement libAElement = context.computeLibraryElement(libA);
176 expect(libAElement, isNotNull); 87 expect(libAElement, isNotNull);
177 List<LibraryElement> importedLibraries = libAElement.importedLibraries; 88 List<LibraryElement> importedLibraries = libAElement.importedLibraries;
178 expect(importedLibraries, hasLength(2)); 89 expect(importedLibraries, hasLength(2));
179 _context.computeErrors(libA); 90 context.computeErrors(libA);
180 _context.computeErrors(libB); 91 context.computeErrors(libB);
181 expect(_context.sourcesNeedingProcessing, hasLength(0)); 92 expect(context.sourcesNeedingProcessing, hasLength(0));
182 _context.setContents(libB, null); 93 context.setContents(libB, null);
183 _removeSource(libB); 94 _removeSource(libB);
184 List<Source> sources = _context.sourcesNeedingProcessing; 95 List<Source> sources = context.sourcesNeedingProcessing;
185 expect(sources, hasLength(1)); 96 expect(sources, hasLength(1));
186 expect(sources[0], same(libA)); 97 expect(sources[0], same(libA));
187 libAElement = _context.computeLibraryElement(libA); 98 libAElement = context.computeLibraryElement(libA);
188 importedLibraries = libAElement.importedLibraries; 99 importedLibraries = libAElement.importedLibraries;
189 expect(importedLibraries, hasLength(1)); 100 expect(importedLibraries, hasLength(1));
190 return pumpEventQueue().then((_) { 101 return pumpEventQueue().then((_) {
191 listener.assertEvent(wereSourcesAdded: true); 102 listener.assertEvent(wereSourcesAdded: true);
192 listener.assertEvent(changedSources: [libA]); 103 listener.assertEvent(changedSources: [libA]);
193 listener.assertEvent(wereSourcesAdded: true); 104 listener.assertEvent(wereSourcesAdded: true);
194 listener.assertEvent(changedSources: [libB]); 105 listener.assertEvent(changedSources: [libB]);
195 listener.assertEvent(changedSources: [libB]); 106 listener.assertEvent(changedSources: [libB]);
196 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 107 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
197 listener.assertNoMoreEvents(); 108 listener.assertNoMoreEvents();
198 }); 109 });
199 } 110 }
200 111
201 Future fail_applyChanges_removeContainer() { 112 Future fail_applyChanges_removeContainer() {
202 _context = contextWithCore();
203 SourcesChangedListener listener = new SourcesChangedListener(); 113 SourcesChangedListener listener = new SourcesChangedListener();
204 _context.onSourcesChanged.listen(listener.onData); 114 context.onSourcesChanged.listen(listener.onData);
205 _sourceFactory = _context.sourceFactory;
206 String libAContents = r''' 115 String libAContents = r'''
207 library libA; 116 library libA;
208 import 'libB.dart';'''; 117 import 'libB.dart';''';
209 Source libA = _addSource("/libA.dart", libAContents); 118 Source libA = addSource("/libA.dart", libAContents);
210 String libBContents = "library libB;"; 119 String libBContents = "library libB;";
211 Source libB = _addSource("/libB.dart", libBContents); 120 Source libB = addSource("/libB.dart", libBContents);
212 _context.computeLibraryElement(libA); 121 context.computeLibraryElement(libA);
213 _context.computeErrors(libA); 122 context.computeErrors(libA);
214 _context.computeErrors(libB); 123 context.computeErrors(libB);
215 expect(_context.sourcesNeedingProcessing, hasLength(0)); 124 expect(context.sourcesNeedingProcessing, hasLength(0));
216 ChangeSet changeSet = new ChangeSet(); 125 ChangeSet changeSet = new ChangeSet();
217 SourceContainer removedContainer = 126 SourceContainer removedContainer =
218 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB); 127 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB);
219 changeSet.removedContainer(removedContainer); 128 changeSet.removedContainer(removedContainer);
220 _context.applyChanges(changeSet); 129 context.applyChanges(changeSet);
221 List<Source> sources = _context.sourcesNeedingProcessing; 130 List<Source> sources = context.sourcesNeedingProcessing;
222 expect(sources, hasLength(1)); 131 expect(sources, hasLength(1));
223 expect(sources[0], same(libA)); 132 expect(sources[0], same(libA));
224 return pumpEventQueue().then((_) { 133 return pumpEventQueue().then((_) {
225 listener.assertEvent(wereSourcesAdded: true); 134 listener.assertEvent(wereSourcesAdded: true);
226 listener.assertEvent(changedSources: [libA]); 135 listener.assertEvent(changedSources: [libA]);
227 listener.assertEvent(wereSourcesAdded: true); 136 listener.assertEvent(wereSourcesAdded: true);
228 listener.assertEvent(changedSources: [libB]); 137 listener.assertEvent(changedSources: [libB]);
229 listener.assertEvent(wereSourcesRemovedOrDeleted: true); 138 listener.assertEvent(wereSourcesRemovedOrDeleted: true);
230 listener.assertNoMoreEvents(); 139 listener.assertNoMoreEvents();
231 }); 140 });
232 } 141 }
233 142
234 void fail_computeErrors_dart_none() { 143 void fail_computeErrors_dart_none() {
235 Source source = _addSource("/lib.dart", "library lib;"); 144 Source source = addSource("/lib.dart", "library lib;");
236 List<AnalysisError> errors = _context.computeErrors(source); 145 List<AnalysisError> errors = context.computeErrors(source);
237 expect(errors, hasLength(0)); 146 expect(errors, hasLength(0));
238 } 147 }
239 148
240 void fail_computeErrors_dart_part() { 149 void fail_computeErrors_dart_part() {
241 Source librarySource = 150 Source librarySource =
242 _addSource("/lib.dart", "library lib; part 'part.dart';"); 151 addSource("/lib.dart", "library lib; part 'part.dart';");
243 Source partSource = _addSource("/part.dart", "part of 'lib';"); 152 Source partSource = addSource("/part.dart", "part of 'lib';");
244 _context.parseCompilationUnit(librarySource); 153 context.parseCompilationUnit(librarySource);
245 List<AnalysisError> errors = _context.computeErrors(partSource); 154 List<AnalysisError> errors = context.computeErrors(partSource);
246 expect(errors, isNotNull); 155 expect(errors, isNotNull);
247 expect(errors.length > 0, isTrue); 156 expect(errors.length > 0, isTrue);
248 } 157 }
249 158
250 void fail_computeErrors_dart_some() { 159 void fail_computeErrors_dart_some() {
251 Source source = _addSource("/lib.dart", "library 'lib';"); 160 Source source = addSource("/lib.dart", "library 'lib';");
252 List<AnalysisError> errors = _context.computeErrors(source); 161 List<AnalysisError> errors = context.computeErrors(source);
253 expect(errors, isNotNull); 162 expect(errors, isNotNull);
254 expect(errors.length > 0, isTrue); 163 expect(errors.length > 0, isTrue);
255 } 164 }
256 165
257 void fail_computeErrors_html_none() { 166 void fail_computeErrors_html_none() {
258 Source source = _addSource("/test.html", "<html></html>"); 167 Source source = addSource("/test.html", "<html></html>");
259 List<AnalysisError> errors = _context.computeErrors(source); 168 List<AnalysisError> errors = context.computeErrors(source);
260 expect(errors, hasLength(0)); 169 expect(errors, hasLength(0));
261 } 170 }
262 171
263 void fail_computeHtmlElement_valid() { 172 void fail_computeHtmlElement_valid() {
264 Source source = _addSource("/test.html", "<html></html>"); 173 Source source = addSource("/test.html", "<html></html>");
265 HtmlElement element = _context.computeHtmlElement(source); 174 HtmlElement element = context.computeHtmlElement(source);
266 expect(element, isNotNull); 175 expect(element, isNotNull);
267 expect(_context.computeHtmlElement(source), same(element)); 176 expect(context.computeHtmlElement(source), same(element));
268 } 177 }
269 178
270 void fail_computeImportedLibraries_none() { 179 void fail_computeImportedLibraries_none() {
271 // This is failing because computeImportedLibraries now always includes 180 // This is failing because computeImportedLibraries now always includes
272 // dart:core, and we don't have any way of knowing whether it was explicit. 181 // dart:core, and we don't have any way of knowing whether it was explicit.
273 Source source = _addSource("/test.dart", "library test;"); 182 Source source = addSource("/test.dart", "library test;");
274 expect(_context.computeImportedLibraries(source), hasLength(0)); 183 expect(context.computeImportedLibraries(source), hasLength(0));
275 } 184 }
276 185
277 void fail_computeImportedLibraries_some() { 186 void fail_computeImportedLibraries_some() {
278 // This is failing because computeImportedLibraries now always includes 187 // This is failing because computeImportedLibraries now always includes
279 // dart:core, and we don't have any way of knowing whether it was explicit. 188 // dart:core, and we don't have any way of knowing whether it was explicit.
280 // addSource("/lib1.dart", "library lib1;"); 189 // addSource("/lib1.dart", "library lib1;");
281 // addSource("/lib2.dart", "library lib2;"); 190 // addSource("/lib2.dart", "library lib2;");
282 Source source = _addSource( 191 Source source = addSource(
283 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); 192 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';");
284 expect(_context.computeImportedLibraries(source), hasLength(2)); 193 expect(context.computeImportedLibraries(source), hasLength(2));
285 } 194 }
286 195
287 void fail_computeResolvableCompilationUnit_dart_exception() { 196 void fail_computeResolvableCompilationUnit_dart_exception() {
288 TestSource source = _addSourceWithException("/test.dart"); 197 TestSource source = _addSourceWithException("/test.dart");
289 try { 198 try {
290 _context.computeResolvableCompilationUnit(source); 199 context.computeResolvableCompilationUnit(source);
291 fail("Expected AnalysisException"); 200 fail("Expected AnalysisException");
292 } on AnalysisException { 201 } on AnalysisException {
293 // Expected 202 // Expected
294 } 203 }
295 } 204 }
296 205
297 void fail_computeResolvableCompilationUnit_html_exception() { 206 void fail_computeResolvableCompilationUnit_html_exception() {
298 Source source = _addSource("/lib.html", "<html></html>"); 207 Source source = addSource("/lib.html", "<html></html>");
299 try { 208 try {
300 _context.computeResolvableCompilationUnit(source); 209 context.computeResolvableCompilationUnit(source);
301 fail("Expected AnalysisException"); 210 fail("Expected AnalysisException");
302 } on AnalysisException { 211 } on AnalysisException {
303 // Expected 212 // Expected
304 } 213 }
305 } 214 }
306 215
307 void fail_computeResolvableCompilationUnit_valid() { 216 void fail_computeResolvableCompilationUnit_valid() {
308 Source source = _addSource("/lib.dart", "library lib;"); 217 Source source = addSource("/lib.dart", "library lib;");
309 CompilationUnit parsedUnit = _context.parseCompilationUnit(source); 218 CompilationUnit parsedUnit = context.parseCompilationUnit(source);
310 expect(parsedUnit, isNotNull); 219 expect(parsedUnit, isNotNull);
311 CompilationUnit resolvedUnit = 220 CompilationUnit resolvedUnit =
312 _context.computeResolvableCompilationUnit(source); 221 context.computeResolvableCompilationUnit(source);
313 expect(resolvedUnit, isNotNull); 222 expect(resolvedUnit, isNotNull);
314 expect(resolvedUnit, same(parsedUnit)); 223 expect(resolvedUnit, same(parsedUnit));
315 } 224 }
316 225
317 Future fail_computeResolvedCompilationUnitAsync_dispose() { 226 Future fail_computeResolvedCompilationUnitAsync_dispose() {
318 _context = contextWithCore(); 227 Source source = addSource("/lib.dart", "library lib;");
319 _sourceFactory = _context.sourceFactory;
320 Source source = _addSource("/lib.dart", "library lib;");
321 // Complete all pending analysis tasks and flush the AST so that it won't 228 // Complete all pending analysis tasks and flush the AST so that it won't
322 // be available immediately. 229 // be available immediately.
323 _performPendingAnalysisTasks(); 230 _performPendingAnalysisTasks();
324 _flushAst(source); 231 _flushAst(source);
325 CancelableFuture<CompilationUnit> future = 232 CancelableFuture<CompilationUnit> future =
326 _context.computeResolvedCompilationUnitAsync(source, source); 233 context.computeResolvedCompilationUnitAsync(source, source);
327 bool completed = false; 234 bool completed = false;
328 future.then((CompilationUnit unit) { 235 future.then((CompilationUnit unit) {
329 fail('Future should have completed with error'); 236 fail('Future should have completed with error');
330 }, onError: (error) { 237 }, onError: (error) {
331 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); 238 expect(error, new isInstanceOf<AnalysisNotScheduledError>());
332 completed = true; 239 completed = true;
333 }); 240 });
334 expect(completed, isFalse); 241 expect(completed, isFalse);
335 expect(_context.pendingFutureSources_forTesting, isNotEmpty); 242 expect(context.pendingFutureSources_forTesting, isNotEmpty);
336 // Disposing of the context should cause all pending futures to complete 243 // Disposing of the context should cause all pending futures to complete
337 // with AnalysisNotScheduled, so that no clients are left hanging. 244 // with AnalysisNotScheduled, so that no clients are left hanging.
338 _context.dispose(); 245 context.dispose();
339 expect(_context.pendingFutureSources_forTesting, isEmpty); 246 expect(context.pendingFutureSources_forTesting, isEmpty);
340 return pumpEventQueue().then((_) { 247 return pumpEventQueue().then((_) {
341 expect(completed, isTrue); 248 expect(completed, isTrue);
342 expect(_context.pendingFutureSources_forTesting, isEmpty); 249 expect(context.pendingFutureSources_forTesting, isEmpty);
343 }); 250 });
344 } 251 }
345 252
346 Future fail_computeResolvedCompilationUnitAsync_unrelatedLibrary() { 253 Future fail_computeResolvedCompilationUnitAsync_unrelatedLibrary() {
347 _context = contextWithCore(); 254 Source librarySource = addSource("/lib.dart", "library lib;");
348 _sourceFactory = _context.sourceFactory; 255 Source partSource = addSource("/part.dart", "part of foo;");
349 Source librarySource = _addSource("/lib.dart", "library lib;");
350 Source partSource = _addSource("/part.dart", "part of foo;");
351 bool completed = false; 256 bool completed = false;
352 _context 257 context
353 .computeResolvedCompilationUnitAsync(partSource, librarySource) 258 .computeResolvedCompilationUnitAsync(partSource, librarySource)
354 .then((_) { 259 .then((_) {
355 fail('Expected resolution to fail'); 260 fail('Expected resolution to fail');
356 }, onError: (e) { 261 }, onError: (e) {
357 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); 262 expect(e, new isInstanceOf<AnalysisNotScheduledError>());
358 completed = true; 263 completed = true;
359 }); 264 });
360 return pumpEventQueue().then((_) { 265 return pumpEventQueue().then((_) {
361 expect(completed, isFalse); 266 expect(completed, isFalse);
362 _performPendingAnalysisTasks(); 267 _performPendingAnalysisTasks();
363 }).then((_) => pumpEventQueue()).then((_) { 268 }).then((_) => pumpEventQueue()).then((_) {
364 expect(completed, isTrue); 269 expect(completed, isTrue);
365 }); 270 });
366 } 271 }
367 272
368 void fail_extractContext() { 273 void fail_extractContext() {
369 fail("Implement this"); 274 fail("Implement this");
370 } 275 }
371 276
372 void fail_getElement_constructor_named() { 277 void test_getElement_constructor_named() {
373 Source source = _addSource("/lib.dart", r''' 278 Source source = addSource("/lib.dart", r'''
374 class A { 279 class A {
375 A.named() {} 280 A.named() {}
376 }'''); 281 }''');
377 _analyzeAll_assertFinished(); 282 _analyzeAll_assertFinished();
378 LibraryElement library = _context.computeLibraryElement(source); 283 LibraryElement library = context.computeLibraryElement(source);
379 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); 284 ClassElement classA = _findClass(library.definingCompilationUnit, "A");
380 ConstructorElement constructor = classA.constructors[0]; 285 ConstructorElement constructor = classA.constructors[0];
381 ElementLocation location = constructor.location; 286 ElementLocation location = constructor.location;
382 Element element = _context.getElement(location); 287 Element element = context.getElement(location);
383 expect(element, same(constructor)); 288 expect(element, same(constructor));
384 } 289 }
385 290
386 void fail_getElement_constructor_unnamed() { 291 void test_getElement_constructor_unnamed() {
387 Source source = _addSource("/lib.dart", r''' 292 Source source = addSource("/lib.dart", r'''
388 class A { 293 class A {
389 A() {} 294 A() {}
390 }'''); 295 }''');
391 _analyzeAll_assertFinished(); 296 _analyzeAll_assertFinished();
392 LibraryElement library = _context.computeLibraryElement(source); 297 LibraryElement library = context.computeLibraryElement(source);
393 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); 298 ClassElement classA = _findClass(library.definingCompilationUnit, "A");
394 ConstructorElement constructor = classA.constructors[0]; 299 ConstructorElement constructor = classA.constructors[0];
395 ElementLocation location = constructor.location; 300 ElementLocation location = constructor.location;
396 Element element = _context.getElement(location); 301 Element element = context.getElement(location);
397 expect(element, same(constructor)); 302 expect(element, same(constructor));
398 } 303 }
399 304
400 void fail_getElement_enum() { 305 void test_getElement_enum() {
401 Source source = _addSource('/test.dart', 'enum MyEnum {A, B, C}'); 306 Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}');
402 _analyzeAll_assertFinished(); 307 _analyzeAll_assertFinished();
403 LibraryElement library = _context.computeLibraryElement(source); 308 LibraryElement library = context.computeLibraryElement(source);
404 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); 309 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum');
405 ElementLocation location = myEnum.location; 310 ElementLocation location = myEnum.location;
406 Element element = _context.getElement(location); 311 Element element = context.getElement(location);
407 expect(element, same(myEnum)); 312 expect(element, same(myEnum));
408 } 313 }
409 314
410 void fail_getErrors_dart_none() { 315 void fail_getErrors_dart_none() {
411 Source source = _addSource("/lib.dart", "library lib;"); 316 Source source = addSource("/lib.dart", "library lib;");
412 var errorInfo = _context.getErrors(source); 317 var errorInfo = context.getErrors(source);
413 expect(errorInfo, isNotNull); 318 expect(errorInfo, isNotNull);
414 List<AnalysisError> errors = errorInfo.errors; 319 List<AnalysisError> errors = errorInfo.errors;
415 expect(errors, hasLength(0)); 320 expect(errors, hasLength(0));
416 _context.computeErrors(source); 321 context.computeErrors(source);
417 errors = errorInfo.errors; 322 errors = errorInfo.errors;
418 expect(errors, hasLength(0)); 323 expect(errors, hasLength(0));
419 } 324 }
420 325
421 void fail_getErrors_dart_some() { 326 void fail_getErrors_dart_some() {
422 Source source = _addSource("/lib.dart", "library 'lib';"); 327 Source source = addSource("/lib.dart", "library 'lib';");
423 var errorInfo = _context.getErrors(source); 328 var errorInfo = context.getErrors(source);
424 expect(errorInfo, isNotNull); 329 expect(errorInfo, isNotNull);
425 List<AnalysisError> errors = errorInfo.errors; 330 List<AnalysisError> errors = errorInfo.errors;
426 expect(errors, hasLength(0)); 331 expect(errors, hasLength(0));
427 _context.computeErrors(source); 332 context.computeErrors(source);
428 errors = errorInfo.errors; 333 errors = errorInfo.errors;
429 expect(errors, hasLength(1)); 334 expect(errors, hasLength(1));
430 } 335 }
431 336
432 void fail_getErrors_html_none() { 337 void fail_getErrors_html_none() {
433 Source source = _addSource("/test.html", "<html></html>"); 338 Source source = addSource("/test.html", "<html></html>");
434 AnalysisErrorInfo errorInfo = _context.getErrors(source); 339 AnalysisErrorInfo errorInfo = context.getErrors(source);
435 expect(errorInfo, isNotNull); 340 expect(errorInfo, isNotNull);
436 List<AnalysisError> errors = errorInfo.errors; 341 List<AnalysisError> errors = errorInfo.errors;
437 expect(errors, hasLength(0)); 342 expect(errors, hasLength(0));
438 _context.computeErrors(source); 343 context.computeErrors(source);
439 errors = errorInfo.errors; 344 errors = errorInfo.errors;
440 expect(errors, hasLength(0)); 345 expect(errors, hasLength(0));
441 } 346 }
442 347
443 void fail_getErrors_html_some() { 348 void fail_getErrors_html_some() {
444 Source source = _addSource("/test.html", r''' 349 Source source = addSource("/test.html", r'''
445 <html><head> 350 <html><head>
446 <script type='application/dart' src='test.dart'/> 351 <script type='application/dart' src='test.dart'/>
447 </head></html>'''); 352 </head></html>''');
448 AnalysisErrorInfo errorInfo = _context.getErrors(source); 353 AnalysisErrorInfo errorInfo = context.getErrors(source);
449 expect(errorInfo, isNotNull); 354 expect(errorInfo, isNotNull);
450 List<AnalysisError> errors = errorInfo.errors; 355 List<AnalysisError> errors = errorInfo.errors;
451 expect(errors, hasLength(0)); 356 expect(errors, hasLength(0));
452 _context.computeErrors(source); 357 context.computeErrors(source);
453 errors = errorInfo.errors; 358 errors = errorInfo.errors;
454 expect(errors, hasLength(1)); 359 expect(errors, hasLength(1));
455 } 360 }
456 361
457 void fail_getHtmlElement_html() { 362 void fail_getHtmlElement_html() {
458 Source source = _addSource("/test.html", "<html></html>"); 363 Source source = addSource("/test.html", "<html></html>");
459 HtmlElement element = _context.getHtmlElement(source); 364 HtmlElement element = context.getHtmlElement(source);
460 expect(element, isNull); 365 expect(element, isNull);
461 _context.computeHtmlElement(source); 366 context.computeHtmlElement(source);
462 element = _context.getHtmlElement(source); 367 element = context.getHtmlElement(source);
463 expect(element, isNotNull); 368 expect(element, isNotNull);
464 } 369 }
465 370
466 void fail_getHtmlFilesReferencing_library() { 371 void fail_getHtmlFilesReferencing_library() {
467 Source htmlSource = _addSource("/test.html", r''' 372 Source htmlSource = addSource("/test.html", r'''
468 <html><head> 373 <html><head>
469 <script type='application/dart' src='test.dart'/> 374 <script type='application/dart' src='test.dart'/>
470 <script type='application/dart' src='test.js'/> 375 <script type='application/dart' src='test.js'/>
471 </head></html>'''); 376 </head></html>''');
472 Source librarySource = _addSource("/test.dart", "library lib;"); 377 Source librarySource = addSource("/test.dart", "library lib;");
473 List<Source> result = _context.getHtmlFilesReferencing(librarySource); 378 List<Source> result = context.getHtmlFilesReferencing(librarySource);
474 expect(result, hasLength(0)); 379 expect(result, hasLength(0));
475 _context.parseHtmlUnit(htmlSource); 380 context.parseHtmlUnit(htmlSource);
476 result = _context.getHtmlFilesReferencing(librarySource); 381 result = context.getHtmlFilesReferencing(librarySource);
477 expect(result, hasLength(1)); 382 expect(result, hasLength(1));
478 expect(result[0], htmlSource); 383 expect(result[0], htmlSource);
479 } 384 }
480 385
481 void fail_getHtmlFilesReferencing_part() { 386 void fail_getHtmlFilesReferencing_part() {
482 _context = contextWithCore(); 387 Source htmlSource = addSource("/test.html", r'''
483 _sourceFactory = _context.sourceFactory;
484 Source htmlSource = _addSource("/test.html", r'''
485 <html><head> 388 <html><head>
486 <script type='application/dart' src='test.dart'/> 389 <script type='application/dart' src='test.dart'/>
487 <script type='application/dart' src='test.js'/> 390 <script type='application/dart' src='test.js'/>
488 </head></html>'''); 391 </head></html>''');
489 Source librarySource = 392 Source librarySource =
490 _addSource("/test.dart", "library lib; part 'part.dart';"); 393 addSource("/test.dart", "library lib; part 'part.dart';");
491 Source partSource = _addSource("/part.dart", "part of lib;"); 394 Source partSource = addSource("/part.dart", "part of lib;");
492 _context.computeLibraryElement(librarySource); 395 context.computeLibraryElement(librarySource);
493 List<Source> result = _context.getHtmlFilesReferencing(partSource); 396 List<Source> result = context.getHtmlFilesReferencing(partSource);
494 expect(result, hasLength(0)); 397 expect(result, hasLength(0));
495 _context.parseHtmlUnit(htmlSource); 398 context.parseHtmlUnit(htmlSource);
496 result = _context.getHtmlFilesReferencing(partSource); 399 result = context.getHtmlFilesReferencing(partSource);
497 expect(result, hasLength(1)); 400 expect(result, hasLength(1));
498 expect(result[0], htmlSource); 401 expect(result[0], htmlSource);
499 } 402 }
500 403
501 void fail_getHtmlSources() { 404 void fail_getHtmlSources() {
502 List<Source> sources = _context.htmlSources; 405 List<Source> sources = context.htmlSources;
503 expect(sources, hasLength(0)); 406 expect(sources, hasLength(0));
504 Source source = _addSource("/test.html", ""); 407 Source source = addSource("/test.html", "");
505 _context.computeKindOf(source); 408 context.computeKindOf(source);
506 sources = _context.htmlSources; 409 sources = context.htmlSources;
507 expect(sources, hasLength(1)); 410 expect(sources, hasLength(1));
508 expect(sources[0], source); 411 expect(sources[0], source);
509 } 412 }
510 413
511 void fail_getLibrariesReferencedFromHtml() { 414 void fail_getLibrariesReferencedFromHtml() {
512 _context = contextWithCore(); 415 Source htmlSource = addSource("/test.html", r'''
513 _sourceFactory = _context.sourceFactory;
514 Source htmlSource = _addSource("/test.html", r'''
515 <html><head> 416 <html><head>
516 <script type='application/dart' src='test.dart'/> 417 <script type='application/dart' src='test.dart'/>
517 <script type='application/dart' src='test.js'/> 418 <script type='application/dart' src='test.js'/>
518 </head></html>'''); 419 </head></html>''');
519 Source librarySource = _addSource("/test.dart", "library lib;"); 420 Source librarySource = addSource("/test.dart", "library lib;");
520 _context.computeLibraryElement(librarySource); 421 context.computeLibraryElement(librarySource);
521 _context.parseHtmlUnit(htmlSource); 422 context.parseHtmlUnit(htmlSource);
522 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); 423 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource);
523 expect(result, hasLength(1)); 424 expect(result, hasLength(1));
524 expect(result[0], librarySource); 425 expect(result[0], librarySource);
525 } 426 }
526 427
527 void fail_getResolvedCompilationUnit_library() { 428 void fail_getResolvedCompilationUnit_library() {
528 _context = contextWithCore(); 429 Source source = addSource("/lib.dart", "library libb;");
529 _sourceFactory = _context.sourceFactory; 430 LibraryElement library = context.computeLibraryElement(source);
530 Source source = _addSource("/lib.dart", "library libb;"); 431 expect(context.getResolvedCompilationUnit(source, library), isNotNull);
531 LibraryElement library = _context.computeLibraryElement(source); 432 context.setContents(source, "library lib;");
532 expect(_context.getResolvedCompilationUnit(source, library), isNotNull); 433 expect(context.getResolvedCompilationUnit(source, library), isNull);
533 _context.setContents(source, "library lib;");
534 expect(_context.getResolvedCompilationUnit(source, library), isNull);
535 } 434 }
536 435
537 void fail_getResolvedHtmlUnit() { 436 void fail_getResolvedHtmlUnit() {
538 _context = contextWithCore(); 437 Source source = addSource("/test.html", "<html></html>");
539 _sourceFactory = _context.sourceFactory; 438 expect(context.getResolvedHtmlUnit(source), isNull);
540 Source source = _addSource("/test.html", "<html></html>"); 439 context.resolveHtmlUnit(source);
541 expect(_context.getResolvedHtmlUnit(source), isNull); 440 expect(context.getResolvedHtmlUnit(source), isNotNull);
542 _context.resolveHtmlUnit(source);
543 expect(_context.getResolvedHtmlUnit(source), isNotNull);
544 } 441 }
545 442
546 void fail_mergeContext() { 443 void fail_mergeContext() {
547 fail("Implement this"); 444 fail("Implement this");
548 } 445 }
549 446
550 void fail_parseHtmlUnit_noErrors() { 447 void fail_parseHtmlUnit_noErrors() {
551 Source source = _addSource("/lib.html", "<html></html>"); 448 Source source = addSource("/lib.html", "<html></html>");
552 ht.HtmlUnit unit = _context.parseHtmlUnit(source); 449 ht.HtmlUnit unit = context.parseHtmlUnit(source);
553 expect(unit, isNotNull); 450 expect(unit, isNotNull);
554 } 451 }
555 452
556 void fail_parseHtmlUnit_resolveDirectives() { 453 void fail_parseHtmlUnit_resolveDirectives() {
557 Source libSource = _addSource("/lib.dart", r''' 454 Source libSource = addSource("/lib.dart", r'''
558 library lib; 455 library lib;
559 class ClassA {}'''); 456 class ClassA {}''');
560 Source source = _addSource("/lib.html", r''' 457 Source source = addSource("/lib.html", r'''
561 <html> 458 <html>
562 <head> 459 <head>
563 <script type='application/dart'> 460 <script type='application/dart'>
564 import 'lib.dart'; 461 import 'lib.dart';
565 ClassA v = null; 462 ClassA v = null;
566 </script> 463 </script>
567 </head> 464 </head>
568 <body> 465 <body>
569 </body> 466 </body>
570 </html>'''); 467 </html>''');
571 ht.HtmlUnit unit = _context.parseHtmlUnit(source); 468 ht.HtmlUnit unit = context.parseHtmlUnit(source);
572 expect(unit, isNotNull); 469 expect(unit, isNotNull);
573 // import directive should be resolved 470 // import directive should be resolved
574 ht.XmlTagNode htmlNode = unit.tagNodes[0]; 471 ht.XmlTagNode htmlNode = unit.tagNodes[0];
575 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; 472 ht.XmlTagNode headNode = htmlNode.tagNodes[0];
576 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; 473 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0];
577 CompilationUnit script = scriptNode.script; 474 CompilationUnit script = scriptNode.script;
578 ImportDirective importNode = script.directives[0] as ImportDirective; 475 ImportDirective importNode = script.directives[0] as ImportDirective;
579 expect(importNode.uriContent, isNotNull); 476 expect(importNode.uriContent, isNotNull);
580 expect(importNode.source, libSource); 477 expect(importNode.source, libSource);
581 } 478 }
582 479
583 void fail_performAnalysisTask_addPart() { 480 void fail_performAnalysisTask_addPart() {
584 Source libSource = _addSource("/lib.dart", r''' 481 Source libSource = addSource("/lib.dart", r'''
585 library lib; 482 library lib;
586 part 'part.dart';'''); 483 part 'part.dart';''');
587 // run all tasks without part 484 // run all tasks without part
588 _analyzeAll_assertFinished(); 485 _analyzeAll_assertFinished();
589 // add part and run all tasks 486 // add part and run all tasks
590 Source partSource = _addSource("/part.dart", r''' 487 Source partSource = addSource("/part.dart", r'''
591 part of lib; 488 part of lib;
592 '''); 489 ''');
593 _analyzeAll_assertFinished(); 490 _analyzeAll_assertFinished();
594 // "libSource" should be here 491 // "libSource" should be here
595 List<Source> librariesWithPart = 492 List<Source> librariesWithPart = context.getLibrariesContaining(partSource);
596 _context.getLibrariesContaining(partSource);
597 expect(librariesWithPart, unorderedEquals([libSource])); 493 expect(librariesWithPart, unorderedEquals([libSource]));
598 } 494 }
599 495
600 void fail_performAnalysisTask_changeLibraryContents() { 496 void fail_performAnalysisTask_changeLibraryContents() {
601 Source libSource = 497 Source libSource =
602 _addSource("/test.dart", "library lib; part 'test-part.dart';"); 498 addSource("/test.dart", "library lib; part 'test-part.dart';");
603 Source partSource = _addSource("/test-part.dart", "part of lib;"); 499 Source partSource = addSource("/test-part.dart", "part of lib;");
604 _analyzeAll_assertFinished(); 500 _analyzeAll_assertFinished();
605 expect( 501 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
606 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
607 reason: "library resolved 1"); 502 reason: "library resolved 1");
608 expect( 503 expect(
609 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 504 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
610 reason: "part resolved 1"); 505 reason: "part resolved 1");
611 // update and analyze #1 506 // update and analyze #1
612 _context.setContents(libSource, "library lib;"); 507 context.setContents(libSource, "library lib;");
613 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 508 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
614 reason: "library changed 2"); 509 reason: "library changed 2");
615 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 510 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
616 reason: "part changed 2"); 511 reason: "part changed 2");
617 _analyzeAll_assertFinished(); 512 _analyzeAll_assertFinished();
618 expect( 513 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
619 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
620 reason: "library resolved 2"); 514 reason: "library resolved 2");
621 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 515 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
622 reason: "part resolved 2"); 516 reason: "part resolved 2");
623 // update and analyze #2 517 // update and analyze #2
624 _context.setContents(libSource, "library lib; part 'test-part.dart';"); 518 context.setContents(libSource, "library lib; part 'test-part.dart';");
625 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 519 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
626 reason: "library changed 3"); 520 reason: "library changed 3");
627 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 521 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
628 reason: "part changed 3"); 522 reason: "part changed 3");
629 _analyzeAll_assertFinished(); 523 _analyzeAll_assertFinished();
630 expect( 524 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
631 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
632 reason: "library resolved 2"); 525 reason: "library resolved 2");
633 expect( 526 expect(
634 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 527 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
635 reason: "part resolved 3"); 528 reason: "part resolved 3");
636 } 529 }
637 530
638 void fail_performAnalysisTask_changeLibraryThenPartContents() { 531 void fail_performAnalysisTask_changeLibraryThenPartContents() {
639 Source libSource = 532 Source libSource =
640 _addSource("/test.dart", "library lib; part 'test-part.dart';"); 533 addSource("/test.dart", "library lib; part 'test-part.dart';");
641 Source partSource = _addSource("/test-part.dart", "part of lib;"); 534 Source partSource = addSource("/test-part.dart", "part of lib;");
642 _analyzeAll_assertFinished(); 535 _analyzeAll_assertFinished();
643 expect( 536 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
644 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
645 reason: "library resolved 1"); 537 reason: "library resolved 1");
646 expect( 538 expect(
647 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 539 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
648 reason: "part resolved 1"); 540 reason: "part resolved 1");
649 // update and analyze #1 541 // update and analyze #1
650 _context.setContents(libSource, "library lib;"); 542 context.setContents(libSource, "library lib;");
651 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 543 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
652 reason: "library changed 2"); 544 reason: "library changed 2");
653 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 545 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
654 reason: "part changed 2"); 546 reason: "part changed 2");
655 _analyzeAll_assertFinished(); 547 _analyzeAll_assertFinished();
656 expect( 548 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
657 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
658 reason: "library resolved 2"); 549 reason: "library resolved 2");
659 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 550 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
660 reason: "part resolved 2"); 551 reason: "part resolved 2");
661 // update and analyze #2 552 // update and analyze #2
662 _context.setContents(partSource, "part of lib; // 1"); 553 context.setContents(partSource, "part of lib; // 1");
663 // Assert that changing the part's content does not effect the library 554 // Assert that changing the part's content does not effect the library
664 // now that it is no longer part of that library 555 // now that it is no longer part of that library
665 expect( 556 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
666 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
667 reason: "library changed 3"); 557 reason: "library changed 3");
668 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 558 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
669 reason: "part changed 3"); 559 reason: "part changed 3");
670 _analyzeAll_assertFinished(); 560 _analyzeAll_assertFinished();
671 expect( 561 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
672 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
673 reason: "library resolved 3"); 562 reason: "library resolved 3");
674 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 563 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
675 reason: "part resolved 3"); 564 reason: "part resolved 3");
676 } 565 }
677 566
678 void fail_performAnalysisTask_changePartContents_makeItAPart() { 567 void fail_performAnalysisTask_changePartContents_makeItAPart() {
679 Source libSource = _addSource("/lib.dart", r''' 568 Source libSource = addSource("/lib.dart", r'''
680 library lib; 569 library lib;
681 part 'part.dart'; 570 part 'part.dart';
682 void f(x) {}'''); 571 void f(x) {}''');
683 Source partSource = _addSource("/part.dart", "void g() { f(null); }"); 572 Source partSource = addSource("/part.dart", "void g() { f(null); }");
684 _analyzeAll_assertFinished(); 573 _analyzeAll_assertFinished();
685 expect( 574 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
686 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
687 reason: "library resolved 1"); 575 reason: "library resolved 1");
688 expect( 576 expect(
689 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 577 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
690 reason: "part resolved 1"); 578 reason: "part resolved 1");
691 // update and analyze 579 // update and analyze
692 _context.setContents(partSource, r''' 580 context.setContents(partSource, r'''
693 part of lib; 581 part of lib;
694 void g() { f(null); }'''); 582 void g() { f(null); }''');
695 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 583 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
696 reason: "library changed 2"); 584 reason: "library changed 2");
697 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 585 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
698 reason: "part changed 2"); 586 reason: "part changed 2");
699 _analyzeAll_assertFinished(); 587 _analyzeAll_assertFinished();
700 expect( 588 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
701 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
702 reason: "library resolved 2"); 589 reason: "library resolved 2");
703 expect( 590 expect(
704 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 591 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
705 reason: "part resolved 2"); 592 reason: "part resolved 2");
706 expect(_context.getErrors(libSource).errors, hasLength(0)); 593 expect(context.getErrors(libSource).errors, hasLength(0));
707 expect(_context.getErrors(partSource).errors, hasLength(0)); 594 expect(context.getErrors(partSource).errors, hasLength(0));
708 } 595 }
709 596
710 /** 597 /**
711 * https://code.google.com/p/dart/issues/detail?id=12424 598 * https://code.google.com/p/dart/issues/detail?id=12424
712 */ 599 */
713 void fail_performAnalysisTask_changePartContents_makeItNotPart() { 600 void fail_performAnalysisTask_changePartContents_makeItNotPart() {
714 Source libSource = _addSource("/lib.dart", r''' 601 Source libSource = addSource("/lib.dart", r'''
715 library lib; 602 library lib;
716 part 'part.dart'; 603 part 'part.dart';
717 void f(x) {}'''); 604 void f(x) {}''');
718 Source partSource = _addSource("/part.dart", r''' 605 Source partSource = addSource("/part.dart", r'''
719 part of lib; 606 part of lib;
720 void g() { f(null); }'''); 607 void g() { f(null); }''');
721 _analyzeAll_assertFinished(); 608 _analyzeAll_assertFinished();
722 expect(_context.getErrors(libSource).errors, hasLength(0)); 609 expect(context.getErrors(libSource).errors, hasLength(0));
723 expect(_context.getErrors(partSource).errors, hasLength(0)); 610 expect(context.getErrors(partSource).errors, hasLength(0));
724 // Remove 'part' directive, which should make "f(null)" an error. 611 // Remove 'part' directive, which should make "f(null)" an error.
725 _context.setContents(partSource, r''' 612 context.setContents(partSource, r'''
726 //part of lib; 613 //part of lib;
727 void g() { f(null); }'''); 614 void g() { f(null); }''');
728 _analyzeAll_assertFinished(); 615 _analyzeAll_assertFinished();
729 expect(_context.getErrors(libSource).errors.length != 0, isTrue); 616 expect(context.getErrors(libSource).errors.length != 0, isTrue);
730 } 617 }
731 618
732 void fail_performAnalysisTask_changePartContents_noSemanticChanges() { 619 void fail_performAnalysisTask_changePartContents_noSemanticChanges() {
733 Source libSource = 620 Source libSource =
734 _addSource("/test.dart", "library lib; part 'test-part.dart';"); 621 addSource("/test.dart", "library lib; part 'test-part.dart';");
735 Source partSource = _addSource("/test-part.dart", "part of lib;"); 622 Source partSource = addSource("/test-part.dart", "part of lib;");
736 _analyzeAll_assertFinished(); 623 _analyzeAll_assertFinished();
737 expect( 624 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
738 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
739 reason: "library resolved 1"); 625 reason: "library resolved 1");
740 expect( 626 expect(
741 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 627 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
742 reason: "part resolved 1"); 628 reason: "part resolved 1");
743 // update and analyze #1 629 // update and analyze #1
744 _context.setContents(partSource, "part of lib; // 1"); 630 context.setContents(partSource, "part of lib; // 1");
745 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 631 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
746 reason: "library changed 2"); 632 reason: "library changed 2");
747 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 633 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
748 reason: "part changed 2"); 634 reason: "part changed 2");
749 _analyzeAll_assertFinished(); 635 _analyzeAll_assertFinished();
750 expect( 636 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
751 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
752 reason: "library resolved 2"); 637 reason: "library resolved 2");
753 expect( 638 expect(
754 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 639 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
755 reason: "part resolved 2"); 640 reason: "part resolved 2");
756 // update and analyze #2 641 // update and analyze #2
757 _context.setContents(partSource, "part of lib; // 12"); 642 context.setContents(partSource, "part of lib; // 12");
758 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, 643 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull,
759 reason: "library changed 3"); 644 reason: "library changed 3");
760 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, 645 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull,
761 reason: "part changed 3"); 646 reason: "part changed 3");
762 _analyzeAll_assertFinished(); 647 _analyzeAll_assertFinished();
763 expect( 648 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
764 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull,
765 reason: "library resolved 3"); 649 reason: "library resolved 3");
766 expect( 650 expect(
767 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, 651 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull,
768 reason: "part resolved 3"); 652 reason: "part resolved 3");
769 } 653 }
770 654
771 void fail_performAnalysisTask_getContentException_dart() { 655 void fail_performAnalysisTask_getContentException_dart() {
772 // add source that throw an exception on "get content" 656 // add source that throw an exception on "get content"
773 Source source = new _Source_getContent_throwException('test.dart'); 657 Source source = new _Source_getContent_throwException('test.dart');
774 { 658 {
775 ChangeSet changeSet = new ChangeSet(); 659 ChangeSet changeSet = new ChangeSet();
776 changeSet.addedSource(source); 660 changeSet.addedSource(source);
777 _context.applyChanges(changeSet); 661 context.applyChanges(changeSet);
778 } 662 }
779 // prepare errors 663 // prepare errors
780 _analyzeAll_assertFinished(); 664 _analyzeAll_assertFinished();
781 List<AnalysisError> errors = _context.getErrors(source).errors; 665 List<AnalysisError> errors = context.getErrors(source).errors;
782 // validate errors 666 // validate errors
783 expect(errors, hasLength(1)); 667 expect(errors, hasLength(1));
784 AnalysisError error = errors[0]; 668 AnalysisError error = errors[0];
785 expect(error.source, same(source)); 669 expect(error.source, same(source));
786 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); 670 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT);
787 } 671 }
788 672
789 void fail_performAnalysisTask_getContentException_html() { 673 void fail_performAnalysisTask_getContentException_html() {
790 // add source that throw an exception on "get content" 674 // add source that throw an exception on "get content"
791 Source source = new _Source_getContent_throwException('test.html'); 675 Source source = new _Source_getContent_throwException('test.html');
792 { 676 {
793 ChangeSet changeSet = new ChangeSet(); 677 ChangeSet changeSet = new ChangeSet();
794 changeSet.addedSource(source); 678 changeSet.addedSource(source);
795 _context.applyChanges(changeSet); 679 context.applyChanges(changeSet);
796 } 680 }
797 // prepare errors 681 // prepare errors
798 _analyzeAll_assertFinished(); 682 _analyzeAll_assertFinished();
799 List<AnalysisError> errors = _context.getErrors(source).errors; 683 List<AnalysisError> errors = context.getErrors(source).errors;
800 // validate errors 684 // validate errors
801 expect(errors, hasLength(1)); 685 expect(errors, hasLength(1));
802 AnalysisError error = errors[0]; 686 AnalysisError error = errors[0];
803 expect(error.source, same(source)); 687 expect(error.source, same(source));
804 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); 688 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT);
805 } 689 }
806 690
807 void fail_performAnalysisTask_importedLibraryAdd() { 691 void fail_performAnalysisTask_importedLibraryAdd() {
808 Source libASource = 692 Source libASource =
809 _addSource("/libA.dart", "library libA; import 'libB.dart';"); 693 addSource("/libA.dart", "library libA; import 'libB.dart';");
810 _analyzeAll_assertFinished(); 694 _analyzeAll_assertFinished();
811 expect( 695 expect(
812 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, 696 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull,
813 reason: "libA resolved 1"); 697 reason: "libA resolved 1");
814 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), 698 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)),
815 isTrue, reason: "libA has an error"); 699 isTrue, reason: "libA has an error");
816 // add libB.dart and analyze 700 // add libB.dart and analyze
817 Source libBSource = _addSource("/libB.dart", "library libB;"); 701 Source libBSource = addSource("/libB.dart", "library libB;");
818 _analyzeAll_assertFinished(); 702 _analyzeAll_assertFinished();
819 expect( 703 expect(
820 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, 704 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull,
821 reason: "libA resolved 2"); 705 reason: "libA resolved 2");
822 expect( 706 expect(
823 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 707 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
824 reason: "libB resolved 2"); 708 reason: "libB resolved 2");
825 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), 709 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)),
826 isTrue, reason: "libA doesn't have errors"); 710 isTrue, reason: "libA doesn't have errors");
827 } 711 }
828 712
829 void fail_performAnalysisTask_importedLibraryAdd_html() { 713 void fail_performAnalysisTask_importedLibraryAdd_html() {
830 Source htmlSource = _addSource("/page.html", r''' 714 Source htmlSource = addSource("/page.html", r'''
831 <html><body><script type="application/dart"> 715 <html><body><script type="application/dart">
832 import '/libB.dart'; 716 import '/libB.dart';
833 main() {print('hello dart');} 717 main() {print('hello dart');}
834 </script></body></html>'''); 718 </script></body></html>''');
835 _analyzeAll_assertFinished(); 719 _analyzeAll_assertFinished();
836 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, 720 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
837 reason: "htmlUnit resolved 1"); 721 reason: "htmlUnit resolved 1");
838 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), 722 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)),
839 isTrue, reason: "htmlSource has an error"); 723 isTrue, reason: "htmlSource has an error");
840 // add libB.dart and analyze 724 // add libB.dart and analyze
841 Source libBSource = _addSource("/libB.dart", "library libB;"); 725 Source libBSource = addSource("/libB.dart", "library libB;");
842 _analyzeAll_assertFinished(); 726 _analyzeAll_assertFinished();
843 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, 727 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
844 reason: "htmlUnit resolved 1"); 728 reason: "htmlUnit resolved 1");
845 expect( 729 expect(
846 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 730 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
847 reason: "libB resolved 2"); 731 reason: "libB resolved 2");
848 // TODO (danrubel) commented out to fix red bots 732 // TODO (danrubel) commented out to fix red bots
849 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); 733 // AnalysisErrorInfo errors = _context.getErrors(htmlSource);
850 // expect( 734 // expect(
851 // !_hasAnalysisErrorWithErrorSeverity(errors), 735 // !_hasAnalysisErrorWithErrorSeverity(errors),
852 // isTrue, 736 // isTrue,
853 // reason: "htmlSource doesn't have errors"); 737 // reason: "htmlSource doesn't have errors");
854 } 738 }
855 739
856 void fail_performAnalysisTask_importedLibraryDelete() { 740 void fail_performAnalysisTask_importedLibraryDelete() {
857 Source libASource = 741 Source libASource =
858 _addSource("/libA.dart", "library libA; import 'libB.dart';"); 742 addSource("/libA.dart", "library libA; import 'libB.dart';");
859 Source libBSource = _addSource("/libB.dart", "library libB;"); 743 Source libBSource = addSource("/libB.dart", "library libB;");
860 _analyzeAll_assertFinished(); 744 _analyzeAll_assertFinished();
861 expect( 745 expect(
862 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, 746 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull,
863 reason: "libA resolved 1"); 747 reason: "libA resolved 1");
864 expect( 748 expect(
865 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 749 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
866 reason: "libB resolved 1"); 750 reason: "libB resolved 1");
867 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), 751 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)),
868 isTrue, reason: "libA doesn't have errors"); 752 isTrue, reason: "libA doesn't have errors");
869 // remove libB.dart content and analyze 753 // remove libB.dart content and analyze
870 _context.setContents(libBSource, null); 754 context.setContents(libBSource, null);
871 _analyzeAll_assertFinished(); 755 _analyzeAll_assertFinished();
872 expect( 756 expect(
873 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, 757 context.getResolvedCompilationUnit2(libASource, libASource), isNotNull,
874 reason: "libA resolved 2"); 758 reason: "libA resolved 2");
875 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), 759 expect(_hasAnalysisErrorWithErrorSeverity(context.getErrors(libASource)),
876 isTrue, reason: "libA has an error"); 760 isTrue, reason: "libA has an error");
877 } 761 }
878 762
879 void fail_performAnalysisTask_importedLibraryDelete_html() { 763 void fail_performAnalysisTask_importedLibraryDelete_html() {
880 // NOTE: This was failing before converting to the new task model. 764 // NOTE: This was failing before converting to the new task model.
881 Source htmlSource = _addSource("/page.html", r''' 765 Source htmlSource = addSource("/page.html", r'''
882 <html><body><script type="application/dart"> 766 <html><body><script type="application/dart">
883 import 'libB.dart'; 767 import 'libB.dart';
884 main() {print('hello dart');} 768 main() {print('hello dart');}
885 </script></body></html>'''); 769 </script></body></html>''');
886 Source libBSource = _addSource("/libB.dart", "library libB;"); 770 Source libBSource = addSource("/libB.dart", "library libB;");
887 _analyzeAll_assertFinished(); 771 _analyzeAll_assertFinished();
888 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, 772 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
889 reason: "htmlUnit resolved 1"); 773 reason: "htmlUnit resolved 1");
890 expect( 774 expect(
891 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, 775 context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull,
892 reason: "libB resolved 1"); 776 reason: "libB resolved 1");
893 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), 777 expect(!_hasAnalysisErrorWithErrorSeverity(context.getErrors(htmlSource)),
894 isTrue, reason: "htmlSource doesn't have errors"); 778 isTrue, reason: "htmlSource doesn't have errors");
895 // remove libB.dart content and analyze 779 // remove libB.dart content and analyze
896 _context.setContents(libBSource, null); 780 context.setContents(libBSource, null);
897 _analyzeAll_assertFinished(); 781 _analyzeAll_assertFinished();
898 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, 782 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
899 reason: "htmlUnit resolved 1"); 783 reason: "htmlUnit resolved 1");
900 AnalysisErrorInfo errors = _context.getErrors(htmlSource); 784 AnalysisErrorInfo errors = context.getErrors(htmlSource);
901 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, 785 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue,
902 reason: "htmlSource has an error"); 786 reason: "htmlSource has an error");
903 } 787 }
904 788
905 void fail_performAnalysisTask_IOException() { 789 void fail_performAnalysisTask_IOException() {
906 TestSource source = _addSourceWithException2("/test.dart", "library test;"); 790 TestSource source = _addSourceWithException2("/test.dart", "library test;");
907 int oldTimestamp = _context.getModificationStamp(source); 791 int oldTimestamp = context.getModificationStamp(source);
908 source.generateExceptionOnRead = false; 792 source.generateExceptionOnRead = false;
909 _analyzeAll_assertFinished(); 793 _analyzeAll_assertFinished();
910 expect(source.readCount, 1); 794 expect(source.readCount, 1);
911 source.generateExceptionOnRead = true; 795 source.generateExceptionOnRead = true;
912 do { 796 do {
913 _changeSource(source, ""); 797 _changeSource(source, "");
914 // Ensure that the timestamp differs, 798 // Ensure that the timestamp differs,
915 // so that analysis engine notices the change 799 // so that analysis engine notices the change
916 } while (oldTimestamp == _context.getModificationStamp(source)); 800 } while (oldTimestamp == context.getModificationStamp(source));
917 _analyzeAll_assertFinished(); 801 _analyzeAll_assertFinished();
918 expect(source.readCount, 2); 802 expect(source.readCount, 2);
919 } 803 }
920 804
921 void fail_performAnalysisTask_missingPart() { 805 void fail_performAnalysisTask_missingPart() {
922 Source source = 806 Source source =
923 _addSource("/test.dart", "library lib; part 'no-such-file.dart';"); 807 addSource("/test.dart", "library lib; part 'no-such-file.dart';");
924 _analyzeAll_assertFinished(); 808 _analyzeAll_assertFinished();
925 expect(_context.getLibraryElement(source), isNotNull, 809 expect(context.getLibraryElement(source), isNotNull,
926 reason: "performAnalysisTask failed to compute an element model"); 810 reason: "performAnalysisTask failed to compute an element model");
927 } 811 }
928 812
929 void fail_recordLibraryElements() { 813 void fail_recordLibraryElements() {
930 fail("Implement this"); 814 fail("Implement this");
931 } 815 }
932 816
933 void fail_resolveCompilationUnit_import_relative() { 817 void fail_resolveCompilationUnit_import_relative() {
934 _context = contextWithCore();
935 Source sourceA = 818 Source sourceA =
936 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); 819 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}");
937 _addSource("/libB.dart", "library libB; class B{}"); 820 addSource("/libB.dart", "library libB; class B{}");
938 CompilationUnit compilationUnit = 821 CompilationUnit compilationUnit =
939 _context.resolveCompilationUnit2(sourceA, sourceA); 822 context.resolveCompilationUnit2(sourceA, sourceA);
940 expect(compilationUnit, isNotNull); 823 expect(compilationUnit, isNotNull);
941 LibraryElement library = compilationUnit.element.library; 824 LibraryElement library = compilationUnit.element.library;
942 List<LibraryElement> importedLibraries = library.importedLibraries; 825 List<LibraryElement> importedLibraries = library.importedLibraries;
943 assertNamedElements(importedLibraries, ["dart.core", "libB"]); 826 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
944 List<LibraryElement> visibleLibraries = library.visibleLibraries; 827 List<LibraryElement> visibleLibraries = library.visibleLibraries;
945 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); 828 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]);
946 } 829 }
947 830
948 void fail_resolveCompilationUnit_import_relative_cyclic() { 831 void fail_resolveCompilationUnit_import_relative_cyclic() {
949 _context = contextWithCore();
950 Source sourceA = 832 Source sourceA =
951 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); 833 addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}");
952 _addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}"); 834 addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}");
953 CompilationUnit compilationUnit = 835 CompilationUnit compilationUnit =
954 _context.resolveCompilationUnit2(sourceA, sourceA); 836 context.resolveCompilationUnit2(sourceA, sourceA);
955 expect(compilationUnit, isNotNull); 837 expect(compilationUnit, isNotNull);
956 LibraryElement library = compilationUnit.element.library; 838 LibraryElement library = compilationUnit.element.library;
957 List<LibraryElement> importedLibraries = library.importedLibraries; 839 List<LibraryElement> importedLibraries = library.importedLibraries;
958 assertNamedElements(importedLibraries, ["dart.core", "libB"]); 840 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
959 List<LibraryElement> visibleLibraries = library.visibleLibraries; 841 List<LibraryElement> visibleLibraries = library.visibleLibraries;
960 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); 842 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]);
961 } 843 }
962 844
963 void fail_resolveHtmlUnit() { 845 void fail_resolveHtmlUnit() {
964 Source source = _addSource("/lib.html", "<html></html>"); 846 Source source = addSource("/lib.html", "<html></html>");
965 ht.HtmlUnit unit = _context.resolveHtmlUnit(source); 847 ht.HtmlUnit unit = context.resolveHtmlUnit(source);
966 expect(unit, isNotNull); 848 expect(unit, isNotNull);
967 } 849 }
968 850
969 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() { 851 void fail_setAnalysisOptions_reduceAnalysisPriorityOrder() {
970 AnalysisOptionsImpl options = 852 AnalysisOptionsImpl options =
971 new AnalysisOptionsImpl.con1(_context.analysisOptions); 853 new AnalysisOptionsImpl.con1(context.analysisOptions);
972 List<Source> sources = new List<Source>(); 854 List<Source> sources = new List<Source>();
973 for (int index = 0; index < options.cacheSize; index++) { 855 for (int index = 0; index < options.cacheSize; index++) {
974 sources.add(_addSource("/lib.dart$index", "")); 856 sources.add(addSource("/lib.dart$index", ""));
975 } 857 }
976 _context.analysisPriorityOrder = sources; 858 context.analysisPriorityOrder = sources;
977 int oldPriorityOrderSize = _getPriorityOrder(_context).length; 859 int oldPriorityOrderSize = _getPriorityOrder(context).length;
978 options.cacheSize = options.cacheSize - 10; 860 options.cacheSize = options.cacheSize - 10;
979 _context.analysisOptions = options; 861 context.analysisOptions = options;
980 expect(oldPriorityOrderSize > _getPriorityOrder(_context).length, isTrue); 862 expect(oldPriorityOrderSize > _getPriorityOrder(context).length, isTrue);
981 } 863 }
982 864
983 void fail_setAnalysisPriorityOrder_lessThanCacheSize() { 865 void fail_setAnalysisPriorityOrder_lessThanCacheSize() {
984 AnalysisOptions options = _context.analysisOptions; 866 AnalysisOptions options = context.analysisOptions;
985 List<Source> sources = new List<Source>(); 867 List<Source> sources = new List<Source>();
986 for (int index = 0; index < options.cacheSize; index++) { 868 for (int index = 0; index < options.cacheSize; index++) {
987 sources.add(_addSource("/lib.dart$index", "")); 869 sources.add(addSource("/lib.dart$index", ""));
988 } 870 }
989 _context.analysisPriorityOrder = sources; 871 context.analysisPriorityOrder = sources;
990 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue); 872 expect(options.cacheSize > _getPriorityOrder(context).length, isTrue);
991 } 873 }
992 874
993 Future fail_setChangedContents_libraryWithPart() { 875 Future fail_setChangedContents_libraryWithPart() {
994 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 876 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
995 options.incremental = true; 877 options.incremental = true;
996 _context = new AnalysisContextForTests(); 878 context.analysisOptions = options;
997 _context.analysisOptions = options;
998 SourcesChangedListener listener = new SourcesChangedListener(); 879 SourcesChangedListener listener = new SourcesChangedListener();
999 _context.onSourcesChanged.listen(listener.onData); 880 context.onSourcesChanged.listen(listener.onData);
1000 _sourceFactory = _context.sourceFactory;
1001 String oldCode = r''' 881 String oldCode = r'''
1002 library lib; 882 library lib;
1003 part 'part.dart'; 883 part 'part.dart';
1004 int a = 0;'''; 884 int a = 0;''';
1005 Source librarySource = _addSource("/lib.dart", oldCode); 885 Source librarySource = addSource("/lib.dart", oldCode);
1006 String partContents = r''' 886 String partContents = r'''
1007 part of lib; 887 part of lib;
1008 int b = a;'''; 888 int b = a;''';
1009 Source partSource = _addSource("/part.dart", partContents); 889 Source partSource = addSource("/part.dart", partContents);
1010 LibraryElement element = _context.computeLibraryElement(librarySource); 890 LibraryElement element = context.computeLibraryElement(librarySource);
1011 CompilationUnit unit = 891 CompilationUnit unit =
1012 _context.getResolvedCompilationUnit(librarySource, element); 892 context.getResolvedCompilationUnit(librarySource, element);
1013 expect(unit, isNotNull); 893 expect(unit, isNotNull);
1014 int offset = oldCode.indexOf("int a") + 4; 894 int offset = oldCode.indexOf("int a") + 4;
1015 String newCode = r''' 895 String newCode = r'''
1016 library lib; 896 library lib;
1017 part 'part.dart'; 897 part 'part.dart';
1018 int ya = 0;'''; 898 int ya = 0;''';
1019 expect(_getIncrementalAnalysisCache(_context), isNull); 899 expect(_getIncrementalAnalysisCache(context), isNull);
1020 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 900 context.setChangedContents(librarySource, newCode, offset, 0, 1);
1021 expect(_context.getContents(librarySource).data, newCode); 901 expect(context.getContents(librarySource).data, newCode);
1022 IncrementalAnalysisCache incrementalCache = 902 IncrementalAnalysisCache incrementalCache =
1023 _getIncrementalAnalysisCache(_context); 903 _getIncrementalAnalysisCache(context);
1024 expect(incrementalCache.librarySource, librarySource); 904 expect(incrementalCache.librarySource, librarySource);
1025 expect(incrementalCache.resolvedUnit, same(unit)); 905 expect(incrementalCache.resolvedUnit, same(unit));
1026 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), 906 expect(
1027 isNull); 907 context.getResolvedCompilationUnit2(partSource, librarySource), isNull);
1028 expect(incrementalCache.newContents, newCode); 908 expect(incrementalCache.newContents, newCode);
1029 return pumpEventQueue().then((_) { 909 return pumpEventQueue().then((_) {
1030 listener.assertEvent(wereSourcesAdded: true); 910 listener.assertEvent(wereSourcesAdded: true);
1031 listener.assertEvent(changedSources: [librarySource]); 911 listener.assertEvent(changedSources: [librarySource]);
1032 listener.assertEvent(wereSourcesAdded: true); 912 listener.assertEvent(wereSourcesAdded: true);
1033 listener.assertEvent(changedSources: [partSource]); 913 listener.assertEvent(changedSources: [partSource]);
1034 listener.assertEvent(changedSources: [librarySource]); 914 listener.assertEvent(changedSources: [librarySource]);
1035 listener.assertNoMoreEvents(); 915 listener.assertNoMoreEvents();
1036 }); 916 });
1037 } 917 }
1038 918
1039 void fail_setContents_unchanged_consistentModificationTime() { 919 void test_setContents_unchanged_consistentModificationTime() {
1040 String contents = "// foo"; 920 String contents = "// foo";
1041 Source source = _addSource("/test.dart", contents); 921 Source source = addSource("/test.dart", contents);
1042 // do all, no tasks 922 // do all, no tasks
1043 _analyzeAll_assertFinished(); 923 _analyzeAll_assertFinished();
1044 { 924 {
1045 AnalysisResult result = _context.performAnalysisTask(); 925 AnalysisResult result = context.performAnalysisTask();
1046 expect(result.changeNotices, isNull); 926 expect(result.changeNotices, isNull);
1047 } 927 }
1048 // set the same contents, still no tasks 928 // set the same contents, still no tasks
1049 _context.setContents(source, contents); 929 context.setContents(source, contents);
1050 { 930 {
1051 AnalysisResult result = _context.performAnalysisTask(); 931 AnalysisResult result = context.performAnalysisTask();
1052 expect(result.changeNotices, isNull); 932 expect(result.changeNotices, isNull);
1053 } 933 }
1054 } 934 }
1055 935
1056 void fail_unreadableSource() { 936 void fail_unreadableSource() {
1057 _context = contextWithCore(); 937 Source test1 = addSource("/test1.dart", r'''
1058 _sourceFactory = _context.sourceFactory;
1059 Source test1 = _addSource("/test1.dart", r'''
1060 import 'test2.dart'; 938 import 'test2.dart';
1061 library test1;'''); 939 library test1;''');
1062 Source test2 = _addSource("/test2.dart", r''' 940 Source test2 = addSource("/test2.dart", r'''
1063 import 'test1.dart'; 941 import 'test1.dart';
1064 import 'test3.dart'; 942 import 'test3.dart';
1065 library test2;'''); 943 library test2;''');
1066 Source test3 = _addSourceWithException("/test3.dart"); 944 Source test3 = _addSourceWithException("/test3.dart");
1067 _analyzeAll_assertFinished(); 945 _analyzeAll_assertFinished();
1068 // test1 and test2 should have been successfully analyzed 946 // test1 and test2 should have been successfully analyzed
1069 // despite the fact that test3 couldn't be read. 947 // despite the fact that test3 couldn't be read.
1070 expect(_context.computeLibraryElement(test1), isNotNull); 948 expect(context.computeLibraryElement(test1), isNotNull);
1071 expect(_context.computeLibraryElement(test2), isNotNull); 949 expect(context.computeLibraryElement(test2), isNotNull);
1072 expect(_context.computeLibraryElement(test3), isNull); 950 expect(context.computeLibraryElement(test3), isNull);
1073 }
1074
1075 @override
1076 void setUp() {
1077 EnginePlugin enginePlugin = AnalysisEngine.instance.enginePlugin;
1078 if (enginePlugin.taskExtensionPoint == null) {
1079 ExtensionManager manager = new ExtensionManager();
1080 manager.processPlugins([enginePlugin]);
1081 }
1082
1083 _context = new AnalysisContextImpl();
1084 _sourceFactory = new SourceFactory([
1085 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk),
1086 new FileUriResolver()
1087 ]);
1088 _context.sourceFactory = _sourceFactory;
1089 AnalysisOptionsImpl options =
1090 new AnalysisOptionsImpl.con1(_context.analysisOptions);
1091 options.cacheSize = 256;
1092 _context.analysisOptions = options;
1093 }
1094
1095 void test_applyChanges_change_flush_element() {
1096 _context = contextWithCore();
1097 _sourceFactory = _context.sourceFactory;
1098 Source librarySource = _addSource("/lib.dart", r'''
1099 library lib;
1100 int a = 0;''');
1101 expect(_context.computeLibraryElement(librarySource), isNotNull);
1102 _context.setContents(librarySource, r'''
1103 library lib;
1104 int aa = 0;''');
1105 expect(_context.getLibraryElement(librarySource), isNull);
1106 } 951 }
1107 952
1108 @override 953 @override
1109 void tearDown() { 954 void tearDown() {
1110 _context = null; 955 context = null;
1111 _sourceFactory = null; 956 sourceFactory = null;
1112 super.tearDown(); 957 super.tearDown();
1113 } 958 }
1114 959
1115 Future test_applyChanges_add() { 960 Future test_applyChanges_add() {
1116 SourcesChangedListener listener = new SourcesChangedListener(); 961 SourcesChangedListener listener = new SourcesChangedListener();
1117 _context.onSourcesChanged.listen(listener.onData); 962 context.onSourcesChanged.listen(listener.onData);
1118 expect(_context.sourcesNeedingProcessing, isEmpty); 963 expect(context.sourcesNeedingProcessing, isEmpty);
1119 Source source = 964 Source source = newSource('/test.dart');
1120 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
1121 ChangeSet changeSet = new ChangeSet(); 965 ChangeSet changeSet = new ChangeSet();
1122 changeSet.addedSource(source); 966 changeSet.addedSource(source);
1123 _context.applyChanges(changeSet); 967 context.applyChanges(changeSet);
1124 expect(_context.sourcesNeedingProcessing, contains(source)); 968 expect(context.sourcesNeedingProcessing, contains(source));
1125 return pumpEventQueue().then((_) { 969 return pumpEventQueue().then((_) {
1126 listener.assertEvent(wereSourcesAdded: true); 970 listener.assertEvent(wereSourcesAdded: true);
1127 listener.assertNoMoreEvents(); 971 listener.assertNoMoreEvents();
1128 }); 972 });
1129 } 973 }
1130 974
1131 Future test_applyChanges_change() { 975 Future test_applyChanges_change() {
1132 SourcesChangedListener listener = new SourcesChangedListener(); 976 SourcesChangedListener listener = new SourcesChangedListener();
1133 _context.onSourcesChanged.listen(listener.onData); 977 context.onSourcesChanged.listen(listener.onData);
1134 expect(_context.sourcesNeedingProcessing, isEmpty); 978 expect(context.sourcesNeedingProcessing, isEmpty);
1135 Source source = 979 Source source = newSource('/test.dart');
1136 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
1137 ChangeSet changeSet1 = new ChangeSet(); 980 ChangeSet changeSet1 = new ChangeSet();
1138 changeSet1.addedSource(source); 981 changeSet1.addedSource(source);
1139 _context.applyChanges(changeSet1); 982 context.applyChanges(changeSet1);
1140 expect(_context.sourcesNeedingProcessing, contains(source)); 983 expect(context.sourcesNeedingProcessing, contains(source));
1141 Source source2 = 984 Source source2 = newSource('/test2.dart');
1142 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
1143 ChangeSet changeSet2 = new ChangeSet(); 985 ChangeSet changeSet2 = new ChangeSet();
1144 changeSet2.addedSource(source2); 986 changeSet2.addedSource(source2);
1145 changeSet2.changedSource(source); 987 changeSet2.changedSource(source);
1146 _context.applyChanges(changeSet2); 988 context.applyChanges(changeSet2);
1147 return pumpEventQueue().then((_) { 989 return pumpEventQueue().then((_) {
1148 listener.assertEvent(wereSourcesAdded: true); 990 listener.assertEvent(wereSourcesAdded: true);
1149 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); 991 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
1150 listener.assertNoMoreEvents(); 992 listener.assertNoMoreEvents();
1151 }); 993 });
1152 } 994 }
1153 995
1154 Future test_applyChanges_change_content() { 996 Future test_applyChanges_change_content() {
1155 SourcesChangedListener listener = new SourcesChangedListener(); 997 SourcesChangedListener listener = new SourcesChangedListener();
1156 _context.onSourcesChanged.listen(listener.onData); 998 context.onSourcesChanged.listen(listener.onData);
1157 expect(_context.sourcesNeedingProcessing, isEmpty); 999 expect(context.sourcesNeedingProcessing, isEmpty);
1158 Source source = 1000 Source source = newSource('/test.dart');
1159 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
1160 ChangeSet changeSet1 = new ChangeSet(); 1001 ChangeSet changeSet1 = new ChangeSet();
1161 changeSet1.addedSource(source); 1002 changeSet1.addedSource(source);
1162 _context.applyChanges(changeSet1); 1003 context.applyChanges(changeSet1);
1163 expect(_context.sourcesNeedingProcessing, contains(source)); 1004 expect(context.sourcesNeedingProcessing, contains(source));
1164 Source source2 = 1005 Source source2 = newSource('/test2.dart');
1165 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
1166 ChangeSet changeSet2 = new ChangeSet(); 1006 ChangeSet changeSet2 = new ChangeSet();
1167 changeSet2.addedSource(source2); 1007 changeSet2.addedSource(source2);
1168 changeSet2.changedContent(source, 'library test;'); 1008 changeSet2.changedContent(source, 'library test;');
1169 _context.applyChanges(changeSet2); 1009 context.applyChanges(changeSet2);
1170 return pumpEventQueue().then((_) { 1010 return pumpEventQueue().then((_) {
1171 listener.assertEvent(wereSourcesAdded: true); 1011 listener.assertEvent(wereSourcesAdded: true);
1172 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); 1012 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
1173 listener.assertNoMoreEvents(); 1013 listener.assertNoMoreEvents();
1174 }); 1014 });
1175 } 1015 }
1176 1016
1017 void test_applyChanges_change_flush_element() {
1018 Source librarySource = addSource("/lib.dart", r'''
1019 library lib;
1020 int a = 0;''');
1021 expect(context.computeLibraryElement(librarySource), isNotNull);
1022 context.setContents(librarySource, r'''
1023 library lib;
1024 int aa = 0;''');
1025 expect(context.getLibraryElement(librarySource), isNull);
1026 }
1027
1177 Future test_applyChanges_change_multiple() { 1028 Future test_applyChanges_change_multiple() {
1178 _context = contextWithCore();
1179 SourcesChangedListener listener = new SourcesChangedListener(); 1029 SourcesChangedListener listener = new SourcesChangedListener();
1180 _context.onSourcesChanged.listen(listener.onData); 1030 context.onSourcesChanged.listen(listener.onData);
1181 _sourceFactory = _context.sourceFactory;
1182 String libraryContents1 = r''' 1031 String libraryContents1 = r'''
1183 library lib; 1032 library lib;
1184 part 'part.dart'; 1033 part 'part.dart';
1185 int a = 0;'''; 1034 int a = 0;''';
1186 Source librarySource = _addSource("/lib.dart", libraryContents1); 1035 Source librarySource = addSource("/lib.dart", libraryContents1);
1187 String partContents1 = r''' 1036 String partContents1 = r'''
1188 part of lib; 1037 part of lib;
1189 int b = a;'''; 1038 int b = a;''';
1190 Source partSource = _addSource("/part.dart", partContents1); 1039 Source partSource = addSource("/part.dart", partContents1);
1191 _context.computeLibraryElement(librarySource); 1040 context.computeLibraryElement(librarySource);
1192 String libraryContents2 = r''' 1041 String libraryContents2 = r'''
1193 library lib; 1042 library lib;
1194 part 'part.dart'; 1043 part 'part.dart';
1195 int aa = 0;'''; 1044 int aa = 0;''';
1196 _context.setContents(librarySource, libraryContents2); 1045 context.setContents(librarySource, libraryContents2);
1197 String partContents2 = r''' 1046 String partContents2 = r'''
1198 part of lib; 1047 part of lib;
1199 int b = aa;'''; 1048 int b = aa;''';
1200 _context.setContents(partSource, partContents2); 1049 context.setContents(partSource, partContents2);
1201 _context.computeLibraryElement(librarySource); 1050 context.computeLibraryElement(librarySource);
1202 CompilationUnit libraryUnit = 1051 CompilationUnit libraryUnit =
1203 _context.resolveCompilationUnit2(librarySource, librarySource); 1052 context.resolveCompilationUnit2(librarySource, librarySource);
1204 expect(libraryUnit, isNotNull); 1053 expect(libraryUnit, isNotNull);
1205 CompilationUnit partUnit = 1054 CompilationUnit partUnit =
1206 _context.resolveCompilationUnit2(partSource, librarySource); 1055 context.resolveCompilationUnit2(partSource, librarySource);
1207 expect(partUnit, isNotNull); 1056 expect(partUnit, isNotNull);
1208 TopLevelVariableDeclaration declaration = 1057 TopLevelVariableDeclaration declaration =
1209 libraryUnit.declarations[0] as TopLevelVariableDeclaration; 1058 libraryUnit.declarations[0] as TopLevelVariableDeclaration;
1210 Element declarationElement = declaration.variables.variables[0].element; 1059 Element declarationElement = declaration.variables.variables[0].element;
1211 TopLevelVariableDeclaration use = 1060 TopLevelVariableDeclaration use =
1212 partUnit.declarations[0] as TopLevelVariableDeclaration; 1061 partUnit.declarations[0] as TopLevelVariableDeclaration;
1213 Element useElement = (use.variables.variables[ 1062 Element useElement = (use.variables.variables[
1214 0].initializer as SimpleIdentifier).staticElement; 1063 0].initializer as SimpleIdentifier).staticElement;
1215 expect((useElement as PropertyAccessorElement).variable, 1064 expect((useElement as PropertyAccessorElement).variable,
1216 same(declarationElement)); 1065 same(declarationElement));
1217 return pumpEventQueue().then((_) { 1066 return pumpEventQueue().then((_) {
1218 listener.assertEvent(wereSourcesAdded: true); 1067 listener.assertEvent(wereSourcesAdded: true);
1219 listener.assertEvent(changedSources: [librarySource]); 1068 listener.assertEvent(changedSources: [librarySource]);
1220 listener.assertEvent(wereSourcesAdded: true); 1069 listener.assertEvent(wereSourcesAdded: true);
1221 listener.assertEvent(changedSources: [partSource]); 1070 listener.assertEvent(changedSources: [partSource]);
1222 listener.assertEvent(changedSources: [librarySource]); 1071 listener.assertEvent(changedSources: [librarySource]);
1223 listener.assertEvent(changedSources: [partSource]); 1072 listener.assertEvent(changedSources: [partSource]);
1224 listener.assertNoMoreEvents(); 1073 listener.assertNoMoreEvents();
1225 }); 1074 });
1226 } 1075 }
1227 1076
1228 Future test_applyChanges_change_range() { 1077 Future test_applyChanges_change_range() {
1229 SourcesChangedListener listener = new SourcesChangedListener(); 1078 SourcesChangedListener listener = new SourcesChangedListener();
1230 _context.onSourcesChanged.listen(listener.onData); 1079 context.onSourcesChanged.listen(listener.onData);
1231 expect(_context.sourcesNeedingProcessing, isEmpty); 1080 expect(context.sourcesNeedingProcessing, isEmpty);
1232 Source source = 1081 Source source = newSource('/test.dart');
1233 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
1234 ChangeSet changeSet1 = new ChangeSet(); 1082 ChangeSet changeSet1 = new ChangeSet();
1235 changeSet1.addedSource(source); 1083 changeSet1.addedSource(source);
1236 _context.applyChanges(changeSet1); 1084 context.applyChanges(changeSet1);
1237 expect(_context.sourcesNeedingProcessing, contains(source)); 1085 expect(context.sourcesNeedingProcessing, contains(source));
1238 Source source2 = 1086 Source source2 = newSource('/test2.dart');
1239 new FileBasedSource.con1(FileUtilities2.createFile("/test2.dart"));
1240 ChangeSet changeSet2 = new ChangeSet(); 1087 ChangeSet changeSet2 = new ChangeSet();
1241 changeSet2.addedSource(source2); 1088 changeSet2.addedSource(source2);
1242 changeSet2.changedRange(source, 'library test;', 0, 0, 13); 1089 changeSet2.changedRange(source, 'library test;', 0, 0, 13);
1243 _context.applyChanges(changeSet2); 1090 context.applyChanges(changeSet2);
1244 return pumpEventQueue().then((_) { 1091 return pumpEventQueue().then((_) {
1245 listener.assertEvent(wereSourcesAdded: true); 1092 listener.assertEvent(wereSourcesAdded: true);
1246 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); 1093 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]);
1247 listener.assertNoMoreEvents(); 1094 listener.assertNoMoreEvents();
1248 }); 1095 });
1249 } 1096 }
1250 1097
1251 void test_computeDocumentationComment_block() { 1098 void test_computeDocumentationComment_block() {
1252 _context = contextWithCore();
1253 _sourceFactory = _context.sourceFactory;
1254 String comment = "/** Comment */"; 1099 String comment = "/** Comment */";
1255 Source source = _addSource("/test.dart", """ 1100 Source source = addSource("/test.dart", """
1256 $comment 1101 $comment
1257 class A {}"""); 1102 class A {}""");
1258 LibraryElement libraryElement = _context.computeLibraryElement(source); 1103 LibraryElement libraryElement = context.computeLibraryElement(source);
1259 expect(libraryElement, isNotNull); 1104 expect(libraryElement, isNotNull);
1260 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 1105 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
1261 expect(libraryElement, isNotNull); 1106 expect(libraryElement, isNotNull);
1262 expect(_context.computeDocumentationComment(classElement), comment); 1107 expect(context.computeDocumentationComment(classElement), comment);
1263 } 1108 }
1264 1109
1265 void test_computeDocumentationComment_none() { 1110 void test_computeDocumentationComment_none() {
1266 _context = contextWithCore(); 1111 Source source = addSource("/test.dart", "class A {}");
1267 _sourceFactory = _context.sourceFactory; 1112 LibraryElement libraryElement = context.computeLibraryElement(source);
1268 Source source = _addSource("/test.dart", "class A {}");
1269 LibraryElement libraryElement = _context.computeLibraryElement(source);
1270 expect(libraryElement, isNotNull); 1113 expect(libraryElement, isNotNull);
1271 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 1114 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
1272 expect(libraryElement, isNotNull); 1115 expect(libraryElement, isNotNull);
1273 expect(_context.computeDocumentationComment(classElement), isNull); 1116 expect(context.computeDocumentationComment(classElement), isNull);
1274 } 1117 }
1275 1118
1276 void test_computeDocumentationComment_null() { 1119 void test_computeDocumentationComment_null() {
1277 expect(_context.computeDocumentationComment(null), isNull); 1120 expect(context.computeDocumentationComment(null), isNull);
1278 } 1121 }
1279 1122
1280 void test_computeDocumentationComment_singleLine_multiple_EOL_n() { 1123 void test_computeDocumentationComment_singleLine_multiple_EOL_n() {
1281 _context = contextWithCore();
1282 _sourceFactory = _context.sourceFactory;
1283 String comment = "/// line 1\n/// line 2\n/// line 3\n"; 1124 String comment = "/// line 1\n/// line 2\n/// line 3\n";
1284 Source source = _addSource("/test.dart", "${comment}class A {}"); 1125 Source source = addSource("/test.dart", "${comment}class A {}");
1285 LibraryElement libraryElement = _context.computeLibraryElement(source); 1126 LibraryElement libraryElement = context.computeLibraryElement(source);
1286 expect(libraryElement, isNotNull); 1127 expect(libraryElement, isNotNull);
1287 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 1128 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
1288 expect(libraryElement, isNotNull); 1129 expect(libraryElement, isNotNull);
1289 String actual = _context.computeDocumentationComment(classElement); 1130 String actual = context.computeDocumentationComment(classElement);
1290 expect(actual, "/// line 1\n/// line 2\n/// line 3"); 1131 expect(actual, "/// line 1\n/// line 2\n/// line 3");
1291 } 1132 }
1292 1133
1293 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() { 1134 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() {
1294 _context = contextWithCore();
1295 _sourceFactory = _context.sourceFactory;
1296 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; 1135 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n";
1297 Source source = _addSource("/test.dart", "${comment}class A {}"); 1136 Source source = addSource("/test.dart", "${comment}class A {}");
1298 LibraryElement libraryElement = _context.computeLibraryElement(source); 1137 LibraryElement libraryElement = context.computeLibraryElement(source);
1299 expect(libraryElement, isNotNull); 1138 expect(libraryElement, isNotNull);
1300 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; 1139 ClassElement classElement = libraryElement.definingCompilationUnit.types[0];
1301 expect(libraryElement, isNotNull); 1140 expect(libraryElement, isNotNull);
1302 String actual = _context.computeDocumentationComment(classElement); 1141 String actual = context.computeDocumentationComment(classElement);
1303 expect(actual, "/// line 1\n/// line 2\n/// line 3"); 1142 expect(actual, "/// line 1\n/// line 2\n/// line 3");
1304 } 1143 }
1305 1144
1306 void test_computeExportedLibraries_none() { 1145 void test_computeExportedLibraries_none() {
1307 Source source = _addSource("/test.dart", "library test;"); 1146 Source source = addSource("/test.dart", "library test;");
1308 expect(_context.computeExportedLibraries(source), hasLength(0)); 1147 expect(context.computeExportedLibraries(source), hasLength(0));
1309 } 1148 }
1310 1149
1311 void test_computeExportedLibraries_some() { 1150 void test_computeExportedLibraries_some() {
1312 // addSource("/lib1.dart", "library lib1;"); 1151 // addSource("/lib1.dart", "library lib1;");
1313 // addSource("/lib2.dart", "library lib2;"); 1152 // addSource("/lib2.dart", "library lib2;");
1314 Source source = _addSource( 1153 Source source = addSource(
1315 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); 1154 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';");
1316 expect(_context.computeExportedLibraries(source), hasLength(2)); 1155 expect(context.computeExportedLibraries(source), hasLength(2));
1317 } 1156 }
1318 1157
1319 void test_computeHtmlElement_nonHtml() { 1158 void test_computeHtmlElement_nonHtml() {
1320 Source source = _addSource("/test.dart", "library test;"); 1159 Source source = addSource("/test.dart", "library test;");
1321 expect(_context.computeHtmlElement(source), isNull); 1160 expect(context.computeHtmlElement(source), isNull);
1322 } 1161 }
1323 1162
1324 void test_computeKindOf_html() { 1163 void test_computeKindOf_html() {
1325 Source source = _addSource("/test.html", ""); 1164 Source source = addSource("/test.html", "");
1326 expect(_context.computeKindOf(source), same(SourceKind.HTML)); 1165 expect(context.computeKindOf(source), same(SourceKind.HTML));
1327 } 1166 }
1328 1167
1329 void test_computeKindOf_library() { 1168 void test_computeKindOf_library() {
1330 Source source = _addSource("/test.dart", "library lib;"); 1169 Source source = addSource("/test.dart", "library lib;");
1331 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); 1170 expect(context.computeKindOf(source), same(SourceKind.LIBRARY));
1332 } 1171 }
1333 1172
1334 void test_computeKindOf_libraryAndPart() { 1173 void test_computeKindOf_libraryAndPart() {
1335 Source source = _addSource("/test.dart", "library lib; part of lib;"); 1174 Source source = addSource("/test.dart", "library lib; part of lib;");
1336 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); 1175 expect(context.computeKindOf(source), same(SourceKind.LIBRARY));
1337 } 1176 }
1338 1177
1339 void test_computeKindOf_part() { 1178 void test_computeKindOf_part() {
1340 Source source = _addSource("/test.dart", "part of lib;"); 1179 Source source = addSource("/test.dart", "part of lib;");
1341 expect(_context.computeKindOf(source), same(SourceKind.PART)); 1180 expect(context.computeKindOf(source), same(SourceKind.PART));
1342 } 1181 }
1343 1182
1344 void test_computeLibraryElement() { 1183 void test_computeLibraryElement() {
1345 _context = contextWithCore(); 1184 Source source = addSource("/test.dart", "library lib;");
1346 _sourceFactory = _context.sourceFactory; 1185 LibraryElement element = context.computeLibraryElement(source);
1347 Source source = _addSource("/test.dart", "library lib;");
1348 LibraryElement element = _context.computeLibraryElement(source);
1349 expect(element, isNotNull); 1186 expect(element, isNotNull);
1350 } 1187 }
1351 1188
1352 void test_computeLineInfo_dart() { 1189 void test_computeLineInfo_dart() {
1353 Source source = _addSource("/test.dart", r''' 1190 Source source = addSource("/test.dart", r'''
1354 library lib; 1191 library lib;
1355 1192
1356 main() {}'''); 1193 main() {}''');
1357 LineInfo info = _context.computeLineInfo(source); 1194 LineInfo info = context.computeLineInfo(source);
1358 expect(info, isNotNull); 1195 expect(info, isNotNull);
1359 } 1196 }
1360 1197
1361 void test_computeLineInfo_html() { 1198 void test_computeLineInfo_html() {
1362 Source source = _addSource("/test.html", r''' 1199 Source source = addSource("/test.html", r'''
1363 <html> 1200 <html>
1364 <body> 1201 <body>
1365 <h1>A</h1> 1202 <h1>A</h1>
1366 </body> 1203 </body>
1367 </html>'''); 1204 </html>''');
1368 LineInfo info = _context.computeLineInfo(source); 1205 LineInfo info = context.computeLineInfo(source);
1369 expect(info, isNotNull); 1206 expect(info, isNotNull);
1370 } 1207 }
1371 1208
1372 Future test_computeResolvedCompilationUnitAsync_afterDispose() { 1209 Future test_computeResolvedCompilationUnitAsync_afterDispose() {
1373 _context = contextWithCore(); 1210 Source source = addSource("/lib.dart", "library lib;");
1374 _sourceFactory = _context.sourceFactory;
1375 Source source = _addSource("/lib.dart", "library lib;");
1376 // Complete all pending analysis tasks and flush the AST so that it won't 1211 // Complete all pending analysis tasks and flush the AST so that it won't
1377 // be available immediately. 1212 // be available immediately.
1378 _performPendingAnalysisTasks(); 1213 _performPendingAnalysisTasks();
1379 _flushAst(source); 1214 _flushAst(source);
1380 // Dispose of the context. 1215 // Dispose of the context.
1381 _context.dispose(); 1216 context.dispose();
1382 // Any attempt to start an asynchronous computation should return a future 1217 // Any attempt to start an asynchronous computation should return a future
1383 // which completes with error. 1218 // which completes with error.
1384 CancelableFuture<CompilationUnit> future = 1219 CancelableFuture<CompilationUnit> future =
1385 _context.computeResolvedCompilationUnitAsync(source, source); 1220 context.computeResolvedCompilationUnitAsync(source, source);
1386 bool completed = false; 1221 bool completed = false;
1387 future.then((CompilationUnit unit) { 1222 future.then((CompilationUnit unit) {
1388 fail('Future should have completed with error'); 1223 fail('Future should have completed with error');
1389 }, onError: (error) { 1224 }, onError: (error) {
1390 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); 1225 expect(error, new isInstanceOf<AnalysisNotScheduledError>());
1391 completed = true; 1226 completed = true;
1392 }); 1227 });
1393 return pumpEventQueue().then((_) { 1228 return pumpEventQueue().then((_) {
1394 expect(completed, isTrue); 1229 expect(completed, isTrue);
1395 }); 1230 });
1396 } 1231 }
1397 1232
1398 void test_dispose() { 1233 void test_dispose() {
1399 expect(_context.isDisposed, isFalse); 1234 expect(context.isDisposed, isFalse);
1400 _context.dispose(); 1235 context.dispose();
1401 expect(_context.isDisposed, isTrue); 1236 expect(context.isDisposed, isTrue);
1402 } 1237 }
1403 1238
1404 void test_exists_false() { 1239 void test_exists_false() {
1405 TestSource source = new TestSource(); 1240 TestSource source = new TestSource();
1406 source.exists2 = false; 1241 source.exists2 = false;
1407 expect(_context.exists(source), isFalse); 1242 expect(context.exists(source), isFalse);
1408 } 1243 }
1409 1244
1410 void test_exists_null() { 1245 void test_exists_null() {
1411 expect(_context.exists(null), isFalse); 1246 expect(context.exists(null), isFalse);
1412 } 1247 }
1413 1248
1414 void test_exists_overridden() { 1249 void test_exists_overridden() {
1415 Source source = new TestSource(); 1250 Source source = new TestSource();
1416 _context.setContents(source, ""); 1251 context.setContents(source, "");
1417 expect(_context.exists(source), isTrue); 1252 expect(context.exists(source), isTrue);
1418 } 1253 }
1419 1254
1420 void test_exists_true() { 1255 void test_exists_true() {
1421 expect(_context.exists(new AnalysisContextImplTest_Source_exists_true()), 1256 expect(context.exists(new AnalysisContextImplTest_Source_exists_true()),
1422 isTrue); 1257 isTrue);
1423 } 1258 }
1424 1259
1425 void test_getAnalysisOptions() { 1260 void test_getAnalysisOptions() {
1426 expect(_context.analysisOptions, isNotNull); 1261 expect(context.analysisOptions, isNotNull);
1427 } 1262 }
1428 1263
1429 void test_getContents_fromSource() { 1264 void test_getContents_fromSource() {
1430 String content = "library lib;"; 1265 String content = "library lib;";
1431 TimestampedData<String> contents = 1266 TimestampedData<String> contents =
1432 _context.getContents(new TestSource('/test.dart', content)); 1267 context.getContents(new TestSource('/test.dart', content));
1433 expect(contents.data.toString(), content); 1268 expect(contents.data.toString(), content);
1434 } 1269 }
1435 1270
1436 void test_getContents_overridden() { 1271 void test_getContents_overridden() {
1437 String content = "library lib;"; 1272 String content = "library lib;";
1438 Source source = new TestSource(); 1273 Source source = new TestSource();
1439 _context.setContents(source, content); 1274 context.setContents(source, content);
1440 TimestampedData<String> contents = _context.getContents(source); 1275 TimestampedData<String> contents = context.getContents(source);
1441 expect(contents.data.toString(), content); 1276 expect(contents.data.toString(), content);
1442 } 1277 }
1443 1278
1444 void test_getContents_unoverridden() { 1279 void test_getContents_unoverridden() {
1445 String content = "library lib;"; 1280 String content = "library lib;";
1446 Source source = new TestSource('/test.dart', content); 1281 Source source = new TestSource('/test.dart', content);
1447 _context.setContents(source, "part of lib;"); 1282 context.setContents(source, "part of lib;");
1448 _context.setContents(source, null); 1283 context.setContents(source, null);
1449 TimestampedData<String> contents = _context.getContents(source); 1284 TimestampedData<String> contents = context.getContents(source);
1450 expect(contents.data.toString(), content); 1285 expect(contents.data.toString(), content);
1451 } 1286 }
1452 1287
1453 void test_getDeclaredVariables() { 1288 void test_getDeclaredVariables() {
1454 _context = contextWithCore(); 1289 expect(context.declaredVariables, isNotNull);
1455 expect(_context.declaredVariables, isNotNull);
1456 } 1290 }
1457 1291
1458 void test_getElement() { 1292 void test_getElement() {
1459 _context = contextWithCore();
1460 _sourceFactory = _context.sourceFactory;
1461 LibraryElement core = 1293 LibraryElement core =
1462 _context.computeLibraryElement(_sourceFactory.forUri("dart:core")); 1294 context.computeLibraryElement(sourceFactory.forUri("dart:core"));
1463 expect(core, isNotNull); 1295 expect(core, isNotNull);
1464 ClassElement classObject = 1296 ClassElement classObject =
1465 _findClass(core.definingCompilationUnit, "Object"); 1297 _findClass(core.definingCompilationUnit, "Object");
1466 expect(classObject, isNotNull); 1298 expect(classObject, isNotNull);
1467 ElementLocation location = classObject.location; 1299 ElementLocation location = classObject.location;
1468 Element element = _context.getElement(location); 1300 Element element = context.getElement(location);
1469 expect(element, same(classObject)); 1301 expect(element, same(classObject));
1470 } 1302 }
1471 1303
1472 void test_getHtmlElement_dart() { 1304 void test_getHtmlElement_dart() {
1473 Source source = _addSource("/test.dart", ""); 1305 Source source = addSource("/test.dart", "");
1474 expect(_context.getHtmlElement(source), isNull); 1306 expect(context.getHtmlElement(source), isNull);
1475 expect(_context.computeHtmlElement(source), isNull); 1307 expect(context.computeHtmlElement(source), isNull);
1476 expect(_context.getHtmlElement(source), isNull); 1308 expect(context.getHtmlElement(source), isNull);
1477 } 1309 }
1478 1310
1479 void test_getHtmlFilesReferencing_html() { 1311 void test_getHtmlFilesReferencing_html() {
1480 _context = contextWithCore(); 1312 Source htmlSource = addSource("/test.html", r'''
1481 _sourceFactory = _context.sourceFactory;
1482 Source htmlSource = _addSource("/test.html", r'''
1483 <html><head> 1313 <html><head>
1484 <script type='application/dart' src='test.dart'/> 1314 <script type='application/dart' src='test.dart'/>
1485 <script type='application/dart' src='test.js'/> 1315 <script type='application/dart' src='test.js'/>
1486 </head></html>'''); 1316 </head></html>''');
1487 Source librarySource = _addSource("/test.dart", "library lib;"); 1317 Source librarySource = addSource("/test.dart", "library lib;");
1488 Source secondHtmlSource = _addSource("/test.html", "<html></html>"); 1318 Source secondHtmlSource = addSource("/test.html", "<html></html>");
1489 _context.computeLibraryElement(librarySource); 1319 context.computeLibraryElement(librarySource);
1490 List<Source> result = _context.getHtmlFilesReferencing(secondHtmlSource); 1320 List<Source> result = context.getHtmlFilesReferencing(secondHtmlSource);
1491 expect(result, hasLength(0)); 1321 expect(result, hasLength(0));
1492 _context.parseHtmlUnit(htmlSource); 1322 context.parseHtmlUnit(htmlSource);
1493 result = _context.getHtmlFilesReferencing(secondHtmlSource); 1323 result = context.getHtmlFilesReferencing(secondHtmlSource);
1494 expect(result, hasLength(0)); 1324 expect(result, hasLength(0));
1495 } 1325 }
1496 1326
1497 void test_getKindOf_html() { 1327 void test_getKindOf_html() {
1498 Source source = _addSource("/test.html", ""); 1328 Source source = addSource("/test.html", "");
1499 expect(_context.getKindOf(source), same(SourceKind.HTML)); 1329 expect(context.getKindOf(source), same(SourceKind.HTML));
1500 } 1330 }
1501 1331
1502 void test_getKindOf_library() { 1332 void test_getKindOf_library() {
1503 Source source = _addSource("/test.dart", "library lib;"); 1333 Source source = addSource("/test.dart", "library lib;");
1504 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); 1334 expect(context.getKindOf(source), same(SourceKind.UNKNOWN));
1505 _context.computeKindOf(source); 1335 context.computeKindOf(source);
1506 expect(_context.getKindOf(source), same(SourceKind.LIBRARY)); 1336 expect(context.getKindOf(source), same(SourceKind.LIBRARY));
1507 } 1337 }
1508 1338
1509 void test_getKindOf_part() { 1339 void test_getKindOf_part() {
1510 Source source = _addSource("/test.dart", "part of lib;"); 1340 Source source = addSource("/test.dart", "part of lib;");
1511 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); 1341 expect(context.getKindOf(source), same(SourceKind.UNKNOWN));
1512 _context.computeKindOf(source); 1342 context.computeKindOf(source);
1513 expect(_context.getKindOf(source), same(SourceKind.PART)); 1343 expect(context.getKindOf(source), same(SourceKind.PART));
1514 } 1344 }
1515 1345
1516 void test_getKindOf_unknown() { 1346 void test_getKindOf_unknown() {
1517 Source source = _addSource("/test.css", ""); 1347 Source source = addSource("/test.css", "");
1518 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); 1348 expect(context.getKindOf(source), same(SourceKind.UNKNOWN));
1519 } 1349 }
1520 1350
1521 void test_getLaunchableClientLibrarySources_doesNotImportHtml() { 1351 void test_getLaunchableClientLibrarySources_doesNotImportHtml() {
1522 _context = contextWithCore(); 1352 Source source = addSource("/test.dart", r'''
1523 _sourceFactory = _context.sourceFactory; 1353 main() {}''');
1524 Source source = _addSource("/test.dart", r''' 1354 context.computeLibraryElement(source);
1525 main() {}'''); 1355 List<Source> sources = context.launchableClientLibrarySources;
1526 _context.computeLibraryElement(source);
1527 List<Source> sources = _context.launchableClientLibrarySources;
1528 expect(sources, isEmpty); 1356 expect(sources, isEmpty);
1529 } 1357 }
1530 1358
1531 void test_getLaunchableClientLibrarySources_importsHtml_explicitly() { 1359 void test_getLaunchableClientLibrarySources_importsHtml_explicitly() {
1532 _context = contextWithCore(); 1360 List<Source> sources = context.launchableClientLibrarySources;
1533 _sourceFactory = _context.sourceFactory; 1361 expect(sources, isEmpty);
1534 List<Source> sources = _context.launchableClientLibrarySources; 1362 Source source = addSource("/test.dart", r'''
1535 expect(sources, isEmpty); 1363 import 'dart:html';
1536 Source source = _addSource("/test.dart", r''' 1364 main() {}''');
1537 import 'dart:html'; 1365 context.computeLibraryElement(source);
1538 main() {}'''); 1366 sources = context.launchableClientLibrarySources;
1539 _context.computeLibraryElement(source);
1540 sources = _context.launchableClientLibrarySources;
1541 expect(sources, unorderedEquals([source])); 1367 expect(sources, unorderedEquals([source]));
1542 } 1368 }
1543 1369
1544 void test_getLaunchableClientLibrarySources_importsHtml_implicitly() { 1370 void test_getLaunchableClientLibrarySources_importsHtml_implicitly() {
1545 _context = contextWithCore(); 1371 List<Source> sources = context.launchableClientLibrarySources;
1546 _sourceFactory = _context.sourceFactory; 1372 expect(sources, isEmpty);
1547 List<Source> sources = _context.launchableClientLibrarySources; 1373 addSource("/a.dart", r'''
1548 expect(sources, isEmpty); 1374 import 'dart:html';
1549 _addSource("/a.dart", r''' 1375 ''');
1550 import 'dart:html'; 1376 Source source = addSource("/test.dart", r'''
1551 ''');
1552 Source source = _addSource("/test.dart", r'''
1553 import 'a.dart'; 1377 import 'a.dart';
1554 main() {}'''); 1378 main() {}''');
1555 _context.computeLibraryElement(source); 1379 context.computeLibraryElement(source);
1556 sources = _context.launchableClientLibrarySources; 1380 sources = context.launchableClientLibrarySources;
1557 expect(sources, unorderedEquals([source])); 1381 expect(sources, unorderedEquals([source]));
1558 } 1382 }
1559 1383
1560 void test_getLaunchableClientLibrarySources_importsHtml_implicitly2() { 1384 void test_getLaunchableClientLibrarySources_importsHtml_implicitly2() {
1561 _context = contextWithCore(); 1385 List<Source> sources = context.launchableClientLibrarySources;
1562 _sourceFactory = _context.sourceFactory; 1386 expect(sources, isEmpty);
1563 List<Source> sources = _context.launchableClientLibrarySources; 1387 addSource("/a.dart", r'''
1564 expect(sources, isEmpty);
1565 _addSource("/a.dart", r'''
1566 export 'dart:html'; 1388 export 'dart:html';
1567 '''); 1389 ''');
1568 Source source = _addSource("/test.dart", r''' 1390 Source source = addSource("/test.dart", r'''
1569 import 'a.dart'; 1391 import 'a.dart';
1570 main() {}'''); 1392 main() {}''');
1571 _context.computeLibraryElement(source); 1393 context.computeLibraryElement(source);
1572 sources = _context.launchableClientLibrarySources; 1394 sources = context.launchableClientLibrarySources;
1573 expect(sources, unorderedEquals([source])); 1395 expect(sources, unorderedEquals([source]));
1574 } 1396 }
1575 1397
1576 void test_getLaunchableServerLibrarySources() { 1398 void test_getLaunchableServerLibrarySources() {
1577 _context = contextWithCore(); 1399 expect(context.launchableServerLibrarySources, isEmpty);
1578 _sourceFactory = _context.sourceFactory; 1400 Source source = addSource("/test.dart", "main() {}");
1579 expect(_context.launchableServerLibrarySources, isEmpty); 1401 context.computeLibraryElement(source);
1580 Source source = _addSource("/test.dart", "main() {}"); 1402 expect(context.launchableServerLibrarySources, unorderedEquals([source]));
1581 _context.computeLibraryElement(source);
1582 expect(_context.launchableServerLibrarySources, unorderedEquals([source]));
1583 } 1403 }
1584 1404
1585 void test_getLaunchableServerLibrarySources_importsHtml_explicitly() { 1405 void test_getLaunchableServerLibrarySources_importsHtml_explicitly() {
1586 _context = contextWithCore(); 1406 Source source = addSource("/test.dart", r'''
1587 _sourceFactory = _context.sourceFactory;
1588 Source source = _addSource("/test.dart", r'''
1589 import 'dart:html'; 1407 import 'dart:html';
1590 main() {} 1408 main() {}
1591 '''); 1409 ''');
1592 _context.computeLibraryElement(source); 1410 context.computeLibraryElement(source);
1593 expect(_context.launchableServerLibrarySources, isEmpty); 1411 expect(context.launchableServerLibrarySources, isEmpty);
1594 } 1412 }
1595 1413
1596 void test_getLaunchableServerLibrarySources_importsHtml_implicitly() { 1414 void test_getLaunchableServerLibrarySources_importsHtml_implicitly() {
1597 _context = contextWithCore(); 1415 addSource("/imports_html.dart", r'''
1598 _sourceFactory = _context.sourceFactory; 1416 import 'dart:html';
1599 _addSource("/imports_html.dart", r''' 1417 ''');
1600 import 'dart:html'; 1418 Source source = addSource("/test.dart", r'''
1601 ''');
1602 Source source = _addSource("/test.dart", r'''
1603 import 'imports_html.dart'; 1419 import 'imports_html.dart';
1604 main() {}'''); 1420 main() {}''');
1605 _context.computeLibraryElement(source); 1421 context.computeLibraryElement(source);
1606 expect(_context.launchableServerLibrarySources, isEmpty); 1422 expect(context.launchableServerLibrarySources, isEmpty);
1607 } 1423 }
1608 1424
1609 void test_getLaunchableServerLibrarySources_noMain() { 1425 void test_getLaunchableServerLibrarySources_noMain() {
1610 _context = contextWithCore(); 1426 Source source = addSource("/test.dart", '');
1611 _sourceFactory = _context.sourceFactory; 1427 context.computeLibraryElement(source);
1612 Source source = _addSource("/test.dart", ''); 1428 expect(context.launchableServerLibrarySources, isEmpty);
1613 _context.computeLibraryElement(source);
1614 expect(_context.launchableServerLibrarySources, isEmpty);
1615 } 1429 }
1616 1430
1617 void test_getLibrariesContaining() { 1431 void test_getLibrariesContaining() {
1618 _context = contextWithCore(); 1432 Source librarySource = addSource("/lib.dart", r'''
1619 _sourceFactory = _context.sourceFactory;
1620 Source librarySource = _addSource("/lib.dart", r'''
1621 library lib; 1433 library lib;
1622 part 'part.dart';'''); 1434 part 'part.dart';''');
1623 Source partSource = _addSource("/part.dart", "part of lib;"); 1435 Source partSource = addSource("/part.dart", "part of lib;");
1624 _context.computeLibraryElement(librarySource); 1436 context.computeLibraryElement(librarySource);
1625 List<Source> result = _context.getLibrariesContaining(librarySource); 1437 List<Source> result = context.getLibrariesContaining(librarySource);
1626 expect(result, hasLength(1)); 1438 expect(result, hasLength(1));
1627 expect(result[0], librarySource); 1439 expect(result[0], librarySource);
1628 result = _context.getLibrariesContaining(partSource); 1440 result = context.getLibrariesContaining(partSource);
1629 expect(result, hasLength(1)); 1441 expect(result, hasLength(1));
1630 expect(result[0], librarySource); 1442 expect(result[0], librarySource);
1631 } 1443 }
1632 1444
1633 void test_getLibrariesDependingOn() { 1445 void test_getLibrariesDependingOn() {
1634 _context = contextWithCore(); 1446 Source libASource = addSource("/libA.dart", "library libA;");
1635 _sourceFactory = _context.sourceFactory; 1447 addSource("/libB.dart", "library libB;");
1636 Source libASource = _addSource("/libA.dart", "library libA;"); 1448 Source lib1Source = addSource("/lib1.dart", r'''
1637 _addSource("/libB.dart", "library libB;");
1638 Source lib1Source = _addSource("/lib1.dart", r'''
1639 library lib1; 1449 library lib1;
1640 import 'libA.dart'; 1450 import 'libA.dart';
1641 export 'libB.dart';'''); 1451 export 'libB.dart';''');
1642 Source lib2Source = _addSource("/lib2.dart", r''' 1452 Source lib2Source = addSource("/lib2.dart", r'''
1643 library lib2; 1453 library lib2;
1644 import 'libB.dart'; 1454 import 'libB.dart';
1645 export 'libA.dart';'''); 1455 export 'libA.dart';''');
1646 _context.computeLibraryElement(lib1Source); 1456 context.computeLibraryElement(lib1Source);
1647 _context.computeLibraryElement(lib2Source); 1457 context.computeLibraryElement(lib2Source);
1648 List<Source> result = _context.getLibrariesDependingOn(libASource); 1458 List<Source> result = context.getLibrariesDependingOn(libASource);
1649 expect(result, unorderedEquals([lib1Source, lib2Source])); 1459 expect(result, unorderedEquals([lib1Source, lib2Source]));
1650 } 1460 }
1651 1461
1652 void test_getLibrariesReferencedFromHtml_no() { 1462 void test_getLibrariesReferencedFromHtml_no() {
1653 _context = contextWithCore(); 1463 Source htmlSource = addSource("/test.html", r'''
1654 _sourceFactory = _context.sourceFactory;
1655 Source htmlSource = _addSource("/test.html", r'''
1656 <html><head> 1464 <html><head>
1657 <script type='application/dart' src='test.js'/> 1465 <script type='application/dart' src='test.js'/>
1658 </head></html>'''); 1466 </head></html>''');
1659 _addSource("/test.dart", "library lib;"); 1467 addSource("/test.dart", "library lib;");
1660 _context.parseHtmlUnit(htmlSource); 1468 context.parseHtmlUnit(htmlSource);
1661 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); 1469 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource);
1662 expect(result, hasLength(0)); 1470 expect(result, hasLength(0));
1663 } 1471 }
1664 1472
1665 void test_getLibraryElement() { 1473 void test_getLibraryElement() {
1666 _context = contextWithCore(); 1474 Source source = addSource("/test.dart", "library lib;");
1667 _sourceFactory = _context.sourceFactory; 1475 LibraryElement element = context.getLibraryElement(source);
1668 Source source = _addSource("/test.dart", "library lib;");
1669 LibraryElement element = _context.getLibraryElement(source);
1670 expect(element, isNull); 1476 expect(element, isNull);
1671 _context.computeLibraryElement(source); 1477 context.computeLibraryElement(source);
1672 element = _context.getLibraryElement(source); 1478 element = context.getLibraryElement(source);
1673 expect(element, isNotNull); 1479 expect(element, isNotNull);
1674 } 1480 }
1675 1481
1676 void test_getLibrarySources() { 1482 void test_getLibrarySources() {
1677 List<Source> sources = _context.librarySources; 1483 List<Source> sources = context.librarySources;
1678 int originalLength = sources.length; 1484 int originalLength = sources.length;
1679 Source source = _addSource("/test.dart", "library lib;"); 1485 Source source = addSource("/test.dart", "library lib;");
1680 _context.computeKindOf(source); 1486 context.computeKindOf(source);
1681 sources = _context.librarySources; 1487 sources = context.librarySources;
1682 expect(sources, hasLength(originalLength + 1)); 1488 expect(sources, hasLength(originalLength + 1));
1683 for (Source returnedSource in sources) { 1489 for (Source returnedSource in sources) {
1684 if (returnedSource == source) { 1490 if (returnedSource == source) {
1685 return; 1491 return;
1686 } 1492 }
1687 } 1493 }
1688 fail("The added source was not in the list of library sources"); 1494 fail("The added source was not in the list of library sources");
1689 } 1495 }
1690 1496
1691 void test_getLineInfo() { 1497 void test_getLineInfo() {
1692 Source source = _addSource("/test.dart", r''' 1498 Source source = addSource("/test.dart", r'''
1693 library lib; 1499 library lib;
1694 1500
1695 main() {}'''); 1501 main() {}''');
1696 LineInfo info = _context.getLineInfo(source); 1502 LineInfo info = context.getLineInfo(source);
1697 expect(info, isNull); 1503 expect(info, isNull);
1698 _context.parseCompilationUnit(source); 1504 context.parseCompilationUnit(source);
1699 info = _context.getLineInfo(source); 1505 info = context.getLineInfo(source);
1700 expect(info, isNotNull); 1506 expect(info, isNotNull);
1701 } 1507 }
1702 1508
1703 void test_getModificationStamp_fromSource() { 1509 void test_getModificationStamp_fromSource() {
1704 int stamp = 42; 1510 int stamp = 42;
1705 expect(_context.getModificationStamp( 1511 expect(context.getModificationStamp(
1706 new AnalysisContextImplTest_Source_getModificationStamp_fromSource( 1512 new AnalysisContextImplTest_Source_getModificationStamp_fromSource(
1707 stamp)), stamp); 1513 stamp)), stamp);
1708 } 1514 }
1709 1515
1710 void test_getModificationStamp_overridden() { 1516 void test_getModificationStamp_overridden() {
1711 int stamp = 42; 1517 int stamp = 42;
1712 Source source = 1518 Source source =
1713 new AnalysisContextImplTest_Source_getModificationStamp_overridden( 1519 new AnalysisContextImplTest_Source_getModificationStamp_overridden(
1714 stamp); 1520 stamp);
1715 _context.setContents(source, ""); 1521 context.setContents(source, "");
1716 expect(stamp != _context.getModificationStamp(source), isTrue); 1522 expect(stamp != context.getModificationStamp(source), isTrue);
1717 } 1523 }
1718 1524
1719 void test_getPublicNamespace_element() { 1525 void test_getPublicNamespace_element() {
1720 _context = contextWithCore(); 1526 Source source = addSource("/test.dart", "class A {}");
1721 _sourceFactory = _context.sourceFactory; 1527 LibraryElement library = context.computeLibraryElement(source);
1722 Source source = _addSource("/test.dart", "class A {}");
1723 LibraryElement library = _context.computeLibraryElement(source);
1724 expect(library, isNotNull); 1528 expect(library, isNotNull);
1725 Namespace namespace = _context.getPublicNamespace(library); 1529 Namespace namespace = context.getPublicNamespace(library);
1726 expect(namespace, isNotNull); 1530 expect(namespace, isNotNull);
1727 EngineTestCase.assertInstanceOf( 1531 EngineTestCase.assertInstanceOf(
1728 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); 1532 (obj) => obj is ClassElement, ClassElement, namespace.get("A"));
1729 } 1533 }
1730 1534
1731 void test_getResolvedCompilationUnit_library_null() { 1535 void test_getResolvedCompilationUnit_library_null() {
1732 _context = contextWithCore(); 1536 Source source = addSource("/lib.dart", "library lib;");
1733 _sourceFactory = _context.sourceFactory; 1537 expect(context.getResolvedCompilationUnit(source, null), isNull);
1734 Source source = _addSource("/lib.dart", "library lib;");
1735 expect(_context.getResolvedCompilationUnit(source, null), isNull);
1736 } 1538 }
1737 1539
1738 void test_getResolvedCompilationUnit_source_dart() { 1540 void test_getResolvedCompilationUnit_source_dart() {
1739 _context = contextWithCore(); 1541 Source source = addSource("/lib.dart", "library lib;");
1740 _sourceFactory = _context.sourceFactory; 1542 expect(context.getResolvedCompilationUnit2(source, source), isNull);
1741 Source source = _addSource("/lib.dart", "library lib;"); 1543 context.resolveCompilationUnit2(source, source);
1742 expect(_context.getResolvedCompilationUnit2(source, source), isNull); 1544 expect(context.getResolvedCompilationUnit2(source, source), isNotNull);
1743 _context.resolveCompilationUnit2(source, source);
1744 expect(_context.getResolvedCompilationUnit2(source, source), isNotNull);
1745 } 1545 }
1746 1546
1747 void test_getResolvedCompilationUnit_source_html() { 1547 void test_getResolvedCompilationUnit_source_html() {
1748 _context = contextWithCore(); 1548 Source source = addSource("/test.html", "<html></html>");
1749 _sourceFactory = _context.sourceFactory; 1549 expect(context.getResolvedCompilationUnit2(source, source), isNull);
1750 Source source = _addSource("/test.html", "<html></html>"); 1550 expect(context.resolveCompilationUnit2(source, source), isNull);
1751 expect(_context.getResolvedCompilationUnit2(source, source), isNull); 1551 expect(context.getResolvedCompilationUnit2(source, source), isNull);
1752 expect(_context.resolveCompilationUnit2(source, source), isNull);
1753 expect(_context.getResolvedCompilationUnit2(source, source), isNull);
1754 } 1552 }
1755 1553
1756 void test_getSourceFactory() { 1554 void test_getSourceFactory() {
1757 expect(_context.sourceFactory, same(_sourceFactory)); 1555 expect(context.sourceFactory, same(sourceFactory));
1758 } 1556 }
1759 1557
1760 void test_getSourcesWithFullName() { 1558 void test_getSourcesWithFullName() {
1761 String filePath = '/foo/lib/file.dart'; 1559 String filePath = '/foo/lib/file.dart';
1762 List<Source> expected = <Source>[]; 1560 List<Source> expected = <Source>[];
1763 ChangeSet changeSet = new ChangeSet(); 1561 ChangeSet changeSet = new ChangeSet();
1764 1562
1765 TestSourceWithUri source1 = 1563 TestSourceWithUri source1 =
1766 new TestSourceWithUri(filePath, Uri.parse('file://$filePath')); 1564 new TestSourceWithUri(filePath, Uri.parse('file://$filePath'));
1767 expected.add(source1); 1565 expected.add(source1);
1768 changeSet.addedSource(source1); 1566 changeSet.addedSource(source1);
1769 1567
1770 TestSourceWithUri source2 = 1568 TestSourceWithUri source2 =
1771 new TestSourceWithUri(filePath, Uri.parse('package:foo/file.dart')); 1569 new TestSourceWithUri(filePath, Uri.parse('package:foo/file.dart'));
1772 expected.add(source2); 1570 expected.add(source2);
1773 changeSet.addedSource(source2); 1571 changeSet.addedSource(source2);
1774 1572
1775 _context.applyChanges(changeSet); 1573 context.applyChanges(changeSet);
1776 expect( 1574 expect(context.getSourcesWithFullName(filePath), unorderedEquals(expected));
1777 _context.getSourcesWithFullName(filePath), unorderedEquals(expected));
1778 } 1575 }
1779 1576
1780 void test_getStatistics() { 1577 void test_getStatistics() {
1781 AnalysisContextStatistics statistics = _context.statistics; 1578 AnalysisContextStatistics statistics = context.statistics;
1782 expect(statistics, isNotNull); 1579 expect(statistics, isNotNull);
1783 // The following lines are fragile. 1580 // The following lines are fragile.
1784 // The values depend on the number of libraries in the SDK. 1581 // The values depend on the number of libraries in the SDK.
1785 // assertLength(0, statistics.getCacheRows()); 1582 // assertLength(0, statistics.getCacheRows());
1786 // assertLength(0, statistics.getExceptions()); 1583 // assertLength(0, statistics.getExceptions());
1787 // assertLength(0, statistics.getSources()); 1584 // assertLength(0, statistics.getSources());
1788 } 1585 }
1789 1586
1790 void test_isClientLibrary_dart() { 1587 void test_isClientLibrary_dart() {
1791 _context = contextWithCore(); 1588 Source source = addSource("/test.dart", r'''
1792 _sourceFactory = _context.sourceFactory;
1793 Source source = _addSource("/test.dart", r'''
1794 import 'dart:html'; 1589 import 'dart:html';
1795 1590
1796 main() {}'''); 1591 main() {}''');
1797 expect(_context.isClientLibrary(source), isFalse); 1592 expect(context.isClientLibrary(source), isFalse);
1798 expect(_context.isServerLibrary(source), isFalse); 1593 expect(context.isServerLibrary(source), isFalse);
1799 _context.computeLibraryElement(source); 1594 context.computeLibraryElement(source);
1800 expect(_context.isClientLibrary(source), isTrue); 1595 expect(context.isClientLibrary(source), isTrue);
1801 expect(_context.isServerLibrary(source), isFalse); 1596 expect(context.isServerLibrary(source), isFalse);
1802 } 1597 }
1803 1598
1804 void test_isClientLibrary_html() { 1599 void test_isClientLibrary_html() {
1805 Source source = _addSource("/test.html", "<html></html>"); 1600 Source source = addSource("/test.html", "<html></html>");
1806 expect(_context.isClientLibrary(source), isFalse); 1601 expect(context.isClientLibrary(source), isFalse);
1807 } 1602 }
1808 1603
1809 void test_isServerLibrary_dart() { 1604 void test_isServerLibrary_dart() {
1810 _context = contextWithCore(); 1605 Source source = addSource("/test.dart", r'''
1811 _sourceFactory = _context.sourceFactory;
1812 Source source = _addSource("/test.dart", r'''
1813 library lib; 1606 library lib;
1814 1607
1815 main() {}'''); 1608 main() {}''');
1816 expect(_context.isClientLibrary(source), isFalse); 1609 expect(context.isClientLibrary(source), isFalse);
1817 expect(_context.isServerLibrary(source), isFalse); 1610 expect(context.isServerLibrary(source), isFalse);
1818 _context.computeLibraryElement(source); 1611 context.computeLibraryElement(source);
1819 expect(_context.isClientLibrary(source), isFalse); 1612 expect(context.isClientLibrary(source), isFalse);
1820 expect(_context.isServerLibrary(source), isTrue); 1613 expect(context.isServerLibrary(source), isTrue);
1821 } 1614 }
1822 1615
1823 void test_isServerLibrary_html() { 1616 void test_isServerLibrary_html() {
1824 Source source = _addSource("/test.html", "<html></html>"); 1617 Source source = addSource("/test.html", "<html></html>");
1825 expect(_context.isServerLibrary(source), isFalse); 1618 expect(context.isServerLibrary(source), isFalse);
1826 } 1619 }
1827 1620
1828 void test_parseCompilationUnit_errors() { 1621 void test_parseCompilationUnit_errors() {
1829 Source source = _addSource("/lib.dart", "library {"); 1622 Source source = addSource("/lib.dart", "library {");
1830 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); 1623 CompilationUnit compilationUnit = context.parseCompilationUnit(source);
1831 expect(compilationUnit, isNotNull); 1624 expect(compilationUnit, isNotNull);
1832 var errorInfo = _context.getErrors(source); 1625 var errorInfo = context.getErrors(source);
1833 expect(errorInfo, isNotNull); 1626 expect(errorInfo, isNotNull);
1834 List<AnalysisError> errors = errorInfo.errors; 1627 List<AnalysisError> errors = errorInfo.errors;
1835 expect(errors, isNotNull); 1628 expect(errors, isNotNull);
1836 expect(errors.length > 0, isTrue); 1629 expect(errors.length > 0, isTrue);
1837 } 1630 }
1838 1631
1839 void test_parseCompilationUnit_exception() { 1632 void test_parseCompilationUnit_exception() {
1840 Source source = _addSourceWithException("/test.dart"); 1633 Source source = _addSourceWithException("/test.dart");
1841 try { 1634 try {
1842 _context.parseCompilationUnit(source); 1635 context.parseCompilationUnit(source);
1843 fail("Expected AnalysisException"); 1636 fail("Expected AnalysisException");
1844 } on AnalysisException { 1637 } on AnalysisException {
1845 // Expected 1638 // Expected
1846 } 1639 }
1847 } 1640 }
1848 1641
1849 void test_parseCompilationUnit_html() { 1642 void test_parseCompilationUnit_html() {
1850 Source source = _addSource("/test.html", "<html></html>"); 1643 Source source = addSource("/test.html", "<html></html>");
1851 expect(_context.parseCompilationUnit(source), isNull); 1644 expect(context.parseCompilationUnit(source), isNull);
1852 } 1645 }
1853 1646
1854 void test_parseCompilationUnit_noErrors() { 1647 void test_parseCompilationUnit_noErrors() {
1855 Source source = _addSource("/lib.dart", "library lib;"); 1648 Source source = addSource("/lib.dart", "library lib;");
1856 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); 1649 CompilationUnit compilationUnit = context.parseCompilationUnit(source);
1857 expect(compilationUnit, isNotNull); 1650 expect(compilationUnit, isNotNull);
1858 AnalysisErrorInfo errorInfo = _context.getErrors(source); 1651 AnalysisErrorInfo errorInfo = context.getErrors(source);
1859 expect(errorInfo, isNotNull); 1652 expect(errorInfo, isNotNull);
1860 expect(errorInfo.errors, hasLength(0)); 1653 expect(errorInfo.errors, hasLength(0));
1861 } 1654 }
1862 1655
1863 void test_parseCompilationUnit_nonExistentSource() { 1656 void test_parseCompilationUnit_nonExistentSource() {
1864 Source source = 1657 Source source = newSource('/test.dart');
1865 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 1658 resourceProvider.deleteFile('/test.dart');
1866 try { 1659 try {
1867 _context.parseCompilationUnit(source); 1660 context.parseCompilationUnit(source);
1868 fail("Expected AnalysisException because file does not exist"); 1661 fail("Expected AnalysisException because file does not exist");
1869 } on AnalysisException { 1662 } on AnalysisException {
1870 // Expected result 1663 // Expected result
1871 } 1664 }
1872 } 1665 }
1873 1666
1874 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { 1667 // void test_resolveCompilationUnit_sourceChangeDuringResolution() {
1875 // _context = new _AnalysisContext_sourceChangeDuringResolution(); 1668 // _context = new _AnalysisContext_sourceChangeDuringResolution();
1876 // AnalysisContextFactory.initContextWithCore(_context); 1669 // AnalysisContextFactory.initContextWithCore(_context);
1877 // _sourceFactory = _context.sourceFactory; 1670 // _sourceFactory = _context.sourceFactory;
(...skipping 16 matching lines...) Expand all
1894 // Thread.sleep(1); 1687 // Thread.sleep(1);
1895 // // Force the modification time to be different. 1688 // // Force the modification time to be different.
1896 // } 1689 // }
1897 // _context.setContents(source, "library test;"); 1690 // _context.setContents(source, "library test;");
1898 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour ce)); 1691 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour ce));
1899 // _analyzeAll_assertFinished(); 1692 // _analyzeAll_assertFinished();
1900 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e lement model", _context.getLibraryElement(source)); 1693 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e lement model", _context.getLibraryElement(source));
1901 } 1694 }
1902 1695
1903 void test_resolveCompilationUnit_library() { 1696 void test_resolveCompilationUnit_library() {
1904 _context = contextWithCore(); 1697 Source source = addSource("/lib.dart", "library lib;");
1905 _sourceFactory = _context.sourceFactory; 1698 LibraryElement library = context.computeLibraryElement(source);
1906 Source source = _addSource("/lib.dart", "library lib;");
1907 LibraryElement library = _context.computeLibraryElement(source);
1908 CompilationUnit compilationUnit = 1699 CompilationUnit compilationUnit =
1909 _context.resolveCompilationUnit(source, library); 1700 context.resolveCompilationUnit(source, library);
1910 expect(compilationUnit, isNotNull); 1701 expect(compilationUnit, isNotNull);
1911 expect(compilationUnit.element, isNotNull); 1702 expect(compilationUnit.element, isNotNull);
1912 } 1703 }
1913 1704
1914 void test_resolveCompilationUnit_source() { 1705 void test_resolveCompilationUnit_source() {
1915 _context = contextWithCore(); 1706 Source source = addSource("/lib.dart", "library lib;");
1916 _sourceFactory = _context.sourceFactory;
1917 Source source = _addSource("/lib.dart", "library lib;");
1918 CompilationUnit compilationUnit = 1707 CompilationUnit compilationUnit =
1919 _context.resolveCompilationUnit2(source, source); 1708 context.resolveCompilationUnit2(source, source);
1920 expect(compilationUnit, isNotNull); 1709 expect(compilationUnit, isNotNull);
1921 } 1710 }
1922 1711
1923 void test_setAnalysisOptions() { 1712 void test_setAnalysisOptions() {
1924 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 1713 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
1925 options.cacheSize = 42; 1714 options.cacheSize = 42;
1926 options.dart2jsHint = false; 1715 options.dart2jsHint = false;
1927 options.hint = false; 1716 options.hint = false;
1928 _context.analysisOptions = options; 1717 context.analysisOptions = options;
1929 AnalysisOptions result = _context.analysisOptions; 1718 AnalysisOptions result = context.analysisOptions;
1930 expect(result.cacheSize, options.cacheSize); 1719 expect(result.cacheSize, options.cacheSize);
1931 expect(result.dart2jsHint, options.dart2jsHint); 1720 expect(result.dart2jsHint, options.dart2jsHint);
1932 expect(result.hint, options.hint); 1721 expect(result.hint, options.hint);
1933 } 1722 }
1934 1723
1935 void test_setAnalysisPriorityOrder_empty() { 1724 void test_setAnalysisPriorityOrder_empty() {
1936 _context.analysisPriorityOrder = new List<Source>(); 1725 context.analysisPriorityOrder = new List<Source>();
1937 } 1726 }
1938 1727
1939 void test_setAnalysisPriorityOrder_nonEmpty() { 1728 void test_setAnalysisPriorityOrder_nonEmpty() {
1940 List<Source> sources = new List<Source>(); 1729 List<Source> sources = new List<Source>();
1941 sources.add(_addSource("/lib.dart", "library lib;")); 1730 sources.add(addSource("/lib.dart", "library lib;"));
1942 _context.analysisPriorityOrder = sources; 1731 context.analysisPriorityOrder = sources;
1943 } 1732 }
1944 1733
1945 void test_setChangedContents_notResolved() { 1734 void test_setChangedContents_notResolved() {
1946 _context = contextWithCore();
1947 AnalysisOptionsImpl options = 1735 AnalysisOptionsImpl options =
1948 new AnalysisOptionsImpl.con1(_context.analysisOptions); 1736 new AnalysisOptionsImpl.con1(context.analysisOptions);
1949 options.incremental = true; 1737 options.incremental = true;
1950 _context.analysisOptions = options; 1738 context.analysisOptions = options;
1951 _sourceFactory = _context.sourceFactory;
1952 String oldCode = r''' 1739 String oldCode = r'''
1953 library lib; 1740 library lib;
1954 int a = 0;'''; 1741 int a = 0;''';
1955 Source librarySource = _addSource("/lib.dart", oldCode); 1742 Source librarySource = addSource("/lib.dart", oldCode);
1956 int offset = oldCode.indexOf("int a") + 4; 1743 int offset = oldCode.indexOf("int a") + 4;
1957 String newCode = r''' 1744 String newCode = r'''
1958 library lib; 1745 library lib;
1959 int ya = 0;'''; 1746 int ya = 0;''';
1960 _context.setChangedContents(librarySource, newCode, offset, 0, 1); 1747 context.setChangedContents(librarySource, newCode, offset, 0, 1);
1961 expect(_context.getContents(librarySource).data, newCode); 1748 expect(context.getContents(librarySource).data, newCode);
1962 expect(_getIncrementalAnalysisCache(_context), isNull); 1749 expect(_getIncrementalAnalysisCache(context), isNull);
1963 } 1750 }
1964 1751
1965 Future test_setContents_libraryWithPart() { 1752 Future test_setContents_libraryWithPart() {
1966 _context = contextWithCore();
1967 SourcesChangedListener listener = new SourcesChangedListener(); 1753 SourcesChangedListener listener = new SourcesChangedListener();
1968 _context.onSourcesChanged.listen(listener.onData); 1754 context.onSourcesChanged.listen(listener.onData);
1969 _sourceFactory = _context.sourceFactory;
1970 String libraryContents1 = r''' 1755 String libraryContents1 = r'''
1971 library lib; 1756 library lib;
1972 part 'part.dart'; 1757 part 'part.dart';
1973 int a = 0;'''; 1758 int a = 0;''';
1974 Source librarySource = _addSource("/lib.dart", libraryContents1); 1759 Source librarySource = addSource("/lib.dart", libraryContents1);
1975 String partContents1 = r''' 1760 String partContents1 = r'''
1976 part of lib; 1761 part of lib;
1977 int b = a;'''; 1762 int b = a;''';
1978 Source partSource = _addSource("/part.dart", partContents1); 1763 Source partSource = addSource("/part.dart", partContents1);
1979 _context.computeLibraryElement(librarySource); 1764 context.computeLibraryElement(librarySource);
1980 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1765 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
1981 librarySource, librarySource, null, null, null, 0, 0, 0); 1766 librarySource, librarySource, null, null, null, 0, 0, 0);
1982 _setIncrementalAnalysisCache(_context, incrementalCache); 1767 _setIncrementalAnalysisCache(context, incrementalCache);
1983 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); 1768 expect(_getIncrementalAnalysisCache(context), same(incrementalCache));
1984 String libraryContents2 = r''' 1769 String libraryContents2 = r'''
1985 library lib; 1770 library lib;
1986 part 'part.dart'; 1771 part 'part.dart';
1987 int aa = 0;'''; 1772 int aa = 0;''';
1988 _context.setContents(librarySource, libraryContents2); 1773 context.setContents(librarySource, libraryContents2);
1989 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), 1774 expect(
1990 isNull); 1775 context.getResolvedCompilationUnit2(partSource, librarySource), isNull);
1991 expect(_getIncrementalAnalysisCache(_context), isNull); 1776 expect(_getIncrementalAnalysisCache(context), isNull);
1992 return pumpEventQueue().then((_) { 1777 return pumpEventQueue().then((_) {
1993 listener.assertEvent(wereSourcesAdded: true); 1778 listener.assertEvent(wereSourcesAdded: true);
1994 listener.assertEvent(changedSources: [librarySource]); 1779 listener.assertEvent(changedSources: [librarySource]);
1995 listener.assertEvent(wereSourcesAdded: true); 1780 listener.assertEvent(wereSourcesAdded: true);
1996 listener.assertEvent(changedSources: [partSource]); 1781 listener.assertEvent(changedSources: [partSource]);
1997 listener.assertEvent(changedSources: [librarySource]); 1782 listener.assertEvent(changedSources: [librarySource]);
1998 listener.assertNoMoreEvents(); 1783 listener.assertNoMoreEvents();
1999 }); 1784 });
2000 } 1785 }
2001 1786
2002 void test_setContents_null() { 1787 void test_setContents_null() {
2003 _context = contextWithCore(); 1788 Source librarySource = addSource("/lib.dart", r'''
2004 _sourceFactory = _context.sourceFactory;
2005 Source librarySource = _addSource("/lib.dart", r'''
2006 library lib; 1789 library lib;
2007 int a = 0;'''); 1790 int a = 0;''');
2008 _context.computeLibraryElement(librarySource); 1791 context.computeLibraryElement(librarySource);
2009 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( 1792 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache(
2010 librarySource, librarySource, null, null, null, 0, 0, 0); 1793 librarySource, librarySource, null, null, null, 0, 0, 0);
2011 _setIncrementalAnalysisCache(_context, incrementalCache); 1794 _setIncrementalAnalysisCache(context, incrementalCache);
2012 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); 1795 expect(_getIncrementalAnalysisCache(context), same(incrementalCache));
2013 _context.setContents(librarySource, null); 1796 context.setContents(librarySource, null);
2014 expect(_context.getResolvedCompilationUnit2(librarySource, librarySource), 1797 expect(context.getResolvedCompilationUnit2(librarySource, librarySource),
2015 isNull); 1798 isNull);
2016 expect(_getIncrementalAnalysisCache(_context), isNull); 1799 expect(_getIncrementalAnalysisCache(context), isNull);
2017 } 1800 }
2018 1801
2019 void test_setSourceFactory() { 1802 void test_setSourceFactory() {
2020 expect(_context.sourceFactory, _sourceFactory); 1803 expect(context.sourceFactory, sourceFactory);
2021 SourceFactory factory = new SourceFactory([]); 1804 SourceFactory factory = new SourceFactory([]);
2022 _context.sourceFactory = factory; 1805 context.sourceFactory = factory;
2023 expect(_context.sourceFactory, factory); 1806 expect(context.sourceFactory, factory);
2024 } 1807 }
2025 1808
2026 void test_updateAnalysis() { 1809 void test_updateAnalysis() {
2027 expect(_context.sourcesNeedingProcessing, isEmpty); 1810 expect(context.sourcesNeedingProcessing, isEmpty);
2028 Source source = 1811 Source source = newSource('/test.dart');
2029 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
2030 AnalysisDelta delta = new AnalysisDelta(); 1812 AnalysisDelta delta = new AnalysisDelta();
2031 delta.setAnalysisLevel(source, AnalysisLevel.ALL); 1813 delta.setAnalysisLevel(source, AnalysisLevel.ALL);
2032 _context.applyAnalysisDelta(delta); 1814 context.applyAnalysisDelta(delta);
2033 expect(_context.sourcesNeedingProcessing, contains(source)); 1815 expect(context.sourcesNeedingProcessing, contains(source));
2034 delta = new AnalysisDelta(); 1816 delta = new AnalysisDelta();
2035 delta.setAnalysisLevel(source, AnalysisLevel.NONE); 1817 delta.setAnalysisLevel(source, AnalysisLevel.NONE);
2036 _context.applyAnalysisDelta(delta); 1818 context.applyAnalysisDelta(delta);
2037 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); 1819 expect(context.sourcesNeedingProcessing.contains(source), isFalse);
2038 } 1820 }
2039 1821
2040 Future xtest_computeResolvedCompilationUnitAsync() { 1822 Future xtest_computeResolvedCompilationUnitAsync() {
2041 _context = contextWithCore(); 1823 Source source = addSource("/lib.dart", "library lib;");
2042 _sourceFactory = _context.sourceFactory;
2043 Source source = _addSource("/lib.dart", "library lib;");
2044 // Complete all pending analysis tasks and flush the AST so that it won't 1824 // Complete all pending analysis tasks and flush the AST so that it won't
2045 // be available immediately. 1825 // be available immediately.
2046 _performPendingAnalysisTasks(); 1826 _performPendingAnalysisTasks();
2047 _flushAst(source); 1827 _flushAst(source);
2048 bool completed = false; 1828 bool completed = false;
2049 _context 1829 context
2050 .computeResolvedCompilationUnitAsync(source, source) 1830 .computeResolvedCompilationUnitAsync(source, source)
2051 .then((CompilationUnit unit) { 1831 .then((CompilationUnit unit) {
2052 expect(unit, isNotNull); 1832 expect(unit, isNotNull);
2053 completed = true; 1833 completed = true;
2054 }); 1834 });
2055 return pumpEventQueue().then((_) { 1835 return pumpEventQueue().then((_) {
2056 expect(completed, isFalse); 1836 expect(completed, isFalse);
2057 _performPendingAnalysisTasks(); 1837 _performPendingAnalysisTasks();
2058 }).then((_) => pumpEventQueue()).then((_) { 1838 }).then((_) => pumpEventQueue()).then((_) {
2059 expect(completed, isTrue); 1839 expect(completed, isTrue);
2060 }); 1840 });
2061 } 1841 }
2062 1842
2063 Future xtest_computeResolvedCompilationUnitAsync_cancel() { 1843 Future xtest_computeResolvedCompilationUnitAsync_cancel() {
2064 _context = contextWithCore(); 1844 Source source = addSource("/lib.dart", "library lib;");
2065 _sourceFactory = _context.sourceFactory;
2066 Source source = _addSource("/lib.dart", "library lib;");
2067 // Complete all pending analysis tasks and flush the AST so that it won't 1845 // Complete all pending analysis tasks and flush the AST so that it won't
2068 // be available immediately. 1846 // be available immediately.
2069 _performPendingAnalysisTasks(); 1847 _performPendingAnalysisTasks();
2070 _flushAst(source); 1848 _flushAst(source);
2071 CancelableFuture<CompilationUnit> future = 1849 CancelableFuture<CompilationUnit> future =
2072 _context.computeResolvedCompilationUnitAsync(source, source); 1850 context.computeResolvedCompilationUnitAsync(source, source);
2073 bool completed = false; 1851 bool completed = false;
2074 future.then((CompilationUnit unit) { 1852 future.then((CompilationUnit unit) {
2075 fail('Future should have been canceled'); 1853 fail('Future should have been canceled');
2076 }, onError: (error) { 1854 }, onError: (error) {
2077 expect(error, new isInstanceOf<FutureCanceledError>()); 1855 expect(error, new isInstanceOf<FutureCanceledError>());
2078 completed = true; 1856 completed = true;
2079 }); 1857 });
2080 expect(completed, isFalse); 1858 expect(completed, isFalse);
2081 expect(_context.pendingFutureSources_forTesting, isNotEmpty); 1859 expect(context.pendingFutureSources_forTesting, isNotEmpty);
2082 future.cancel(); 1860 future.cancel();
2083 expect(_context.pendingFutureSources_forTesting, isEmpty); 1861 expect(context.pendingFutureSources_forTesting, isEmpty);
2084 return pumpEventQueue().then((_) { 1862 return pumpEventQueue().then((_) {
2085 expect(completed, isTrue); 1863 expect(completed, isTrue);
2086 expect(_context.pendingFutureSources_forTesting, isEmpty); 1864 expect(context.pendingFutureSources_forTesting, isEmpty);
2087 }); 1865 });
2088 } 1866 }
2089 1867
2090 void xtest_performAnalysisTask_stress() { 1868 void xtest_performAnalysisTask_stress() {
2091 int maxCacheSize = 4; 1869 int maxCacheSize = 4;
2092 AnalysisOptionsImpl options = 1870 AnalysisOptionsImpl options =
2093 new AnalysisOptionsImpl.con1(_context.analysisOptions); 1871 new AnalysisOptionsImpl.con1(context.analysisOptions);
2094 options.cacheSize = maxCacheSize; 1872 options.cacheSize = maxCacheSize;
2095 _context.analysisOptions = options; 1873 context.analysisOptions = options;
2096 int sourceCount = maxCacheSize + 2; 1874 int sourceCount = maxCacheSize + 2;
2097 List<Source> sources = new List<Source>(); 1875 List<Source> sources = new List<Source>();
2098 ChangeSet changeSet = new ChangeSet(); 1876 ChangeSet changeSet = new ChangeSet();
2099 for (int i = 0; i < sourceCount; i++) { 1877 for (int i = 0; i < sourceCount; i++) {
2100 Source source = _addSource("/lib$i.dart", "library lib$i;"); 1878 Source source = addSource("/lib$i.dart", "library lib$i;");
2101 sources.add(source); 1879 sources.add(source);
2102 changeSet.addedSource(source); 1880 changeSet.addedSource(source);
2103 } 1881 }
2104 _context.applyChanges(changeSet); 1882 context.applyChanges(changeSet);
2105 _context.analysisPriorityOrder = sources; 1883 context.analysisPriorityOrder = sources;
2106 for (int i = 0; i < 1000; i++) { 1884 for (int i = 0; i < 1000; i++) {
2107 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; 1885 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices;
2108 if (notice == null) { 1886 if (notice == null) {
2109 //System.out.println("test_performAnalysisTask_stress: " + i); 1887 //System.out.println("test_performAnalysisTask_stress: " + i);
2110 break; 1888 break;
2111 } 1889 }
2112 } 1890 }
2113 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; 1891 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices;
2114 if (notice != null) { 1892 if (notice != null) {
2115 fail( 1893 fail(
2116 "performAnalysisTask failed to terminate after analyzing all sources") ; 1894 "performAnalysisTask failed to terminate after analyzing all sources") ;
2117 } 1895 }
2118 } 1896 }
2119 1897
2120 Source _addSource(String fileName, String contents) {
2121 Source source =
2122 new FileBasedSource.con1(FileUtilities2.createFile(fileName));
2123 ChangeSet changeSet = new ChangeSet();
2124 changeSet.addedSource(source);
2125 _context.applyChanges(changeSet);
2126 _context.setContents(source, contents);
2127 return source;
2128 }
2129
2130 TestSource _addSourceWithException(String fileName) { 1898 TestSource _addSourceWithException(String fileName) {
2131 return _addSourceWithException2(fileName, ""); 1899 return _addSourceWithException2(fileName, "");
2132 } 1900 }
2133 1901
2134 TestSource _addSourceWithException2(String fileName, String contents) { 1902 TestSource _addSourceWithException2(String fileName, String contents) {
2135 TestSource source = new TestSource(fileName, contents); 1903 TestSource source = new TestSource(fileName, contents);
2136 source.generateExceptionOnRead = true; 1904 source.generateExceptionOnRead = true;
2137 ChangeSet changeSet = new ChangeSet(); 1905 ChangeSet changeSet = new ChangeSet();
2138 changeSet.addedSource(source); 1906 changeSet.addedSource(source);
2139 _context.applyChanges(changeSet); 1907 context.applyChanges(changeSet);
2140 return source; 1908 return source;
2141 } 1909 }
2142 1910
2143 /** 1911 /**
2144 * Perform analysis tasks up to 512 times and asserts that that was enough. 1912 * Perform analysis tasks up to 512 times and asserts that that was enough.
2145 */ 1913 */
2146 void _analyzeAll_assertFinished() { 1914 void _analyzeAll_assertFinished() {
2147 _analyzeAll_assertFinished2(512); 1915 _analyzeAll_assertFinished2(512);
2148 } 1916 }
2149 1917
2150 /** 1918 /**
2151 * Perform analysis tasks up to the given number of times and asserts that tha t was enough. 1919 * Perform analysis tasks up to the given number of times and asserts that tha t was enough.
2152 * 1920 *
2153 * @param maxIterations the maximum number of tasks to perform 1921 * @param maxIterations the maximum number of tasks to perform
2154 */ 1922 */
2155 void _analyzeAll_assertFinished2(int maxIterations) { 1923 void _analyzeAll_assertFinished2(int maxIterations) {
2156 for (int i = 0; i < maxIterations; i++) { 1924 for (int i = 0; i < maxIterations; i++) {
2157 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; 1925 List<ChangeNotice> notice = context.performAnalysisTask().changeNotices;
2158 if (notice == null) { 1926 if (notice == null) {
2159 return; 1927 return;
2160 } 1928 }
2161 } 1929 }
2162 fail("performAnalysisTask failed to terminate after analyzing all sources"); 1930 fail("performAnalysisTask failed to terminate after analyzing all sources");
2163 } 1931 }
2164 1932
2165 void _changeSource(TestSource source, String contents) { 1933 void _changeSource(TestSource source, String contents) {
2166 source.setContents(contents); 1934 source.setContents(contents);
2167 ChangeSet changeSet = new ChangeSet(); 1935 ChangeSet changeSet = new ChangeSet();
2168 changeSet.changedSource(source); 1936 changeSet.changedSource(source);
2169 _context.applyChanges(changeSet); 1937 context.applyChanges(changeSet);
2170 } 1938 }
2171 1939
2172 /** 1940 /**
2173 * Search the given compilation unit for a class with the given name. Return t he class with the 1941 * Search the given compilation unit for a class with the given name. Return t he class with the
2174 * given name, or `null` if the class cannot be found. 1942 * given name, or `null` if the class cannot be found.
2175 * 1943 *
2176 * @param unit the compilation unit being searched 1944 * @param unit the compilation unit being searched
2177 * @param className the name of the class being searched for 1945 * @param className the name of the class being searched for
2178 * @return the class with the given name 1946 * @return the class with the given name
2179 */ 1947 */
2180 ClassElement _findClass(CompilationUnitElement unit, String className) { 1948 ClassElement _findClass(CompilationUnitElement unit, String className) {
2181 for (ClassElement classElement in unit.types) { 1949 for (ClassElement classElement in unit.types) {
2182 if (classElement.displayName == className) { 1950 if (classElement.displayName == className) {
2183 return classElement; 1951 return classElement;
2184 } 1952 }
2185 } 1953 }
2186 return null; 1954 return null;
2187 } 1955 }
2188 1956
2189 void _flushAst(Source source) { 1957 void _flushAst(Source source) {
2190 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); 1958 CacheEntry entry = context.getReadableSourceEntryOrNull(source);
2191 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); 1959 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED);
2192 } 1960 }
2193 1961
2194 IncrementalAnalysisCache _getIncrementalAnalysisCache( 1962 IncrementalAnalysisCache _getIncrementalAnalysisCache(
2195 AnalysisContextImpl context2) { 1963 AnalysisContextImpl context2) {
2196 return context2.test_incrementalAnalysisCache; 1964 return context2.test_incrementalAnalysisCache;
2197 } 1965 }
2198 1966
2199 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { 1967 List<Source> _getPriorityOrder(AnalysisContextImpl context2) {
2200 return context2.test_priorityOrder; 1968 return context2.test_priorityOrder;
2201 } 1969 }
2202 1970
2203 void _performPendingAnalysisTasks([int maxTasks = 20]) { 1971 void _performPendingAnalysisTasks([int maxTasks = 20]) {
2204 for (int i = 0; _context.performAnalysisTask().hasMoreWork; i++) { 1972 for (int i = 0; context.performAnalysisTask().hasMoreWork; i++) {
2205 if (i > maxTasks) { 1973 if (i > maxTasks) {
2206 fail('Analysis did not terminate.'); 1974 fail('Analysis did not terminate.');
2207 } 1975 }
2208 } 1976 }
2209 } 1977 }
2210 1978
2211 void _removeSource(Source source) { 1979 void _removeSource(Source source) {
2212 ChangeSet changeSet = new ChangeSet(); 1980 ChangeSet changeSet = new ChangeSet();
2213 changeSet.removedSource(source); 1981 changeSet.removedSource(source);
2214 _context.applyChanges(changeSet); 1982 context.applyChanges(changeSet);
2215 } 1983 }
2216 1984
2217 void _setIncrementalAnalysisCache( 1985 void _setIncrementalAnalysisCache(
2218 AnalysisContextImpl context, IncrementalAnalysisCache incrementalCache) { 1986 AnalysisContextImpl context, IncrementalAnalysisCache incrementalCache) {
2219 context.test_incrementalAnalysisCache = incrementalCache; 1987 context.test_incrementalAnalysisCache = incrementalCache;
2220 } 1988 }
2221 1989
2222 /** 1990 /**
2223 * Returns `true` if there is an [AnalysisError] with [ErrorSeverity.ERROR] in 1991 * Returns `true` if there is an [AnalysisError] with [ErrorSeverity.ERROR] in
2224 * the given [AnalysisErrorInfo]. 1992 * the given [AnalysisErrorInfo].
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 : super(name, UriKind.FILE_URI); 2040 : super(name, UriKind.FILE_URI);
2273 2041
2274 @override 2042 @override
2275 TimestampedData<String> get contents { 2043 TimestampedData<String> get contents {
2276 throw 'Read error'; 2044 throw 'Read error';
2277 } 2045 }
2278 2046
2279 @override 2047 @override
2280 bool exists() => true; 2048 bool exists() => true;
2281 } 2049 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/abstract_context.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698