| OLD | NEW |
| 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 engine.engine_test; | 5 library analyzer.test.generated.engine_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 |
| 9 | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/file_system/memory_file_system.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 11 import 'package:analyzer/src/cancelable_future.dart'; | 13 import 'package:analyzer/src/cancelable_future.dart'; |
| 12 import 'package:analyzer/src/context/cache.dart' show CacheEntry; | 14 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 15 import 'package:analyzer/src/context/cache.dart'; |
| 16 import 'package:analyzer/src/context/context.dart'; |
| 17 import 'package:analyzer/src/context/source.dart'; |
| 14 import 'package:analyzer/src/generated/constant.dart'; | 18 import 'package:analyzer/src/generated/constant.dart'; |
| 15 import 'package:analyzer/src/generated/element.dart'; | |
| 16 import 'package:analyzer/src/generated/engine.dart'; | 19 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/error.dart'; | |
| 18 import 'package:analyzer/src/generated/html.dart' as ht; | |
| 19 import 'package:analyzer/src/generated/java_core.dart'; | |
| 20 import 'package:analyzer/src/generated/java_engine.dart'; | |
| 21 import 'package:analyzer/src/generated/java_engine_io.dart'; | |
| 22 import 'package:analyzer/src/generated/java_io.dart'; | |
| 23 import 'package:analyzer/src/generated/parser.dart'; | |
| 24 import 'package:analyzer/src/generated/resolver.dart'; | 20 import 'package:analyzer/src/generated/resolver.dart'; |
| 25 import 'package:analyzer/src/generated/scanner.dart'; | |
| 26 import 'package:analyzer/src/generated/sdk.dart'; | |
| 27 import 'package:analyzer/src/generated/sdk_io.dart'; | |
| 28 import 'package:analyzer/src/generated/source_io.dart'; | 21 import 'package:analyzer/src/generated/source_io.dart'; |
| 29 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | |
| 30 import 'package:analyzer/src/generated/testing/element_factory.dart'; | |
| 31 import 'package:analyzer/src/generated/utilities_collection.dart'; | |
| 32 import 'package:analyzer/src/services/lint.dart'; | |
| 33 import 'package:analyzer/src/string_source.dart'; | 22 import 'package:analyzer/src/string_source.dart'; |
| 34 import 'package:analyzer/task/model.dart' as newContext; | 23 import 'package:analyzer/task/model.dart'; |
| 35 import 'package:html/dom.dart' show Document; | 24 import 'package:html/dom.dart' show Document; |
| 36 import 'package:path/path.dart' as pathos; | 25 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 37 import 'package:typed_mock/typed_mock.dart'; | 26 import 'package:typed_mock/typed_mock.dart'; |
| 38 import 'package:unittest/unittest.dart'; | 27 import 'package:unittest/unittest.dart'; |
| 39 import 'package:watcher/src/utils.dart'; | 28 |
| 40 | |
| 41 import '../reflective_tests.dart'; | |
| 42 import '../utils.dart'; | 29 import '../utils.dart'; |
| 43 import 'all_the_rest_test.dart'; | |
| 44 import 'resolver_test.dart'; | |
| 45 import 'test_support.dart'; | |
| 46 | 30 |
| 47 main() { | 31 main() { |
| 48 initializeTestEnvironment(); | 32 initializeTestEnvironment(); |
| 49 // Tests for the classes used in both old and new analysis implementations. | 33 defineReflectiveTests(SourcesChangedEventTest); |
| 50 runReflectiveTests(SourcesChangedEventTest); | |
| 51 // Tests for the classes used in the old analysis implementation. | |
| 52 if (!AnalysisEngine.instance.useTaskModel) { | |
| 53 runReflectiveTests(AnalysisCacheTest); | |
| 54 runReflectiveTests(AnalysisContextImplTest); | |
| 55 runReflectiveTests(AnalysisTaskTest); | |
| 56 runReflectiveTests(AnalysisOptionsImplTest); | |
| 57 runReflectiveTests(DartEntryTest); | |
| 58 runReflectiveTests(GenerateDartErrorsTaskTest); | |
| 59 runReflectiveTests(GenerateDartHintsTaskTest); | |
| 60 runReflectiveTests(GenerateDartLintsTaskTest); | |
| 61 runReflectiveTests(GetContentTaskTest); | |
| 62 runReflectiveTests(HtmlEntryTest); | |
| 63 runReflectiveTests(IncrementalAnalysisCacheTest); | |
| 64 runReflectiveTests(IncrementalAnalysisTaskTest); | |
| 65 runReflectiveTests(LintGeneratorTest); | |
| 66 runReflectiveTests(ParseDartTaskTest); | |
| 67 runReflectiveTests(ParseHtmlTaskTest); | |
| 68 runReflectiveTests(PartitionManagerTest); | |
| 69 runReflectiveTests(ResolveDartLibraryTaskTest); | |
| 70 runReflectiveTests(ResolveDartUnitTaskTest); | |
| 71 runReflectiveTests(ResolveHtmlTaskTest); | |
| 72 runReflectiveTests(ScanDartTaskTest); | |
| 73 runReflectiveTests(SdkCachePartitionTest); | |
| 74 runReflectiveTests(UniversalCachePartitionTest); | |
| 75 runReflectiveTests(WorkManagerTest); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 @reflectiveTest | |
| 80 class AnalysisCacheTest extends EngineTestCase { | |
| 81 void test_creation() { | |
| 82 expect(new AnalysisCache(new List<CachePartition>(0)), isNotNull); | |
| 83 } | |
| 84 | |
| 85 void test_get() { | |
| 86 AnalysisCache cache = new AnalysisCache(new List<CachePartition>(0)); | |
| 87 TestSource source = new TestSource(); | |
| 88 expect(cache.get(source), isNull); | |
| 89 } | |
| 90 | |
| 91 void test_iterator() { | |
| 92 CachePartition partition = | |
| 93 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); | |
| 94 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); | |
| 95 TestSource source = new TestSource(); | |
| 96 DartEntry entry = new DartEntry(); | |
| 97 cache.put(source, entry); | |
| 98 MapIterator<Source, SourceEntry> iterator = cache.iterator(); | |
| 99 expect(iterator.moveNext(), isTrue); | |
| 100 expect(iterator.key, same(source)); | |
| 101 expect(iterator.value, same(entry)); | |
| 102 expect(iterator.moveNext(), isFalse); | |
| 103 } | |
| 104 | |
| 105 /** | |
| 106 * Verify that if multiple Source objects refer to the same file via | |
| 107 * different URIs, they are treated as separate entries in the cache. | |
| 108 */ | |
| 109 void test_lookup_distinguishes_uris() { | |
| 110 CachePartition partition = | |
| 111 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); | |
| 112 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); | |
| 113 JavaFile file = new JavaFile('baz.dart'); | |
| 114 Source source1 = new FileBasedSource(file); | |
| 115 Source source2 = | |
| 116 new FileBasedSource(file, Uri.parse('package:foo/baz.dart')); | |
| 117 Source source3 = | |
| 118 new FileBasedSource(file, Uri.parse('package:bar/baz.dart')); | |
| 119 DartEntry entry1 = new DartEntry(); | |
| 120 DartEntry entry2 = new DartEntry(); | |
| 121 DartEntry entry3 = new DartEntry(); | |
| 122 cache.put(source1, entry1); | |
| 123 cache.put(source2, entry2); | |
| 124 cache.put(source3, entry3); | |
| 125 expect(cache.get(source1), same(entry1)); | |
| 126 expect(cache.get(source2), same(entry2)); | |
| 127 expect(cache.get(source3), same(entry3)); | |
| 128 } | |
| 129 | |
| 130 void test_put_noFlush() { | |
| 131 CachePartition partition = | |
| 132 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); | |
| 133 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); | |
| 134 TestSource source = new TestSource(); | |
| 135 DartEntry entry = new DartEntry(); | |
| 136 cache.put(source, entry); | |
| 137 expect(cache.get(source), same(entry)); | |
| 138 } | |
| 139 | |
| 140 void test_setMaxCacheSize() { | |
| 141 CachePartition partition = new UniversalCachePartition( | |
| 142 null, 8, new _AnalysisCacheTest_test_setMaxCacheSize()); | |
| 143 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); | |
| 144 int size = 6; | |
| 145 for (int i = 0; i < size; i++) { | |
| 146 Source source = new TestSource("/test$i.dart"); | |
| 147 DartEntry entry = new DartEntry(); | |
| 148 entry.setValue(DartEntry.PARSED_UNIT, null); | |
| 149 cache.put(source, entry); | |
| 150 cache.accessedAst(source); | |
| 151 } | |
| 152 _assertNonFlushedCount(size, cache); | |
| 153 int newSize = size - 2; | |
| 154 partition.maxCacheSize = newSize; | |
| 155 _assertNonFlushedCount(newSize, cache); | |
| 156 } | |
| 157 | |
| 158 void test_size() { | |
| 159 CachePartition partition = | |
| 160 new UniversalCachePartition(null, 8, new DefaultRetentionPolicy()); | |
| 161 AnalysisCache cache = new AnalysisCache(<CachePartition>[partition]); | |
| 162 int size = 4; | |
| 163 for (int i = 0; i < size; i++) { | |
| 164 Source source = new TestSource("/test$i.dart"); | |
| 165 cache.put(source, new DartEntry()); | |
| 166 cache.accessedAst(source); | |
| 167 } | |
| 168 expect(cache.size(), size); | |
| 169 } | |
| 170 | |
| 171 void _assertNonFlushedCount(int expectedCount, AnalysisCache cache) { | |
| 172 int nonFlushedCount = 0; | |
| 173 MapIterator<Source, SourceEntry> iterator = cache.iterator(); | |
| 174 while (iterator.moveNext()) { | |
| 175 if (iterator.value.getState(DartEntry.PARSED_UNIT) != | |
| 176 CacheState.FLUSHED) { | |
| 177 nonFlushedCount++; | |
| 178 } | |
| 179 } | |
| 180 expect(nonFlushedCount, expectedCount); | |
| 181 } | |
| 182 } | |
| 183 | |
| 184 @reflectiveTest | |
| 185 class AnalysisContextImplTest extends EngineTestCase { | |
| 186 /** | |
| 187 * An analysis context whose source factory is [sourceFactory]. | |
| 188 */ | |
| 189 AnalysisContextImpl _context; | |
| 190 | |
| 191 /** | |
| 192 * The source factory associated with the analysis [context]. | |
| 193 */ | |
| 194 SourceFactory _sourceFactory; | |
| 195 | |
| 196 void fail_performAnalysisTask_importedLibraryDelete_html() { | |
| 197 Source htmlSource = _addSource( | |
| 198 "/page.html", | |
| 199 r''' | |
| 200 <html><body><script type="application/dart"> | |
| 201 import 'libB.dart'; | |
| 202 main() {print('hello dart');} | |
| 203 </script></body></html>'''); | |
| 204 Source libBSource = _addSource("/libB.dart", "library libB;"); | |
| 205 _analyzeAll_assertFinished(); | |
| 206 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, | |
| 207 reason: "htmlUnit resolved 1"); | |
| 208 expect( | |
| 209 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | |
| 210 reason: "libB resolved 1"); | |
| 211 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), | |
| 212 isTrue, | |
| 213 reason: "htmlSource doesn't have errors"); | |
| 214 // remove libB.dart content and analyze | |
| 215 _context.setContents(libBSource, null); | |
| 216 _analyzeAll_assertFinished(); | |
| 217 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, | |
| 218 reason: "htmlUnit resolved 1"); | |
| 219 AnalysisErrorInfo errors = _context.getErrors(htmlSource); | |
| 220 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, | |
| 221 reason: "htmlSource has an error"); | |
| 222 } | |
| 223 | |
| 224 void fail_recordLibraryElements() { | |
| 225 fail("Implement this"); | |
| 226 } | |
| 227 | |
| 228 @override | |
| 229 void setUp() { | |
| 230 _context = new AnalysisContextImpl(); | |
| 231 _sourceFactory = new SourceFactory([ | |
| 232 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), | |
| 233 new FileUriResolver() | |
| 234 ]); | |
| 235 _context.sourceFactory = _sourceFactory; | |
| 236 AnalysisOptionsImpl options = | |
| 237 new AnalysisOptionsImpl.from(_context.analysisOptions); | |
| 238 options.cacheSize = 256; | |
| 239 _context.analysisOptions = options; | |
| 240 } | |
| 241 | |
| 242 @override | |
| 243 void tearDown() { | |
| 244 _context = null; | |
| 245 _sourceFactory = null; | |
| 246 super.tearDown(); | |
| 247 } | |
| 248 | |
| 249 Future test_applyChanges_add() { | |
| 250 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 251 _context.onSourcesChanged.listen(listener.onData); | |
| 252 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | |
| 253 Source source = | |
| 254 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 255 ChangeSet changeSet = new ChangeSet(); | |
| 256 changeSet.addedSource(source); | |
| 257 _context.applyChanges(changeSet); | |
| 258 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | |
| 259 return pumpEventQueue().then((_) { | |
| 260 listener.assertEvent(wereSourcesAdded: true); | |
| 261 listener.assertNoMoreEvents(); | |
| 262 }); | |
| 263 } | |
| 264 | |
| 265 Future test_applyChanges_change() { | |
| 266 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 267 _context.onSourcesChanged.listen(listener.onData); | |
| 268 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | |
| 269 Source source = | |
| 270 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 271 ChangeSet changeSet1 = new ChangeSet(); | |
| 272 changeSet1.addedSource(source); | |
| 273 _context.applyChanges(changeSet1); | |
| 274 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | |
| 275 Source source2 = | |
| 276 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); | |
| 277 ChangeSet changeSet2 = new ChangeSet(); | |
| 278 changeSet2.addedSource(source2); | |
| 279 changeSet2.changedSource(source); | |
| 280 _context.applyChanges(changeSet2); | |
| 281 return pumpEventQueue().then((_) { | |
| 282 listener.assertEvent(wereSourcesAdded: true); | |
| 283 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | |
| 284 listener.assertNoMoreEvents(); | |
| 285 }); | |
| 286 } | |
| 287 | |
| 288 Future test_applyChanges_change_content() { | |
| 289 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 290 _context.onSourcesChanged.listen(listener.onData); | |
| 291 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | |
| 292 Source source = | |
| 293 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 294 ChangeSet changeSet1 = new ChangeSet(); | |
| 295 changeSet1.addedSource(source); | |
| 296 _context.applyChanges(changeSet1); | |
| 297 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | |
| 298 Source source2 = | |
| 299 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); | |
| 300 ChangeSet changeSet2 = new ChangeSet(); | |
| 301 changeSet2.addedSource(source2); | |
| 302 changeSet2.changedContent(source, 'library test;'); | |
| 303 _context.applyChanges(changeSet2); | |
| 304 return pumpEventQueue().then((_) { | |
| 305 listener.assertEvent(wereSourcesAdded: true); | |
| 306 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | |
| 307 listener.assertNoMoreEvents(); | |
| 308 }); | |
| 309 } | |
| 310 | |
| 311 void test_applyChanges_change_flush_element() { | |
| 312 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 313 _sourceFactory = _context.sourceFactory; | |
| 314 Source librarySource = _addSource( | |
| 315 "/lib.dart", | |
| 316 r''' | |
| 317 library lib; | |
| 318 int a = 0;'''); | |
| 319 expect(_context.computeLibraryElement(librarySource), isNotNull); | |
| 320 _context.setContents( | |
| 321 librarySource, | |
| 322 r''' | |
| 323 library lib; | |
| 324 int aa = 0;'''); | |
| 325 expect(_context.getLibraryElement(librarySource), isNull); | |
| 326 } | |
| 327 | |
| 328 Future test_applyChanges_change_multiple() { | |
| 329 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 330 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 331 _context.onSourcesChanged.listen(listener.onData); | |
| 332 _sourceFactory = _context.sourceFactory; | |
| 333 String libraryContents1 = r''' | |
| 334 library lib; | |
| 335 part 'part.dart'; | |
| 336 int a = 0;'''; | |
| 337 Source librarySource = _addSource("/lib.dart", libraryContents1); | |
| 338 String partContents1 = r''' | |
| 339 part of lib; | |
| 340 int b = a;'''; | |
| 341 Source partSource = _addSource("/part.dart", partContents1); | |
| 342 _context.computeLibraryElement(librarySource); | |
| 343 String libraryContents2 = r''' | |
| 344 library lib; | |
| 345 part 'part.dart'; | |
| 346 int aa = 0;'''; | |
| 347 _context.setContents(librarySource, libraryContents2); | |
| 348 String partContents2 = r''' | |
| 349 part of lib; | |
| 350 int b = aa;'''; | |
| 351 _context.setContents(partSource, partContents2); | |
| 352 _context.computeLibraryElement(librarySource); | |
| 353 CompilationUnit libraryUnit = | |
| 354 _context.resolveCompilationUnit2(librarySource, librarySource); | |
| 355 CompilationUnit partUnit = | |
| 356 _context.resolveCompilationUnit2(partSource, librarySource); | |
| 357 TopLevelVariableDeclaration declaration = | |
| 358 libraryUnit.declarations[0] as TopLevelVariableDeclaration; | |
| 359 Element declarationElement = declaration.variables.variables[0].element; | |
| 360 TopLevelVariableDeclaration use = | |
| 361 partUnit.declarations[0] as TopLevelVariableDeclaration; | |
| 362 Element useElement = (use.variables.variables[0].initializer | |
| 363 as SimpleIdentifier).staticElement; | |
| 364 expect((useElement as PropertyAccessorElement).variable, | |
| 365 same(declarationElement)); | |
| 366 return pumpEventQueue().then((_) { | |
| 367 listener.assertEvent(wereSourcesAdded: true); | |
| 368 listener.assertEvent(changedSources: [librarySource]); | |
| 369 listener.assertEvent(wereSourcesAdded: true); | |
| 370 listener.assertEvent(changedSources: [partSource]); | |
| 371 listener.assertEvent(changedSources: [librarySource]); | |
| 372 listener.assertEvent(changedSources: [partSource]); | |
| 373 listener.assertNoMoreEvents(); | |
| 374 }); | |
| 375 } | |
| 376 | |
| 377 Future test_applyChanges_change_range() { | |
| 378 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 379 _context.onSourcesChanged.listen(listener.onData); | |
| 380 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | |
| 381 Source source = | |
| 382 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 383 ChangeSet changeSet1 = new ChangeSet(); | |
| 384 changeSet1.addedSource(source); | |
| 385 _context.applyChanges(changeSet1); | |
| 386 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | |
| 387 Source source2 = | |
| 388 new FileBasedSource(FileUtilities2.createFile("/test2.dart")); | |
| 389 ChangeSet changeSet2 = new ChangeSet(); | |
| 390 changeSet2.addedSource(source2); | |
| 391 changeSet2.changedRange(source, 'library test;', 0, 0, 13); | |
| 392 _context.applyChanges(changeSet2); | |
| 393 return pumpEventQueue().then((_) { | |
| 394 listener.assertEvent(wereSourcesAdded: true); | |
| 395 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | |
| 396 listener.assertNoMoreEvents(); | |
| 397 }); | |
| 398 } | |
| 399 | |
| 400 void test_applyChanges_empty() { | |
| 401 _context.applyChanges(new ChangeSet()); | |
| 402 expect(_context.performAnalysisTask().changeNotices, isNull); | |
| 403 } | |
| 404 | |
| 405 void test_applyChanges_overriddenSource() { | |
| 406 // Note: addSource adds the source to the contentCache. | |
| 407 Source source = _addSource("/test.dart", "library test;"); | |
| 408 _context.computeErrors(source); | |
| 409 while (!_context.sourcesNeedingProcessing.isEmpty) { | |
| 410 _context.performAnalysisTask(); | |
| 411 } | |
| 412 // Adding the source as a changedSource should have no effect since | |
| 413 // it is already overridden in the content cache. | |
| 414 ChangeSet changeSet = new ChangeSet(); | |
| 415 changeSet.changedSource(source); | |
| 416 _context.applyChanges(changeSet); | |
| 417 expect(_context.sourcesNeedingProcessing, hasLength(0)); | |
| 418 } | |
| 419 | |
| 420 Future test_applyChanges_remove() { | |
| 421 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 422 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 423 _context.onSourcesChanged.listen(listener.onData); | |
| 424 _sourceFactory = _context.sourceFactory; | |
| 425 String libAContents = r''' | |
| 426 library libA; | |
| 427 import 'libB.dart';'''; | |
| 428 Source libA = _addSource("/libA.dart", libAContents); | |
| 429 String libBContents = "library libB;"; | |
| 430 Source libB = _addSource("/libB.dart", libBContents); | |
| 431 LibraryElement libAElement = _context.computeLibraryElement(libA); | |
| 432 List<LibraryElement> importedLibraries = libAElement.importedLibraries; | |
| 433 expect(importedLibraries, hasLength(2)); | |
| 434 _context.computeErrors(libA); | |
| 435 _context.computeErrors(libB); | |
| 436 expect(_context.sourcesNeedingProcessing, hasLength(0)); | |
| 437 _context.setContents(libB, null); | |
| 438 _removeSource(libB); | |
| 439 List<Source> sources = _context.sourcesNeedingProcessing; | |
| 440 expect(sources, hasLength(1)); | |
| 441 expect(sources[0], same(libA)); | |
| 442 libAElement = _context.computeLibraryElement(libA); | |
| 443 importedLibraries = libAElement.importedLibraries; | |
| 444 expect(importedLibraries, hasLength(1)); | |
| 445 return pumpEventQueue().then((_) { | |
| 446 listener.assertEvent(wereSourcesAdded: true); | |
| 447 listener.assertEvent(changedSources: [libA]); | |
| 448 listener.assertEvent(wereSourcesAdded: true); | |
| 449 listener.assertEvent(changedSources: [libB]); | |
| 450 listener.assertEvent(changedSources: [libB]); | |
| 451 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | |
| 452 listener.assertNoMoreEvents(); | |
| 453 }); | |
| 454 } | |
| 455 | |
| 456 /** | |
| 457 * IDEA uses the following scenario: | |
| 458 * 1. Add overlay. | |
| 459 * 2. Change overlay. | |
| 460 * 3. If the contents of the document buffer is the same as the contents | |
| 461 * of the file, remove overlay. | |
| 462 * So, we need to try to use incremental resolution for removing overlays too. | |
| 463 */ | |
| 464 void test_applyChanges_remove_incremental() { | |
| 465 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | |
| 466 Source source = resourceProvider | |
| 467 .newFile( | |
| 468 '/test.dart', | |
| 469 r''' | |
| 470 main() { | |
| 471 print(1); | |
| 472 } | |
| 473 ''') | |
| 474 .createSource(); | |
| 475 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 476 _context.analysisOptions = new AnalysisOptionsImpl()..incremental = true; | |
| 477 _context.applyChanges(new ChangeSet()..addedSource(source)); | |
| 478 // remember compilation unit | |
| 479 _analyzeAll_assertFinished(); | |
| 480 CompilationUnit unit = _context.getResolvedCompilationUnit2(source, source); | |
| 481 // add overlay | |
| 482 _context.setContents( | |
| 483 source, | |
| 484 r''' | |
| 485 main() { | |
| 486 print(12); | |
| 487 } | |
| 488 '''); | |
| 489 _analyzeAll_assertFinished(); | |
| 490 expect(_context.getResolvedCompilationUnit2(source, source), unit); | |
| 491 // remove overlay | |
| 492 _context.setContents(source, null); | |
| 493 _context.validateCacheConsistency(); | |
| 494 _analyzeAll_assertFinished(); | |
| 495 expect(_context.getResolvedCompilationUnit2(source, source), unit); | |
| 496 } | |
| 497 | |
| 498 Future test_applyChanges_removeContainer() { | |
| 499 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 500 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 501 _context.onSourcesChanged.listen(listener.onData); | |
| 502 _sourceFactory = _context.sourceFactory; | |
| 503 String libAContents = r''' | |
| 504 library libA; | |
| 505 import 'libB.dart';'''; | |
| 506 Source libA = _addSource("/libA.dart", libAContents); | |
| 507 String libBContents = "library libB;"; | |
| 508 Source libB = _addSource("/libB.dart", libBContents); | |
| 509 _context.computeLibraryElement(libA); | |
| 510 _context.computeErrors(libA); | |
| 511 _context.computeErrors(libB); | |
| 512 expect(_context.sourcesNeedingProcessing, hasLength(0)); | |
| 513 ChangeSet changeSet = new ChangeSet(); | |
| 514 SourceContainer removedContainer = | |
| 515 new _AnalysisContextImplTest_test_applyChanges_removeContainer(libB); | |
| 516 changeSet.removedContainer(removedContainer); | |
| 517 _context.applyChanges(changeSet); | |
| 518 List<Source> sources = _context.sourcesNeedingProcessing; | |
| 519 expect(sources, hasLength(1)); | |
| 520 expect(sources[0], same(libA)); | |
| 521 return pumpEventQueue().then((_) { | |
| 522 listener.assertEvent(wereSourcesAdded: true); | |
| 523 listener.assertEvent(changedSources: [libA]); | |
| 524 listener.assertEvent(wereSourcesAdded: true); | |
| 525 listener.assertEvent(changedSources: [libB]); | |
| 526 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | |
| 527 listener.assertNoMoreEvents(); | |
| 528 }); | |
| 529 } | |
| 530 | |
| 531 void test_computeDocumentationComment_block() { | |
| 532 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 533 _sourceFactory = _context.sourceFactory; | |
| 534 String comment = "/** Comment */"; | |
| 535 Source source = _addSource( | |
| 536 "/test.dart", | |
| 537 """ | |
| 538 $comment | |
| 539 class A {}"""); | |
| 540 LibraryElement libraryElement = _context.computeLibraryElement(source); | |
| 541 expect(libraryElement, isNotNull); | |
| 542 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | |
| 543 expect(libraryElement, isNotNull); | |
| 544 expect(_context.computeDocumentationComment(classElement), comment); | |
| 545 } | |
| 546 | |
| 547 void test_computeDocumentationComment_none() { | |
| 548 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 549 _sourceFactory = _context.sourceFactory; | |
| 550 Source source = _addSource("/test.dart", "class A {}"); | |
| 551 LibraryElement libraryElement = _context.computeLibraryElement(source); | |
| 552 expect(libraryElement, isNotNull); | |
| 553 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | |
| 554 expect(libraryElement, isNotNull); | |
| 555 expect(_context.computeDocumentationComment(classElement), isNull); | |
| 556 } | |
| 557 | |
| 558 void test_computeDocumentationComment_null() { | |
| 559 expect(_context.computeDocumentationComment(null), isNull); | |
| 560 } | |
| 561 | |
| 562 void test_computeDocumentationComment_singleLine_multiple_EOL_n() { | |
| 563 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 564 _sourceFactory = _context.sourceFactory; | |
| 565 String comment = "/// line 1\n/// line 2\n/// line 3\n"; | |
| 566 Source source = _addSource("/test.dart", "${comment}class A {}"); | |
| 567 LibraryElement libraryElement = _context.computeLibraryElement(source); | |
| 568 expect(libraryElement, isNotNull); | |
| 569 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | |
| 570 expect(libraryElement, isNotNull); | |
| 571 String actual = _context.computeDocumentationComment(classElement); | |
| 572 expect(actual, "/// line 1\n/// line 2\n/// line 3"); | |
| 573 } | |
| 574 | |
| 575 void test_computeDocumentationComment_singleLine_multiple_EOL_rn() { | |
| 576 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 577 _sourceFactory = _context.sourceFactory; | |
| 578 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; | |
| 579 Source source = _addSource("/test.dart", "${comment}class A {}"); | |
| 580 LibraryElement libraryElement = _context.computeLibraryElement(source); | |
| 581 expect(libraryElement, isNotNull); | |
| 582 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | |
| 583 expect(libraryElement, isNotNull); | |
| 584 String actual = _context.computeDocumentationComment(classElement); | |
| 585 expect(actual, "/// line 1\n/// line 2\n/// line 3"); | |
| 586 } | |
| 587 | |
| 588 void test_computeErrors_dart_none() { | |
| 589 Source source = _addSource("/lib.dart", "library lib;"); | |
| 590 List<AnalysisError> errors = _context.computeErrors(source); | |
| 591 expect(errors, hasLength(0)); | |
| 592 } | |
| 593 | |
| 594 void test_computeErrors_dart_part() { | |
| 595 Source librarySource = | |
| 596 _addSource("/lib.dart", "library lib; part 'part.dart';"); | |
| 597 Source partSource = _addSource("/part.dart", "part of 'lib';"); | |
| 598 _context.parseCompilationUnit(librarySource); | |
| 599 List<AnalysisError> errors = _context.computeErrors(partSource); | |
| 600 expect(errors, isNotNull); | |
| 601 expect(errors.length > 0, isTrue); | |
| 602 } | |
| 603 | |
| 604 void test_computeErrors_dart_some() { | |
| 605 Source source = _addSource("/lib.dart", "library 'lib';"); | |
| 606 List<AnalysisError> errors = _context.computeErrors(source); | |
| 607 expect(errors, isNotNull); | |
| 608 expect(errors.length > 0, isTrue); | |
| 609 } | |
| 610 | |
| 611 void test_computeErrors_html_none() { | |
| 612 Source source = _addSource("/test.html", "<html></html>"); | |
| 613 List<AnalysisError> errors = _context.computeErrors(source); | |
| 614 expect(errors, hasLength(0)); | |
| 615 } | |
| 616 | |
| 617 void test_computeExportedLibraries_none() { | |
| 618 Source source = _addSource("/test.dart", "library test;"); | |
| 619 expect(_context.computeExportedLibraries(source), hasLength(0)); | |
| 620 } | |
| 621 | |
| 622 void test_computeExportedLibraries_some() { | |
| 623 // addSource("/lib1.dart", "library lib1;"); | |
| 624 // addSource("/lib2.dart", "library lib2;"); | |
| 625 Source source = _addSource( | |
| 626 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); | |
| 627 expect(_context.computeExportedLibraries(source), hasLength(2)); | |
| 628 } | |
| 629 | |
| 630 void test_computeHtmlElement_nonHtml() { | |
| 631 Source source = _addSource("/test.dart", "library test;"); | |
| 632 expect(_context.computeHtmlElement(source), isNull); | |
| 633 } | |
| 634 | |
| 635 void test_computeHtmlElement_valid() { | |
| 636 Source source = _addSource("/test.html", "<html></html>"); | |
| 637 HtmlElement element = _context.computeHtmlElement(source); | |
| 638 expect(element, isNotNull); | |
| 639 expect(_context.computeHtmlElement(source), same(element)); | |
| 640 } | |
| 641 | |
| 642 void test_computeImportedLibraries_none() { | |
| 643 Source source = _addSource("/test.dart", "library test;"); | |
| 644 expect(_context.computeImportedLibraries(source), hasLength(0)); | |
| 645 } | |
| 646 | |
| 647 void test_computeImportedLibraries_some() { | |
| 648 // addSource("/lib1.dart", "library lib1;"); | |
| 649 // addSource("/lib2.dart", "library lib2;"); | |
| 650 Source source = _addSource( | |
| 651 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | |
| 652 expect(_context.computeImportedLibraries(source), hasLength(2)); | |
| 653 } | |
| 654 | |
| 655 void test_computeKindOf_html() { | |
| 656 Source source = _addSource("/test.html", ""); | |
| 657 expect(_context.computeKindOf(source), same(SourceKind.HTML)); | |
| 658 } | |
| 659 | |
| 660 void test_computeKindOf_library() { | |
| 661 Source source = _addSource("/test.dart", "library lib;"); | |
| 662 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); | |
| 663 } | |
| 664 | |
| 665 void test_computeKindOf_libraryAndPart() { | |
| 666 Source source = _addSource("/test.dart", "library lib; part of lib;"); | |
| 667 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); | |
| 668 } | |
| 669 | |
| 670 void test_computeKindOf_part() { | |
| 671 Source source = _addSource("/test.dart", "part of lib;"); | |
| 672 expect(_context.computeKindOf(source), same(SourceKind.PART)); | |
| 673 } | |
| 674 | |
| 675 void test_computeLibraryElement() { | |
| 676 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 677 _sourceFactory = _context.sourceFactory; | |
| 678 Source source = _addSource("/test.dart", "library lib;"); | |
| 679 LibraryElement element = _context.computeLibraryElement(source); | |
| 680 expect(element, isNotNull); | |
| 681 } | |
| 682 | |
| 683 void test_computeLineInfo_dart() { | |
| 684 Source source = _addSource( | |
| 685 "/test.dart", | |
| 686 r''' | |
| 687 library lib; | |
| 688 | |
| 689 main() {}'''); | |
| 690 LineInfo info = _context.computeLineInfo(source); | |
| 691 expect(info, isNotNull); | |
| 692 } | |
| 693 | |
| 694 void test_computeLineInfo_html() { | |
| 695 Source source = _addSource( | |
| 696 "/test.html", | |
| 697 r''' | |
| 698 <html> | |
| 699 <body> | |
| 700 <h1>A</h1> | |
| 701 </body> | |
| 702 </html>'''); | |
| 703 LineInfo info = _context.computeLineInfo(source); | |
| 704 expect(info, isNotNull); | |
| 705 } | |
| 706 | |
| 707 void test_computeResolvableCompilationUnit_dart_exception() { | |
| 708 TestSource source = _addSourceWithException("/test.dart"); | |
| 709 try { | |
| 710 _context.computeResolvableCompilationUnit(source); | |
| 711 fail("Expected AnalysisException"); | |
| 712 } on AnalysisException { | |
| 713 // Expected | |
| 714 } | |
| 715 } | |
| 716 | |
| 717 void test_computeResolvableCompilationUnit_html_exception() { | |
| 718 Source source = _addSource("/lib.html", "<html></html>"); | |
| 719 try { | |
| 720 _context.computeResolvableCompilationUnit(source); | |
| 721 fail("Expected AnalysisException"); | |
| 722 } on AnalysisException { | |
| 723 // Expected | |
| 724 } | |
| 725 } | |
| 726 | |
| 727 void test_computeResolvableCompilationUnit_valid() { | |
| 728 Source source = _addSource("/lib.dart", "library lib;"); | |
| 729 CompilationUnit parsedUnit = _context.parseCompilationUnit(source); | |
| 730 expect(parsedUnit, isNotNull); | |
| 731 CompilationUnit resolvedUnit = | |
| 732 _context.computeResolvableCompilationUnit(source); | |
| 733 expect(resolvedUnit, isNotNull); | |
| 734 expect(resolvedUnit, same(parsedUnit)); | |
| 735 } | |
| 736 | |
| 737 Future test_computeResolvedCompilationUnitAsync() { | |
| 738 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 739 _sourceFactory = _context.sourceFactory; | |
| 740 Source source = _addSource("/lib.dart", "library lib;"); | |
| 741 // Complete all pending analysis tasks and flush the AST so that it won't | |
| 742 // be available immediately. | |
| 743 _performPendingAnalysisTasks(); | |
| 744 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
| 745 dartEntry.flushAstStructures(); | |
| 746 bool completed = false; | |
| 747 _context | |
| 748 .computeResolvedCompilationUnitAsync(source, source) | |
| 749 .then((CompilationUnit unit) { | |
| 750 expect(unit, isNotNull); | |
| 751 completed = true; | |
| 752 }); | |
| 753 return pumpEventQueue().then((_) { | |
| 754 expect(completed, isFalse); | |
| 755 _performPendingAnalysisTasks(); | |
| 756 }).then((_) => pumpEventQueue()).then((_) { | |
| 757 expect(completed, isTrue); | |
| 758 }); | |
| 759 } | |
| 760 | |
| 761 Future test_computeResolvedCompilationUnitAsync_afterDispose() { | |
| 762 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 763 _sourceFactory = _context.sourceFactory; | |
| 764 Source source = _addSource("/lib.dart", "library lib;"); | |
| 765 // Complete all pending analysis tasks and flush the AST so that it won't | |
| 766 // be available immediately. | |
| 767 _performPendingAnalysisTasks(); | |
| 768 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
| 769 dartEntry.flushAstStructures(); | |
| 770 // Dispose of the context. | |
| 771 _context.dispose(); | |
| 772 // Any attempt to start an asynchronous computation should return a future | |
| 773 // which completes with error. | |
| 774 CancelableFuture<CompilationUnit> future = | |
| 775 _context.computeResolvedCompilationUnitAsync(source, source); | |
| 776 bool completed = false; | |
| 777 future.then((CompilationUnit unit) { | |
| 778 fail('Future should have completed with error'); | |
| 779 }, onError: (error) { | |
| 780 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); | |
| 781 completed = true; | |
| 782 }); | |
| 783 return pumpEventQueue().then((_) { | |
| 784 expect(completed, isTrue); | |
| 785 }); | |
| 786 } | |
| 787 | |
| 788 Future test_computeResolvedCompilationUnitAsync_cancel() { | |
| 789 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 790 _sourceFactory = _context.sourceFactory; | |
| 791 Source source = _addSource("/lib.dart", "library lib;"); | |
| 792 // Complete all pending analysis tasks and flush the AST so that it won't | |
| 793 // be available immediately. | |
| 794 _performPendingAnalysisTasks(); | |
| 795 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
| 796 dartEntry.flushAstStructures(); | |
| 797 CancelableFuture<CompilationUnit> future = | |
| 798 _context.computeResolvedCompilationUnitAsync(source, source); | |
| 799 bool completed = false; | |
| 800 future.then((CompilationUnit unit) { | |
| 801 fail('Future should have been canceled'); | |
| 802 }, onError: (error) { | |
| 803 expect(error, new isInstanceOf<FutureCanceledError>()); | |
| 804 completed = true; | |
| 805 }); | |
| 806 expect(completed, isFalse); | |
| 807 expect(_context.pendingFutureSources_forTesting, isNotEmpty); | |
| 808 future.cancel(); | |
| 809 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
| 810 return pumpEventQueue().then((_) { | |
| 811 expect(completed, isTrue); | |
| 812 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
| 813 }); | |
| 814 } | |
| 815 | |
| 816 Future test_computeResolvedCompilationUnitAsync_dispose() { | |
| 817 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 818 _sourceFactory = _context.sourceFactory; | |
| 819 Source source = _addSource("/lib.dart", "library lib;"); | |
| 820 // Complete all pending analysis tasks and flush the AST so that it won't | |
| 821 // be available immediately. | |
| 822 _performPendingAnalysisTasks(); | |
| 823 DartEntry dartEntry = _context.getReadableSourceEntryOrNull(source); | |
| 824 dartEntry.flushAstStructures(); | |
| 825 CancelableFuture<CompilationUnit> future = | |
| 826 _context.computeResolvedCompilationUnitAsync(source, source); | |
| 827 bool completed = false; | |
| 828 future.then((CompilationUnit unit) { | |
| 829 fail('Future should have completed with error'); | |
| 830 }, onError: (error) { | |
| 831 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); | |
| 832 completed = true; | |
| 833 }); | |
| 834 expect(completed, isFalse); | |
| 835 expect(_context.pendingFutureSources_forTesting, isNotEmpty); | |
| 836 // Disposing of the context should cause all pending futures to complete | |
| 837 // with AnalysisNotScheduled, so that no clients are left hanging. | |
| 838 _context.dispose(); | |
| 839 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
| 840 return pumpEventQueue().then((_) { | |
| 841 expect(completed, isTrue); | |
| 842 expect(_context.pendingFutureSources_forTesting, isEmpty); | |
| 843 }); | |
| 844 } | |
| 845 | |
| 846 Future test_computeResolvedCompilationUnitAsync_unrelatedLibrary() { | |
| 847 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 848 _sourceFactory = _context.sourceFactory; | |
| 849 Source librarySource = _addSource("/lib.dart", "library lib;"); | |
| 850 Source partSource = _addSource("/part.dart", "part of foo;"); | |
| 851 bool completed = false; | |
| 852 _context | |
| 853 .computeResolvedCompilationUnitAsync(partSource, librarySource) | |
| 854 .then((_) { | |
| 855 fail('Expected resolution to fail'); | |
| 856 }, onError: (e) { | |
| 857 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); | |
| 858 completed = true; | |
| 859 }); | |
| 860 return pumpEventQueue().then((_) { | |
| 861 expect(completed, isFalse); | |
| 862 _performPendingAnalysisTasks(); | |
| 863 }).then((_) => pumpEventQueue()).then((_) { | |
| 864 expect(completed, isTrue); | |
| 865 }); | |
| 866 } | |
| 867 | |
| 868 void test_configurationData() { | |
| 869 var key = new newContext.ResultDescriptor('test_key', ''); | |
| 870 var testData = ['test', 'data']; | |
| 871 _context.setConfigurationData(key, testData); | |
| 872 expect(_context.getConfigurationData(key), testData); | |
| 873 var unusedKey = new newContext.ResultDescriptor('unused_key', ''); | |
| 874 expect(_context.getConfigurationData(unusedKey), null); | |
| 875 } | |
| 876 | |
| 877 void test_dispose() { | |
| 878 expect(_context.isDisposed, isFalse); | |
| 879 _context.dispose(); | |
| 880 expect(_context.isDisposed, isTrue); | |
| 881 } | |
| 882 | |
| 883 void test_exists_false() { | |
| 884 TestSource source = new TestSource(); | |
| 885 source.exists2 = false; | |
| 886 expect(_context.exists(source), isFalse); | |
| 887 } | |
| 888 | |
| 889 void test_exists_null() { | |
| 890 expect(_context.exists(null), isFalse); | |
| 891 } | |
| 892 | |
| 893 void test_exists_overridden() { | |
| 894 Source source = new TestSource(); | |
| 895 _context.setContents(source, ""); | |
| 896 expect(_context.exists(source), isTrue); | |
| 897 } | |
| 898 | |
| 899 void test_exists_true() { | |
| 900 expect(_context.exists(new AnalysisContextImplTest_Source_exists_true()), | |
| 901 isTrue); | |
| 902 } | |
| 903 | |
| 904 void test_getAnalysisOptions() { | |
| 905 expect(_context.analysisOptions, isNotNull); | |
| 906 } | |
| 907 | |
| 908 void test_getContents_fromSource() { | |
| 909 String content = "library lib;"; | |
| 910 TimestampedData<String> contents = | |
| 911 _context.getContents(new TestSource('/test.dart', content)); | |
| 912 expect(contents.data.toString(), content); | |
| 913 } | |
| 914 | |
| 915 void test_getContents_overridden() { | |
| 916 String content = "library lib;"; | |
| 917 Source source = new TestSource(); | |
| 918 _context.setContents(source, content); | |
| 919 TimestampedData<String> contents = _context.getContents(source); | |
| 920 expect(contents.data.toString(), content); | |
| 921 } | |
| 922 | |
| 923 void test_getContents_unoverridden() { | |
| 924 String content = "library lib;"; | |
| 925 Source source = new TestSource('/test.dart', content); | |
| 926 _context.setContents(source, "part of lib;"); | |
| 927 _context.setContents(source, null); | |
| 928 TimestampedData<String> contents = _context.getContents(source); | |
| 929 expect(contents.data.toString(), content); | |
| 930 } | |
| 931 | |
| 932 void test_getDeclaredVariables() { | |
| 933 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 934 expect(_context.declaredVariables, isNotNull); | |
| 935 } | |
| 936 | |
| 937 void test_getElement() { | |
| 938 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 939 _sourceFactory = _context.sourceFactory; | |
| 940 LibraryElement core = | |
| 941 _context.computeLibraryElement(_sourceFactory.forUri("dart:core")); | |
| 942 expect(core, isNotNull); | |
| 943 ClassElement classObject = | |
| 944 _findClass(core.definingCompilationUnit, "Object"); | |
| 945 expect(classObject, isNotNull); | |
| 946 ElementLocation location = classObject.location; | |
| 947 Element element = _context.getElement(location); | |
| 948 expect(element, same(classObject)); | |
| 949 } | |
| 950 | |
| 951 void test_getElement_constructor_named() { | |
| 952 Source source = _addSource( | |
| 953 "/lib.dart", | |
| 954 r''' | |
| 955 class A { | |
| 956 A.named() {} | |
| 957 }'''); | |
| 958 _analyzeAll_assertFinished(); | |
| 959 LibraryElement library = _context.computeLibraryElement(source); | |
| 960 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
| 961 ConstructorElement constructor = classA.constructors[0]; | |
| 962 ElementLocation location = constructor.location; | |
| 963 Element element = _context.getElement(location); | |
| 964 expect(element, same(constructor)); | |
| 965 } | |
| 966 | |
| 967 void test_getElement_constructor_unnamed() { | |
| 968 Source source = _addSource( | |
| 969 "/lib.dart", | |
| 970 r''' | |
| 971 class A { | |
| 972 A() {} | |
| 973 }'''); | |
| 974 _analyzeAll_assertFinished(); | |
| 975 LibraryElement library = _context.computeLibraryElement(source); | |
| 976 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
| 977 ConstructorElement constructor = classA.constructors[0]; | |
| 978 ElementLocation location = constructor.location; | |
| 979 Element element = _context.getElement(location); | |
| 980 expect(element, same(constructor)); | |
| 981 } | |
| 982 | |
| 983 void test_getElement_enum() { | |
| 984 Source source = _addSource('/test.dart', 'enum MyEnum {A, B, C}'); | |
| 985 _analyzeAll_assertFinished(); | |
| 986 LibraryElement library = _context.computeLibraryElement(source); | |
| 987 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); | |
| 988 ElementLocation location = myEnum.location; | |
| 989 Element element = _context.getElement(location); | |
| 990 expect(element, same(myEnum)); | |
| 991 } | |
| 992 | |
| 993 void test_getErrors_dart_none() { | |
| 994 Source source = _addSource("/lib.dart", "library lib;"); | |
| 995 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 996 expect(errors, hasLength(0)); | |
| 997 _context.computeErrors(source); | |
| 998 errors = _context.getErrors(source).errors; | |
| 999 expect(errors, hasLength(0)); | |
| 1000 } | |
| 1001 | |
| 1002 void test_getErrors_dart_some() { | |
| 1003 Source source = _addSource("/lib.dart", "library 'lib';"); | |
| 1004 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1005 expect(errors, hasLength(0)); | |
| 1006 _context.computeErrors(source); | |
| 1007 errors = _context.getErrors(source).errors; | |
| 1008 expect(errors, hasLength(1)); | |
| 1009 } | |
| 1010 | |
| 1011 void test_getErrors_html_none() { | |
| 1012 Source source = _addSource("/test.html", "<html></html>"); | |
| 1013 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1014 expect(errors, hasLength(0)); | |
| 1015 _context.computeErrors(source); | |
| 1016 errors = _context.getErrors(source).errors; | |
| 1017 expect(errors, hasLength(0)); | |
| 1018 } | |
| 1019 | |
| 1020 void test_getErrors_html_some() { | |
| 1021 Source source = _addSource( | |
| 1022 "/test.html", | |
| 1023 r''' | |
| 1024 <html><head> | |
| 1025 <script type='application/dart' src='test.dart'/> | |
| 1026 </head></html>'''); | |
| 1027 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1028 expect(errors, hasLength(0)); | |
| 1029 _context.computeErrors(source); | |
| 1030 errors = _context.getErrors(source).errors; | |
| 1031 expect(errors, hasLength(1)); | |
| 1032 } | |
| 1033 | |
| 1034 void test_getHtmlElement_dart() { | |
| 1035 Source source = _addSource("/test.dart", ""); | |
| 1036 expect(_context.getHtmlElement(source), isNull); | |
| 1037 expect(_context.computeHtmlElement(source), isNull); | |
| 1038 expect(_context.getHtmlElement(source), isNull); | |
| 1039 } | |
| 1040 | |
| 1041 void test_getHtmlElement_html() { | |
| 1042 Source source = _addSource("/test.html", "<html></html>"); | |
| 1043 HtmlElement element = _context.getHtmlElement(source); | |
| 1044 expect(element, isNull); | |
| 1045 _context.computeHtmlElement(source); | |
| 1046 element = _context.getHtmlElement(source); | |
| 1047 expect(element, isNotNull); | |
| 1048 } | |
| 1049 | |
| 1050 void test_getHtmlFilesReferencing_html() { | |
| 1051 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1052 _sourceFactory = _context.sourceFactory; | |
| 1053 Source htmlSource = _addSource( | |
| 1054 "/test.html", | |
| 1055 r''' | |
| 1056 <html><head> | |
| 1057 <script type='application/dart' src='test.dart'/> | |
| 1058 <script type='application/dart' src='test.js'/> | |
| 1059 </head></html>'''); | |
| 1060 Source librarySource = _addSource("/test.dart", "library lib;"); | |
| 1061 Source secondHtmlSource = _addSource("/test.html", "<html></html>"); | |
| 1062 _context.computeLibraryElement(librarySource); | |
| 1063 List<Source> result = _context.getHtmlFilesReferencing(secondHtmlSource); | |
| 1064 expect(result, hasLength(0)); | |
| 1065 _context.parseHtmlUnit(htmlSource); | |
| 1066 result = _context.getHtmlFilesReferencing(secondHtmlSource); | |
| 1067 expect(result, hasLength(0)); | |
| 1068 } | |
| 1069 | |
| 1070 void test_getHtmlFilesReferencing_library() { | |
| 1071 Source htmlSource = _addSource( | |
| 1072 "/test.html", | |
| 1073 r''' | |
| 1074 <html><head> | |
| 1075 <script type='application/dart' src='test.dart'/> | |
| 1076 <script type='application/dart' src='test.js'/> | |
| 1077 </head></html>'''); | |
| 1078 Source librarySource = _addSource("/test.dart", "library lib;"); | |
| 1079 List<Source> result = _context.getHtmlFilesReferencing(librarySource); | |
| 1080 expect(result, hasLength(0)); | |
| 1081 _context.parseHtmlUnit(htmlSource); | |
| 1082 result = _context.getHtmlFilesReferencing(librarySource); | |
| 1083 expect(result, hasLength(1)); | |
| 1084 expect(result[0], htmlSource); | |
| 1085 } | |
| 1086 | |
| 1087 void test_getHtmlFilesReferencing_part() { | |
| 1088 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1089 _sourceFactory = _context.sourceFactory; | |
| 1090 Source htmlSource = _addSource( | |
| 1091 "/test.html", | |
| 1092 r''' | |
| 1093 <html><head> | |
| 1094 <script type='application/dart' src='test.dart'/> | |
| 1095 <script type='application/dart' src='test.js'/> | |
| 1096 </head></html>'''); | |
| 1097 Source librarySource = | |
| 1098 _addSource("/test.dart", "library lib; part 'part.dart';"); | |
| 1099 Source partSource = _addSource("/part.dart", "part of lib;"); | |
| 1100 _context.computeLibraryElement(librarySource); | |
| 1101 List<Source> result = _context.getHtmlFilesReferencing(partSource); | |
| 1102 expect(result, hasLength(0)); | |
| 1103 _context.parseHtmlUnit(htmlSource); | |
| 1104 result = _context.getHtmlFilesReferencing(partSource); | |
| 1105 expect(result, hasLength(1)); | |
| 1106 expect(result[0], htmlSource); | |
| 1107 } | |
| 1108 | |
| 1109 void test_getHtmlSources() { | |
| 1110 List<Source> sources = _context.htmlSources; | |
| 1111 expect(sources, hasLength(0)); | |
| 1112 Source source = _addSource("/test.html", ""); | |
| 1113 _context.computeKindOf(source); | |
| 1114 sources = _context.htmlSources; | |
| 1115 expect(sources, hasLength(1)); | |
| 1116 expect(sources[0], source); | |
| 1117 } | |
| 1118 | |
| 1119 void test_getKindOf_html() { | |
| 1120 Source source = _addSource("/test.html", ""); | |
| 1121 expect(_context.getKindOf(source), same(SourceKind.HTML)); | |
| 1122 } | |
| 1123 | |
| 1124 void test_getKindOf_library() { | |
| 1125 Source source = _addSource("/test.dart", "library lib;"); | |
| 1126 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); | |
| 1127 _context.computeKindOf(source); | |
| 1128 expect(_context.getKindOf(source), same(SourceKind.LIBRARY)); | |
| 1129 } | |
| 1130 | |
| 1131 void test_getKindOf_part() { | |
| 1132 Source source = _addSource("/test.dart", "part of lib;"); | |
| 1133 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); | |
| 1134 _context.computeKindOf(source); | |
| 1135 expect(_context.getKindOf(source), same(SourceKind.PART)); | |
| 1136 } | |
| 1137 | |
| 1138 void test_getKindOf_unknown() { | |
| 1139 Source source = _addSource("/test.css", ""); | |
| 1140 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); | |
| 1141 } | |
| 1142 | |
| 1143 void test_getLaunchableClientLibrarySources() { | |
| 1144 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1145 _sourceFactory = _context.sourceFactory; | |
| 1146 List<Source> sources = _context.launchableClientLibrarySources; | |
| 1147 expect(sources, hasLength(0)); | |
| 1148 Source source = _addSource( | |
| 1149 "/test.dart", | |
| 1150 r''' | |
| 1151 import 'dart:html'; | |
| 1152 main() {}'''); | |
| 1153 _context.computeLibraryElement(source); | |
| 1154 sources = _context.launchableClientLibrarySources; | |
| 1155 expect(sources, hasLength(1)); | |
| 1156 } | |
| 1157 | |
| 1158 void test_getLaunchableServerLibrarySources() { | |
| 1159 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1160 _sourceFactory = _context.sourceFactory; | |
| 1161 List<Source> sources = _context.launchableServerLibrarySources; | |
| 1162 expect(sources, hasLength(0)); | |
| 1163 Source source = _addSource("/test.dart", "main() {}"); | |
| 1164 _context.computeLibraryElement(source); | |
| 1165 sources = _context.launchableServerLibrarySources; | |
| 1166 expect(sources, hasLength(1)); | |
| 1167 } | |
| 1168 | |
| 1169 void test_getLibrariesContaining() { | |
| 1170 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1171 _sourceFactory = _context.sourceFactory; | |
| 1172 Source librarySource = _addSource( | |
| 1173 "/lib.dart", | |
| 1174 r''' | |
| 1175 library lib; | |
| 1176 part 'part.dart';'''); | |
| 1177 Source partSource = _addSource("/part.dart", "part of lib;"); | |
| 1178 _context.computeLibraryElement(librarySource); | |
| 1179 List<Source> result = _context.getLibrariesContaining(librarySource); | |
| 1180 expect(result, hasLength(1)); | |
| 1181 expect(result[0], librarySource); | |
| 1182 result = _context.getLibrariesContaining(partSource); | |
| 1183 expect(result, hasLength(1)); | |
| 1184 expect(result[0], librarySource); | |
| 1185 } | |
| 1186 | |
| 1187 void test_getLibrariesDependingOn() { | |
| 1188 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1189 _sourceFactory = _context.sourceFactory; | |
| 1190 Source libASource = _addSource("/libA.dart", "library libA;"); | |
| 1191 _addSource("/libB.dart", "library libB;"); | |
| 1192 Source lib1Source = _addSource( | |
| 1193 "/lib1.dart", | |
| 1194 r''' | |
| 1195 library lib1; | |
| 1196 import 'libA.dart'; | |
| 1197 export 'libB.dart';'''); | |
| 1198 Source lib2Source = _addSource( | |
| 1199 "/lib2.dart", | |
| 1200 r''' | |
| 1201 library lib2; | |
| 1202 import 'libB.dart'; | |
| 1203 export 'libA.dart';'''); | |
| 1204 _context.computeLibraryElement(lib1Source); | |
| 1205 _context.computeLibraryElement(lib2Source); | |
| 1206 List<Source> result = _context.getLibrariesDependingOn(libASource); | |
| 1207 expect(result, unorderedEquals([lib1Source, lib2Source])); | |
| 1208 } | |
| 1209 | |
| 1210 void test_getLibrariesReferencedFromHtml() { | |
| 1211 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1212 _sourceFactory = _context.sourceFactory; | |
| 1213 Source htmlSource = _addSource( | |
| 1214 "/test.html", | |
| 1215 r''' | |
| 1216 <html><head> | |
| 1217 <script type='application/dart' src='test.dart'/> | |
| 1218 <script type='application/dart' src='test.js'/> | |
| 1219 </head></html>'''); | |
| 1220 Source librarySource = _addSource("/test.dart", "library lib;"); | |
| 1221 _context.computeLibraryElement(librarySource); | |
| 1222 _context.parseHtmlUnit(htmlSource); | |
| 1223 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); | |
| 1224 expect(result, hasLength(1)); | |
| 1225 expect(result[0], librarySource); | |
| 1226 } | |
| 1227 | |
| 1228 void test_getLibrariesReferencedFromHtml_no() { | |
| 1229 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1230 _sourceFactory = _context.sourceFactory; | |
| 1231 Source htmlSource = _addSource( | |
| 1232 "/test.html", | |
| 1233 r''' | |
| 1234 <html><head> | |
| 1235 <script type='application/dart' src='test.js'/> | |
| 1236 </head></html>'''); | |
| 1237 _addSource("/test.dart", "library lib;"); | |
| 1238 _context.parseHtmlUnit(htmlSource); | |
| 1239 List<Source> result = _context.getLibrariesReferencedFromHtml(htmlSource); | |
| 1240 expect(result, hasLength(0)); | |
| 1241 } | |
| 1242 | |
| 1243 void test_getLibraryElement() { | |
| 1244 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1245 _sourceFactory = _context.sourceFactory; | |
| 1246 Source source = _addSource("/test.dart", "library lib;"); | |
| 1247 LibraryElement element = _context.getLibraryElement(source); | |
| 1248 expect(element, isNull); | |
| 1249 _context.computeLibraryElement(source); | |
| 1250 element = _context.getLibraryElement(source); | |
| 1251 expect(element, isNotNull); | |
| 1252 } | |
| 1253 | |
| 1254 void test_getLibrarySources() { | |
| 1255 List<Source> sources = _context.librarySources; | |
| 1256 int originalLength = sources.length; | |
| 1257 Source source = _addSource("/test.dart", "library lib;"); | |
| 1258 _context.computeKindOf(source); | |
| 1259 sources = _context.librarySources; | |
| 1260 expect(sources, hasLength(originalLength + 1)); | |
| 1261 for (Source returnedSource in sources) { | |
| 1262 if (returnedSource == source) { | |
| 1263 return; | |
| 1264 } | |
| 1265 } | |
| 1266 fail("The added source was not in the list of library sources"); | |
| 1267 } | |
| 1268 | |
| 1269 void test_getLineInfo() { | |
| 1270 Source source = _addSource( | |
| 1271 "/test.dart", | |
| 1272 r''' | |
| 1273 library lib; | |
| 1274 | |
| 1275 main() {}'''); | |
| 1276 LineInfo info = _context.getLineInfo(source); | |
| 1277 expect(info, isNull); | |
| 1278 _context.parseCompilationUnit(source); | |
| 1279 info = _context.getLineInfo(source); | |
| 1280 expect(info, isNotNull); | |
| 1281 } | |
| 1282 | |
| 1283 void test_getModificationStamp_fromSource() { | |
| 1284 int stamp = 42; | |
| 1285 expect( | |
| 1286 _context.getModificationStamp( | |
| 1287 new AnalysisContextImplTest_Source_getModificationStamp_fromSource( | |
| 1288 stamp)), | |
| 1289 stamp); | |
| 1290 } | |
| 1291 | |
| 1292 void test_getModificationStamp_overridden() { | |
| 1293 int stamp = 42; | |
| 1294 Source source = | |
| 1295 new AnalysisContextImplTest_Source_getModificationStamp_overridden( | |
| 1296 stamp); | |
| 1297 _context.setContents(source, ""); | |
| 1298 expect(stamp != _context.getModificationStamp(source), isTrue); | |
| 1299 } | |
| 1300 | |
| 1301 void test_getPublicNamespace_element() { | |
| 1302 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1303 _sourceFactory = _context.sourceFactory; | |
| 1304 Source source = _addSource("/test.dart", "class A {}"); | |
| 1305 LibraryElement library = _context.computeLibraryElement(source); | |
| 1306 Namespace namespace = _context.getPublicNamespace(library); | |
| 1307 expect(namespace, isNotNull); | |
| 1308 EngineTestCase.assertInstanceOf( | |
| 1309 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); | |
| 1310 } | |
| 1311 | |
| 1312 void test_getResolvedCompilationUnit_library() { | |
| 1313 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1314 _sourceFactory = _context.sourceFactory; | |
| 1315 Source source = _addSource("/lib.dart", "library libb;"); | |
| 1316 LibraryElement library = _context.computeLibraryElement(source); | |
| 1317 expect(_context.getResolvedCompilationUnit(source, library), isNotNull); | |
| 1318 _context.setContents(source, "library lib;"); | |
| 1319 expect(_context.getResolvedCompilationUnit(source, library), isNull); | |
| 1320 } | |
| 1321 | |
| 1322 void test_getResolvedCompilationUnit_library_null() { | |
| 1323 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1324 _sourceFactory = _context.sourceFactory; | |
| 1325 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1326 expect(_context.getResolvedCompilationUnit(source, null), isNull); | |
| 1327 } | |
| 1328 | |
| 1329 void test_getResolvedCompilationUnit_source_dart() { | |
| 1330 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1331 _sourceFactory = _context.sourceFactory; | |
| 1332 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1333 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | |
| 1334 _context.resolveCompilationUnit2(source, source); | |
| 1335 expect(_context.getResolvedCompilationUnit2(source, source), isNotNull); | |
| 1336 } | |
| 1337 | |
| 1338 void test_getResolvedCompilationUnit_source_html() { | |
| 1339 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1340 _sourceFactory = _context.sourceFactory; | |
| 1341 Source source = _addSource("/test.html", "<html></html>"); | |
| 1342 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | |
| 1343 expect(_context.resolveCompilationUnit2(source, source), isNull); | |
| 1344 expect(_context.getResolvedCompilationUnit2(source, source), isNull); | |
| 1345 } | |
| 1346 | |
| 1347 void test_getResolvedHtmlUnit() { | |
| 1348 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1349 _sourceFactory = _context.sourceFactory; | |
| 1350 Source source = _addSource("/test.html", "<html></html>"); | |
| 1351 expect(_context.getResolvedHtmlUnit(source), isNull); | |
| 1352 _context.resolveHtmlUnit(source); | |
| 1353 expect(_context.getResolvedHtmlUnit(source), isNotNull); | |
| 1354 } | |
| 1355 | |
| 1356 void test_getSourceFactory() { | |
| 1357 expect(_context.sourceFactory, same(_sourceFactory)); | |
| 1358 } | |
| 1359 | |
| 1360 void test_getSourcesWithFullName() { | |
| 1361 String filePath = '/foo/lib/file.dart'; | |
| 1362 List<Source> expected = <Source>[]; | |
| 1363 ChangeSet changeSet = new ChangeSet(); | |
| 1364 | |
| 1365 TestSourceWithUri source1 = | |
| 1366 new TestSourceWithUri(filePath, Uri.parse('file://$filePath')); | |
| 1367 expected.add(source1); | |
| 1368 changeSet.addedSource(source1); | |
| 1369 | |
| 1370 TestSourceWithUri source2 = | |
| 1371 new TestSourceWithUri(filePath, Uri.parse('package:foo/file.dart')); | |
| 1372 expected.add(source2); | |
| 1373 changeSet.addedSource(source2); | |
| 1374 | |
| 1375 _context.applyChanges(changeSet); | |
| 1376 expect( | |
| 1377 _context.getSourcesWithFullName(filePath), unorderedEquals(expected)); | |
| 1378 } | |
| 1379 | |
| 1380 void test_getStatistics() { | |
| 1381 AnalysisContextStatistics statistics = _context.statistics; | |
| 1382 expect(statistics, isNotNull); | |
| 1383 // The following lines are fragile. | |
| 1384 // The values depend on the number of libraries in the SDK. | |
| 1385 // assertLength(0, statistics.getCacheRows()); | |
| 1386 // assertLength(0, statistics.getExceptions()); | |
| 1387 // assertLength(0, statistics.getSources()); | |
| 1388 } | |
| 1389 | |
| 1390 Future test_implicitAnalysisEvents_added() async { | |
| 1391 AnalyzedSourcesListener listener = new AnalyzedSourcesListener(); | |
| 1392 _context.implicitAnalysisEvents.listen(listener.onData); | |
| 1393 // | |
| 1394 // Create a file that references an file that is not explicitly being | |
| 1395 // analyzed and fully analyze it. Ensure that the listener is told about | |
| 1396 // the implicitly analyzed file. | |
| 1397 // | |
| 1398 Source sourceA = _addSource('/a.dart', "library a; import 'b.dart';"); | |
| 1399 Source sourceB = _createSource('/b.dart', "library b;"); | |
| 1400 _context.computeErrors(sourceA); | |
| 1401 await pumpEventQueue(); | |
| 1402 listener.expectAnalyzed(sourceB); | |
| 1403 } | |
| 1404 | |
| 1405 void test_isClientLibrary_dart() { | |
| 1406 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1407 _sourceFactory = _context.sourceFactory; | |
| 1408 Source source = _addSource( | |
| 1409 "/test.dart", | |
| 1410 r''' | |
| 1411 import 'dart:html'; | |
| 1412 | |
| 1413 main() {}'''); | |
| 1414 expect(_context.isClientLibrary(source), isFalse); | |
| 1415 expect(_context.isServerLibrary(source), isFalse); | |
| 1416 _context.computeLibraryElement(source); | |
| 1417 expect(_context.isClientLibrary(source), isTrue); | |
| 1418 expect(_context.isServerLibrary(source), isFalse); | |
| 1419 } | |
| 1420 | |
| 1421 void test_isClientLibrary_html() { | |
| 1422 Source source = _addSource("/test.html", "<html></html>"); | |
| 1423 expect(_context.isClientLibrary(source), isFalse); | |
| 1424 } | |
| 1425 | |
| 1426 void test_isServerLibrary_dart() { | |
| 1427 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1428 _sourceFactory = _context.sourceFactory; | |
| 1429 Source source = _addSource( | |
| 1430 "/test.dart", | |
| 1431 r''' | |
| 1432 library lib; | |
| 1433 | |
| 1434 main() {}'''); | |
| 1435 expect(_context.isClientLibrary(source), isFalse); | |
| 1436 expect(_context.isServerLibrary(source), isFalse); | |
| 1437 _context.computeLibraryElement(source); | |
| 1438 expect(_context.isClientLibrary(source), isFalse); | |
| 1439 expect(_context.isServerLibrary(source), isTrue); | |
| 1440 } | |
| 1441 | |
| 1442 void test_isServerLibrary_html() { | |
| 1443 Source source = _addSource("/test.html", "<html></html>"); | |
| 1444 expect(_context.isServerLibrary(source), isFalse); | |
| 1445 } | |
| 1446 | |
| 1447 void test_parseCompilationUnit_errors() { | |
| 1448 Source source = _addSource("/lib.dart", "library {"); | |
| 1449 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); | |
| 1450 expect(compilationUnit, isNotNull); | |
| 1451 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1452 expect(errors, isNotNull); | |
| 1453 expect(errors.length > 0, isTrue); | |
| 1454 } | |
| 1455 | |
| 1456 void test_parseCompilationUnit_exception() { | |
| 1457 Source source = _addSourceWithException("/test.dart"); | |
| 1458 try { | |
| 1459 _context.parseCompilationUnit(source); | |
| 1460 fail("Expected AnalysisException"); | |
| 1461 } on AnalysisException { | |
| 1462 // Expected | |
| 1463 } | |
| 1464 } | |
| 1465 | |
| 1466 void test_parseCompilationUnit_html() { | |
| 1467 Source source = _addSource("/test.html", "<html></html>"); | |
| 1468 expect(_context.parseCompilationUnit(source), isNull); | |
| 1469 } | |
| 1470 | |
| 1471 void test_parseCompilationUnit_noErrors() { | |
| 1472 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1473 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); | |
| 1474 expect(compilationUnit, isNotNull); | |
| 1475 expect(_context.getErrors(source).errors, hasLength(0)); | |
| 1476 } | |
| 1477 | |
| 1478 void test_parseCompilationUnit_nonExistentSource() { | |
| 1479 Source source = | |
| 1480 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 1481 try { | |
| 1482 _context.parseCompilationUnit(source); | |
| 1483 fail("Expected AnalysisException because file does not exist"); | |
| 1484 } on AnalysisException { | |
| 1485 // Expected result | |
| 1486 } | |
| 1487 } | |
| 1488 | |
| 1489 void test_parseHtmlUnit_noErrors() { | |
| 1490 Source source = _addSource("/lib.html", "<html></html>"); | |
| 1491 ht.HtmlUnit unit = _context.parseHtmlUnit(source); | |
| 1492 expect(unit, isNotNull); | |
| 1493 } | |
| 1494 | |
| 1495 void test_parseHtmlUnit_resolveDirectives() { | |
| 1496 Source libSource = _addSource( | |
| 1497 "/lib.dart", | |
| 1498 r''' | |
| 1499 library lib; | |
| 1500 class ClassA {}'''); | |
| 1501 Source source = _addSource( | |
| 1502 "/lib.html", | |
| 1503 r''' | |
| 1504 <html> | |
| 1505 <head> | |
| 1506 <script type='application/dart'> | |
| 1507 import 'lib.dart'; | |
| 1508 ClassA v = null; | |
| 1509 </script> | |
| 1510 </head> | |
| 1511 <body> | |
| 1512 </body> | |
| 1513 </html>'''); | |
| 1514 ht.HtmlUnit unit = _context.parseHtmlUnit(source); | |
| 1515 // import directive should be resolved | |
| 1516 ht.XmlTagNode htmlNode = unit.tagNodes[0]; | |
| 1517 ht.XmlTagNode headNode = htmlNode.tagNodes[0]; | |
| 1518 ht.HtmlScriptTagNode scriptNode = headNode.tagNodes[0]; | |
| 1519 CompilationUnit script = scriptNode.script; | |
| 1520 ImportDirective importNode = script.directives[0] as ImportDirective; | |
| 1521 expect(importNode.uriContent, isNotNull); | |
| 1522 expect(importNode.source, libSource); | |
| 1523 } | |
| 1524 | |
| 1525 void test_performAnalysisTask_addPart() { | |
| 1526 Source libSource = _addSource( | |
| 1527 "/lib.dart", | |
| 1528 r''' | |
| 1529 library lib; | |
| 1530 part 'part.dart';'''); | |
| 1531 // run all tasks without part | |
| 1532 _analyzeAll_assertFinished(); | |
| 1533 // add part and run all tasks | |
| 1534 Source partSource = _addSource( | |
| 1535 "/part.dart", | |
| 1536 r''' | |
| 1537 part of lib; | |
| 1538 '''); | |
| 1539 _analyzeAll_assertFinished(); | |
| 1540 // "libSource" should be here | |
| 1541 List<Source> librariesWithPart = | |
| 1542 _context.getLibrariesContaining(partSource); | |
| 1543 expect(librariesWithPart, unorderedEquals([libSource])); | |
| 1544 } | |
| 1545 | |
| 1546 void test_performAnalysisTask_changeLibraryContents() { | |
| 1547 Source libSource = | |
| 1548 _addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
| 1549 Source partSource = _addSource("/test-part.dart", "part of lib;"); | |
| 1550 _analyzeAll_assertFinished(); | |
| 1551 expect( | |
| 1552 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1553 reason: "library resolved 1"); | |
| 1554 expect( | |
| 1555 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1556 reason: "part resolved 1"); | |
| 1557 // update and analyze #1 | |
| 1558 _context.setContents(libSource, "library lib;"); | |
| 1559 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1560 reason: "library changed 2"); | |
| 1561 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1562 reason: "part changed 2"); | |
| 1563 _analyzeAll_assertFinished(); | |
| 1564 expect( | |
| 1565 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1566 reason: "library resolved 2"); | |
| 1567 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1568 reason: "part resolved 2"); | |
| 1569 // update and analyze #2 | |
| 1570 _context.setContents(libSource, "library lib; part 'test-part.dart';"); | |
| 1571 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1572 reason: "library changed 3"); | |
| 1573 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1574 reason: "part changed 3"); | |
| 1575 _analyzeAll_assertFinished(); | |
| 1576 expect( | |
| 1577 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1578 reason: "library resolved 2"); | |
| 1579 expect( | |
| 1580 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1581 reason: "part resolved 3"); | |
| 1582 } | |
| 1583 | |
| 1584 void test_performAnalysisTask_changeLibraryThenPartContents() { | |
| 1585 Source libSource = | |
| 1586 _addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
| 1587 Source partSource = _addSource("/test-part.dart", "part of lib;"); | |
| 1588 _analyzeAll_assertFinished(); | |
| 1589 expect( | |
| 1590 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1591 reason: "library resolved 1"); | |
| 1592 expect( | |
| 1593 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1594 reason: "part resolved 1"); | |
| 1595 // update and analyze #1 | |
| 1596 _context.setContents(libSource, "library lib;"); | |
| 1597 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1598 reason: "library changed 2"); | |
| 1599 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1600 reason: "part changed 2"); | |
| 1601 _analyzeAll_assertFinished(); | |
| 1602 expect( | |
| 1603 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1604 reason: "library resolved 2"); | |
| 1605 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1606 reason: "part resolved 2"); | |
| 1607 // update and analyze #2 | |
| 1608 _context.setContents(partSource, "part of lib; // 1"); | |
| 1609 // Assert that changing the part's content does not effect the library | |
| 1610 // now that it is no longer part of that library | |
| 1611 expect( | |
| 1612 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1613 reason: "library changed 3"); | |
| 1614 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1615 reason: "part changed 3"); | |
| 1616 _analyzeAll_assertFinished(); | |
| 1617 expect( | |
| 1618 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1619 reason: "library resolved 3"); | |
| 1620 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1621 reason: "part resolved 3"); | |
| 1622 } | |
| 1623 | |
| 1624 void test_performAnalysisTask_changePartContents_makeItAPart() { | |
| 1625 Source libSource = _addSource( | |
| 1626 "/lib.dart", | |
| 1627 r''' | |
| 1628 library lib; | |
| 1629 part 'part.dart'; | |
| 1630 void f(x) {}'''); | |
| 1631 Source partSource = _addSource("/part.dart", "void g() { f(null); }"); | |
| 1632 _analyzeAll_assertFinished(); | |
| 1633 expect( | |
| 1634 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1635 reason: "library resolved 1"); | |
| 1636 expect( | |
| 1637 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1638 reason: "part resolved 1"); | |
| 1639 // update and analyze | |
| 1640 _context.setContents( | |
| 1641 partSource, | |
| 1642 r''' | |
| 1643 part of lib; | |
| 1644 void g() { f(null); }'''); | |
| 1645 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1646 reason: "library changed 2"); | |
| 1647 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1648 reason: "part changed 2"); | |
| 1649 _analyzeAll_assertFinished(); | |
| 1650 expect( | |
| 1651 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1652 reason: "library resolved 2"); | |
| 1653 expect( | |
| 1654 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1655 reason: "part resolved 2"); | |
| 1656 expect(_context.getErrors(libSource).errors, hasLength(0)); | |
| 1657 expect(_context.getErrors(partSource).errors, hasLength(0)); | |
| 1658 } | |
| 1659 | |
| 1660 /** | |
| 1661 * https://code.google.com/p/dart/issues/detail?id=12424 | |
| 1662 */ | |
| 1663 void test_performAnalysisTask_changePartContents_makeItNotPart() { | |
| 1664 Source libSource = _addSource( | |
| 1665 "/lib.dart", | |
| 1666 r''' | |
| 1667 library lib; | |
| 1668 part 'part.dart'; | |
| 1669 void f(x) {}'''); | |
| 1670 Source partSource = _addSource( | |
| 1671 "/part.dart", | |
| 1672 r''' | |
| 1673 part of lib; | |
| 1674 void g() { f(null); }'''); | |
| 1675 _analyzeAll_assertFinished(); | |
| 1676 expect(_context.getErrors(libSource).errors, hasLength(0)); | |
| 1677 expect(_context.getErrors(partSource).errors, hasLength(0)); | |
| 1678 // Remove 'part' directive, which should make "f(null)" an error. | |
| 1679 _context.setContents( | |
| 1680 partSource, | |
| 1681 r''' | |
| 1682 //part of lib; | |
| 1683 void g() { f(null); }'''); | |
| 1684 _analyzeAll_assertFinished(); | |
| 1685 expect(_context.getErrors(libSource).errors.length != 0, isTrue); | |
| 1686 } | |
| 1687 | |
| 1688 void test_performAnalysisTask_changePartContents_noSemanticChanges() { | |
| 1689 Source libSource = | |
| 1690 _addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
| 1691 Source partSource = _addSource("/test-part.dart", "part of lib;"); | |
| 1692 _analyzeAll_assertFinished(); | |
| 1693 expect( | |
| 1694 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1695 reason: "library resolved 1"); | |
| 1696 expect( | |
| 1697 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1698 reason: "part resolved 1"); | |
| 1699 // update and analyze #1 | |
| 1700 _context.setContents(partSource, "part of lib; // 1"); | |
| 1701 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1702 reason: "library changed 2"); | |
| 1703 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1704 reason: "part changed 2"); | |
| 1705 _analyzeAll_assertFinished(); | |
| 1706 expect( | |
| 1707 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1708 reason: "library resolved 2"); | |
| 1709 expect( | |
| 1710 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1711 reason: "part resolved 2"); | |
| 1712 // update and analyze #2 | |
| 1713 _context.setContents(partSource, "part of lib; // 12"); | |
| 1714 expect(_context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
| 1715 reason: "library changed 3"); | |
| 1716 expect(_context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
| 1717 reason: "part changed 3"); | |
| 1718 _analyzeAll_assertFinished(); | |
| 1719 expect( | |
| 1720 _context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
| 1721 reason: "library resolved 3"); | |
| 1722 expect( | |
| 1723 _context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
| 1724 reason: "part resolved 3"); | |
| 1725 } | |
| 1726 | |
| 1727 void test_performAnalysisTask_getContentException_dart() { | |
| 1728 // add source that throw an exception on "get content" | |
| 1729 Source source = new _Source_getContent_throwException('test.dart'); | |
| 1730 { | |
| 1731 ChangeSet changeSet = new ChangeSet(); | |
| 1732 changeSet.addedSource(source); | |
| 1733 _context.applyChanges(changeSet); | |
| 1734 } | |
| 1735 // prepare errors | |
| 1736 _analyzeAll_assertFinished(); | |
| 1737 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1738 // validate errors | |
| 1739 expect(errors, hasLength(1)); | |
| 1740 AnalysisError error = errors[0]; | |
| 1741 expect(error.source, same(source)); | |
| 1742 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); | |
| 1743 } | |
| 1744 | |
| 1745 void test_performAnalysisTask_getContentException_html() { | |
| 1746 // add source that throw an exception on "get content" | |
| 1747 Source source = new _Source_getContent_throwException('test.html'); | |
| 1748 { | |
| 1749 ChangeSet changeSet = new ChangeSet(); | |
| 1750 changeSet.addedSource(source); | |
| 1751 _context.applyChanges(changeSet); | |
| 1752 } | |
| 1753 // prepare errors | |
| 1754 _analyzeAll_assertFinished(); | |
| 1755 List<AnalysisError> errors = _context.getErrors(source).errors; | |
| 1756 // validate errors | |
| 1757 expect(errors, hasLength(1)); | |
| 1758 AnalysisError error = errors[0]; | |
| 1759 expect(error.source, same(source)); | |
| 1760 expect(error.errorCode, ScannerErrorCode.UNABLE_GET_CONTENT); | |
| 1761 } | |
| 1762 | |
| 1763 void test_performAnalysisTask_importedLibraryAdd() { | |
| 1764 Source libASource = | |
| 1765 _addSource("/libA.dart", "library libA; import 'libB.dart';"); | |
| 1766 _analyzeAll_assertFinished(); | |
| 1767 expect( | |
| 1768 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | |
| 1769 reason: "libA resolved 1"); | |
| 1770 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), | |
| 1771 isTrue, | |
| 1772 reason: "libA has an error"); | |
| 1773 // add libB.dart and analyze | |
| 1774 Source libBSource = _addSource("/libB.dart", "library libB;"); | |
| 1775 _analyzeAll_assertFinished(); | |
| 1776 expect( | |
| 1777 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | |
| 1778 reason: "libA resolved 2"); | |
| 1779 expect( | |
| 1780 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | |
| 1781 reason: "libB resolved 2"); | |
| 1782 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), | |
| 1783 isTrue, | |
| 1784 reason: "libA doesn't have errors"); | |
| 1785 } | |
| 1786 | |
| 1787 void test_performAnalysisTask_importedLibraryAdd_html() { | |
| 1788 Source htmlSource = _addSource( | |
| 1789 "/page.html", | |
| 1790 r''' | |
| 1791 <html><body><script type="application/dart"> | |
| 1792 import '/libB.dart'; | |
| 1793 main() {print('hello dart');} | |
| 1794 </script></body></html>'''); | |
| 1795 _analyzeAll_assertFinished(); | |
| 1796 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, | |
| 1797 reason: "htmlUnit resolved 1"); | |
| 1798 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(htmlSource)), | |
| 1799 isTrue, | |
| 1800 reason: "htmlSource has an error"); | |
| 1801 // add libB.dart and analyze | |
| 1802 Source libBSource = _addSource("/libB.dart", "library libB;"); | |
| 1803 _analyzeAll_assertFinished(); | |
| 1804 expect(_context.getResolvedHtmlUnit(htmlSource), isNotNull, | |
| 1805 reason: "htmlUnit resolved 1"); | |
| 1806 expect( | |
| 1807 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | |
| 1808 reason: "libB resolved 2"); | |
| 1809 // TODO (danrubel) commented out to fix red bots | |
| 1810 // AnalysisErrorInfo errors = _context.getErrors(htmlSource); | |
| 1811 // expect( | |
| 1812 // !_hasAnalysisErrorWithErrorSeverity(errors), | |
| 1813 // isTrue, | |
| 1814 // reason: "htmlSource doesn't have errors"); | |
| 1815 } | |
| 1816 | |
| 1817 void test_performAnalysisTask_importedLibraryDelete() { | |
| 1818 Source libASource = | |
| 1819 _addSource("/libA.dart", "library libA; import 'libB.dart';"); | |
| 1820 Source libBSource = _addSource("/libB.dart", "library libB;"); | |
| 1821 _analyzeAll_assertFinished(); | |
| 1822 expect( | |
| 1823 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | |
| 1824 reason: "libA resolved 1"); | |
| 1825 expect( | |
| 1826 _context.getResolvedCompilationUnit2(libBSource, libBSource), isNotNull, | |
| 1827 reason: "libB resolved 1"); | |
| 1828 expect(!_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), | |
| 1829 isTrue, | |
| 1830 reason: "libA doesn't have errors"); | |
| 1831 // remove libB.dart content and analyze | |
| 1832 _context.setContents(libBSource, null); | |
| 1833 _analyzeAll_assertFinished(); | |
| 1834 expect( | |
| 1835 _context.getResolvedCompilationUnit2(libASource, libASource), isNotNull, | |
| 1836 reason: "libA resolved 2"); | |
| 1837 expect(_hasAnalysisErrorWithErrorSeverity(_context.getErrors(libASource)), | |
| 1838 isTrue, | |
| 1839 reason: "libA has an error"); | |
| 1840 } | |
| 1841 | |
| 1842 void test_performAnalysisTask_IOException() { | |
| 1843 TestSource source = _addSourceWithException2("/test.dart", "library test;"); | |
| 1844 int oldTimestamp = _context.getModificationStamp(source); | |
| 1845 source.generateExceptionOnRead = false; | |
| 1846 _analyzeAll_assertFinished(); | |
| 1847 expect(source.readCount, 1); | |
| 1848 source.generateExceptionOnRead = true; | |
| 1849 do { | |
| 1850 _changeSource(source, ""); | |
| 1851 // Ensure that the timestamp differs, | |
| 1852 // so that analysis engine notices the change | |
| 1853 } while (oldTimestamp == _context.getModificationStamp(source)); | |
| 1854 _analyzeAll_assertFinished(); | |
| 1855 expect(source.readCount, 2); | |
| 1856 } | |
| 1857 | |
| 1858 void test_performAnalysisTask_missingPart() { | |
| 1859 Source source = | |
| 1860 _addSource("/test.dart", "library lib; part 'no-such-file.dart';"); | |
| 1861 _analyzeAll_assertFinished(); | |
| 1862 expect(_context.getLibraryElement(source), isNotNull, | |
| 1863 reason: "performAnalysisTask failed to compute an element model"); | |
| 1864 } | |
| 1865 | |
| 1866 void test_performAnalysisTask_modifiedAfterParse() { | |
| 1867 // TODO(scheglov) no threads in Dart | |
| 1868 // Source source = _addSource("/test.dart", "library lib;"); | |
| 1869 // int initialTime = _context.getModificationStamp(source); | |
| 1870 // List<Source> sources = new List<Source>(); | |
| 1871 // sources.add(source); | |
| 1872 // _context.analysisPriorityOrder = sources; | |
| 1873 // _context.parseCompilationUnit(source); | |
| 1874 // while (initialTime == JavaSystem.currentTimeMillis()) { | |
| 1875 // Thread.sleep(1); | |
| 1876 // // Force the modification time to be different. | |
| 1877 // } | |
| 1878 // _context.setContents(source, "library test;"); | |
| 1879 // JUnitTestCase.assertTrue(initialTime != _context.getModificationStamp(sour
ce)); | |
| 1880 // _analyzeAll_assertFinished(); | |
| 1881 // JUnitTestCase.assertNotNullMsg("performAnalysisTask failed to compute an e
lement model", _context.getLibraryElement(source)); | |
| 1882 } | |
| 1883 | |
| 1884 void test_resolveCompilationUnit_import_relative() { | |
| 1885 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1886 Source sourceA = | |
| 1887 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); | |
| 1888 _addSource("/libB.dart", "library libB; class B{}"); | |
| 1889 CompilationUnit compilationUnit = | |
| 1890 _context.resolveCompilationUnit2(sourceA, sourceA); | |
| 1891 LibraryElement library = compilationUnit.element.library; | |
| 1892 List<LibraryElement> importedLibraries = library.importedLibraries; | |
| 1893 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | |
| 1894 List<LibraryElement> visibleLibraries = library.visibleLibraries; | |
| 1895 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); | |
| 1896 } | |
| 1897 | |
| 1898 void test_resolveCompilationUnit_import_relative_cyclic() { | |
| 1899 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1900 Source sourceA = | |
| 1901 _addSource("/libA.dart", "library libA; import 'libB.dart'; class A{}"); | |
| 1902 _addSource("/libB.dart", "library libB; import 'libA.dart'; class B{}"); | |
| 1903 CompilationUnit compilationUnit = | |
| 1904 _context.resolveCompilationUnit2(sourceA, sourceA); | |
| 1905 LibraryElement library = compilationUnit.element.library; | |
| 1906 List<LibraryElement> importedLibraries = library.importedLibraries; | |
| 1907 assertNamedElements(importedLibraries, ["dart.core", "libB"]); | |
| 1908 List<LibraryElement> visibleLibraries = library.visibleLibraries; | |
| 1909 assertNamedElements(visibleLibraries, ["dart.core", "libA", "libB"]); | |
| 1910 } | |
| 1911 | |
| 1912 void test_resolveCompilationUnit_library() { | |
| 1913 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1914 _sourceFactory = _context.sourceFactory; | |
| 1915 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1916 LibraryElement library = _context.computeLibraryElement(source); | |
| 1917 CompilationUnit compilationUnit = | |
| 1918 _context.resolveCompilationUnit(source, library); | |
| 1919 expect(compilationUnit, isNotNull); | |
| 1920 expect(compilationUnit.element, isNotNull); | |
| 1921 } | |
| 1922 | |
| 1923 void test_resolveCompilationUnit_source() { | |
| 1924 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 1925 _sourceFactory = _context.sourceFactory; | |
| 1926 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1927 CompilationUnit compilationUnit = | |
| 1928 _context.resolveCompilationUnit2(source, source); | |
| 1929 expect(compilationUnit, isNotNull); | |
| 1930 } | |
| 1931 | |
| 1932 void test_resolveCompilationUnit_sourceChangeDuringResolution() { | |
| 1933 _context = new _AnalysisContext_sourceChangeDuringResolution(); | |
| 1934 AnalysisContextFactory.initContextWithCore(_context); | |
| 1935 _sourceFactory = _context.sourceFactory; | |
| 1936 Source source = _addSource("/lib.dart", "library lib;"); | |
| 1937 CompilationUnit compilationUnit = | |
| 1938 _context.resolveCompilationUnit2(source, source); | |
| 1939 expect(compilationUnit, isNotNull); | |
| 1940 expect(_context.getLineInfo(source), isNotNull); | |
| 1941 } | |
| 1942 | |
| 1943 void test_resolveHtmlUnit() { | |
| 1944 Source source = _addSource("/lib.html", "<html></html>"); | |
| 1945 ht.HtmlUnit unit = _context.resolveHtmlUnit(source); | |
| 1946 expect(unit, isNotNull); | |
| 1947 } | |
| 1948 | |
| 1949 void test_setAnalysisOptions() { | |
| 1950 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 1951 options.cacheSize = 42; | |
| 1952 options.dart2jsHint = false; | |
| 1953 options.hint = false; | |
| 1954 _context.analysisOptions = options; | |
| 1955 AnalysisOptions result = _context.analysisOptions; | |
| 1956 expect(result.cacheSize, options.cacheSize); | |
| 1957 expect(result.dart2jsHint, options.dart2jsHint); | |
| 1958 expect(result.hint, options.hint); | |
| 1959 } | |
| 1960 | |
| 1961 void test_setAnalysisOptions_reduceAnalysisPriorityOrder() { | |
| 1962 AnalysisOptionsImpl options = | |
| 1963 new AnalysisOptionsImpl.from(_context.analysisOptions); | |
| 1964 List<Source> sources = new List<Source>(); | |
| 1965 for (int index = 0; index < options.cacheSize; index++) { | |
| 1966 sources.add(_addSource("/lib.dart$index", "")); | |
| 1967 } | |
| 1968 _context.analysisPriorityOrder = sources; | |
| 1969 int oldPriorityOrderSize = _getPriorityOrder(_context).length; | |
| 1970 options.cacheSize = options.cacheSize - 10; | |
| 1971 _context.analysisOptions = options; | |
| 1972 expect(oldPriorityOrderSize > _getPriorityOrder(_context).length, isTrue); | |
| 1973 } | |
| 1974 | |
| 1975 void test_setAnalysisPriorityOrder_empty() { | |
| 1976 _context.analysisPriorityOrder = new List<Source>(); | |
| 1977 } | |
| 1978 | |
| 1979 void test_setAnalysisPriorityOrder_lessThanCacheSize() { | |
| 1980 AnalysisOptions options = _context.analysisOptions; | |
| 1981 List<Source> sources = new List<Source>(); | |
| 1982 for (int index = 0; index < options.cacheSize; index++) { | |
| 1983 sources.add(_addSource("/lib.dart$index", "")); | |
| 1984 } | |
| 1985 _context.analysisPriorityOrder = sources; | |
| 1986 expect(options.cacheSize > _getPriorityOrder(_context).length, isTrue); | |
| 1987 } | |
| 1988 | |
| 1989 void test_setAnalysisPriorityOrder_nonEmpty() { | |
| 1990 List<Source> sources = new List<Source>(); | |
| 1991 sources.add(_addSource("/lib.dart", "library lib;")); | |
| 1992 _context.analysisPriorityOrder = sources; | |
| 1993 } | |
| 1994 | |
| 1995 Future test_setChangedContents_libraryWithPart() { | |
| 1996 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 1997 options.incremental = true; | |
| 1998 _context = AnalysisContextFactory.oldContextWithCoreAndOptions(options); | |
| 1999 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 2000 _context.onSourcesChanged.listen(listener.onData); | |
| 2001 _sourceFactory = _context.sourceFactory; | |
| 2002 String oldCode = r''' | |
| 2003 library lib; | |
| 2004 part 'part.dart'; | |
| 2005 int a = 0;'''; | |
| 2006 Source librarySource = _addSource("/lib.dart", oldCode); | |
| 2007 String partContents = r''' | |
| 2008 part of lib; | |
| 2009 int b = a;'''; | |
| 2010 Source partSource = _addSource("/part.dart", partContents); | |
| 2011 LibraryElement element = _context.computeLibraryElement(librarySource); | |
| 2012 CompilationUnit unit = | |
| 2013 _context.getResolvedCompilationUnit(librarySource, element); | |
| 2014 expect(unit, isNotNull); | |
| 2015 int offset = oldCode.indexOf("int a") + 4; | |
| 2016 String newCode = r''' | |
| 2017 library lib; | |
| 2018 part 'part.dart'; | |
| 2019 int ya = 0;'''; | |
| 2020 expect(_getIncrementalAnalysisCache(_context), isNull); | |
| 2021 _context.setChangedContents(librarySource, newCode, offset, 0, 1); | |
| 2022 expect(_context.getContents(librarySource).data, newCode); | |
| 2023 IncrementalAnalysisCache incrementalCache = | |
| 2024 _getIncrementalAnalysisCache(_context); | |
| 2025 expect(incrementalCache.librarySource, librarySource); | |
| 2026 expect(incrementalCache.resolvedUnit, same(unit)); | |
| 2027 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), | |
| 2028 isNull); | |
| 2029 expect(incrementalCache.newContents, newCode); | |
| 2030 return pumpEventQueue().then((_) { | |
| 2031 listener.assertEvent(wereSourcesAdded: true); | |
| 2032 listener.assertEvent(changedSources: [librarySource]); | |
| 2033 listener.assertEvent(wereSourcesAdded: true); | |
| 2034 listener.assertEvent(changedSources: [partSource]); | |
| 2035 listener.assertEvent(changedSources: [librarySource]); | |
| 2036 listener.assertNoMoreEvents(); | |
| 2037 }); | |
| 2038 } | |
| 2039 | |
| 2040 void test_setChangedContents_notResolved() { | |
| 2041 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 2042 AnalysisOptionsImpl options = | |
| 2043 new AnalysisOptionsImpl.from(_context.analysisOptions); | |
| 2044 options.incremental = true; | |
| 2045 _context.analysisOptions = options; | |
| 2046 _sourceFactory = _context.sourceFactory; | |
| 2047 String oldCode = r''' | |
| 2048 library lib; | |
| 2049 int a = 0;'''; | |
| 2050 Source librarySource = _addSource("/lib.dart", oldCode); | |
| 2051 int offset = oldCode.indexOf("int a") + 4; | |
| 2052 String newCode = r''' | |
| 2053 library lib; | |
| 2054 int ya = 0;'''; | |
| 2055 _context.setChangedContents(librarySource, newCode, offset, 0, 1); | |
| 2056 expect(_context.getContents(librarySource).data, newCode); | |
| 2057 expect(_getIncrementalAnalysisCache(_context), isNull); | |
| 2058 } | |
| 2059 | |
| 2060 Future test_setContents_libraryWithPart() { | |
| 2061 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 2062 SourcesChangedListener listener = new SourcesChangedListener(); | |
| 2063 _context.onSourcesChanged.listen(listener.onData); | |
| 2064 _sourceFactory = _context.sourceFactory; | |
| 2065 String libraryContents1 = r''' | |
| 2066 library lib; | |
| 2067 part 'part.dart'; | |
| 2068 int a = 0;'''; | |
| 2069 Source librarySource = _addSource("/lib.dart", libraryContents1); | |
| 2070 String partContents1 = r''' | |
| 2071 part of lib; | |
| 2072 int b = a;'''; | |
| 2073 Source partSource = _addSource("/part.dart", partContents1); | |
| 2074 _context.computeLibraryElement(librarySource); | |
| 2075 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( | |
| 2076 librarySource, librarySource, null, null, null, 0, 0, 0); | |
| 2077 _setIncrementalAnalysisCache(_context, incrementalCache); | |
| 2078 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); | |
| 2079 String libraryContents2 = r''' | |
| 2080 library lib; | |
| 2081 part 'part.dart'; | |
| 2082 int aa = 0;'''; | |
| 2083 _context.setContents(librarySource, libraryContents2); | |
| 2084 expect(_context.getResolvedCompilationUnit2(partSource, librarySource), | |
| 2085 isNull); | |
| 2086 expect(_getIncrementalAnalysisCache(_context), isNull); | |
| 2087 return pumpEventQueue().then((_) { | |
| 2088 listener.assertEvent(wereSourcesAdded: true); | |
| 2089 listener.assertEvent(changedSources: [librarySource]); | |
| 2090 listener.assertEvent(wereSourcesAdded: true); | |
| 2091 listener.assertEvent(changedSources: [partSource]); | |
| 2092 listener.assertEvent(changedSources: [librarySource]); | |
| 2093 listener.assertNoMoreEvents(); | |
| 2094 }); | |
| 2095 } | |
| 2096 | |
| 2097 void test_setContents_null() { | |
| 2098 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 2099 _sourceFactory = _context.sourceFactory; | |
| 2100 Source librarySource = _addSource( | |
| 2101 "/lib.dart", | |
| 2102 r''' | |
| 2103 library lib; | |
| 2104 int a = 0;'''); | |
| 2105 _context.computeLibraryElement(librarySource); | |
| 2106 IncrementalAnalysisCache incrementalCache = new IncrementalAnalysisCache( | |
| 2107 librarySource, librarySource, null, null, null, 0, 0, 0); | |
| 2108 _setIncrementalAnalysisCache(_context, incrementalCache); | |
| 2109 expect(_getIncrementalAnalysisCache(_context), same(incrementalCache)); | |
| 2110 _context.setContents(librarySource, null); | |
| 2111 expect(_context.getResolvedCompilationUnit2(librarySource, librarySource), | |
| 2112 isNull); | |
| 2113 expect(_getIncrementalAnalysisCache(_context), isNull); | |
| 2114 } | |
| 2115 | |
| 2116 void test_setContents_unchanged_consistentModificationTime() { | |
| 2117 String contents = "// foo"; | |
| 2118 Source source = _addSource("/test.dart", contents); | |
| 2119 // do all, no tasks | |
| 2120 _analyzeAll_assertFinished(); | |
| 2121 { | |
| 2122 AnalysisResult result = _context.performAnalysisTask(); | |
| 2123 expect(result.changeNotices, isNull); | |
| 2124 } | |
| 2125 // set the same contents, still no tasks | |
| 2126 _context.setContents(source, contents); | |
| 2127 { | |
| 2128 AnalysisResult result = _context.performAnalysisTask(); | |
| 2129 expect(result.changeNotices, isNull); | |
| 2130 } | |
| 2131 } | |
| 2132 | |
| 2133 void test_setSourceFactory() { | |
| 2134 expect(_context.sourceFactory, _sourceFactory); | |
| 2135 SourceFactory factory = new SourceFactory([]); | |
| 2136 _context.sourceFactory = factory; | |
| 2137 expect(_context.sourceFactory, factory); | |
| 2138 } | |
| 2139 | |
| 2140 void test_unreadableSource() { | |
| 2141 _context = AnalysisContextFactory.oldContextWithCore(); | |
| 2142 _sourceFactory = _context.sourceFactory; | |
| 2143 Source test1 = _addSource( | |
| 2144 "/test1.dart", | |
| 2145 r''' | |
| 2146 import 'test2.dart'; | |
| 2147 library test1;'''); | |
| 2148 Source test2 = _addSource( | |
| 2149 "/test2.dart", | |
| 2150 r''' | |
| 2151 import 'test1.dart'; | |
| 2152 import 'test3.dart'; | |
| 2153 library test2;'''); | |
| 2154 Source test3 = _addSourceWithException("/test3.dart"); | |
| 2155 _analyzeAll_assertFinished(); | |
| 2156 // test1 and test2 should have been successfully analyzed | |
| 2157 // despite the fact that test3 couldn't be read. | |
| 2158 expect(_context.computeLibraryElement(test1), isNotNull); | |
| 2159 expect(_context.computeLibraryElement(test2), isNotNull); | |
| 2160 expect(_context.computeLibraryElement(test3), isNull); | |
| 2161 } | |
| 2162 | |
| 2163 void test_updateAnalysis() { | |
| 2164 expect(_context.sourcesNeedingProcessing.isEmpty, isTrue); | |
| 2165 Source source = | |
| 2166 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 2167 AnalysisDelta delta = new AnalysisDelta(); | |
| 2168 delta.setAnalysisLevel(source, AnalysisLevel.ALL); | |
| 2169 _context.applyAnalysisDelta(delta); | |
| 2170 expect(_context.sourcesNeedingProcessing.contains(source), isTrue); | |
| 2171 delta = new AnalysisDelta(); | |
| 2172 delta.setAnalysisLevel(source, AnalysisLevel.NONE); | |
| 2173 _context.applyAnalysisDelta(delta); | |
| 2174 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); | |
| 2175 } | |
| 2176 | |
| 2177 void xtest_performAnalysisTask_stress() { | |
| 2178 int maxCacheSize = 4; | |
| 2179 AnalysisOptionsImpl options = | |
| 2180 new AnalysisOptionsImpl.from(_context.analysisOptions); | |
| 2181 options.cacheSize = maxCacheSize; | |
| 2182 _context.analysisOptions = options; | |
| 2183 int sourceCount = maxCacheSize + 2; | |
| 2184 List<Source> sources = new List<Source>(); | |
| 2185 ChangeSet changeSet = new ChangeSet(); | |
| 2186 for (int i = 0; i < sourceCount; i++) { | |
| 2187 Source source = _addSource("/lib$i.dart", "library lib$i;"); | |
| 2188 sources.add(source); | |
| 2189 changeSet.addedSource(source); | |
| 2190 } | |
| 2191 _context.applyChanges(changeSet); | |
| 2192 _context.analysisPriorityOrder = sources; | |
| 2193 for (int i = 0; i < 1000; i++) { | |
| 2194 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; | |
| 2195 if (notice == null) { | |
| 2196 //System.out.println("test_performAnalysisTask_stress: " + i); | |
| 2197 break; | |
| 2198 } | |
| 2199 } | |
| 2200 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; | |
| 2201 if (notice != null) { | |
| 2202 fail( | |
| 2203 "performAnalysisTask failed to terminate after analyzing all sources")
; | |
| 2204 } | |
| 2205 } | |
| 2206 | |
| 2207 Source _addSource(String fileName, String contents) { | |
| 2208 Source source = new FileBasedSource(FileUtilities2.createFile(fileName)); | |
| 2209 ChangeSet changeSet = new ChangeSet(); | |
| 2210 changeSet.addedSource(source); | |
| 2211 _context.applyChanges(changeSet); | |
| 2212 _context.setContents(source, contents); | |
| 2213 return source; | |
| 2214 } | |
| 2215 | |
| 2216 TestSource _addSourceWithException(String fileName) { | |
| 2217 return _addSourceWithException2(fileName, ""); | |
| 2218 } | |
| 2219 | |
| 2220 TestSource _addSourceWithException2(String fileName, String contents) { | |
| 2221 TestSource source = new TestSource(fileName, contents); | |
| 2222 source.generateExceptionOnRead = true; | |
| 2223 ChangeSet changeSet = new ChangeSet(); | |
| 2224 changeSet.addedSource(source); | |
| 2225 _context.applyChanges(changeSet); | |
| 2226 return source; | |
| 2227 } | |
| 2228 | |
| 2229 /** | |
| 2230 * Perform analysis tasks up to 512 times and asserts that that was enough. | |
| 2231 */ | |
| 2232 void _analyzeAll_assertFinished() { | |
| 2233 _analyzeAll_assertFinished2(512); | |
| 2234 } | |
| 2235 | |
| 2236 /** | |
| 2237 * Perform analysis tasks up to the given number of times and asserts that tha
t was enough. | |
| 2238 * | |
| 2239 * @param maxIterations the maximum number of tasks to perform | |
| 2240 */ | |
| 2241 void _analyzeAll_assertFinished2(int maxIterations) { | |
| 2242 for (int i = 0; i < maxIterations; i++) { | |
| 2243 List<ChangeNotice> notice = _context.performAnalysisTask().changeNotices; | |
| 2244 if (notice == null) { | |
| 2245 return; | |
| 2246 } | |
| 2247 } | |
| 2248 fail("performAnalysisTask failed to terminate after analyzing all sources"); | |
| 2249 } | |
| 2250 | |
| 2251 void _changeSource(TestSource source, String contents) { | |
| 2252 source.setContents(contents); | |
| 2253 ChangeSet changeSet = new ChangeSet(); | |
| 2254 changeSet.changedSource(source); | |
| 2255 _context.applyChanges(changeSet); | |
| 2256 } | |
| 2257 | |
| 2258 Source _createSource(String fileName, String contents) { | |
| 2259 Source source = new FileBasedSource(FileUtilities2.createFile(fileName)); | |
| 2260 _context.setContents(source, contents); | |
| 2261 return source; | |
| 2262 } | |
| 2263 | |
| 2264 /** | |
| 2265 * Search the given compilation unit for a class with the given name. Return t
he class with the | |
| 2266 * given name, or `null` if the class cannot be found. | |
| 2267 * | |
| 2268 * @param unit the compilation unit being searched | |
| 2269 * @param className the name of the class being searched for | |
| 2270 * @return the class with the given name | |
| 2271 */ | |
| 2272 ClassElement _findClass(CompilationUnitElement unit, String className) { | |
| 2273 for (ClassElement classElement in unit.types) { | |
| 2274 if (classElement.displayName == className) { | |
| 2275 return classElement; | |
| 2276 } | |
| 2277 } | |
| 2278 return null; | |
| 2279 } | |
| 2280 | |
| 2281 IncrementalAnalysisCache _getIncrementalAnalysisCache( | |
| 2282 AnalysisContextImpl context2) { | |
| 2283 return context2.test_incrementalAnalysisCache; | |
| 2284 } | |
| 2285 | |
| 2286 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { | |
| 2287 return context2.test_priorityOrder; | |
| 2288 } | |
| 2289 | |
| 2290 void _performPendingAnalysisTasks([int maxTasks = 20]) { | |
| 2291 for (int i = 0; _context.performAnalysisTask().hasMoreWork; i++) { | |
| 2292 if (i > maxTasks) { | |
| 2293 fail('Analysis did not terminate.'); | |
| 2294 } | |
| 2295 } | |
| 2296 } | |
| 2297 | |
| 2298 void _removeSource(Source source) { | |
| 2299 ChangeSet changeSet = new ChangeSet(); | |
| 2300 changeSet.removedSource(source); | |
| 2301 _context.applyChanges(changeSet); | |
| 2302 } | |
| 2303 | |
| 2304 void _setIncrementalAnalysisCache( | |
| 2305 AnalysisContextImpl context, IncrementalAnalysisCache incrementalCache) { | |
| 2306 context.test_incrementalAnalysisCache = incrementalCache; | |
| 2307 } | |
| 2308 | |
| 2309 /** | |
| 2310 * Returns `true` if there is an [AnalysisError] with [ErrorSeverity.ERROR] in | |
| 2311 * the given [AnalysisErrorInfo]. | |
| 2312 */ | |
| 2313 static bool _hasAnalysisErrorWithErrorSeverity(AnalysisErrorInfo errorInfo) { | |
| 2314 List<AnalysisError> errors = errorInfo.errors; | |
| 2315 for (AnalysisError analysisError in errors) { | |
| 2316 if (analysisError.errorCode.errorSeverity == ErrorSeverity.ERROR) { | |
| 2317 return true; | |
| 2318 } | |
| 2319 } | |
| 2320 return false; | |
| 2321 } | |
| 2322 } | |
| 2323 | |
| 2324 class AnalysisContextImplTest_Source_exists_true extends TestSource { | |
| 2325 @override | |
| 2326 bool exists() => true; | |
| 2327 } | |
| 2328 | |
| 2329 class AnalysisContextImplTest_Source_getModificationStamp_fromSource | |
| 2330 extends TestSource { | |
| 2331 int stamp; | |
| 2332 AnalysisContextImplTest_Source_getModificationStamp_fromSource(this.stamp); | |
| 2333 @override | |
| 2334 int get modificationStamp => stamp; | |
| 2335 } | |
| 2336 | |
| 2337 class AnalysisContextImplTest_Source_getModificationStamp_overridden | |
| 2338 extends TestSource { | |
| 2339 int stamp; | |
| 2340 AnalysisContextImplTest_Source_getModificationStamp_overridden(this.stamp); | |
| 2341 @override | |
| 2342 int get modificationStamp => stamp; | |
| 2343 } | |
| 2344 | |
| 2345 @reflectiveTest | |
| 2346 class AnalysisOptionsImplTest extends EngineTestCase { | |
| 2347 void test_AnalysisOptionsImpl_copy() { | |
| 2348 bool booleanValue = true; | |
| 2349 for (int i = 0; i < 2; i++, booleanValue = !booleanValue) { | |
| 2350 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2351 options.analyzeFunctionBodies = booleanValue; | |
| 2352 options.cacheSize = i; | |
| 2353 options.dart2jsHint = booleanValue; | |
| 2354 options.enableStrictCallChecks = booleanValue; | |
| 2355 options.enableSuperMixins = booleanValue; | |
| 2356 options.generateImplicitErrors = booleanValue; | |
| 2357 options.generateSdkErrors = booleanValue; | |
| 2358 options.hint = booleanValue; | |
| 2359 options.incremental = booleanValue; | |
| 2360 options.preserveComments = booleanValue; | |
| 2361 options.strongMode = booleanValue; | |
| 2362 AnalysisOptionsImpl copy = new AnalysisOptionsImpl.from(options); | |
| 2363 expect(copy.analyzeFunctionBodies, options.analyzeFunctionBodies); | |
| 2364 expect(copy.cacheSize, options.cacheSize); | |
| 2365 expect(copy.dart2jsHint, options.dart2jsHint); | |
| 2366 expect(copy.enableStrictCallChecks, options.enableStrictCallChecks); | |
| 2367 expect(copy.enableSuperMixins, options.enableSuperMixins); | |
| 2368 expect(copy.generateImplicitErrors, options.generateImplicitErrors); | |
| 2369 expect(copy.generateSdkErrors, options.generateSdkErrors); | |
| 2370 expect(copy.hint, options.hint); | |
| 2371 expect(copy.incremental, options.incremental); | |
| 2372 expect(copy.preserveComments, options.preserveComments); | |
| 2373 expect(copy.strongMode, options.strongMode); | |
| 2374 } | |
| 2375 } | |
| 2376 | |
| 2377 void test_analyzeFunctionBodies() { | |
| 2378 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2379 bool value = !options.analyzeFunctionBodies; | |
| 2380 options.analyzeFunctionBodies = value; | |
| 2381 expect(options.analyzeFunctionBodies, value); | |
| 2382 } | |
| 2383 | |
| 2384 void test_cacheSize() { | |
| 2385 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2386 expect(options.cacheSize, AnalysisOptionsImpl.DEFAULT_CACHE_SIZE); | |
| 2387 int value = options.cacheSize + 1; | |
| 2388 options.cacheSize = value; | |
| 2389 expect(options.cacheSize, value); | |
| 2390 } | |
| 2391 | |
| 2392 void test_dart2jsHint() { | |
| 2393 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2394 bool value = !options.dart2jsHint; | |
| 2395 options.dart2jsHint = value; | |
| 2396 expect(options.dart2jsHint, value); | |
| 2397 } | |
| 2398 | |
| 2399 void test_enableSuperMixins() { | |
| 2400 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2401 bool value = !options.enableSuperMixins; | |
| 2402 options.enableSuperMixins = value; | |
| 2403 expect(options.enableSuperMixins, value); | |
| 2404 } | |
| 2405 | |
| 2406 void test_generateImplicitErrors() { | |
| 2407 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2408 bool value = !options.generateImplicitErrors; | |
| 2409 options.generateImplicitErrors = value; | |
| 2410 expect(options.generateImplicitErrors, value); | |
| 2411 } | |
| 2412 | |
| 2413 void test_generateSdkErrors() { | |
| 2414 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2415 bool value = !options.generateSdkErrors; | |
| 2416 options.generateSdkErrors = value; | |
| 2417 expect(options.generateSdkErrors, value); | |
| 2418 } | |
| 2419 | |
| 2420 void test_hint() { | |
| 2421 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2422 bool value = !options.hint; | |
| 2423 options.hint = value; | |
| 2424 expect(options.hint, value); | |
| 2425 } | |
| 2426 | |
| 2427 void test_incremental() { | |
| 2428 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2429 bool value = !options.incremental; | |
| 2430 options.incremental = value; | |
| 2431 expect(options.incremental, value); | |
| 2432 } | |
| 2433 | |
| 2434 void test_preserveComments() { | |
| 2435 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2436 bool value = !options.preserveComments; | |
| 2437 options.preserveComments = value; | |
| 2438 expect(options.preserveComments, value); | |
| 2439 } | |
| 2440 | |
| 2441 void test_strongMode() { | |
| 2442 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 2443 bool value = !options.strongMode; | |
| 2444 options.strongMode = value; | |
| 2445 expect(options.strongMode, value); | |
| 2446 } | |
| 2447 } | |
| 2448 | |
| 2449 class AnalysisTask_test_perform_exception extends AnalysisTask { | |
| 2450 AnalysisTask_test_perform_exception(InternalAnalysisContext arg0) | |
| 2451 : super(arg0); | |
| 2452 @override | |
| 2453 String get taskDescription => null; | |
| 2454 @override | |
| 2455 accept(AnalysisTaskVisitor visitor) { | |
| 2456 expect(exception, isNotNull); | |
| 2457 return null; | |
| 2458 } | |
| 2459 | |
| 2460 @override | |
| 2461 void internalPerform() { | |
| 2462 throw new AnalysisException("Forced exception"); | |
| 2463 } | |
| 2464 } | |
| 2465 | |
| 2466 @reflectiveTest | |
| 2467 class AnalysisTaskTest extends EngineTestCase { | |
| 2468 void test_perform_exception() { | |
| 2469 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 2470 AnalysisTask task = new AnalysisTask_test_perform_exception(context); | |
| 2471 task.perform(new TestTaskVisitor<Object>()); | |
| 2472 } | |
| 2473 } | 34 } |
| 2474 | 35 |
| 2475 /** | 36 /** |
| 2476 * A listener used to gather the [ImplicitAnalysisEvent]s that are produced | 37 * A listener used to gather the [ImplicitAnalysisEvent]s that are produced |
| 2477 * during analysis. | 38 * during analysis. |
| 2478 */ | 39 */ |
| 2479 class AnalyzedSourcesListener { | 40 class AnalyzedSourcesListener { |
| 2480 /** | 41 /** |
| 2481 * The events that have been gathered. | 42 * The events that have been gathered. |
| 2482 */ | 43 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2507 void onData(ImplicitAnalysisEvent event) { | 68 void onData(ImplicitAnalysisEvent event) { |
| 2508 actualEvents.add(event); | 69 actualEvents.add(event); |
| 2509 if (event.isAnalyzed) { | 70 if (event.isAnalyzed) { |
| 2510 analyzedSources.add(event.source); | 71 analyzedSources.add(event.source); |
| 2511 } else { | 72 } else { |
| 2512 analyzedSources.remove(event.source); | 73 analyzedSources.remove(event.source); |
| 2513 } | 74 } |
| 2514 } | 75 } |
| 2515 } | 76 } |
| 2516 | 77 |
| 2517 class CompilationUnitMock extends TypedMock implements CompilationUnit { | 78 class CompilationUnitMock extends TypedMock implements CompilationUnit {} |
| 2518 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 79 |
| 2519 } | 80 class MockSourceFactory extends SourceFactoryImpl { |
| 2520 | |
| 2521 @reflectiveTest | |
| 2522 class DartEntryTest extends EngineTestCase { | |
| 2523 void test_allErrors() { | |
| 2524 Source source = new TestSource(); | |
| 2525 DartEntry entry = new DartEntry(); | |
| 2526 expect(entry.allErrors, hasLength(0)); | |
| 2527 entry.setValue(SourceEntry.CONTENT_ERRORS, <AnalysisError>[ | |
| 2528 new AnalysisError(source, 0, 0, ScannerErrorCode.UNABLE_GET_CONTENT, | |
| 2529 ['exception details']) | |
| 2530 ]); | |
| 2531 entry.setValue(DartEntry.SCAN_ERRORS, <AnalysisError>[ | |
| 2532 new AnalysisError( | |
| 2533 source, 0, 0, ScannerErrorCode.UNTERMINATED_STRING_LITERAL) | |
| 2534 ]); | |
| 2535 entry.setValue(DartEntry.PARSE_ERRORS, <AnalysisError>[ | |
| 2536 new AnalysisError(source, 0, 0, ParserErrorCode.ABSTRACT_CLASS_MEMBER) | |
| 2537 ]); | |
| 2538 entry.setValueInLibrary( | |
| 2539 DartEntry.RESOLUTION_ERRORS, source, <AnalysisError>[ | |
| 2540 new AnalysisError( | |
| 2541 source, 0, 0, CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION) | |
| 2542 ]); | |
| 2543 entry.setValueInLibrary( | |
| 2544 DartEntry.VERIFICATION_ERRORS, source, <AnalysisError>[ | |
| 2545 new AnalysisError( | |
| 2546 source, 0, 0, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED) | |
| 2547 ]); | |
| 2548 entry.setValueInLibrary(DartEntry.HINTS, source, | |
| 2549 <AnalysisError>[new AnalysisError(source, 0, 0, HintCode.DEAD_CODE)]); | |
| 2550 expect(entry.allErrors, hasLength(6)); | |
| 2551 } | |
| 2552 | |
| 2553 void test_creation() { | |
| 2554 Source librarySource = new TestSource(); | |
| 2555 DartEntry entry = new DartEntry(); | |
| 2556 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.INVALID)); | |
| 2557 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.INVALID)); | |
| 2558 expect(entry.getState(DartEntry.CONTAINING_LIBRARIES), | |
| 2559 same(CacheState.INVALID)); | |
| 2560 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); | |
| 2561 expect( | |
| 2562 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2563 expect( | |
| 2564 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2565 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); | |
| 2566 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); | |
| 2567 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); | |
| 2568 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.INVALID)); | |
| 2569 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.INVALID)); | |
| 2570 expect( | |
| 2571 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); | |
| 2572 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.INVALID)); | |
| 2573 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.INVALID)); | |
| 2574 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.INVALID)); | |
| 2575 | |
| 2576 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), | |
| 2577 same(CacheState.INVALID)); | |
| 2578 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), | |
| 2579 same(CacheState.INVALID)); | |
| 2580 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), | |
| 2581 same(CacheState.INVALID)); | |
| 2582 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), | |
| 2583 same(CacheState.INVALID)); | |
| 2584 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), | |
| 2585 same(CacheState.INVALID)); | |
| 2586 expect( | |
| 2587 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), | |
| 2588 same(CacheState.INVALID)); | |
| 2589 } | |
| 2590 | |
| 2591 void test_getResolvableCompilationUnit_none() { | |
| 2592 DartEntry entry = new DartEntry(); | |
| 2593 expect(entry.resolvableCompilationUnit, isNull); | |
| 2594 } | |
| 2595 | |
| 2596 void test_getResolvableCompilationUnit_parsed_accessed() { | |
| 2597 Source librarySource = new TestSource("/lib.dart"); | |
| 2598 String importUri = "/f1.dart"; | |
| 2599 Source importSource = new TestSource(importUri); | |
| 2600 ImportDirective importDirective = | |
| 2601 AstFactory.importDirective3(importUri, null); | |
| 2602 importDirective.source = importSource; | |
| 2603 importDirective.uriContent = importUri; | |
| 2604 String exportUri = "/f2.dart"; | |
| 2605 Source exportSource = new TestSource(exportUri); | |
| 2606 ExportDirective exportDirective = AstFactory.exportDirective2(exportUri); | |
| 2607 exportDirective.source = exportSource; | |
| 2608 exportDirective.uriContent = exportUri; | |
| 2609 String partUri = "/f3.dart"; | |
| 2610 Source partSource = new TestSource(partUri); | |
| 2611 PartDirective partDirective = AstFactory.partDirective2(partUri); | |
| 2612 partDirective.source = partSource; | |
| 2613 partDirective.uriContent = partUri; | |
| 2614 CompilationUnit unit = AstFactory | |
| 2615 .compilationUnit3([importDirective, exportDirective, partDirective]); | |
| 2616 DartEntry entry = new DartEntry(); | |
| 2617 entry.setValue(DartEntry.PARSED_UNIT, unit); | |
| 2618 entry.getValue(DartEntry.PARSED_UNIT); | |
| 2619 CompilationUnit result = entry.resolvableCompilationUnit; | |
| 2620 expect(result, same(unit)); | |
| 2621 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource, unit); | |
| 2622 result = entry.resolvableCompilationUnit; | |
| 2623 expect(result, isNot(same(unit))); | |
| 2624 NodeList<Directive> directives = result.directives; | |
| 2625 ImportDirective resultImportDirective = directives[0] as ImportDirective; | |
| 2626 expect(resultImportDirective.uriContent, importUri); | |
| 2627 expect(resultImportDirective.source, same(importSource)); | |
| 2628 ExportDirective resultExportDirective = directives[1] as ExportDirective; | |
| 2629 expect(resultExportDirective.uriContent, exportUri); | |
| 2630 expect(resultExportDirective.source, same(exportSource)); | |
| 2631 PartDirective resultPartDirective = directives[2] as PartDirective; | |
| 2632 expect(resultPartDirective.uriContent, partUri); | |
| 2633 expect(resultPartDirective.source, same(partSource)); | |
| 2634 } | |
| 2635 | |
| 2636 void test_getResolvableCompilationUnit_parsed_notAccessed() { | |
| 2637 CompilationUnit unit = AstFactory.compilationUnit(); | |
| 2638 DartEntry entry = new DartEntry(); | |
| 2639 entry.setValue(DartEntry.PARSED_UNIT, unit); | |
| 2640 expect(entry.resolvableCompilationUnit, same(unit)); | |
| 2641 } | |
| 2642 | |
| 2643 void test_getResolvableCompilationUnit_resolved() { | |
| 2644 String importUri = "f1.dart"; | |
| 2645 Source importSource = new TestSource(importUri); | |
| 2646 ImportDirective importDirective = | |
| 2647 AstFactory.importDirective3(importUri, null); | |
| 2648 importDirective.source = importSource; | |
| 2649 importDirective.uriContent = importUri; | |
| 2650 String exportUri = "f2.dart"; | |
| 2651 Source exportSource = new TestSource(exportUri); | |
| 2652 ExportDirective exportDirective = AstFactory.exportDirective2(exportUri); | |
| 2653 exportDirective.source = exportSource; | |
| 2654 exportDirective.uriContent = exportUri; | |
| 2655 String partUri = "f3.dart"; | |
| 2656 Source partSource = new TestSource(partUri); | |
| 2657 PartDirective partDirective = AstFactory.partDirective2(partUri); | |
| 2658 partDirective.source = partSource; | |
| 2659 partDirective.uriContent = partUri; | |
| 2660 CompilationUnit unit = AstFactory | |
| 2661 .compilationUnit3([importDirective, exportDirective, partDirective]); | |
| 2662 DartEntry entry = new DartEntry(); | |
| 2663 entry.setValueInLibrary( | |
| 2664 DartEntry.RESOLVED_UNIT, new TestSource("lib.dart"), unit); | |
| 2665 CompilationUnit result = entry.resolvableCompilationUnit; | |
| 2666 expect(result, isNot(same(unit))); | |
| 2667 NodeList<Directive> directives = result.directives; | |
| 2668 ImportDirective resultImportDirective = directives[0] as ImportDirective; | |
| 2669 expect(resultImportDirective.uriContent, importUri); | |
| 2670 expect(resultImportDirective.source, same(importSource)); | |
| 2671 ExportDirective resultExportDirective = directives[1] as ExportDirective; | |
| 2672 expect(resultExportDirective.uriContent, exportUri); | |
| 2673 expect(resultExportDirective.source, same(exportSource)); | |
| 2674 PartDirective resultPartDirective = directives[2] as PartDirective; | |
| 2675 expect(resultPartDirective.uriContent, partUri); | |
| 2676 expect(resultPartDirective.source, same(partSource)); | |
| 2677 } | |
| 2678 | |
| 2679 void test_getState_invalid_resolutionErrors() { | |
| 2680 DartEntry entry = new DartEntry(); | |
| 2681 try { | |
| 2682 entry.getState(DartEntry.RESOLUTION_ERRORS); | |
| 2683 fail("Expected ArgumentError for RESOLUTION_ERRORS"); | |
| 2684 } on ArgumentError { | |
| 2685 // Expected | |
| 2686 } | |
| 2687 } | |
| 2688 | |
| 2689 void test_getState_invalid_verificationErrors() { | |
| 2690 DartEntry entry = new DartEntry(); | |
| 2691 try { | |
| 2692 entry.getState(DartEntry.VERIFICATION_ERRORS); | |
| 2693 fail("Expected ArgumentError for VERIFICATION_ERRORS"); | |
| 2694 } on ArgumentError { | |
| 2695 // Expected | |
| 2696 } | |
| 2697 } | |
| 2698 | |
| 2699 void test_getStateInLibrary_invalid_element() { | |
| 2700 DartEntry entry = new DartEntry(); | |
| 2701 try { | |
| 2702 entry.getStateInLibrary(DartEntry.ELEMENT, new TestSource()); | |
| 2703 fail("Expected ArgumentError for ELEMENT"); | |
| 2704 } on ArgumentError { | |
| 2705 // Expected | |
| 2706 } | |
| 2707 } | |
| 2708 | |
| 2709 void test_getValue_containingLibraries() { | |
| 2710 Source testSource = new TestSource(); | |
| 2711 DartEntry entry = new DartEntry(); | |
| 2712 List<Source> value = entry.containingLibraries; | |
| 2713 expect(value, hasLength(0)); | |
| 2714 entry.addContainingLibrary(testSource); | |
| 2715 value = entry.containingLibraries; | |
| 2716 expect(value, hasLength(1)); | |
| 2717 expect(value[0], testSource); | |
| 2718 entry.removeContainingLibrary(testSource); | |
| 2719 value = entry.containingLibraries; | |
| 2720 expect(value, hasLength(0)); | |
| 2721 } | |
| 2722 | |
| 2723 void test_getValue_invalid_resolutionErrors() { | |
| 2724 DartEntry entry = new DartEntry(); | |
| 2725 try { | |
| 2726 entry.getValue(DartEntry.RESOLUTION_ERRORS); | |
| 2727 fail("Expected ArgumentError for RESOLUTION_ERRORS"); | |
| 2728 } on ArgumentError {} | |
| 2729 } | |
| 2730 | |
| 2731 void test_getValue_invalid_verificationErrors() { | |
| 2732 DartEntry entry = new DartEntry(); | |
| 2733 try { | |
| 2734 entry.getValue(DartEntry.VERIFICATION_ERRORS); | |
| 2735 fail("Expected ArgumentError for VERIFICATION_ERRORS"); | |
| 2736 } on ArgumentError { | |
| 2737 // Expected | |
| 2738 } | |
| 2739 } | |
| 2740 | |
| 2741 void test_getValueInLibrary_invalid_element() { | |
| 2742 DartEntry entry = new DartEntry(); | |
| 2743 try { | |
| 2744 entry.getValueInLibrary(DartEntry.ELEMENT, new TestSource()); | |
| 2745 fail("Expected ArgumentError for ELEMENT"); | |
| 2746 } on ArgumentError { | |
| 2747 // Expected | |
| 2748 } | |
| 2749 } | |
| 2750 | |
| 2751 void test_getValueInLibrary_invalid_resolutionErrors_multiple() { | |
| 2752 Source source1 = new TestSource(); | |
| 2753 Source source2 = new TestSource(); | |
| 2754 Source source3 = new TestSource(); | |
| 2755 DartEntry entry = new DartEntry(); | |
| 2756 entry.setValueInLibrary( | |
| 2757 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); | |
| 2758 entry.setValueInLibrary( | |
| 2759 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); | |
| 2760 entry.setValueInLibrary( | |
| 2761 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); | |
| 2762 try { | |
| 2763 entry.getValueInLibrary(DartEntry.ELEMENT, source3); | |
| 2764 fail("Expected ArgumentError for ELEMENT"); | |
| 2765 } on ArgumentError { | |
| 2766 // Expected | |
| 2767 } | |
| 2768 } | |
| 2769 | |
| 2770 void test_hasInvalidData_false() { | |
| 2771 DartEntry entry = new DartEntry(); | |
| 2772 entry.recordScanError(new CaughtException(new AnalysisException(), null)); | |
| 2773 expect(entry.hasInvalidData(DartEntry.ELEMENT), isFalse); | |
| 2774 expect(entry.hasInvalidData(DartEntry.EXPORTED_LIBRARIES), isFalse); | |
| 2775 expect(entry.hasInvalidData(DartEntry.HINTS), isFalse); | |
| 2776 expect(entry.hasInvalidData(DartEntry.IMPORTED_LIBRARIES), isFalse); | |
| 2777 expect(entry.hasInvalidData(DartEntry.INCLUDED_PARTS), isFalse); | |
| 2778 expect(entry.hasInvalidData(DartEntry.IS_CLIENT), isFalse); | |
| 2779 expect(entry.hasInvalidData(DartEntry.IS_LAUNCHABLE), isFalse); | |
| 2780 expect(entry.hasInvalidData(SourceEntry.LINE_INFO), isFalse); | |
| 2781 expect(entry.hasInvalidData(DartEntry.PARSE_ERRORS), isFalse); | |
| 2782 expect(entry.hasInvalidData(DartEntry.PARSED_UNIT), isFalse); | |
| 2783 expect(entry.hasInvalidData(DartEntry.PUBLIC_NAMESPACE), isFalse); | |
| 2784 expect(entry.hasInvalidData(DartEntry.SOURCE_KIND), isFalse); | |
| 2785 expect(entry.hasInvalidData(DartEntry.RESOLUTION_ERRORS), isFalse); | |
| 2786 expect(entry.hasInvalidData(DartEntry.RESOLVED_UNIT), isFalse); | |
| 2787 expect(entry.hasInvalidData(DartEntry.VERIFICATION_ERRORS), isFalse); | |
| 2788 } | |
| 2789 | |
| 2790 void test_hasInvalidData_true() { | |
| 2791 DartEntry entry = new DartEntry(); | |
| 2792 expect(entry.hasInvalidData(DartEntry.ELEMENT), isTrue); | |
| 2793 expect(entry.hasInvalidData(DartEntry.EXPORTED_LIBRARIES), isTrue); | |
| 2794 expect(entry.hasInvalidData(DartEntry.HINTS), isTrue); | |
| 2795 expect(entry.hasInvalidData(DartEntry.IMPORTED_LIBRARIES), isTrue); | |
| 2796 expect(entry.hasInvalidData(DartEntry.INCLUDED_PARTS), isTrue); | |
| 2797 expect(entry.hasInvalidData(DartEntry.IS_CLIENT), isTrue); | |
| 2798 expect(entry.hasInvalidData(DartEntry.IS_LAUNCHABLE), isTrue); | |
| 2799 expect(entry.hasInvalidData(SourceEntry.LINE_INFO), isTrue); | |
| 2800 expect(entry.hasInvalidData(DartEntry.PARSE_ERRORS), isTrue); | |
| 2801 expect(entry.hasInvalidData(DartEntry.PARSED_UNIT), isTrue); | |
| 2802 expect(entry.hasInvalidData(DartEntry.PUBLIC_NAMESPACE), isTrue); | |
| 2803 expect(entry.hasInvalidData(DartEntry.SOURCE_KIND), isTrue); | |
| 2804 expect(entry.hasInvalidData(DartEntry.RESOLUTION_ERRORS), isTrue); | |
| 2805 expect(entry.hasInvalidData(DartEntry.RESOLVED_UNIT), isTrue); | |
| 2806 expect(entry.hasInvalidData(DartEntry.VERIFICATION_ERRORS), isTrue); | |
| 2807 } | |
| 2808 | |
| 2809 void test_invalidateAllInformation() { | |
| 2810 Source librarySource = new TestSource(); | |
| 2811 DartEntry entry = _entryWithValidState(librarySource); | |
| 2812 entry.invalidateAllInformation(); | |
| 2813 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.INVALID)); | |
| 2814 expect( | |
| 2815 entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.INVALID)); | |
| 2816 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.INVALID)); | |
| 2817 expect( | |
| 2818 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 2819 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); | |
| 2820 expect( | |
| 2821 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2822 expect( | |
| 2823 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2824 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); | |
| 2825 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); | |
| 2826 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); | |
| 2827 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.INVALID)); | |
| 2828 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.INVALID)); | |
| 2829 expect( | |
| 2830 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); | |
| 2831 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.INVALID)); | |
| 2832 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.INVALID)); | |
| 2833 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.INVALID)); | |
| 2834 | |
| 2835 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), | |
| 2836 same(CacheState.INVALID)); | |
| 2837 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), | |
| 2838 same(CacheState.INVALID)); | |
| 2839 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), | |
| 2840 same(CacheState.INVALID)); | |
| 2841 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), | |
| 2842 same(CacheState.INVALID)); | |
| 2843 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), | |
| 2844 same(CacheState.INVALID)); | |
| 2845 expect( | |
| 2846 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), | |
| 2847 same(CacheState.INVALID)); | |
| 2848 } | |
| 2849 | |
| 2850 void test_invalidateAllResolutionInformation() { | |
| 2851 Source librarySource = new TestSource(); | |
| 2852 DartEntry entry = _entryWithValidState(librarySource); | |
| 2853 entry.invalidateAllResolutionInformation(false); | |
| 2854 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 2855 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 2856 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 2857 expect( | |
| 2858 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 2859 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); | |
| 2860 expect( | |
| 2861 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 2862 expect( | |
| 2863 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 2864 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 2865 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); | |
| 2866 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); | |
| 2867 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 2868 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 2869 expect( | |
| 2870 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); | |
| 2871 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 2872 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 2873 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 2874 | |
| 2875 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), | |
| 2876 same(CacheState.INVALID)); | |
| 2877 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), | |
| 2878 same(CacheState.INVALID)); | |
| 2879 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), | |
| 2880 same(CacheState.INVALID)); | |
| 2881 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), | |
| 2882 same(CacheState.INVALID)); | |
| 2883 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), | |
| 2884 same(CacheState.INVALID)); | |
| 2885 expect( | |
| 2886 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), | |
| 2887 same(CacheState.INVALID)); | |
| 2888 } | |
| 2889 | |
| 2890 void test_invalidateAllResolutionInformation_includingUris() { | |
| 2891 Source librarySource = new TestSource(); | |
| 2892 DartEntry entry = _entryWithValidState(librarySource); | |
| 2893 entry.invalidateAllResolutionInformation(true); | |
| 2894 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 2895 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 2896 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 2897 expect( | |
| 2898 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 2899 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.INVALID)); | |
| 2900 expect( | |
| 2901 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2902 expect( | |
| 2903 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.INVALID)); | |
| 2904 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.INVALID)); | |
| 2905 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); | |
| 2906 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); | |
| 2907 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 2908 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 2909 expect( | |
| 2910 entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.INVALID)); | |
| 2911 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 2912 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 2913 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 2914 | |
| 2915 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, librarySource), | |
| 2916 same(CacheState.INVALID)); | |
| 2917 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, librarySource), | |
| 2918 same(CacheState.INVALID)); | |
| 2919 expect(entry.getStateInLibrary(DartEntry.HINTS, librarySource), | |
| 2920 same(CacheState.INVALID)); | |
| 2921 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, librarySource), | |
| 2922 same(CacheState.INVALID)); | |
| 2923 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, librarySource), | |
| 2924 same(CacheState.INVALID)); | |
| 2925 expect( | |
| 2926 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, librarySource), | |
| 2927 same(CacheState.INVALID)); | |
| 2928 } | |
| 2929 | |
| 2930 void test_isClient() { | |
| 2931 DartEntry entry = new DartEntry(); | |
| 2932 // true | |
| 2933 entry.setValue(DartEntry.IS_CLIENT, true); | |
| 2934 expect(entry.getValue(DartEntry.IS_CLIENT), isTrue); | |
| 2935 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); | |
| 2936 // invalidate | |
| 2937 entry.setState(DartEntry.IS_CLIENT, CacheState.INVALID); | |
| 2938 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.INVALID)); | |
| 2939 // false | |
| 2940 entry.setValue(DartEntry.IS_CLIENT, false); | |
| 2941 expect(entry.getValue(DartEntry.IS_CLIENT), isFalse); | |
| 2942 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); | |
| 2943 } | |
| 2944 | |
| 2945 void test_isLaunchable() { | |
| 2946 DartEntry entry = new DartEntry(); | |
| 2947 // true | |
| 2948 entry.setValue(DartEntry.IS_LAUNCHABLE, true); | |
| 2949 expect(entry.getValue(DartEntry.IS_LAUNCHABLE), isTrue); | |
| 2950 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); | |
| 2951 // invalidate | |
| 2952 entry.setState(DartEntry.IS_LAUNCHABLE, CacheState.INVALID); | |
| 2953 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.INVALID)); | |
| 2954 // false | |
| 2955 entry.setValue(DartEntry.IS_LAUNCHABLE, false); | |
| 2956 expect(entry.getValue(DartEntry.IS_LAUNCHABLE), isFalse); | |
| 2957 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); | |
| 2958 } | |
| 2959 | |
| 2960 void test_recordBuildElementError() { | |
| 2961 Source firstLibrary = new TestSource('first.dart'); | |
| 2962 Source secondLibrary = new TestSource('second.dart'); | |
| 2963 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); | |
| 2964 entry.recordBuildElementErrorInLibrary( | |
| 2965 firstLibrary, new CaughtException(new AnalysisException(), null)); | |
| 2966 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 2967 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 2968 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 2969 expect( | |
| 2970 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 2971 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 2972 expect( | |
| 2973 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 2974 expect( | |
| 2975 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 2976 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 2977 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 2978 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 2979 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 2980 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 2981 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 2982 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 2983 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 2984 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 2985 | |
| 2986 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 2987 same(CacheState.ERROR)); | |
| 2988 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 2989 same(CacheState.ERROR)); | |
| 2990 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 2991 same(CacheState.ERROR)); | |
| 2992 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 2993 same(CacheState.ERROR)); | |
| 2994 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 2995 same(CacheState.ERROR)); | |
| 2996 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 2997 same(CacheState.ERROR)); | |
| 2998 | |
| 2999 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), | |
| 3000 same(CacheState.VALID)); | |
| 3001 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), | |
| 3002 same(CacheState.VALID)); | |
| 3003 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), | |
| 3004 same(CacheState.VALID)); | |
| 3005 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), | |
| 3006 same(CacheState.VALID)); | |
| 3007 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), | |
| 3008 same(CacheState.VALID)); | |
| 3009 expect( | |
| 3010 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), | |
| 3011 same(CacheState.VALID)); | |
| 3012 } | |
| 3013 | |
| 3014 void test_recordContentError() { | |
| 3015 Source firstLibrary = new TestSource('first.dart'); | |
| 3016 // Source secondLibrary = new TestSource('second.dart'); | |
| 3017 DartEntry entry = _entryWithValidState(firstLibrary); | |
| 3018 entry | |
| 3019 .recordContentError(new CaughtException(new AnalysisException(), null)); | |
| 3020 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.ERROR)); | |
| 3021 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3022 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.ERROR)); | |
| 3023 expect( | |
| 3024 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3025 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 3026 expect( | |
| 3027 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3028 expect( | |
| 3029 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3030 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); | |
| 3031 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 3032 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 3033 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); | |
| 3034 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); | |
| 3035 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 3036 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.ERROR)); | |
| 3037 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); | |
| 3038 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.ERROR)); | |
| 3039 | |
| 3040 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3041 same(CacheState.ERROR)); | |
| 3042 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3043 same(CacheState.ERROR)); | |
| 3044 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3045 same(CacheState.ERROR)); | |
| 3046 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3047 same(CacheState.ERROR)); | |
| 3048 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3049 same(CacheState.ERROR)); | |
| 3050 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3051 same(CacheState.ERROR)); | |
| 3052 | |
| 3053 // The following lines are commented out because we don't currently have | |
| 3054 // any way of setting the state for data associated with a library we | |
| 3055 // don't know anything about. | |
| 3056 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); | |
| 3057 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3058 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); | |
| 3059 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); | |
| 3060 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); | |
| 3061 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3062 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); | |
| 3063 } | |
| 3064 | |
| 3065 void test_recordHintErrorInLibrary() { | |
| 3066 Source firstLibrary = new TestSource('first.dart'); | |
| 3067 Source secondLibrary = new TestSource('second.dart'); | |
| 3068 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); | |
| 3069 entry.recordHintErrorInLibrary( | |
| 3070 firstLibrary, new CaughtException(new AnalysisException(), null)); | |
| 3071 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3072 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3073 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3074 expect( | |
| 3075 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3076 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); | |
| 3077 expect( | |
| 3078 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3079 expect( | |
| 3080 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3081 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 3082 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); | |
| 3083 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); | |
| 3084 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 3085 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 3086 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); | |
| 3087 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3088 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 3089 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3090 | |
| 3091 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3092 same(CacheState.VALID)); | |
| 3093 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3094 same(CacheState.VALID)); | |
| 3095 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3096 same(CacheState.ERROR)); | |
| 3097 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3098 same(CacheState.VALID)); | |
| 3099 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3100 same(CacheState.VALID)); | |
| 3101 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3102 same(CacheState.VALID)); | |
| 3103 | |
| 3104 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), | |
| 3105 same(CacheState.VALID)); | |
| 3106 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), | |
| 3107 same(CacheState.VALID)); | |
| 3108 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), | |
| 3109 same(CacheState.VALID)); | |
| 3110 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), | |
| 3111 same(CacheState.VALID)); | |
| 3112 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), | |
| 3113 same(CacheState.VALID)); | |
| 3114 expect( | |
| 3115 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), | |
| 3116 same(CacheState.VALID)); | |
| 3117 } | |
| 3118 | |
| 3119 void test_recordParseError() { | |
| 3120 Source firstLibrary = new TestSource('first.dart'); | |
| 3121 // Source secondLibrary = new TestSource('second.dart'); | |
| 3122 DartEntry entry = _entryWithValidState(firstLibrary); | |
| 3123 entry.recordParseError(new CaughtException(new AnalysisException(), null)); | |
| 3124 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3125 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3126 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3127 expect( | |
| 3128 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3129 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 3130 expect( | |
| 3131 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3132 expect( | |
| 3133 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3134 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); | |
| 3135 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 3136 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 3137 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); | |
| 3138 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); | |
| 3139 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 3140 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3141 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); | |
| 3142 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3143 | |
| 3144 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3145 same(CacheState.ERROR)); | |
| 3146 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3147 same(CacheState.ERROR)); | |
| 3148 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3149 same(CacheState.ERROR)); | |
| 3150 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3151 same(CacheState.ERROR)); | |
| 3152 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3153 same(CacheState.ERROR)); | |
| 3154 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3155 same(CacheState.ERROR)); | |
| 3156 | |
| 3157 // The following lines are commented out because we don't currently have | |
| 3158 // any way of setting the state for data associated with a library we | |
| 3159 // don't know anything about. | |
| 3160 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); | |
| 3161 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3162 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); | |
| 3163 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); | |
| 3164 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); | |
| 3165 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3166 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); | |
| 3167 } | |
| 3168 | |
| 3169 void test_recordResolutionError() { | |
| 3170 Source firstLibrary = new TestSource('first.dart'); | |
| 3171 // Source secondLibrary = new TestSource('second.dart'); | |
| 3172 DartEntry entry = _entryWithValidState(firstLibrary); | |
| 3173 entry.recordResolutionError( | |
| 3174 new CaughtException(new AnalysisException(), null)); | |
| 3175 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3176 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3177 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3178 expect( | |
| 3179 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3180 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 3181 expect( | |
| 3182 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3183 expect( | |
| 3184 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3185 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 3186 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 3187 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 3188 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 3189 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 3190 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 3191 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3192 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 3193 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3194 | |
| 3195 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3196 same(CacheState.ERROR)); | |
| 3197 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3198 same(CacheState.ERROR)); | |
| 3199 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3200 same(CacheState.ERROR)); | |
| 3201 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3202 same(CacheState.ERROR)); | |
| 3203 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3204 same(CacheState.ERROR)); | |
| 3205 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3206 same(CacheState.ERROR)); | |
| 3207 | |
| 3208 // The following lines are commented out because we don't currently have | |
| 3209 // any way of setting the state for data associated with a library we | |
| 3210 // don't know anything about. | |
| 3211 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); | |
| 3212 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3213 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); | |
| 3214 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); | |
| 3215 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); | |
| 3216 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3217 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); | |
| 3218 } | |
| 3219 | |
| 3220 void test_recordResolutionErrorInLibrary() { | |
| 3221 Source firstLibrary = new TestSource('first.dart'); | |
| 3222 Source secondLibrary = new TestSource('second.dart'); | |
| 3223 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); | |
| 3224 entry.recordResolutionErrorInLibrary( | |
| 3225 firstLibrary, new CaughtException(new AnalysisException(), null)); | |
| 3226 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3227 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3228 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3229 expect( | |
| 3230 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3231 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 3232 expect( | |
| 3233 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3234 expect( | |
| 3235 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3236 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 3237 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 3238 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 3239 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 3240 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 3241 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 3242 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3243 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 3244 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3245 | |
| 3246 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3247 same(CacheState.VALID)); | |
| 3248 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3249 same(CacheState.VALID)); | |
| 3250 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3251 same(CacheState.ERROR)); | |
| 3252 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3253 same(CacheState.ERROR)); | |
| 3254 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3255 same(CacheState.ERROR)); | |
| 3256 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3257 same(CacheState.ERROR)); | |
| 3258 | |
| 3259 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), | |
| 3260 same(CacheState.VALID)); | |
| 3261 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), | |
| 3262 same(CacheState.VALID)); | |
| 3263 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), | |
| 3264 same(CacheState.VALID)); | |
| 3265 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), | |
| 3266 same(CacheState.VALID)); | |
| 3267 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), | |
| 3268 same(CacheState.VALID)); | |
| 3269 expect( | |
| 3270 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), | |
| 3271 same(CacheState.VALID)); | |
| 3272 } | |
| 3273 | |
| 3274 void test_recordScanError() { | |
| 3275 Source firstLibrary = new TestSource('first.dart'); | |
| 3276 // Source secondLibrary = new TestSource('second.dart'); | |
| 3277 DartEntry entry = _entryWithValidState(firstLibrary); | |
| 3278 entry.recordScanError(new CaughtException(new AnalysisException(), null)); | |
| 3279 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3280 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3281 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.ERROR)); | |
| 3282 expect( | |
| 3283 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3284 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.ERROR)); | |
| 3285 expect( | |
| 3286 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3287 expect( | |
| 3288 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.ERROR)); | |
| 3289 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.ERROR)); | |
| 3290 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.ERROR)); | |
| 3291 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.ERROR)); | |
| 3292 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.ERROR)); | |
| 3293 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.ERROR)); | |
| 3294 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.ERROR)); | |
| 3295 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.ERROR)); | |
| 3296 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.ERROR)); | |
| 3297 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.ERROR)); | |
| 3298 | |
| 3299 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3300 same(CacheState.ERROR)); | |
| 3301 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3302 same(CacheState.ERROR)); | |
| 3303 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3304 same(CacheState.ERROR)); | |
| 3305 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3306 same(CacheState.ERROR)); | |
| 3307 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3308 same(CacheState.ERROR)); | |
| 3309 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3310 same(CacheState.ERROR)); | |
| 3311 | |
| 3312 // The following lines are commented out because we don't currently have | |
| 3313 // any way of setting the state for data associated with a library we | |
| 3314 // don't know anything about. | |
| 3315 // expect(entry.getStateInLibrary(DartEntry.ANGULAR_ERRORS, secondLibrary), s
ame(CacheState.ERROR)); | |
| 3316 // expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3317 // expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), same(
CacheState.ERROR)); | |
| 3318 // expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), same(Cache
State.ERROR)); | |
| 3319 // expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary)
, same(CacheState.ERROR)); | |
| 3320 // expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), sa
me(CacheState.ERROR)); | |
| 3321 // expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrar
y), same(CacheState.ERROR)); | |
| 3322 } | |
| 3323 | |
| 3324 void test_recordVerificationErrorInLibrary() { | |
| 3325 Source firstLibrary = new TestSource('first.dart'); | |
| 3326 Source secondLibrary = new TestSource('second.dart'); | |
| 3327 DartEntry entry = _entryWithValidState(firstLibrary, secondLibrary); | |
| 3328 entry.recordVerificationErrorInLibrary( | |
| 3329 firstLibrary, new CaughtException(new AnalysisException(), null)); | |
| 3330 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3331 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3332 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3333 expect( | |
| 3334 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3335 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); | |
| 3336 expect( | |
| 3337 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3338 expect( | |
| 3339 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3340 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 3341 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); | |
| 3342 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); | |
| 3343 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 3344 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 3345 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); | |
| 3346 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3347 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 3348 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3349 | |
| 3350 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3351 same(CacheState.VALID)); | |
| 3352 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3353 same(CacheState.VALID)); | |
| 3354 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3355 same(CacheState.ERROR)); | |
| 3356 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3357 same(CacheState.VALID)); | |
| 3358 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3359 same(CacheState.VALID)); | |
| 3360 expect(entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3361 same(CacheState.ERROR)); | |
| 3362 | |
| 3363 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), | |
| 3364 same(CacheState.VALID)); | |
| 3365 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), | |
| 3366 same(CacheState.VALID)); | |
| 3367 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), | |
| 3368 same(CacheState.VALID)); | |
| 3369 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), | |
| 3370 same(CacheState.VALID)); | |
| 3371 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), | |
| 3372 same(CacheState.VALID)); | |
| 3373 expect( | |
| 3374 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), | |
| 3375 same(CacheState.VALID)); | |
| 3376 } | |
| 3377 | |
| 3378 void test_removeResolution_multiple_first() { | |
| 3379 Source source1 = new TestSource('first.dart'); | |
| 3380 Source source2 = new TestSource('second.dart'); | |
| 3381 Source source3 = new TestSource('third.dart'); | |
| 3382 DartEntry entry = new DartEntry(); | |
| 3383 entry.setValueInLibrary( | |
| 3384 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); | |
| 3385 entry.setValueInLibrary( | |
| 3386 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); | |
| 3387 entry.setValueInLibrary( | |
| 3388 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); | |
| 3389 entry.removeResolution(source1); | |
| 3390 } | |
| 3391 | |
| 3392 void test_removeResolution_multiple_last() { | |
| 3393 Source source1 = new TestSource('first.dart'); | |
| 3394 Source source2 = new TestSource('second.dart'); | |
| 3395 Source source3 = new TestSource('third.dart'); | |
| 3396 DartEntry entry = new DartEntry(); | |
| 3397 entry.setValueInLibrary( | |
| 3398 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); | |
| 3399 entry.setValueInLibrary( | |
| 3400 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); | |
| 3401 entry.setValueInLibrary( | |
| 3402 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); | |
| 3403 entry.removeResolution(source3); | |
| 3404 } | |
| 3405 | |
| 3406 void test_removeResolution_multiple_middle() { | |
| 3407 Source source1 = new TestSource('first.dart'); | |
| 3408 Source source2 = new TestSource('second.dart'); | |
| 3409 Source source3 = new TestSource('third.dart'); | |
| 3410 DartEntry entry = new DartEntry(); | |
| 3411 entry.setValueInLibrary( | |
| 3412 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); | |
| 3413 entry.setValueInLibrary( | |
| 3414 DartEntry.RESOLVED_UNIT, source2, AstFactory.compilationUnit()); | |
| 3415 entry.setValueInLibrary( | |
| 3416 DartEntry.RESOLVED_UNIT, source3, AstFactory.compilationUnit()); | |
| 3417 entry.removeResolution(source2); | |
| 3418 } | |
| 3419 | |
| 3420 void test_removeResolution_single() { | |
| 3421 Source source1 = new TestSource(); | |
| 3422 DartEntry entry = new DartEntry(); | |
| 3423 entry.setValueInLibrary( | |
| 3424 DartEntry.RESOLVED_UNIT, source1, AstFactory.compilationUnit()); | |
| 3425 entry.removeResolution(source1); | |
| 3426 } | |
| 3427 | |
| 3428 void test_resolvableCompilationUnit_builtUnit() { | |
| 3429 Source librarySource = new TestSource('/lib.dart'); | |
| 3430 CompilationUnit unit = AstFactory.compilationUnit(); | |
| 3431 CompilationUnitElement element = | |
| 3432 ElementFactory.compilationUnit('test.dart'); | |
| 3433 unit.element = element; | |
| 3434 DartEntry entry = new DartEntry(); | |
| 3435 entry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); | |
| 3436 entry.setValueInLibrary(DartEntry.BUILT_UNIT, librarySource, unit); | |
| 3437 entry.invalidateAllResolutionInformation(false); | |
| 3438 CompilationUnit resolvableUnit = entry.resolvableCompilationUnit; | |
| 3439 expect(resolvableUnit, isNotNull); | |
| 3440 expect(resolvableUnit.element, isNull); | |
| 3441 expect(entry.resolvableCompilationUnit, isNull); | |
| 3442 } | |
| 3443 | |
| 3444 void test_resolvableCompilationUnit_none() { | |
| 3445 DartEntry entry = new DartEntry(); | |
| 3446 expect(entry.resolvableCompilationUnit, isNull); | |
| 3447 } | |
| 3448 | |
| 3449 void test_resolvableCompilationUnit_parsed() { | |
| 3450 CompilationUnit unit = AstFactory.compilationUnit(); | |
| 3451 DartEntry entry = new DartEntry(); | |
| 3452 entry.setValue(DartEntry.PARSED_UNIT, unit); | |
| 3453 expect(entry.resolvableCompilationUnit, unit); | |
| 3454 expect(entry.resolvableCompilationUnit, isNull); | |
| 3455 } | |
| 3456 | |
| 3457 void test_resolvableCompilationUnit_resolved() { | |
| 3458 Source librarySource = new TestSource('/lib.dart'); | |
| 3459 CompilationUnit unit = AstFactory.compilationUnit(); | |
| 3460 CompilationUnitElement element = | |
| 3461 ElementFactory.compilationUnit('test.dart'); | |
| 3462 unit.element = element; | |
| 3463 DartEntry entry = new DartEntry(); | |
| 3464 entry.setState(DartEntry.PARSED_UNIT, CacheState.FLUSHED); | |
| 3465 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, librarySource, unit); | |
| 3466 entry.invalidateAllResolutionInformation(false); | |
| 3467 CompilationUnit resolvableUnit = entry.resolvableCompilationUnit; | |
| 3468 expect(resolvableUnit, isNotNull); | |
| 3469 expect(resolvableUnit.element, isNull); | |
| 3470 expect(entry.resolvableCompilationUnit, isNull); | |
| 3471 } | |
| 3472 | |
| 3473 void test_setState_element() { | |
| 3474 _setState(DartEntry.ELEMENT); | |
| 3475 } | |
| 3476 | |
| 3477 void test_setState_exportedLibraries() { | |
| 3478 _setState(DartEntry.EXPORTED_LIBRARIES); | |
| 3479 } | |
| 3480 | |
| 3481 void test_setState_hints() { | |
| 3482 _setStateInLibrary(DartEntry.HINTS); | |
| 3483 } | |
| 3484 | |
| 3485 void test_setState_importedLibraries() { | |
| 3486 _setState(DartEntry.IMPORTED_LIBRARIES); | |
| 3487 } | |
| 3488 | |
| 3489 void test_setState_includedParts() { | |
| 3490 _setState(DartEntry.INCLUDED_PARTS); | |
| 3491 } | |
| 3492 | |
| 3493 void test_setState_invalid_element() { | |
| 3494 DartEntry entry = new DartEntry(); | |
| 3495 try { | |
| 3496 entry.setStateInLibrary(DartEntry.ELEMENT, null, CacheState.FLUSHED); | |
| 3497 fail("Expected ArgumentError for ELEMENT"); | |
| 3498 } on ArgumentError { | |
| 3499 // Expected | |
| 3500 } | |
| 3501 } | |
| 3502 | |
| 3503 void test_setState_invalid_resolutionErrors() { | |
| 3504 DartEntry entry = new DartEntry(); | |
| 3505 try { | |
| 3506 entry.setState(DartEntry.RESOLUTION_ERRORS, CacheState.FLUSHED); | |
| 3507 fail("Expected ArgumentError for RESOLUTION_ERRORS"); | |
| 3508 } on ArgumentError { | |
| 3509 // Expected | |
| 3510 } | |
| 3511 } | |
| 3512 | |
| 3513 void test_setState_invalid_validState() { | |
| 3514 DartEntry entry = new DartEntry(); | |
| 3515 try { | |
| 3516 entry.setState(SourceEntry.LINE_INFO, CacheState.VALID); | |
| 3517 fail("Expected ArgumentError for a state of VALID"); | |
| 3518 } on ArgumentError {} | |
| 3519 } | |
| 3520 | |
| 3521 void test_setState_invalid_verificationErrors() { | |
| 3522 DartEntry entry = new DartEntry(); | |
| 3523 try { | |
| 3524 entry.setState(DartEntry.VERIFICATION_ERRORS, CacheState.FLUSHED); | |
| 3525 fail("Expected ArgumentError for VERIFICATION_ERRORS"); | |
| 3526 } on ArgumentError { | |
| 3527 // Expected | |
| 3528 } | |
| 3529 } | |
| 3530 | |
| 3531 void test_setState_isClient() { | |
| 3532 _setState(DartEntry.IS_CLIENT); | |
| 3533 } | |
| 3534 | |
| 3535 void test_setState_isLaunchable() { | |
| 3536 _setState(DartEntry.IS_LAUNCHABLE); | |
| 3537 } | |
| 3538 | |
| 3539 void test_setState_lineInfo() { | |
| 3540 _setState(SourceEntry.LINE_INFO); | |
| 3541 } | |
| 3542 | |
| 3543 void test_setState_parsedUnit() { | |
| 3544 _setState(DartEntry.PARSED_UNIT); | |
| 3545 } | |
| 3546 | |
| 3547 void test_setState_parseErrors() { | |
| 3548 _setState(DartEntry.PARSE_ERRORS); | |
| 3549 } | |
| 3550 | |
| 3551 void test_setState_publicNamespace() { | |
| 3552 _setState(DartEntry.PUBLIC_NAMESPACE); | |
| 3553 } | |
| 3554 | |
| 3555 void test_setState_resolutionErrors() { | |
| 3556 _setStateInLibrary(DartEntry.RESOLUTION_ERRORS); | |
| 3557 } | |
| 3558 | |
| 3559 void test_setState_resolvedUnit() { | |
| 3560 _setStateInLibrary(DartEntry.RESOLVED_UNIT); | |
| 3561 } | |
| 3562 | |
| 3563 void test_setState_scanErrors() { | |
| 3564 _setState(DartEntry.SCAN_ERRORS); | |
| 3565 } | |
| 3566 | |
| 3567 void test_setState_sourceKind() { | |
| 3568 _setState(DartEntry.SOURCE_KIND); | |
| 3569 } | |
| 3570 | |
| 3571 void test_setState_tokenStream() { | |
| 3572 _setState(DartEntry.TOKEN_STREAM); | |
| 3573 } | |
| 3574 | |
| 3575 void test_setState_verificationErrors() { | |
| 3576 _setStateInLibrary(DartEntry.VERIFICATION_ERRORS); | |
| 3577 } | |
| 3578 | |
| 3579 void test_setValue_element() { | |
| 3580 _setValue( | |
| 3581 DartEntry.ELEMENT, | |
| 3582 new LibraryElementImpl.forNode( | |
| 3583 null, AstFactory.libraryIdentifier2(["lib"]))); | |
| 3584 } | |
| 3585 | |
| 3586 void test_setValue_exportedLibraries() { | |
| 3587 _setValue(DartEntry.EXPORTED_LIBRARIES, <Source>[new TestSource()]); | |
| 3588 } | |
| 3589 | |
| 3590 void test_setValue_hints() { | |
| 3591 _setValueInLibrary(DartEntry.HINTS, | |
| 3592 <AnalysisError>[new AnalysisError(null, 0, 0, HintCode.DEAD_CODE)]); | |
| 3593 } | |
| 3594 | |
| 3595 void test_setValue_importedLibraries() { | |
| 3596 _setValue(DartEntry.IMPORTED_LIBRARIES, <Source>[new TestSource()]); | |
| 3597 } | |
| 3598 | |
| 3599 void test_setValue_includedParts() { | |
| 3600 _setValue(DartEntry.INCLUDED_PARTS, <Source>[new TestSource()]); | |
| 3601 } | |
| 3602 | |
| 3603 void test_setValue_isClient() { | |
| 3604 _setValue(DartEntry.IS_CLIENT, true); | |
| 3605 } | |
| 3606 | |
| 3607 void test_setValue_isLaunchable() { | |
| 3608 _setValue(DartEntry.IS_LAUNCHABLE, true); | |
| 3609 } | |
| 3610 | |
| 3611 void test_setValue_lineInfo() { | |
| 3612 _setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); | |
| 3613 } | |
| 3614 | |
| 3615 void test_setValue_parsedUnit() { | |
| 3616 _setValue(DartEntry.PARSED_UNIT, AstFactory.compilationUnit()); | |
| 3617 } | |
| 3618 | |
| 3619 void test_setValue_parseErrors() { | |
| 3620 _setValue(DartEntry.PARSE_ERRORS, <AnalysisError>[ | |
| 3621 new AnalysisError(null, 0, 0, ParserErrorCode.ABSTRACT_CLASS_MEMBER) | |
| 3622 ]); | |
| 3623 } | |
| 3624 | |
| 3625 void test_setValue_publicNamespace() { | |
| 3626 _setValue(DartEntry.PUBLIC_NAMESPACE, | |
| 3627 new Namespace(new HashMap<String, Element>())); | |
| 3628 } | |
| 3629 | |
| 3630 void test_setValue_resolutionErrors() { | |
| 3631 _setValueInLibrary(DartEntry.RESOLUTION_ERRORS, <AnalysisError>[ | |
| 3632 new AnalysisError( | |
| 3633 null, 0, 0, CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION) | |
| 3634 ]); | |
| 3635 } | |
| 3636 | |
| 3637 void test_setValue_resolvedUnit() { | |
| 3638 _setValueInLibrary(DartEntry.RESOLVED_UNIT, AstFactory.compilationUnit()); | |
| 3639 } | |
| 3640 | |
| 3641 void test_setValue_scanErrors() { | |
| 3642 _setValue(DartEntry.SCAN_ERRORS, <AnalysisError>[ | |
| 3643 new AnalysisError( | |
| 3644 null, 0, 0, ScannerErrorCode.UNTERMINATED_MULTI_LINE_COMMENT) | |
| 3645 ]); | |
| 3646 } | |
| 3647 | |
| 3648 void test_setValue_sourceKind() { | |
| 3649 _setValue(DartEntry.SOURCE_KIND, SourceKind.LIBRARY); | |
| 3650 } | |
| 3651 | |
| 3652 void test_setValue_tokenStream() { | |
| 3653 _setValue(DartEntry.TOKEN_STREAM, new Token(TokenType.LT, 5)); | |
| 3654 } | |
| 3655 | |
| 3656 void test_setValue_verificationErrors() { | |
| 3657 _setValueInLibrary(DartEntry.VERIFICATION_ERRORS, <AnalysisError>[ | |
| 3658 new AnalysisError(null, 0, 0, StaticWarningCode.CASE_BLOCK_NOT_TERMINATED) | |
| 3659 ]); | |
| 3660 } | |
| 3661 | |
| 3662 DartEntry _entryWithValidState([Source firstLibrary, Source secondLibrary]) { | |
| 3663 DartEntry entry = new DartEntry(); | |
| 3664 entry.setValue(SourceEntry.CONTENT, null); | |
| 3665 entry.setValue(SourceEntry.CONTENT_ERRORS, null); | |
| 3666 entry.setValue(SourceEntry.LINE_INFO, null); | |
| 3667 entry.setValue(DartEntry.CONTAINING_LIBRARIES, null); | |
| 3668 entry.setValue(DartEntry.ELEMENT, null); | |
| 3669 entry.setValue(DartEntry.EXPORTED_LIBRARIES, null); | |
| 3670 entry.setValue(DartEntry.IMPORTED_LIBRARIES, null); | |
| 3671 entry.setValue(DartEntry.INCLUDED_PARTS, null); | |
| 3672 entry.setValue(DartEntry.IS_CLIENT, null); | |
| 3673 entry.setValue(DartEntry.IS_LAUNCHABLE, null); | |
| 3674 entry.setValue(DartEntry.PARSE_ERRORS, null); | |
| 3675 entry.setValue(DartEntry.PARSED_UNIT, null); | |
| 3676 entry.setValue(DartEntry.PUBLIC_NAMESPACE, null); | |
| 3677 entry.setValue(DartEntry.SCAN_ERRORS, null); | |
| 3678 entry.setValue(DartEntry.SOURCE_KIND, null); | |
| 3679 entry.setValue(DartEntry.TOKEN_STREAM, null); | |
| 3680 if (firstLibrary != null) { | |
| 3681 entry.setValueInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary, null); | |
| 3682 entry.setValueInLibrary(DartEntry.BUILT_UNIT, firstLibrary, null); | |
| 3683 entry.setValueInLibrary(DartEntry.HINTS, firstLibrary, null); | |
| 3684 entry.setValueInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary, null); | |
| 3685 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary, null); | |
| 3686 entry.setValueInLibrary( | |
| 3687 DartEntry.VERIFICATION_ERRORS, firstLibrary, null); | |
| 3688 } | |
| 3689 if (secondLibrary != null) { | |
| 3690 entry.setValueInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary, null); | |
| 3691 entry.setValueInLibrary(DartEntry.BUILT_UNIT, secondLibrary, null); | |
| 3692 entry.setValueInLibrary(DartEntry.HINTS, secondLibrary, null); | |
| 3693 entry.setValueInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary, null); | |
| 3694 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary, null); | |
| 3695 entry.setValueInLibrary( | |
| 3696 DartEntry.VERIFICATION_ERRORS, secondLibrary, null); | |
| 3697 } | |
| 3698 // | |
| 3699 // Validate that the state was set correctly. | |
| 3700 // | |
| 3701 expect(entry.getState(SourceEntry.CONTENT), same(CacheState.VALID)); | |
| 3702 expect(entry.getState(SourceEntry.CONTENT_ERRORS), same(CacheState.VALID)); | |
| 3703 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 3704 expect( | |
| 3705 entry.getState(DartEntry.CONTAINING_LIBRARIES), same(CacheState.VALID)); | |
| 3706 expect(entry.getState(DartEntry.ELEMENT), same(CacheState.VALID)); | |
| 3707 expect( | |
| 3708 entry.getState(DartEntry.EXPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3709 expect( | |
| 3710 entry.getState(DartEntry.IMPORTED_LIBRARIES), same(CacheState.VALID)); | |
| 3711 expect(entry.getState(DartEntry.INCLUDED_PARTS), same(CacheState.VALID)); | |
| 3712 expect(entry.getState(DartEntry.IS_CLIENT), same(CacheState.VALID)); | |
| 3713 expect(entry.getState(DartEntry.IS_LAUNCHABLE), same(CacheState.VALID)); | |
| 3714 expect(entry.getState(DartEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 3715 expect(entry.getState(DartEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 3716 expect(entry.getState(DartEntry.PUBLIC_NAMESPACE), same(CacheState.VALID)); | |
| 3717 expect(entry.getState(DartEntry.SCAN_ERRORS), same(CacheState.VALID)); | |
| 3718 expect(entry.getState(DartEntry.SOURCE_KIND), same(CacheState.VALID)); | |
| 3719 expect(entry.getState(DartEntry.TOKEN_STREAM), same(CacheState.VALID)); | |
| 3720 if (firstLibrary != null) { | |
| 3721 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, firstLibrary), | |
| 3722 same(CacheState.VALID)); | |
| 3723 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, firstLibrary), | |
| 3724 same(CacheState.VALID)); | |
| 3725 expect(entry.getStateInLibrary(DartEntry.HINTS, firstLibrary), | |
| 3726 same(CacheState.VALID)); | |
| 3727 expect(entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, firstLibrary), | |
| 3728 same(CacheState.VALID)); | |
| 3729 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, firstLibrary), | |
| 3730 same(CacheState.VALID)); | |
| 3731 expect( | |
| 3732 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, firstLibrary), | |
| 3733 same(CacheState.VALID)); | |
| 3734 } | |
| 3735 if (secondLibrary != null) { | |
| 3736 expect(entry.getStateInLibrary(DartEntry.BUILT_ELEMENT, secondLibrary), | |
| 3737 same(CacheState.VALID)); | |
| 3738 expect(entry.getStateInLibrary(DartEntry.BUILT_UNIT, secondLibrary), | |
| 3739 same(CacheState.VALID)); | |
| 3740 expect(entry.getStateInLibrary(DartEntry.HINTS, secondLibrary), | |
| 3741 same(CacheState.VALID)); | |
| 3742 expect( | |
| 3743 entry.getStateInLibrary(DartEntry.RESOLUTION_ERRORS, secondLibrary), | |
| 3744 same(CacheState.VALID)); | |
| 3745 expect(entry.getStateInLibrary(DartEntry.RESOLVED_UNIT, secondLibrary), | |
| 3746 same(CacheState.VALID)); | |
| 3747 expect( | |
| 3748 entry.getStateInLibrary(DartEntry.VERIFICATION_ERRORS, secondLibrary), | |
| 3749 same(CacheState.VALID)); | |
| 3750 } | |
| 3751 return entry; | |
| 3752 } | |
| 3753 | |
| 3754 void _setState(DataDescriptor descriptor) { | |
| 3755 DartEntry entry = new DartEntry(); | |
| 3756 expect(entry.getState(descriptor), isNot(same(CacheState.FLUSHED))); | |
| 3757 entry.setState(descriptor, CacheState.FLUSHED); | |
| 3758 expect(entry.getState(descriptor), same(CacheState.FLUSHED)); | |
| 3759 } | |
| 3760 | |
| 3761 void _setStateInLibrary(DataDescriptor descriptor) { | |
| 3762 Source source = new TestSource(); | |
| 3763 DartEntry entry = new DartEntry(); | |
| 3764 expect(entry.getStateInLibrary(descriptor, source), | |
| 3765 isNot(same(CacheState.FLUSHED))); | |
| 3766 entry.setStateInLibrary(descriptor, source, CacheState.FLUSHED); | |
| 3767 expect( | |
| 3768 entry.getStateInLibrary(descriptor, source), same(CacheState.FLUSHED)); | |
| 3769 } | |
| 3770 | |
| 3771 void _setValue(DataDescriptor descriptor, Object newValue) { | |
| 3772 DartEntry entry = new DartEntry(); | |
| 3773 Object value = entry.getValue(descriptor); | |
| 3774 expect(newValue, isNot(same(value))); | |
| 3775 entry.setValue(descriptor, newValue); | |
| 3776 expect(entry.getState(descriptor), same(CacheState.VALID)); | |
| 3777 expect(entry.getValue(descriptor), same(newValue)); | |
| 3778 } | |
| 3779 | |
| 3780 void _setValueInLibrary(DataDescriptor descriptor, Object newValue) { | |
| 3781 Source source = new TestSource(); | |
| 3782 DartEntry entry = new DartEntry(); | |
| 3783 Object value = entry.getValueInLibrary(descriptor, source); | |
| 3784 expect(newValue, isNot(same(value))); | |
| 3785 entry.setValueInLibrary(descriptor, source, newValue); | |
| 3786 expect(entry.getStateInLibrary(descriptor, source), same(CacheState.VALID)); | |
| 3787 expect(entry.getValueInLibrary(descriptor, source), same(newValue)); | |
| 3788 } | |
| 3789 } | |
| 3790 | |
| 3791 @reflectiveTest | |
| 3792 class GenerateDartErrorsTaskTest extends EngineTestCase { | |
| 3793 void test_accept() { | |
| 3794 GenerateDartErrorsTask task = | |
| 3795 new GenerateDartErrorsTask(null, null, null, null); | |
| 3796 expect(task.accept(new GenerateDartErrorsTaskTestTV_accept()), isTrue); | |
| 3797 } | |
| 3798 | |
| 3799 void test_getException() { | |
| 3800 GenerateDartErrorsTask task = | |
| 3801 new GenerateDartErrorsTask(null, null, null, null); | |
| 3802 expect(task.exception, isNull); | |
| 3803 } | |
| 3804 | |
| 3805 void test_getLibraryElement() { | |
| 3806 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 3807 LibraryElement element = ElementFactory.library(context, "lib"); | |
| 3808 GenerateDartErrorsTask task = | |
| 3809 new GenerateDartErrorsTask(context, null, null, element); | |
| 3810 expect(task.libraryElement, same(element)); | |
| 3811 } | |
| 3812 | |
| 3813 void test_getSource() { | |
| 3814 Source source = | |
| 3815 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 3816 GenerateDartErrorsTask task = | |
| 3817 new GenerateDartErrorsTask(null, source, null, null); | |
| 3818 expect(task.source, same(source)); | |
| 3819 } | |
| 3820 | |
| 3821 void test_perform() { | |
| 3822 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 3823 Source source = | |
| 3824 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 3825 ChangeSet changeSet = new ChangeSet(); | |
| 3826 changeSet.addedSource(source); | |
| 3827 context.applyChanges(changeSet); | |
| 3828 context.setContents( | |
| 3829 source, | |
| 3830 r''' | |
| 3831 library lib; | |
| 3832 class A { | |
| 3833 int f = new A(); | |
| 3834 }'''); | |
| 3835 LibraryElement libraryElement = context.computeLibraryElement(source); | |
| 3836 CompilationUnit unit = | |
| 3837 context.getResolvedCompilationUnit(source, libraryElement); | |
| 3838 GenerateDartErrorsTask task = | |
| 3839 new GenerateDartErrorsTask(context, source, unit, libraryElement); | |
| 3840 task.perform( | |
| 3841 new GenerateDartErrorsTaskTestTV_perform(libraryElement, source)); | |
| 3842 } | |
| 3843 | |
| 3844 void test_perform_validateDirectives() { | |
| 3845 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 3846 Source source = | |
| 3847 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 3848 ChangeSet changeSet = new ChangeSet(); | |
| 3849 changeSet.addedSource(source); | |
| 3850 context.applyChanges(changeSet); | |
| 3851 // TODO(scheglov) "import" causes second error reported | |
| 3852 // context.setContents(source, EngineTestCase.createSource([ | |
| 3853 // "library lib;", | |
| 3854 // "import 'invaliduri^.dart';", | |
| 3855 // "export '\${a}lib3.dart';", | |
| 3856 // "part '/does/not/exist.dart';", | |
| 3857 // "class A {}"])); | |
| 3858 context.setContents( | |
| 3859 source, | |
| 3860 r''' | |
| 3861 library lib; | |
| 3862 part '/does/not/exist.dart'; | |
| 3863 class A {}'''); | |
| 3864 LibraryElement libraryElement = context.computeLibraryElement(source); | |
| 3865 CompilationUnit unit = | |
| 3866 context.getResolvedCompilationUnit(source, libraryElement); | |
| 3867 GenerateDartErrorsTask task = | |
| 3868 new GenerateDartErrorsTask(context, source, unit, libraryElement); | |
| 3869 task.perform(new GenerateDartErrorsTaskTestTV_perform_validateDirectives( | |
| 3870 libraryElement, source)); | |
| 3871 } | |
| 3872 } | |
| 3873 | |
| 3874 class GenerateDartErrorsTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 3875 @override | |
| 3876 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) => true; | |
| 3877 } | |
| 3878 | |
| 3879 class GenerateDartErrorsTaskTestTV_perform extends TestTaskVisitor<bool> { | |
| 3880 LibraryElement libraryElement; | |
| 3881 Source source; | |
| 3882 GenerateDartErrorsTaskTestTV_perform(this.libraryElement, this.source); | |
| 3883 @override | |
| 3884 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { | |
| 3885 CaughtException exception = task.exception; | |
| 3886 if (exception != null) { | |
| 3887 throw exception; | |
| 3888 } | |
| 3889 expect(task.libraryElement, same(libraryElement)); | |
| 3890 expect(task.source, same(source)); | |
| 3891 List<AnalysisError> errors = task.errors; | |
| 3892 expect(errors, hasLength(1)); | |
| 3893 return true; | |
| 3894 } | |
| 3895 } | |
| 3896 | |
| 3897 class GenerateDartErrorsTaskTestTV_perform_validateDirectives | |
| 3898 extends TestTaskVisitor<bool> { | |
| 3899 LibraryElement libraryElement; | |
| 3900 Source source; | |
| 3901 GenerateDartErrorsTaskTestTV_perform_validateDirectives( | |
| 3902 this.libraryElement, this.source); | |
| 3903 @override | |
| 3904 bool visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { | |
| 3905 CaughtException exception = task.exception; | |
| 3906 if (exception != null) { | |
| 3907 throw exception; | |
| 3908 } | |
| 3909 expect(task.libraryElement, same(libraryElement)); | |
| 3910 expect(task.source, same(source)); | |
| 3911 List<AnalysisError> errors = task.errors; | |
| 3912 expect(errors, hasLength(1)); | |
| 3913 expect(errors[0].errorCode, same(CompileTimeErrorCode.URI_DOES_NOT_EXIST)); | |
| 3914 return true; | |
| 3915 } | |
| 3916 } | |
| 3917 | |
| 3918 @reflectiveTest | |
| 3919 class GenerateDartHintsTaskTest extends EngineTestCase { | |
| 3920 void test_accept() { | |
| 3921 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); | |
| 3922 expect(task.accept(new GenerateDartHintsTaskTestTV_accept()), isTrue); | |
| 3923 } | |
| 3924 | |
| 3925 void test_getException() { | |
| 3926 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); | |
| 3927 expect(task.exception, isNull); | |
| 3928 } | |
| 3929 | |
| 3930 void test_getHintMap() { | |
| 3931 GenerateDartHintsTask task = new GenerateDartHintsTask(null, null, null); | |
| 3932 expect(task.hintMap, isNull); | |
| 3933 } | |
| 3934 | |
| 3935 void test_getLibraryElement() { | |
| 3936 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 3937 LibraryElement element = ElementFactory.library(context, "lib"); | |
| 3938 GenerateDartHintsTask task = | |
| 3939 new GenerateDartHintsTask(context, null, element); | |
| 3940 expect(task.libraryElement, same(element)); | |
| 3941 } | |
| 3942 | |
| 3943 void test_perform() { | |
| 3944 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 3945 ChangeSet changeSet = new ChangeSet(); | |
| 3946 Source librarySource = | |
| 3947 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 3948 changeSet.addedSource(librarySource); | |
| 3949 Source unusedSource = | |
| 3950 new FileBasedSource(FileUtilities2.createFile("/unused.dart")); | |
| 3951 changeSet.addedSource(unusedSource); | |
| 3952 Source partSource = | |
| 3953 new FileBasedSource(FileUtilities2.createFile("/part.dart")); | |
| 3954 changeSet.addedSource(partSource); | |
| 3955 context.applyChanges(changeSet); | |
| 3956 context.setContents( | |
| 3957 librarySource, | |
| 3958 r''' | |
| 3959 library lib; | |
| 3960 import 'unused.dart'; | |
| 3961 part 'part.dart';'''); | |
| 3962 context.setContents(unusedSource, "library unused;"); | |
| 3963 context.setContents(partSource, "part of lib;"); | |
| 3964 List<TimestampedData<CompilationUnit>> units = new List<TimestampedData>(2); | |
| 3965 units[0] = new TimestampedData<CompilationUnit>( | |
| 3966 context.getModificationStamp(librarySource), | |
| 3967 context.resolveCompilationUnit2(librarySource, librarySource)); | |
| 3968 units[1] = new TimestampedData<CompilationUnit>( | |
| 3969 context.getModificationStamp(partSource), | |
| 3970 context.resolveCompilationUnit2(partSource, librarySource)); | |
| 3971 GenerateDartHintsTask task = new GenerateDartHintsTask( | |
| 3972 context, units, context.computeLibraryElement(librarySource)); | |
| 3973 task.perform( | |
| 3974 new GenerateDartHintsTaskTestTV_perform(librarySource, partSource)); | |
| 3975 } | |
| 3976 } | |
| 3977 | |
| 3978 class GenerateDartHintsTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 3979 @override | |
| 3980 bool visitGenerateDartHintsTask(GenerateDartHintsTask task) => true; | |
| 3981 } | |
| 3982 | |
| 3983 class GenerateDartHintsTaskTestTV_perform extends TestTaskVisitor<bool> { | |
| 3984 Source librarySource; | |
| 3985 Source partSource; | |
| 3986 GenerateDartHintsTaskTestTV_perform(this.librarySource, this.partSource); | |
| 3987 @override | |
| 3988 bool visitGenerateDartHintsTask(GenerateDartHintsTask task) { | |
| 3989 CaughtException exception = task.exception; | |
| 3990 if (exception != null) { | |
| 3991 throw exception; | |
| 3992 } | |
| 3993 expect(task.libraryElement, isNotNull); | |
| 3994 HashMap<Source, List<AnalysisError>> hintMap = task.hintMap; | |
| 3995 expect(hintMap, hasLength(2)); | |
| 3996 expect(hintMap[librarySource], hasLength(1)); | |
| 3997 expect(hintMap[partSource], hasLength(0)); | |
| 3998 return true; | |
| 3999 } | |
| 4000 } | |
| 4001 | |
| 4002 @reflectiveTest | |
| 4003 class GenerateDartLintsTaskTest extends EngineTestCase { | |
| 4004 void test_accept() { | |
| 4005 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); | |
| 4006 expect(task.accept(new GenerateDartLintsTaskTestTV_accept()), isTrue); | |
| 4007 } | |
| 4008 | |
| 4009 void test_exception() { | |
| 4010 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); | |
| 4011 expect(task.exception, isNull); | |
| 4012 } | |
| 4013 | |
| 4014 void test_libraryElement() { | |
| 4015 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4016 LibraryElement element = ElementFactory.library(context, "lib"); | |
| 4017 GenerateDartLintsTask task = | |
| 4018 new GenerateDartLintsTask(context, null, element); | |
| 4019 expect(task.libraryElement, same(element)); | |
| 4020 } | |
| 4021 | |
| 4022 void test_lintMap() { | |
| 4023 GenerateDartLintsTask task = new GenerateDartLintsTask(null, null, null); | |
| 4024 expect(task.lintMap, isNull); | |
| 4025 } | |
| 4026 | |
| 4027 void test_perform() { | |
| 4028 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4029 ChangeSet changeSet = new ChangeSet(); | |
| 4030 Source librarySource = | |
| 4031 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 4032 changeSet.addedSource(librarySource); | |
| 4033 context.applyChanges(changeSet); | |
| 4034 context.setContents( | |
| 4035 librarySource, | |
| 4036 r''' | |
| 4037 library lib; | |
| 4038 '''); | |
| 4039 List<TimestampedData<CompilationUnit>> units = new List<TimestampedData>(1); | |
| 4040 units[0] = new TimestampedData<CompilationUnit>( | |
| 4041 context.getModificationStamp(librarySource), | |
| 4042 context.resolveCompilationUnit2(librarySource, librarySource)); | |
| 4043 GenerateDartLintsTask task = new GenerateDartLintsTask( | |
| 4044 context, units, context.computeLibraryElement(librarySource)); | |
| 4045 task.perform(new GenerateDartLintsTaskTestTV_perform(librarySource)); | |
| 4046 } | |
| 4047 } | |
| 4048 | |
| 4049 class GenerateDartLintsTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 4050 @override | |
| 4051 bool visitGenerateDartLintsTask(GenerateDartLintsTask task) => true; | |
| 4052 } | |
| 4053 | |
| 4054 class GenerateDartLintsTaskTestTV_perform extends TestTaskVisitor<bool> { | |
| 4055 Source librarySource; | |
| 4056 GenerateDartLintsTaskTestTV_perform(this.librarySource); | |
| 4057 @override | |
| 4058 bool visitGenerateDartLintsTask(GenerateDartLintsTask task) { | |
| 4059 CaughtException exception = task.exception; | |
| 4060 if (exception != null) { | |
| 4061 throw exception; | |
| 4062 } | |
| 4063 expect(task.libraryElement, isNotNull); | |
| 4064 return true; | |
| 4065 } | |
| 4066 } | |
| 4067 | |
| 4068 @reflectiveTest | |
| 4069 class GetContentTaskTest extends EngineTestCase { | |
| 4070 void test_accept() { | |
| 4071 Source source = new TestSource('/test.dart', ''); | |
| 4072 GetContentTask task = new GetContentTask(null, source); | |
| 4073 expect(task.accept(new GetContentTaskTestTV_accept()), isTrue); | |
| 4074 } | |
| 4075 | |
| 4076 void test_getException() { | |
| 4077 Source source = new TestSource('/test.dart', ''); | |
| 4078 GetContentTask task = new GetContentTask(null, source); | |
| 4079 expect(task.exception, isNull); | |
| 4080 } | |
| 4081 | |
| 4082 void test_getModificationTime() { | |
| 4083 Source source = new TestSource('/test.dart', ''); | |
| 4084 GetContentTask task = new GetContentTask(null, source); | |
| 4085 expect(task.modificationTime, -1); | |
| 4086 } | |
| 4087 | |
| 4088 void test_getSource() { | |
| 4089 Source source = new TestSource('/test.dart', ''); | |
| 4090 GetContentTask task = new GetContentTask(null, source); | |
| 4091 expect(task.source, same(source)); | |
| 4092 } | |
| 4093 | |
| 4094 void test_perform_exception() { | |
| 4095 TestSource source = new TestSource(); | |
| 4096 source.generateExceptionOnRead = true; | |
| 4097 // final InternalAnalysisContext context = new AnalysisContextImpl(); | |
| 4098 // context.setSourceFactory(new SourceFactory(new FileUriResolver())); | |
| 4099 GetContentTask task = new GetContentTask(null, source); | |
| 4100 task.perform(new GetContentTaskTestTV_perform_exception()); | |
| 4101 } | |
| 4102 | |
| 4103 void test_perform_valid() { | |
| 4104 Source source = new TestSource('/test.dart', 'class A {}'); | |
| 4105 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4106 GetContentTask task = new GetContentTask(context, source); | |
| 4107 task.perform(new GetContentTaskTestTV_perform_valid(context, source)); | |
| 4108 } | |
| 4109 } | |
| 4110 | |
| 4111 class GetContentTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 4112 @override | |
| 4113 bool visitGetContentTask(GetContentTask task) => true; | |
| 4114 } | |
| 4115 | |
| 4116 class GetContentTaskTestTV_perform_exception extends TestTaskVisitor<bool> { | |
| 4117 @override | |
| 4118 bool visitGetContentTask(GetContentTask task) { | |
| 4119 expect(task.exception, isNotNull); | |
| 4120 return true; | |
| 4121 } | |
| 4122 } | |
| 4123 | |
| 4124 class GetContentTaskTestTV_perform_valid extends TestTaskVisitor<bool> { | |
| 4125 InternalAnalysisContext context; | |
| 4126 Source source; | |
| 4127 GetContentTaskTestTV_perform_valid(this.context, this.source); | |
| 4128 @override | |
| 4129 bool visitGetContentTask(GetContentTask task) { | |
| 4130 CaughtException exception = task.exception; | |
| 4131 if (exception != null) { | |
| 4132 throw exception; | |
| 4133 } | |
| 4134 expect(task.modificationTime, context.getModificationStamp(source)); | |
| 4135 expect(task.source, same(source)); | |
| 4136 return true; | |
| 4137 } | |
| 4138 } | |
| 4139 | |
| 4140 @reflectiveTest | |
| 4141 class HtmlEntryTest extends EngineTestCase { | |
| 4142 void set state(DataDescriptor descriptor) { | |
| 4143 HtmlEntry entry = new HtmlEntry(); | |
| 4144 expect(entry.getState(descriptor), isNot(same(CacheState.FLUSHED))); | |
| 4145 entry.setState(descriptor, CacheState.FLUSHED); | |
| 4146 expect(entry.getState(descriptor), same(CacheState.FLUSHED)); | |
| 4147 } | |
| 4148 | |
| 4149 void test_creation() { | |
| 4150 HtmlEntry entry = new HtmlEntry(); | |
| 4151 expect(entry, isNotNull); | |
| 4152 } | |
| 4153 | |
| 4154 void test_getAllErrors() { | |
| 4155 Source source = new TestSource(); | |
| 4156 HtmlEntry entry = new HtmlEntry(); | |
| 4157 expect(entry.allErrors, hasLength(0)); | |
| 4158 entry.setValue(HtmlEntry.PARSE_ERRORS, <AnalysisError>[ | |
| 4159 new AnalysisError(source, 0, 0, ParserErrorCode.EXPECTED_TOKEN, [";"]) | |
| 4160 ]); | |
| 4161 entry.setValue(HtmlEntry.RESOLUTION_ERRORS, <AnalysisError>[ | |
| 4162 new AnalysisError(source, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) | |
| 4163 ]); | |
| 4164 entry.setValue(HtmlEntry.HINTS, | |
| 4165 <AnalysisError>[new AnalysisError(source, 0, 0, HintCode.DEAD_CODE)]); | |
| 4166 expect(entry.allErrors, hasLength(3)); | |
| 4167 } | |
| 4168 | |
| 4169 void test_invalidateAllResolutionInformation() { | |
| 4170 HtmlEntry entry = _entryWithValidState(); | |
| 4171 entry.invalidateAllResolutionInformation(false); | |
| 4172 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.INVALID)); | |
| 4173 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.INVALID)); | |
| 4174 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 4175 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 4176 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 4177 expect( | |
| 4178 entry.getState(HtmlEntry.REFERENCED_LIBRARIES), same(CacheState.VALID)); | |
| 4179 expect( | |
| 4180 entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.INVALID)); | |
| 4181 } | |
| 4182 | |
| 4183 void test_invalidateAllResolutionInformation_includingUris() { | |
| 4184 HtmlEntry entry = _entryWithValidState(); | |
| 4185 entry.invalidateAllResolutionInformation(true); | |
| 4186 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.INVALID)); | |
| 4187 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.INVALID)); | |
| 4188 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 4189 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 4190 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 4191 expect(entry.getState(HtmlEntry.REFERENCED_LIBRARIES), | |
| 4192 same(CacheState.INVALID)); | |
| 4193 expect( | |
| 4194 entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.INVALID)); | |
| 4195 } | |
| 4196 | |
| 4197 void test_setState_element() { | |
| 4198 state = HtmlEntry.ELEMENT; | |
| 4199 } | |
| 4200 | |
| 4201 void test_setState_hints() { | |
| 4202 state = HtmlEntry.HINTS; | |
| 4203 } | |
| 4204 | |
| 4205 void test_setState_lineInfo() { | |
| 4206 state = SourceEntry.LINE_INFO; | |
| 4207 } | |
| 4208 | |
| 4209 void test_setState_parsedUnit() { | |
| 4210 state = HtmlEntry.PARSED_UNIT; | |
| 4211 } | |
| 4212 | |
| 4213 void test_setState_parseErrors() { | |
| 4214 state = HtmlEntry.PARSE_ERRORS; | |
| 4215 } | |
| 4216 | |
| 4217 void test_setState_referencedLibraries() { | |
| 4218 state = HtmlEntry.REFERENCED_LIBRARIES; | |
| 4219 } | |
| 4220 | |
| 4221 void test_setState_resolutionErrors() { | |
| 4222 state = HtmlEntry.RESOLUTION_ERRORS; | |
| 4223 } | |
| 4224 | |
| 4225 void test_setValue_element() { | |
| 4226 _setValue(HtmlEntry.ELEMENT, new HtmlElementImpl(null, "test.html")); | |
| 4227 } | |
| 4228 | |
| 4229 void test_setValue_hints() { | |
| 4230 _setValue(HtmlEntry.HINTS, | |
| 4231 <AnalysisError>[new AnalysisError(null, 0, 0, HintCode.DEAD_CODE)]); | |
| 4232 } | |
| 4233 | |
| 4234 void test_setValue_illegal() { | |
| 4235 HtmlEntry entry = new HtmlEntry(); | |
| 4236 try { | |
| 4237 entry.setValue(DartEntry.ELEMENT, null); | |
| 4238 fail("Expected ArgumentError for DartEntry.ELEMENT"); | |
| 4239 } on ArgumentError {} | |
| 4240 } | |
| 4241 | |
| 4242 void test_setValue_lineInfo() { | |
| 4243 _setValue(SourceEntry.LINE_INFO, new LineInfo(<int>[0])); | |
| 4244 } | |
| 4245 | |
| 4246 void test_setValue_parsedUnit() { | |
| 4247 _setValue(HtmlEntry.PARSED_UNIT, new ht.HtmlUnit(null, null, null)); | |
| 4248 } | |
| 4249 | |
| 4250 void test_setValue_parseErrors() { | |
| 4251 _setValue(HtmlEntry.PARSE_ERRORS, <AnalysisError>[ | |
| 4252 new AnalysisError(null, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) | |
| 4253 ]); | |
| 4254 } | |
| 4255 | |
| 4256 void test_setValue_referencedLibraries() { | |
| 4257 _setValue(HtmlEntry.REFERENCED_LIBRARIES, <Source>[new TestSource()]); | |
| 4258 } | |
| 4259 | |
| 4260 void test_setValue_resolutionErrors() { | |
| 4261 _setValue(HtmlEntry.RESOLUTION_ERRORS, <AnalysisError>[ | |
| 4262 new AnalysisError(null, 0, 0, HtmlWarningCode.INVALID_URI, ["-"]) | |
| 4263 ]); | |
| 4264 } | |
| 4265 | |
| 4266 HtmlEntry _entryWithValidState() { | |
| 4267 HtmlEntry entry = new HtmlEntry(); | |
| 4268 entry.setValue(HtmlEntry.ELEMENT, null); | |
| 4269 entry.setValue(HtmlEntry.HINTS, null); | |
| 4270 entry.setValue(SourceEntry.LINE_INFO, null); | |
| 4271 entry.setValue(HtmlEntry.PARSE_ERRORS, null); | |
| 4272 entry.setValue(HtmlEntry.PARSED_UNIT, null); | |
| 4273 entry.setValue(HtmlEntry.REFERENCED_LIBRARIES, null); | |
| 4274 entry.setValue(HtmlEntry.RESOLUTION_ERRORS, null); | |
| 4275 expect(entry.getState(HtmlEntry.ELEMENT), same(CacheState.VALID)); | |
| 4276 expect(entry.getState(HtmlEntry.HINTS), same(CacheState.VALID)); | |
| 4277 expect(entry.getState(SourceEntry.LINE_INFO), same(CacheState.VALID)); | |
| 4278 expect(entry.getState(HtmlEntry.PARSE_ERRORS), same(CacheState.VALID)); | |
| 4279 expect(entry.getState(HtmlEntry.PARSED_UNIT), same(CacheState.VALID)); | |
| 4280 expect( | |
| 4281 entry.getState(HtmlEntry.REFERENCED_LIBRARIES), same(CacheState.VALID)); | |
| 4282 expect(entry.getState(HtmlEntry.RESOLUTION_ERRORS), same(CacheState.VALID)); | |
| 4283 return entry; | |
| 4284 } | |
| 4285 | |
| 4286 void _setValue(DataDescriptor descriptor, Object newValue) { | |
| 4287 HtmlEntry entry = new HtmlEntry(); | |
| 4288 Object value = entry.getValue(descriptor); | |
| 4289 expect(newValue, isNot(same(value))); | |
| 4290 entry.setValue(descriptor, newValue); | |
| 4291 expect(entry.getState(descriptor), same(CacheState.VALID)); | |
| 4292 expect(entry.getValue(descriptor), same(newValue)); | |
| 4293 } | |
| 4294 } | |
| 4295 | |
| 4296 @reflectiveTest | |
| 4297 class IncrementalAnalysisCacheTest { | |
| 4298 Source _source = new TestSource(); | |
| 4299 DartEntry _entry = new DartEntry(); | |
| 4300 CompilationUnit _unit = new CompilationUnitMock(); | |
| 4301 IncrementalAnalysisCache _result; | |
| 4302 void setUp() { | |
| 4303 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, _unit); | |
| 4304 } | |
| 4305 | |
| 4306 void test_cacheResult() { | |
| 4307 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4308 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4309 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4310 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); | |
| 4311 expect(_result, isNotNull); | |
| 4312 expect(_result.source, same(_source)); | |
| 4313 expect(_result.resolvedUnit, same(newUnit)); | |
| 4314 expect(_result.oldContents, "hbazlo"); | |
| 4315 expect(_result.newContents, "hbazlo"); | |
| 4316 expect(_result.offset, 0); | |
| 4317 expect(_result.oldLength, 0); | |
| 4318 expect(_result.newLength, 0); | |
| 4319 } | |
| 4320 | |
| 4321 void test_cacheResult_noCache() { | |
| 4322 IncrementalAnalysisCache cache = null; | |
| 4323 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4324 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); | |
| 4325 expect(_result, isNull); | |
| 4326 } | |
| 4327 | |
| 4328 void test_cacheResult_noCacheNoResult() { | |
| 4329 IncrementalAnalysisCache cache = null; | |
| 4330 CompilationUnit newUnit = null; | |
| 4331 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); | |
| 4332 expect(_result, isNull); | |
| 4333 } | |
| 4334 | |
| 4335 void test_cacheResult_noResult() { | |
| 4336 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4337 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4338 CompilationUnit newUnit = null; | |
| 4339 _result = IncrementalAnalysisCache.cacheResult(cache, newUnit); | |
| 4340 expect(_result, isNull); | |
| 4341 } | |
| 4342 | |
| 4343 void test_clear_differentSource() { | |
| 4344 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4345 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4346 Source otherSource = new TestSource("blat.dart", "blat"); | |
| 4347 _result = IncrementalAnalysisCache.clear(cache, otherSource); | |
| 4348 expect(_result, same(cache)); | |
| 4349 } | |
| 4350 | |
| 4351 void test_clear_nullCache() { | |
| 4352 IncrementalAnalysisCache cache = null; | |
| 4353 _result = IncrementalAnalysisCache.clear(cache, _source); | |
| 4354 expect(_result, isNull); | |
| 4355 } | |
| 4356 | |
| 4357 void test_clear_sameSource() { | |
| 4358 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4359 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4360 _result = IncrementalAnalysisCache.clear(cache, _source); | |
| 4361 expect(_result, isNull); | |
| 4362 } | |
| 4363 | |
| 4364 void test_update_append() { | |
| 4365 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4366 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4367 DartEntry newEntry = new DartEntry(); | |
| 4368 _result = IncrementalAnalysisCache.update( | |
| 4369 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); | |
| 4370 expect(_result, isNotNull); | |
| 4371 expect(_result.source, same(_source)); | |
| 4372 expect(_result.resolvedUnit, same(_unit)); | |
| 4373 expect(_result.oldContents, "hello"); | |
| 4374 expect(_result.newContents, "hbazxlo"); | |
| 4375 expect(_result.offset, 1); | |
| 4376 expect(_result.oldLength, 2); | |
| 4377 expect(_result.newLength, 4); | |
| 4378 } | |
| 4379 | |
| 4380 void test_update_appendToCachedResult() { | |
| 4381 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4382 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4383 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4384 cache = IncrementalAnalysisCache.cacheResult(cache, newUnit); | |
| 4385 expect(cache, isNotNull); | |
| 4386 DartEntry newEntry = new DartEntry(); | |
| 4387 _result = IncrementalAnalysisCache.update( | |
| 4388 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); | |
| 4389 expect(_result, isNotNull); | |
| 4390 expect(_result.source, same(_source)); | |
| 4391 expect(_result.resolvedUnit, same(newUnit)); | |
| 4392 expect(_result.oldContents, "hbazlo"); | |
| 4393 expect(_result.newContents, "hbazxlo"); | |
| 4394 expect(_result.offset, 4); | |
| 4395 expect(_result.oldLength, 0); | |
| 4396 expect(_result.newLength, 1); | |
| 4397 } | |
| 4398 | |
| 4399 void test_update_appendWithNewResolvedUnit() { | |
| 4400 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4401 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4402 DartEntry newEntry = new DartEntry(); | |
| 4403 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4404 newEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, newUnit); | |
| 4405 _result = IncrementalAnalysisCache.update( | |
| 4406 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); | |
| 4407 expect(_result, isNotNull); | |
| 4408 expect(_result.source, same(_source)); | |
| 4409 expect(_result.resolvedUnit, same(newUnit)); | |
| 4410 expect(_result.oldContents, "hbazlo"); | |
| 4411 expect(_result.newContents, "hbazxlo"); | |
| 4412 expect(_result.offset, 4); | |
| 4413 expect(_result.oldLength, 0); | |
| 4414 expect(_result.newLength, 1); | |
| 4415 } | |
| 4416 | |
| 4417 void test_update_appendWithNoNewResolvedUnit() { | |
| 4418 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4419 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4420 DartEntry newEntry = new DartEntry(); | |
| 4421 _result = IncrementalAnalysisCache.update( | |
| 4422 cache, _source, "hbazlo", "hbazxlo", 4, 0, 1, newEntry); | |
| 4423 expect(_result, isNotNull); | |
| 4424 expect(_result.source, same(_source)); | |
| 4425 expect(_result.resolvedUnit, same(_unit)); | |
| 4426 expect(_result.oldContents, "hello"); | |
| 4427 expect(_result.newContents, "hbazxlo"); | |
| 4428 expect(_result.offset, 1); | |
| 4429 expect(_result.oldLength, 2); | |
| 4430 expect(_result.newLength, 4); | |
| 4431 } | |
| 4432 | |
| 4433 void test_update_delete() { | |
| 4434 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4435 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4436 DartEntry newEntry = new DartEntry(); | |
| 4437 _result = IncrementalAnalysisCache.update( | |
| 4438 cache, _source, "hbazlo", "hzlo", 1, 2, 0, newEntry); | |
| 4439 expect(_result, isNotNull); | |
| 4440 expect(_result.source, same(_source)); | |
| 4441 expect(_result.resolvedUnit, same(_unit)); | |
| 4442 expect(_result.oldContents, "hello"); | |
| 4443 expect(_result.newContents, "hzlo"); | |
| 4444 expect(_result.offset, 1); | |
| 4445 expect(_result.oldLength, 2); | |
| 4446 expect(_result.newLength, 1); | |
| 4447 } | |
| 4448 | |
| 4449 void test_update_insert_nonContiguous_after() { | |
| 4450 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4451 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4452 DartEntry newEntry = new DartEntry(); | |
| 4453 _result = IncrementalAnalysisCache.update( | |
| 4454 cache, _source, "hbazlo", "hbazlox", 6, 0, 1, newEntry); | |
| 4455 expect(_result, isNull); | |
| 4456 } | |
| 4457 | |
| 4458 void test_update_insert_nonContiguous_before() { | |
| 4459 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4460 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4461 DartEntry newEntry = new DartEntry(); | |
| 4462 _result = IncrementalAnalysisCache.update( | |
| 4463 cache, _source, "hbazlo", "xhbazlo", 0, 0, 1, newEntry); | |
| 4464 expect(_result, isNull); | |
| 4465 } | |
| 4466 | |
| 4467 void test_update_newSource_entry() { | |
| 4468 Source oldSource = new TestSource("blat.dart", "blat"); | |
| 4469 DartEntry oldEntry = new DartEntry(); | |
| 4470 CompilationUnit oldUnit = new CompilationUnitMock(); | |
| 4471 oldEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, oldUnit); | |
| 4472 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4473 null, oldSource, "hello", "hbazlo", 1, 2, 3, oldEntry); | |
| 4474 expect(cache.source, same(oldSource)); | |
| 4475 expect(cache.resolvedUnit, same(oldUnit)); | |
| 4476 _result = IncrementalAnalysisCache.update( | |
| 4477 cache, _source, "foo", "foobz", 3, 0, 2, _entry); | |
| 4478 expect(_result, isNotNull); | |
| 4479 expect(_result.source, same(_source)); | |
| 4480 expect(_result.resolvedUnit, same(_unit)); | |
| 4481 expect(_result.oldContents, "foo"); | |
| 4482 expect(_result.newContents, "foobz"); | |
| 4483 expect(_result.offset, 3); | |
| 4484 expect(_result.oldLength, 0); | |
| 4485 expect(_result.newLength, 2); | |
| 4486 } | |
| 4487 | |
| 4488 void test_update_newSource_noEntry() { | |
| 4489 Source oldSource = new TestSource("blat.dart", "blat"); | |
| 4490 DartEntry oldEntry = new DartEntry(); | |
| 4491 CompilationUnit oldUnit = new CompilationUnitMock(); | |
| 4492 oldEntry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, oldUnit); | |
| 4493 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4494 null, oldSource, "hello", "hbazlo", 1, 2, 3, oldEntry); | |
| 4495 expect(cache.source, same(oldSource)); | |
| 4496 expect(cache.resolvedUnit, same(oldUnit)); | |
| 4497 _result = IncrementalAnalysisCache.update( | |
| 4498 cache, _source, "foo", "foobar", 3, 0, 3, null); | |
| 4499 expect(_result, isNull); | |
| 4500 } | |
| 4501 | |
| 4502 void test_update_noCache_entry() { | |
| 4503 _result = IncrementalAnalysisCache.update( | |
| 4504 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4505 expect(_result, isNotNull); | |
| 4506 expect(_result.source, same(_source)); | |
| 4507 expect(_result.resolvedUnit, same(_unit)); | |
| 4508 expect(_result.oldContents, "hello"); | |
| 4509 expect(_result.newContents, "hbazlo"); | |
| 4510 expect(_result.offset, 1); | |
| 4511 expect(_result.oldLength, 2); | |
| 4512 expect(_result.newLength, 3); | |
| 4513 expect(_result.hasWork, isTrue); | |
| 4514 } | |
| 4515 | |
| 4516 void test_update_noCache_entry_noOldSource_append() { | |
| 4517 _result = IncrementalAnalysisCache.update( | |
| 4518 null, _source, null, "hellxo", 4, 0, 1, _entry); | |
| 4519 expect(_result, isNotNull); | |
| 4520 expect(_result.source, same(_source)); | |
| 4521 expect(_result.resolvedUnit, same(_unit)); | |
| 4522 expect(_result.oldContents, "hello"); | |
| 4523 expect(_result.newContents, "hellxo"); | |
| 4524 expect(_result.offset, 4); | |
| 4525 expect(_result.oldLength, 0); | |
| 4526 expect(_result.newLength, 1); | |
| 4527 expect(_result.hasWork, isTrue); | |
| 4528 } | |
| 4529 | |
| 4530 void test_update_noCache_entry_noOldSource_delete() { | |
| 4531 _result = IncrementalAnalysisCache.update( | |
| 4532 null, _source, null, "helo", 4, 1, 0, _entry); | |
| 4533 expect(_result, isNull); | |
| 4534 } | |
| 4535 | |
| 4536 void test_update_noCache_entry_noOldSource_replace() { | |
| 4537 _result = IncrementalAnalysisCache.update( | |
| 4538 null, _source, null, "helxo", 4, 1, 1, _entry); | |
| 4539 expect(_result, isNull); | |
| 4540 } | |
| 4541 | |
| 4542 void test_update_noCache_noEntry() { | |
| 4543 _result = IncrementalAnalysisCache.update( | |
| 4544 null, _source, "hello", "hbazlo", 1, 2, 3, null); | |
| 4545 expect(_result, isNull); | |
| 4546 } | |
| 4547 | |
| 4548 void test_update_replace() { | |
| 4549 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4550 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4551 _result = IncrementalAnalysisCache.update( | |
| 4552 cache, _source, "hbazlo", "hbarrlo", 3, 1, 2, null); | |
| 4553 expect(_result, isNotNull); | |
| 4554 expect(_result.source, same(_source)); | |
| 4555 expect(_result.resolvedUnit, same(_unit)); | |
| 4556 expect(_result.oldContents, "hello"); | |
| 4557 expect(_result.newContents, "hbarrlo"); | |
| 4558 expect(_result.offset, 1); | |
| 4559 expect(_result.oldLength, 2); | |
| 4560 expect(_result.newLength, 4); | |
| 4561 } | |
| 4562 | |
| 4563 void test_verifyStructure_invalidUnit() { | |
| 4564 String oldCode = "main() {foo;}"; | |
| 4565 String newCode = "main() {boo;}"; | |
| 4566 CompilationUnit badUnit = _parse("main() {bad;}"); | |
| 4567 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, badUnit); | |
| 4568 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4569 null, _source, oldCode, newCode, 8, 1, 1, _entry); | |
| 4570 CompilationUnit newUnit = _parse(newCode); | |
| 4571 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); | |
| 4572 expect(_result, isNull); | |
| 4573 } | |
| 4574 | |
| 4575 void test_verifyStructure_noCache() { | |
| 4576 IncrementalAnalysisCache cache = null; | |
| 4577 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4578 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); | |
| 4579 expect(_result, isNull); | |
| 4580 } | |
| 4581 | |
| 4582 void test_verifyStructure_noCacheNoUnit() { | |
| 4583 IncrementalAnalysisCache cache = null; | |
| 4584 CompilationUnit newUnit = null; | |
| 4585 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); | |
| 4586 expect(_result, isNull); | |
| 4587 } | |
| 4588 | |
| 4589 void test_verifyStructure_noUnit() { | |
| 4590 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4591 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4592 CompilationUnit newUnit = null; | |
| 4593 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); | |
| 4594 expect(_result, same(cache)); | |
| 4595 expect(_result.resolvedUnit, same(_unit)); | |
| 4596 } | |
| 4597 | |
| 4598 void test_verifyStructure_otherSource() { | |
| 4599 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4600 null, _source, "hello", "hbazlo", 1, 2, 3, _entry); | |
| 4601 CompilationUnit newUnit = new CompilationUnitMock(); | |
| 4602 Source otherSource = new TestSource("blat.dart", "blat"); | |
| 4603 _result = | |
| 4604 IncrementalAnalysisCache.verifyStructure(cache, otherSource, newUnit); | |
| 4605 expect(_result, same(cache)); | |
| 4606 expect(_result.resolvedUnit, same(_unit)); | |
| 4607 } | |
| 4608 | |
| 4609 void test_verifyStructure_validUnit() { | |
| 4610 String oldCode = "main() {foo;}"; | |
| 4611 String newCode = "main() {boo;}"; | |
| 4612 CompilationUnit goodUnit = _parse(newCode); | |
| 4613 _entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, _source, goodUnit); | |
| 4614 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4615 null, _source, oldCode, newCode, 1, 2, 3, _entry); | |
| 4616 CompilationUnit newUnit = _parse(newCode); | |
| 4617 _result = IncrementalAnalysisCache.verifyStructure(cache, _source, newUnit); | |
| 4618 expect(_result, same(cache)); | |
| 4619 expect(_result.resolvedUnit, same(goodUnit)); | |
| 4620 } | |
| 4621 | |
| 4622 CompilationUnit _parse(String code) { | |
| 4623 Scanner scanner = new Scanner(_source, new CharSequenceReader(code), | |
| 4624 AnalysisErrorListener.NULL_LISTENER); | |
| 4625 Parser parser = new Parser(_source, AnalysisErrorListener.NULL_LISTENER); | |
| 4626 return parser.parseCompilationUnit(scanner.tokenize()); | |
| 4627 } | |
| 4628 } | |
| 4629 | |
| 4630 @reflectiveTest | |
| 4631 class IncrementalAnalysisTaskTest extends EngineTestCase { | |
| 4632 void test_accept() { | |
| 4633 IncrementalAnalysisTask task = new IncrementalAnalysisTask(null, null); | |
| 4634 expect(task.accept(new IncrementalAnalysisTaskTestTV_accept()), isTrue); | |
| 4635 } | |
| 4636 | |
| 4637 void test_perform() { | |
| 4638 // main() {} String foo; | |
| 4639 // main() {String} String foo; | |
| 4640 CompilationUnit newUnit = | |
| 4641 _assertTask("main() {", "", "String", "} String foo;"); | |
| 4642 NodeList<CompilationUnitMember> declarations = newUnit.declarations; | |
| 4643 FunctionDeclaration main = declarations[0] as FunctionDeclaration; | |
| 4644 expect(main.name.name, "main"); | |
| 4645 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; | |
| 4646 ExpressionStatement statement = | |
| 4647 body.block.statements[0] as ExpressionStatement; | |
| 4648 expect(statement.toSource(), "String;"); | |
| 4649 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | |
| 4650 expect(identifier.name, "String"); | |
| 4651 expect(identifier.staticElement, isNotNull); | |
| 4652 TopLevelVariableDeclaration fooDecl = | |
| 4653 declarations[1] as TopLevelVariableDeclaration; | |
| 4654 SimpleIdentifier fooName = fooDecl.variables.variables[0].name; | |
| 4655 expect(fooName.name, "foo"); | |
| 4656 expect(fooName.staticElement, isNotNull); | |
| 4657 // assert element reference is preserved | |
| 4658 } | |
| 4659 | |
| 4660 CompilationUnit _assertTask( | |
| 4661 String prefix, String removed, String added, String suffix) { | |
| 4662 String oldCode = "$prefix$removed$suffix"; | |
| 4663 String newCode = "$prefix$added$suffix"; | |
| 4664 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4665 Source source = new TestSource("/test.dart", oldCode); | |
| 4666 DartEntry entry = new DartEntry(); | |
| 4667 CompilationUnit oldUnit = context.resolveCompilationUnit2(source, source); | |
| 4668 expect(oldUnit, isNotNull); | |
| 4669 entry.setValueInLibrary(DartEntry.RESOLVED_UNIT, source, oldUnit); | |
| 4670 IncrementalAnalysisCache cache = IncrementalAnalysisCache.update( | |
| 4671 null, | |
| 4672 source, | |
| 4673 oldCode, | |
| 4674 newCode, | |
| 4675 prefix.length, | |
| 4676 removed.length, | |
| 4677 added.length, | |
| 4678 entry); | |
| 4679 expect(cache, isNotNull); | |
| 4680 IncrementalAnalysisTask task = new IncrementalAnalysisTask(context, cache); | |
| 4681 CompilationUnit newUnit = | |
| 4682 task.perform(new IncrementalAnalysisTaskTestTV_assertTask(task)); | |
| 4683 expect(newUnit, isNotNull); | |
| 4684 return newUnit; | |
| 4685 } | |
| 4686 } | |
| 4687 | |
| 4688 class IncrementalAnalysisTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 4689 @override | |
| 4690 bool visitIncrementalAnalysisTask(IncrementalAnalysisTask task) => true; | |
| 4691 } | |
| 4692 | |
| 4693 class IncrementalAnalysisTaskTestTV_assertTask | |
| 4694 extends TestTaskVisitor<CompilationUnit> { | |
| 4695 IncrementalAnalysisTask task; | |
| 4696 IncrementalAnalysisTaskTestTV_assertTask(this.task); | |
| 4697 @override | |
| 4698 CompilationUnit visitIncrementalAnalysisTask( | |
| 4699 IncrementalAnalysisTask incrementalAnalysisTask) => | |
| 4700 task.compilationUnit; | |
| 4701 } | |
| 4702 | |
| 4703 @reflectiveTest | |
| 4704 class LintGeneratorTest extends EngineTestCase { | |
| 4705 void test_generate() { | |
| 4706 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4707 ChangeSet changeSet = new ChangeSet(); | |
| 4708 Source librarySource = | |
| 4709 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 4710 changeSet.addedSource(librarySource); | |
| 4711 context.applyChanges(changeSet); | |
| 4712 context.setContents( | |
| 4713 librarySource, | |
| 4714 r''' | |
| 4715 library lib; | |
| 4716 '''); | |
| 4717 | |
| 4718 CompilationUnit unit = | |
| 4719 context.resolveCompilationUnit2(librarySource, librarySource); | |
| 4720 List<CompilationUnit> units = <CompilationUnit>[]; | |
| 4721 units.add(unit); | |
| 4722 | |
| 4723 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 4724 | |
| 4725 LintGeneratorTest_Linter linter = new LintGeneratorTest_Linter(); | |
| 4726 | |
| 4727 LintGenerator lintGenerator = | |
| 4728 new LintGenerator(units, errorListener, [linter]); | |
| 4729 lintGenerator.generate(); | |
| 4730 | |
| 4731 linter.testExpectations(); | |
| 4732 } | |
| 4733 | |
| 4734 void test_generate_null_visitor() { | |
| 4735 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4736 ChangeSet changeSet = new ChangeSet(); | |
| 4737 Source librarySource = | |
| 4738 new FileBasedSource(FileUtilities2.createFile("/test.dart")); | |
| 4739 changeSet.addedSource(librarySource); | |
| 4740 context.applyChanges(changeSet); | |
| 4741 context.setContents( | |
| 4742 librarySource, | |
| 4743 r''' | |
| 4744 library lib; | |
| 4745 '''); | |
| 4746 | |
| 4747 CompilationUnit unit = | |
| 4748 context.resolveCompilationUnit2(librarySource, librarySource); | |
| 4749 List<CompilationUnit> units = <CompilationUnit>[]; | |
| 4750 units.add(unit); | |
| 4751 | |
| 4752 RecordingErrorListener errorListener = new RecordingErrorListener(); | |
| 4753 | |
| 4754 Linter badLinter = new LintGeneratorTest_Linter_Null_Visitor(); | |
| 4755 LintGeneratorTest_Linter goodLinter = new LintGeneratorTest_Linter(); | |
| 4756 | |
| 4757 LintGenerator lintGenerator = | |
| 4758 new LintGenerator(units, errorListener, [badLinter, goodLinter]); | |
| 4759 // Test that generate does not fall down with a null visitor | |
| 4760 lintGenerator.generate(); | |
| 4761 // Well-formed linter should still get called | |
| 4762 goodLinter.testExpectations(); | |
| 4763 } | |
| 4764 } | |
| 4765 | |
| 4766 class LintGeneratorTest_Linter extends Linter with SimpleAstVisitor<Object> { | |
| 4767 bool visited; | |
| 4768 | |
| 4769 @override | |
| 4770 AstVisitor getVisitor() => this; | |
| 4771 | |
| 4772 testExpectations() { | |
| 4773 expect(reporter, isNotNull); | |
| 4774 expect(visited, isTrue); | |
| 4775 } | |
| 4776 | |
| 4777 @override | |
| 4778 Object visitCompilationUnit(CompilationUnit node) { | |
| 4779 visited = true; | |
| 4780 return null; | |
| 4781 } | |
| 4782 } | |
| 4783 | |
| 4784 class LintGeneratorTest_Linter_Null_Visitor extends Linter { | |
| 4785 @override | |
| 4786 AstVisitor getVisitor() => null; | |
| 4787 } | |
| 4788 | |
| 4789 class MockSourceFactory extends SourceFactory { | |
| 4790 MockSourceFactory() : super([]); | 81 MockSourceFactory() : super([]); |
| 4791 Source resolveUri(Source containingSource, String containedUri) { | 82 Source resolveUri(Source containingSource, String containedUri) { |
| 4792 throw new JavaIOException(); | 83 throw new UnimplementedError(); |
| 4793 } | |
| 4794 } | |
| 4795 | |
| 4796 @reflectiveTest | |
| 4797 class ParseDartTaskTest extends EngineTestCase { | |
| 4798 void test_accept() { | |
| 4799 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4800 expect(task.accept(new ParseDartTaskTestTV_accept()), isTrue); | |
| 4801 } | |
| 4802 | |
| 4803 void test_getCompilationUnit() { | |
| 4804 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4805 expect(task.compilationUnit, isNull); | |
| 4806 } | |
| 4807 | |
| 4808 void test_getErrors() { | |
| 4809 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4810 expect(task.errors, hasLength(0)); | |
| 4811 } | |
| 4812 | |
| 4813 void test_getException() { | |
| 4814 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4815 expect(task.exception, isNull); | |
| 4816 } | |
| 4817 | |
| 4818 void test_getSource() { | |
| 4819 Source source = new TestSource('/test.dart'); | |
| 4820 ParseDartTask task = new ParseDartTask(null, source, null, null); | |
| 4821 expect(task.source, same(source)); | |
| 4822 } | |
| 4823 | |
| 4824 void test_hasNonPartOfDirective() { | |
| 4825 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4826 expect(task.hasNonPartOfDirective, isFalse); | |
| 4827 } | |
| 4828 | |
| 4829 void test_hasPartOfDirective() { | |
| 4830 ParseDartTask task = new ParseDartTask(null, null, null, null); | |
| 4831 expect(task.hasPartOfDirective, isFalse); | |
| 4832 } | |
| 4833 | |
| 4834 void test_perform_exception() { | |
| 4835 TestSource source = new TestSource(); | |
| 4836 source.generateExceptionOnRead = true; | |
| 4837 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4838 ParseDartTask task = new ParseDartTask(context, source, null, null); | |
| 4839 task.perform(new ParseDartTaskTestTV_perform_exception()); | |
| 4840 } | |
| 4841 | |
| 4842 void test_perform_library() { | |
| 4843 String content = r''' | |
| 4844 library lib; | |
| 4845 import 'lib2.dart'; | |
| 4846 export 'lib3.dart'; | |
| 4847 part 'part.dart'; | |
| 4848 class A {'''; | |
| 4849 Source source = new TestSource('/test.dart', content); | |
| 4850 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4851 ParseDartTask task = _createParseTask(context, source, content); | |
| 4852 task.perform(new ParseDartTaskTestTV_perform_library(context, source)); | |
| 4853 } | |
| 4854 | |
| 4855 void test_perform_part() { | |
| 4856 String content = r''' | |
| 4857 part of lib; | |
| 4858 class B {}'''; | |
| 4859 Source source = new TestSource('/test.dart', content); | |
| 4860 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4861 ParseDartTask task = _createParseTask(context, source, content); | |
| 4862 task.perform(new ParseDartTaskTestTV_perform_part(context, source)); | |
| 4863 } | |
| 4864 | |
| 4865 void test_perform_validateDirectives() { | |
| 4866 String content = r''' | |
| 4867 library lib; | |
| 4868 import '/does/not/exist.dart'; | |
| 4869 import '://invaliduri.dart'; | |
| 4870 export '${a}lib3.dart'; | |
| 4871 part 'part.dart'; | |
| 4872 class A {}'''; | |
| 4873 Source source = new TestSource('/test.dart', content); | |
| 4874 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4875 ParseDartTask task = _createParseTask(context, source, content); | |
| 4876 task.perform( | |
| 4877 new ParseDartTaskTestTV_perform_validateDirectives(context, source)); | |
| 4878 } | |
| 4879 | |
| 4880 void test_resolveDirective_dartUri() { | |
| 4881 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 4882 ImportDirective directive = AstFactory.importDirective3('dart:core', null); | |
| 4883 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4884 Source source = | |
| 4885 ParseDartTask.resolveDirective(context, null, directive, listener); | |
| 4886 expect(source, isNotNull); | |
| 4887 } | |
| 4888 | |
| 4889 void test_resolveDirective_exception() { | |
| 4890 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 4891 ImportDirective directive = AstFactory.importDirective3('dart:core', null); | |
| 4892 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 4893 context.sourceFactory = new MockSourceFactory(); | |
| 4894 Source source = | |
| 4895 ParseDartTask.resolveDirective(context, null, directive, listener); | |
| 4896 expect(source, isNull); | |
| 4897 expect(listener.errors, hasLength(1)); | |
| 4898 } | |
| 4899 | |
| 4900 /** | |
| 4901 * Create and return a task that will parse the given content from the given s
ource in the given | |
| 4902 * context. | |
| 4903 * | |
| 4904 * @param context the context to be passed to the task | |
| 4905 * @param source the source to be parsed | |
| 4906 * @param content the content of the source to be parsed | |
| 4907 * @return the task that was created | |
| 4908 * @throws AnalysisException if the task could not be created | |
| 4909 */ | |
| 4910 ParseDartTask _createParseTask( | |
| 4911 InternalAnalysisContext context, Source source, String content) { | |
| 4912 ScanDartTask scanTask = new ScanDartTask(context, source, content); | |
| 4913 scanTask.perform(new ParseDartTaskTestTV_createParseTask()); | |
| 4914 return new ParseDartTask( | |
| 4915 context, source, scanTask.tokenStream, scanTask.lineInfo); | |
| 4916 } | |
| 4917 } | |
| 4918 | |
| 4919 class ParseDartTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 4920 @override | |
| 4921 bool visitParseDartTask(ParseDartTask task) => true; | |
| 4922 } | |
| 4923 | |
| 4924 class ParseDartTaskTestTV_createParseTask extends TestTaskVisitor<Object> { | |
| 4925 @override | |
| 4926 Object visitScanDartTask(ScanDartTask task) => null; | |
| 4927 } | |
| 4928 | |
| 4929 class ParseDartTaskTestTV_perform_exception extends TestTaskVisitor<bool> { | |
| 4930 @override | |
| 4931 bool visitParseDartTask(ParseDartTask task) { | |
| 4932 expect(task.exception, isNotNull); | |
| 4933 return true; | |
| 4934 } | |
| 4935 } | |
| 4936 | |
| 4937 class ParseDartTaskTestTV_perform_library extends TestTaskVisitor<Object> { | |
| 4938 InternalAnalysisContext context; | |
| 4939 Source source; | |
| 4940 ParseDartTaskTestTV_perform_library(this.context, this.source); | |
| 4941 @override | |
| 4942 Object visitParseDartTask(ParseDartTask task) { | |
| 4943 CaughtException exception = task.exception; | |
| 4944 if (exception != null) { | |
| 4945 throw exception; | |
| 4946 } | |
| 4947 expect(task.compilationUnit, isNotNull); | |
| 4948 expect(task.errors, hasLength(1)); | |
| 4949 expect(task.source, same(source)); | |
| 4950 expect(task.hasNonPartOfDirective, isTrue); | |
| 4951 expect(task.hasPartOfDirective, isFalse); | |
| 4952 return null; | |
| 4953 } | |
| 4954 } | |
| 4955 | |
| 4956 class ParseDartTaskTestTV_perform_part extends TestTaskVisitor<Object> { | |
| 4957 InternalAnalysisContext context; | |
| 4958 Source source; | |
| 4959 ParseDartTaskTestTV_perform_part(this.context, this.source); | |
| 4960 @override | |
| 4961 Object visitParseDartTask(ParseDartTask task) { | |
| 4962 CaughtException exception = task.exception; | |
| 4963 if (exception != null) { | |
| 4964 throw exception; | |
| 4965 } | |
| 4966 expect(task.compilationUnit, isNotNull); | |
| 4967 expect(task.errors, hasLength(0)); | |
| 4968 expect(task.source, same(source)); | |
| 4969 expect(task.hasNonPartOfDirective, isFalse); | |
| 4970 expect(task.hasPartOfDirective, isTrue); | |
| 4971 return null; | |
| 4972 } | |
| 4973 } | |
| 4974 | |
| 4975 class ParseDartTaskTestTV_perform_validateDirectives | |
| 4976 extends TestTaskVisitor<Object> { | |
| 4977 InternalAnalysisContext context; | |
| 4978 Source source; | |
| 4979 ParseDartTaskTestTV_perform_validateDirectives(this.context, this.source); | |
| 4980 @override | |
| 4981 Object visitParseDartTask(ParseDartTask task) { | |
| 4982 CaughtException exception = task.exception; | |
| 4983 if (exception != null) { | |
| 4984 throw exception; | |
| 4985 } | |
| 4986 expect(task.compilationUnit, isNotNull); | |
| 4987 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 4988 errorListener.addAll(task.errors); | |
| 4989 errorListener.assertErrorsWithCodes([ | |
| 4990 CompileTimeErrorCode.URI_WITH_INTERPOLATION, | |
| 4991 CompileTimeErrorCode.INVALID_URI | |
| 4992 ]); | |
| 4993 expect(task.source, same(source)); | |
| 4994 expect(task.hasNonPartOfDirective, isTrue); | |
| 4995 expect(task.hasPartOfDirective, isFalse); | |
| 4996 return null; | |
| 4997 } | |
| 4998 } | |
| 4999 | |
| 5000 @reflectiveTest | |
| 5001 class ParseHtmlTaskTest extends EngineTestCase { | |
| 5002 ParseHtmlTask parseContents(String contents, TestLogger testLogger) { | |
| 5003 return parseSource( | |
| 5004 new TestSource('/test.dart', contents), contents, testLogger); | |
| 5005 } | |
| 5006 | |
| 5007 ParseHtmlTask parseSource( | |
| 5008 Source source, String contents, TestLogger testLogger) { | |
| 5009 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5010 context.setContents(source, contents); | |
| 5011 ParseHtmlTask task = new ParseHtmlTask(context, source, contents); | |
| 5012 Logger oldLogger = AnalysisEngine.instance.logger; | |
| 5013 try { | |
| 5014 AnalysisEngine.instance.logger = testLogger; | |
| 5015 task.perform(new ParseHtmlTaskTestTV_parseSource(context, source)); | |
| 5016 } finally { | |
| 5017 AnalysisEngine.instance.logger = oldLogger; | |
| 5018 } | |
| 5019 return task; | |
| 5020 } | |
| 5021 | |
| 5022 void test_accept() { | |
| 5023 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); | |
| 5024 expect(task.accept(new ParseHtmlTaskTestTV_accept()), isTrue); | |
| 5025 } | |
| 5026 | |
| 5027 void test_getException() { | |
| 5028 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); | |
| 5029 expect(task.exception, isNull); | |
| 5030 } | |
| 5031 | |
| 5032 void test_getHtmlUnit() { | |
| 5033 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); | |
| 5034 expect(task.htmlUnit, isNull); | |
| 5035 } | |
| 5036 | |
| 5037 void test_getLineInfo() { | |
| 5038 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); | |
| 5039 expect(task.lineInfo, isNull); | |
| 5040 } | |
| 5041 | |
| 5042 void test_getReferencedLibraries() { | |
| 5043 ParseHtmlTask task = new ParseHtmlTask(null, null, ""); | |
| 5044 expect(task.referencedLibraries, hasLength(0)); | |
| 5045 } | |
| 5046 | |
| 5047 void test_getSource() { | |
| 5048 Source source = new TestSource('/test.dart'); | |
| 5049 ParseHtmlTask task = new ParseHtmlTask(null, source, ""); | |
| 5050 expect(task.source, same(source)); | |
| 5051 } | |
| 5052 | |
| 5053 void test_perform_embedded_source() { | |
| 5054 String contents = r''' | |
| 5055 <html> | |
| 5056 <head> | |
| 5057 <script type='application/dart'> | |
| 5058 void buttonPressed() {} | |
| 5059 </script> | |
| 5060 </head> | |
| 5061 <body> | |
| 5062 </body> | |
| 5063 </html>'''; | |
| 5064 TestLogger testLogger = new TestLogger(); | |
| 5065 ParseHtmlTask task = parseContents(contents, testLogger); | |
| 5066 expect(task.referencedLibraries, hasLength(0)); | |
| 5067 expect(testLogger.errorCount, 0); | |
| 5068 expect(testLogger.infoCount, 0); | |
| 5069 } | |
| 5070 | |
| 5071 void test_perform_empty_source_reference() { | |
| 5072 String contents = r''' | |
| 5073 <html> | |
| 5074 <head> | |
| 5075 <script type='application/dart' src=''/> | |
| 5076 </head> | |
| 5077 <body> | |
| 5078 </body> | |
| 5079 </html>'''; | |
| 5080 TestLogger testLogger = new TestLogger(); | |
| 5081 ParseHtmlTask task = parseContents(contents, testLogger); | |
| 5082 expect(task.referencedLibraries, hasLength(0)); | |
| 5083 expect(testLogger.errorCount, 0); | |
| 5084 expect(testLogger.infoCount, 0); | |
| 5085 } | |
| 5086 | |
| 5087 void test_perform_invalid_source_reference() { | |
| 5088 String contents = r''' | |
| 5089 <html> | |
| 5090 <head> | |
| 5091 <script type='application/dart' src='an;invalid:[]uri'/> | |
| 5092 </head> | |
| 5093 <body> | |
| 5094 </body> | |
| 5095 </html>'''; | |
| 5096 TestLogger testLogger = new TestLogger(); | |
| 5097 ParseHtmlTask task = parseContents(contents, testLogger); | |
| 5098 expect(task.referencedLibraries, hasLength(0)); | |
| 5099 expect(testLogger.errorCount, 0); | |
| 5100 expect(testLogger.infoCount, 0); | |
| 5101 } | |
| 5102 | |
| 5103 void test_perform_non_existing_source_reference() { | |
| 5104 String contents = r''' | |
| 5105 <html> | |
| 5106 <head> | |
| 5107 <script type='application/dart' src='does/not/exist.dart'/> | |
| 5108 </head> | |
| 5109 <body> | |
| 5110 </body> | |
| 5111 </html>'''; | |
| 5112 TestLogger testLogger = new TestLogger(); | |
| 5113 ParseHtmlTask task = parseSource( | |
| 5114 new ParseHtmlTaskTest_non_existing_source(contents), | |
| 5115 contents, | |
| 5116 testLogger); | |
| 5117 expect(task.referencedLibraries, hasLength(0)); | |
| 5118 expect(testLogger.errorCount, 0); | |
| 5119 expect(testLogger.infoCount, 0); | |
| 5120 } | |
| 5121 | |
| 5122 void test_perform_referenced_source() { | |
| 5123 // TODO(scheglov) this test fails because we put into cache TestSource | |
| 5124 // test.dart (and actually should test.html), but resolve | |
| 5125 // src='test.dart' as a FileBasedSource | |
| 5126 // We need to switch to a virtual file system and use it everywhere. | |
| 5127 // String contents = EngineTestCase.createSource([ | |
| 5128 // "<html>", | |
| 5129 // "<head>", | |
| 5130 // " <script type='application/dart' src='test.dart'/>", | |
| 5131 // "</head>", | |
| 5132 // "<body>", | |
| 5133 // "</body>", | |
| 5134 // "</html>"]); | |
| 5135 // TestLogger testLogger = new TestLogger(); | |
| 5136 // ParseHtmlTask task = parseContents(contents, testLogger); | |
| 5137 // EngineTestCase.assertLength(1, task.referencedLibraries); | |
| 5138 // JUnitTestCase.assertEquals(0, testLogger.errorCount); | |
| 5139 // JUnitTestCase.assertEquals(0, testLogger.errorCount); | |
| 5140 } | |
| 5141 } | |
| 5142 | |
| 5143 class ParseHtmlTaskTest_non_existing_source extends TestSource { | |
| 5144 ParseHtmlTaskTest_non_existing_source(String arg0) : super(arg0); | |
| 5145 @override | |
| 5146 Uri resolveRelativeUri(Uri containedUri) { | |
| 5147 try { | |
| 5148 return parseUriWithException("file:/does/not/exist.dart"); | |
| 5149 } on URISyntaxException { | |
| 5150 return null; | |
| 5151 } | |
| 5152 } | |
| 5153 } | |
| 5154 | |
| 5155 class ParseHtmlTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 5156 @override | |
| 5157 bool visitParseHtmlTask(ParseHtmlTask task) => true; | |
| 5158 } | |
| 5159 | |
| 5160 class ParseHtmlTaskTestTV_parseSource extends TestTaskVisitor<bool> { | |
| 5161 InternalAnalysisContext context; | |
| 5162 Source source; | |
| 5163 ParseHtmlTaskTestTV_parseSource(this.context, this.source); | |
| 5164 @override | |
| 5165 bool visitParseHtmlTask(ParseHtmlTask task) { | |
| 5166 CaughtException exception = task.exception; | |
| 5167 if (exception != null) { | |
| 5168 throw exception; | |
| 5169 } | |
| 5170 expect(task.htmlUnit, isNotNull); | |
| 5171 expect(task.lineInfo, isNotNull); | |
| 5172 expect(task.source, same(source)); | |
| 5173 return true; | |
| 5174 } | |
| 5175 } | |
| 5176 | |
| 5177 @reflectiveTest | |
| 5178 class PartitionManagerTest extends EngineTestCase { | |
| 5179 void test_clearCache() { | |
| 5180 PartitionManager manager = new PartitionManager(); | |
| 5181 DartSdk sdk = new MockDartSdk(); | |
| 5182 SdkCachePartition oldPartition = manager.forSdk(sdk); | |
| 5183 manager.clearCache(); | |
| 5184 SdkCachePartition newPartition = manager.forSdk(sdk); | |
| 5185 expect(newPartition, isNot(same(oldPartition))); | |
| 5186 } | |
| 5187 | |
| 5188 void test_creation() { | |
| 5189 expect(new PartitionManager(), isNotNull); | |
| 5190 } | |
| 5191 | |
| 5192 void test_forSdk() { | |
| 5193 PartitionManager manager = new PartitionManager(); | |
| 5194 DartSdk sdk1 = new MockDartSdk(); | |
| 5195 SdkCachePartition partition1 = manager.forSdk(sdk1); | |
| 5196 expect(partition1, isNotNull); | |
| 5197 expect(manager.forSdk(sdk1), same(partition1)); | |
| 5198 DartSdk sdk2 = new MockDartSdk(); | |
| 5199 SdkCachePartition partition2 = manager.forSdk(sdk2); | |
| 5200 expect(partition2, isNotNull); | |
| 5201 expect(manager.forSdk(sdk2), same(partition2)); | |
| 5202 expect(partition2, isNot(same(partition1))); | |
| 5203 } | |
| 5204 } | |
| 5205 | |
| 5206 @reflectiveTest | |
| 5207 class ResolveDartLibraryTaskTest extends EngineTestCase { | |
| 5208 void test_accept() { | |
| 5209 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); | |
| 5210 expect(task.accept(new ResolveDartLibraryTaskTestTV_accept()), isTrue); | |
| 5211 } | |
| 5212 | |
| 5213 void test_getException() { | |
| 5214 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); | |
| 5215 expect(task.exception, isNull); | |
| 5216 } | |
| 5217 | |
| 5218 void test_getLibraryResolver() { | |
| 5219 ResolveDartLibraryTask task = new ResolveDartLibraryTask(null, null, null); | |
| 5220 expect(task.libraryResolver, isNull); | |
| 5221 } | |
| 5222 | |
| 5223 void test_getLibrarySource() { | |
| 5224 Source source = new TestSource('/test.dart'); | |
| 5225 ResolveDartLibraryTask task = | |
| 5226 new ResolveDartLibraryTask(null, null, source); | |
| 5227 expect(task.librarySource, same(source)); | |
| 5228 } | |
| 5229 | |
| 5230 void test_getUnitSource() { | |
| 5231 Source source = new TestSource('/test.dart'); | |
| 5232 ResolveDartLibraryTask task = | |
| 5233 new ResolveDartLibraryTask(null, source, null); | |
| 5234 expect(task.unitSource, same(source)); | |
| 5235 } | |
| 5236 | |
| 5237 void test_perform_exception() { | |
| 5238 TestSource source = new TestSource(); | |
| 5239 source.generateExceptionOnRead = true; | |
| 5240 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5241 ResolveDartLibraryTask task = | |
| 5242 new ResolveDartLibraryTask(context, source, source); | |
| 5243 task.perform(new ResolveDartLibraryTaskTestTV_perform_exception()); | |
| 5244 } | |
| 5245 | |
| 5246 void test_perform_library() { | |
| 5247 Source source = new TestSource( | |
| 5248 '/test.dart', | |
| 5249 r''' | |
| 5250 library lib; | |
| 5251 class A {}'''); | |
| 5252 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5253 ResolveDartLibraryTask task = | |
| 5254 new ResolveDartLibraryTask(context, source, source); | |
| 5255 task.perform(new ResolveDartLibraryTaskTestTV_perform_library(source)); | |
| 5256 } | |
| 5257 } | |
| 5258 | |
| 5259 class ResolveDartLibraryTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 5260 @override | |
| 5261 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) => true; | |
| 5262 } | |
| 5263 | |
| 5264 class ResolveDartLibraryTaskTestTV_perform_exception | |
| 5265 extends TestTaskVisitor<bool> { | |
| 5266 @override | |
| 5267 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) { | |
| 5268 expect(task.exception, isNotNull); | |
| 5269 return true; | |
| 5270 } | |
| 5271 } | |
| 5272 | |
| 5273 class ResolveDartLibraryTaskTestTV_perform_library | |
| 5274 extends TestTaskVisitor<bool> { | |
| 5275 Source source; | |
| 5276 ResolveDartLibraryTaskTestTV_perform_library(this.source); | |
| 5277 @override | |
| 5278 bool visitResolveDartLibraryTask(ResolveDartLibraryTask task) { | |
| 5279 CaughtException exception = task.exception; | |
| 5280 if (exception != null) { | |
| 5281 throw exception; | |
| 5282 } | |
| 5283 expect(task.libraryResolver, isNotNull); | |
| 5284 expect(task.librarySource, same(source)); | |
| 5285 expect(task.unitSource, same(source)); | |
| 5286 return true; | |
| 5287 } | |
| 5288 } | |
| 5289 | |
| 5290 @reflectiveTest | |
| 5291 class ResolveDartUnitTaskTest extends EngineTestCase { | |
| 5292 void test_accept() { | |
| 5293 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); | |
| 5294 expect(task.accept(new ResolveDartUnitTaskTestTV_accept()), isTrue); | |
| 5295 } | |
| 5296 | |
| 5297 void test_getException() { | |
| 5298 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); | |
| 5299 expect(task.exception, isNull); | |
| 5300 } | |
| 5301 | |
| 5302 void test_getLibrarySource() { | |
| 5303 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5304 LibraryElementImpl element = ElementFactory.library(context, "lib"); | |
| 5305 Source source = element.source; | |
| 5306 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, element); | |
| 5307 expect(task.librarySource, same(source)); | |
| 5308 } | |
| 5309 | |
| 5310 void test_getResolvedUnit() { | |
| 5311 ResolveDartUnitTask task = new ResolveDartUnitTask(null, null, null); | |
| 5312 expect(task.resolvedUnit, isNull); | |
| 5313 } | |
| 5314 | |
| 5315 void test_getSource() { | |
| 5316 Source source = new TestSource('/test.dart'); | |
| 5317 ResolveDartUnitTask task = new ResolveDartUnitTask(null, source, null); | |
| 5318 expect(task.source, same(source)); | |
| 5319 } | |
| 5320 | |
| 5321 void test_perform_exception() { | |
| 5322 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5323 LibraryElementImpl element = ElementFactory.library(context, "lib"); | |
| 5324 TestSource source = new TestSource(); | |
| 5325 source.generateExceptionOnRead = true; | |
| 5326 (element.definingCompilationUnit as CompilationUnitElementImpl).source = | |
| 5327 source; | |
| 5328 ResolveDartUnitTask task = | |
| 5329 new ResolveDartUnitTask(context, source, element); | |
| 5330 task.perform(new ResolveDartUnitTaskTestTV_perform_exception()); | |
| 5331 } | |
| 5332 | |
| 5333 void test_perform_library() { | |
| 5334 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5335 LibraryElementImpl libraryElement = ElementFactory.library(context, "lib"); | |
| 5336 CompilationUnitElementImpl unitElement = | |
| 5337 libraryElement.definingCompilationUnit as CompilationUnitElementImpl; | |
| 5338 ClassElementImpl classElement = ElementFactory.classElement2("A"); | |
| 5339 classElement.nameOffset = 19; | |
| 5340 ConstructorElementImpl constructorElement = | |
| 5341 ElementFactory.constructorElement2(classElement, null); | |
| 5342 constructorElement.synthetic = true; | |
| 5343 classElement.constructors = <ConstructorElement>[constructorElement]; | |
| 5344 unitElement.types = <ClassElement>[classElement]; | |
| 5345 Source source = unitElement.source; | |
| 5346 context.setContents( | |
| 5347 source, | |
| 5348 r''' | |
| 5349 library lib; | |
| 5350 class A {}'''); | |
| 5351 ResolveDartUnitTask task = | |
| 5352 new ResolveDartUnitTask(context, source, libraryElement); | |
| 5353 task.perform( | |
| 5354 new ResolveDartUnitTaskTestTV_perform_library(source, context)); | |
| 5355 } | |
| 5356 } | |
| 5357 | |
| 5358 class ResolveDartUnitTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 5359 @override | |
| 5360 bool visitResolveDartUnitTask(ResolveDartUnitTask task) => true; | |
| 5361 } | |
| 5362 | |
| 5363 class ResolveDartUnitTaskTestTV_perform_exception | |
| 5364 extends TestTaskVisitor<bool> { | |
| 5365 @override | |
| 5366 bool visitResolveDartUnitTask(ResolveDartUnitTask task) { | |
| 5367 expect(task.exception, isNotNull); | |
| 5368 return true; | |
| 5369 } | |
| 5370 } | |
| 5371 | |
| 5372 class ResolveDartUnitTaskTestTV_perform_library extends TestTaskVisitor<bool> { | |
| 5373 Source source; | |
| 5374 InternalAnalysisContext context; | |
| 5375 ResolveDartUnitTaskTestTV_perform_library(this.source, this.context); | |
| 5376 @override | |
| 5377 bool visitResolveDartUnitTask(ResolveDartUnitTask task) { | |
| 5378 CaughtException exception = task.exception; | |
| 5379 if (exception != null) { | |
| 5380 throw exception; | |
| 5381 } | |
| 5382 expect(task.librarySource, same(source)); | |
| 5383 expect(task.resolvedUnit, isNotNull); | |
| 5384 expect(task.source, same(source)); | |
| 5385 return true; | |
| 5386 } | |
| 5387 } | |
| 5388 | |
| 5389 @reflectiveTest | |
| 5390 class ResolveHtmlTaskTest extends EngineTestCase { | |
| 5391 void test_accept() { | |
| 5392 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); | |
| 5393 expect(task.accept(new ResolveHtmlTaskTestTV_accept()), isTrue); | |
| 5394 } | |
| 5395 | |
| 5396 void test_getElement() { | |
| 5397 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); | |
| 5398 expect(task.element, isNull); | |
| 5399 } | |
| 5400 | |
| 5401 void test_getException() { | |
| 5402 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); | |
| 5403 expect(task.exception, isNull); | |
| 5404 } | |
| 5405 | |
| 5406 void test_getResolutionErrors() { | |
| 5407 ResolveHtmlTask task = new ResolveHtmlTask(null, null, 0, null); | |
| 5408 expect(task.resolutionErrors, hasLength(0)); | |
| 5409 } | |
| 5410 | |
| 5411 void test_getSource() { | |
| 5412 Source source = new TestSource('test.dart', ''); | |
| 5413 ResolveHtmlTask task = new ResolveHtmlTask(null, source, 0, null); | |
| 5414 expect(task.source, same(source)); | |
| 5415 } | |
| 5416 | |
| 5417 void test_perform_exception() { | |
| 5418 Source source = new TestSource(); | |
| 5419 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5420 ResolveHtmlTask task = new ResolveHtmlTask(context, source, 0, null); | |
| 5421 task.perform(new ResolveHtmlTaskTestTV_perform_exception()); | |
| 5422 } | |
| 5423 | |
| 5424 void test_perform_valid() { | |
| 5425 int modificationStamp = 73; | |
| 5426 String content = r''' | |
| 5427 <html> | |
| 5428 <head> | |
| 5429 <script type='application/dart'> | |
| 5430 void f() { x = 0; } | |
| 5431 </script> | |
| 5432 </head> | |
| 5433 <body> | |
| 5434 </body> | |
| 5435 </html>'''; | |
| 5436 Source source = new TestSource("/test.html", content); | |
| 5437 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5438 ParseHtmlTask parseTask = new ParseHtmlTask(context, source, content); | |
| 5439 parseTask.perform(new ResolveHtmlTaskTestTV_perform_valid_2()); | |
| 5440 ResolveHtmlTask task = new ResolveHtmlTask( | |
| 5441 context, source, modificationStamp, parseTask.htmlUnit); | |
| 5442 task.perform( | |
| 5443 new ResolveHtmlTaskTestTV_perform_valid(modificationStamp, source)); | |
| 5444 } | |
| 5445 } | |
| 5446 | |
| 5447 class ResolveHtmlTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 5448 @override | |
| 5449 bool visitResolveHtmlTask(ResolveHtmlTask task) => true; | |
| 5450 } | |
| 5451 | |
| 5452 class ResolveHtmlTaskTestTV_perform_exception extends TestTaskVisitor<bool> { | |
| 5453 @override | |
| 5454 bool visitResolveHtmlTask(ResolveHtmlTask task) { | |
| 5455 expect(task.exception, isNotNull); | |
| 5456 return true; | |
| 5457 } | |
| 5458 } | |
| 5459 | |
| 5460 class ResolveHtmlTaskTestTV_perform_valid extends TestTaskVisitor<Object> { | |
| 5461 int modificationStamp; | |
| 5462 Source source; | |
| 5463 ResolveHtmlTaskTestTV_perform_valid(this.modificationStamp, this.source); | |
| 5464 @override | |
| 5465 Object visitResolveHtmlTask(ResolveHtmlTask task) { | |
| 5466 CaughtException exception = task.exception; | |
| 5467 if (exception != null) { | |
| 5468 throw exception; | |
| 5469 } | |
| 5470 expect(task.element, isNotNull); | |
| 5471 expect(task.resolutionErrors, hasLength(1)); | |
| 5472 expect(task.source, same(source)); | |
| 5473 return null; | |
| 5474 } | |
| 5475 } | |
| 5476 | |
| 5477 class ResolveHtmlTaskTestTV_perform_valid_2 extends TestTaskVisitor<Object> { | |
| 5478 @override | |
| 5479 Object visitParseHtmlTask(ParseHtmlTask task) => null; | |
| 5480 } | |
| 5481 | |
| 5482 @reflectiveTest | |
| 5483 class ScanDartTaskTest extends EngineTestCase { | |
| 5484 void test_accept() { | |
| 5485 ScanDartTask task = new ScanDartTask(null, null, null); | |
| 5486 expect(task.accept(new ScanDartTaskTestTV_accept()), isTrue); | |
| 5487 } | |
| 5488 | |
| 5489 void test_getErrors() { | |
| 5490 ScanDartTask task = new ScanDartTask(null, null, null); | |
| 5491 expect(task.errors, hasLength(0)); | |
| 5492 } | |
| 5493 | |
| 5494 void test_getException() { | |
| 5495 ScanDartTask task = new ScanDartTask(null, null, null); | |
| 5496 expect(task.exception, isNull); | |
| 5497 } | |
| 5498 | |
| 5499 void test_getLineInfo() { | |
| 5500 ScanDartTask task = new ScanDartTask(null, null, null); | |
| 5501 expect(task.lineInfo, isNull); | |
| 5502 } | |
| 5503 | |
| 5504 void test_getSource() { | |
| 5505 Source source = new TestSource('test.dart', ''); | |
| 5506 ScanDartTask task = new ScanDartTask(null, source, null); | |
| 5507 expect(task.source, same(source)); | |
| 5508 } | |
| 5509 | |
| 5510 void test_perform_valid() { | |
| 5511 String content = 'class A {}'; | |
| 5512 Source source = new TestSource('test.dart', content); | |
| 5513 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | |
| 5514 ScanDartTask task = new ScanDartTask(context, source, content); | |
| 5515 task.perform(new ScanDartTaskTestTV_perform_valid(context, source)); | |
| 5516 } | |
| 5517 } | |
| 5518 | |
| 5519 class ScanDartTaskTestTV_accept extends TestTaskVisitor<bool> { | |
| 5520 @override | |
| 5521 bool visitScanDartTask(ScanDartTask task) => true; | |
| 5522 } | |
| 5523 | |
| 5524 class ScanDartTaskTestTV_perform_valid extends TestTaskVisitor<bool> { | |
| 5525 InternalAnalysisContext context; | |
| 5526 Source source; | |
| 5527 ScanDartTaskTestTV_perform_valid(this.context, this.source); | |
| 5528 @override | |
| 5529 bool visitScanDartTask(ScanDartTask task) { | |
| 5530 CaughtException exception = task.exception; | |
| 5531 if (exception != null) { | |
| 5532 throw exception; | |
| 5533 } | |
| 5534 expect(task.tokenStream, isNotNull); | |
| 5535 expect(task.errors, hasLength(0)); | |
| 5536 expect(task.lineInfo, isNotNull); | |
| 5537 expect(task.source, same(source)); | |
| 5538 return true; | |
| 5539 } | |
| 5540 } | |
| 5541 | |
| 5542 @reflectiveTest | |
| 5543 class SdkCachePartitionTest extends EngineTestCase { | |
| 5544 void test_contains_false() { | |
| 5545 SdkCachePartition partition = new SdkCachePartition(null, 8); | |
| 5546 Source source = new TestSource(); | |
| 5547 expect(partition.contains(source), isFalse); | |
| 5548 } | |
| 5549 | |
| 5550 void test_contains_true() { | |
| 5551 SdkCachePartition partition = new SdkCachePartition(null, 8); | |
| 5552 SourceFactory factory = new SourceFactory( | |
| 5553 [new DartUriResolver(DirectoryBasedDartSdk.defaultSdk)]); | |
| 5554 Source source = factory.forUri("dart:core"); | |
| 5555 expect(partition.contains(source), isTrue); | |
| 5556 } | |
| 5557 | |
| 5558 void test_creation() { | |
| 5559 expect(new SdkCachePartition(null, 8), isNotNull); | |
| 5560 } | 84 } |
| 5561 } | 85 } |
| 5562 | 86 |
| 5563 @reflectiveTest | 87 @reflectiveTest |
| 5564 class SourcesChangedEventTest { | 88 class SourcesChangedEventTest { |
| 5565 void test_added() { | 89 void test_added() { |
| 5566 var source = new StringSource('', '/test.dart'); | 90 var source = new StringSource('', '/test.dart'); |
| 5567 var changeSet = new ChangeSet(); | 91 var changeSet = new ChangeSet(); |
| 5568 changeSet.addedSource(source); | 92 changeSet.addedSource(source); |
| 5569 var event = new SourcesChangedEvent(changeSet); | 93 var event = new SourcesChangedEvent(changeSet); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5600 } | 124 } |
| 5601 | 125 |
| 5602 void test_changedSources() { | 126 void test_changedSources() { |
| 5603 var source = new StringSource('', '/test.dart'); | 127 var source = new StringSource('', '/test.dart'); |
| 5604 var changeSet = new ChangeSet(); | 128 var changeSet = new ChangeSet(); |
| 5605 changeSet.changedSource(source); | 129 changeSet.changedSource(source); |
| 5606 var event = new SourcesChangedEvent(changeSet); | 130 var event = new SourcesChangedEvent(changeSet); |
| 5607 assertEvent(event, changedSources: [source]); | 131 assertEvent(event, changedSources: [source]); |
| 5608 } | 132 } |
| 5609 | 133 |
| 5610 void test_deleted() { | |
| 5611 var source = new StringSource('', '/test.dart'); | |
| 5612 var changeSet = new ChangeSet(); | |
| 5613 changeSet.deletedSource(source); | |
| 5614 var event = new SourcesChangedEvent(changeSet); | |
| 5615 assertEvent(event, wereSourcesRemovedOrDeleted: true); | |
| 5616 } | |
| 5617 | |
| 5618 void test_empty() { | 134 void test_empty() { |
| 5619 var changeSet = new ChangeSet(); | 135 var changeSet = new ChangeSet(); |
| 5620 var event = new SourcesChangedEvent(changeSet); | 136 var event = new SourcesChangedEvent(changeSet); |
| 5621 assertEvent(event); | 137 assertEvent(event); |
| 5622 } | 138 } |
| 5623 | 139 |
| 5624 void test_removed() { | 140 void test_removed() { |
| 5625 var source = new StringSource('', '/test.dart'); | 141 var source = new StringSource('', '/test.dart'); |
| 5626 var changeSet = new ChangeSet(); | 142 var changeSet = new ChangeSet(); |
| 5627 changeSet.removedSource(source); | 143 changeSet.removedSource(source); |
| 5628 var event = new SourcesChangedEvent(changeSet); | 144 var event = new SourcesChangedEvent(changeSet); |
| 5629 assertEvent(event, wereSourcesRemovedOrDeleted: true); | 145 assertEvent(event, wereSourcesRemoved: true); |
| 5630 } | 146 } |
| 5631 | 147 |
| 5632 static void assertEvent(SourcesChangedEvent event, | 148 static void assertEvent(SourcesChangedEvent event, |
| 5633 {bool wereSourcesAdded: false, | 149 {bool wereSourcesAdded: false, |
| 5634 List<Source> changedSources: Source.EMPTY_LIST, | 150 List<Source> changedSources: Source.EMPTY_LIST, |
| 5635 bool wereSourcesRemovedOrDeleted: false}) { | 151 bool wereSourcesRemoved: false}) { |
| 5636 expect(event.wereSourcesAdded, wereSourcesAdded); | 152 expect(event.wereSourcesAdded, wereSourcesAdded); |
| 5637 expect(event.changedSources, changedSources); | 153 expect(event.changedSources, changedSources); |
| 5638 expect(event.wereSourcesRemovedOrDeleted, wereSourcesRemovedOrDeleted); | 154 expect(event.wereSourcesRemoved, wereSourcesRemoved); |
| 5639 } | 155 } |
| 5640 } | 156 } |
| 5641 | 157 |
| 5642 class SourcesChangedListener { | 158 class SourcesChangedListener { |
| 5643 List<SourcesChangedEvent> actualEvents = []; | 159 List<SourcesChangedEvent> actualEvents = []; |
| 5644 | 160 |
| 5645 void assertEvent( | 161 void assertEvent( |
| 5646 {bool wereSourcesAdded: false, | 162 {bool wereSourcesAdded: false, |
| 5647 List<Source> changedSources: Source.EMPTY_LIST, | 163 List<Source> changedSources: Source.EMPTY_LIST, |
| 5648 bool wereSourcesRemovedOrDeleted: false}) { | 164 bool wereSourcesRemovedOrDeleted: false}) { |
| 5649 if (actualEvents.isEmpty) { | 165 if (actualEvents.isEmpty) { |
| 5650 fail('Expected event but found none'); | 166 fail('Expected event but found none'); |
| 5651 } | 167 } |
| 5652 SourcesChangedEvent actual = actualEvents.removeAt(0); | 168 SourcesChangedEvent actual = actualEvents.removeAt(0); |
| 5653 SourcesChangedEventTest.assertEvent(actual, | 169 SourcesChangedEventTest.assertEvent(actual, |
| 5654 wereSourcesAdded: wereSourcesAdded, | 170 wereSourcesAdded: wereSourcesAdded, |
| 5655 changedSources: changedSources, | 171 changedSources: changedSources, |
| 5656 wereSourcesRemovedOrDeleted: wereSourcesRemovedOrDeleted); | 172 wereSourcesRemoved: wereSourcesRemovedOrDeleted); |
| 5657 } | 173 } |
| 5658 | 174 |
| 5659 void assertNoMoreEvents() { | 175 void assertNoMoreEvents() { |
| 5660 expect(actualEvents, []); | 176 expect(actualEvents, []); |
| 5661 } | 177 } |
| 5662 | 178 |
| 5663 void onData(SourcesChangedEvent event) { | 179 void onData(SourcesChangedEvent event) { |
| 5664 actualEvents.add(event); | 180 actualEvents.add(event); |
| 5665 } | 181 } |
| 5666 } | 182 } |
| 5667 | 183 |
| 5668 /** | 184 /** |
| 5669 * Instances of the class `TestAnalysisContext` implement an analysis context in
which every | 185 * An analysis context in which almost every method will cause a test to fail |
| 5670 * method will cause a test to fail when invoked. | 186 * when invoked. |
| 5671 */ | 187 */ |
| 5672 class TestAnalysisContext implements InternalAnalysisContext { | 188 class TestAnalysisContext implements InternalAnalysisContext { |
| 5673 @override | 189 @override |
| 190 final ReentrantSynchronousStream<InvalidatedResult> onResultInvalidated = |
| 191 new ReentrantSynchronousStream<InvalidatedResult>(); |
| 192 |
| 193 @override |
| 194 ResultProvider resultProvider; |
| 195 |
| 196 @override |
| 5674 AnalysisCache get analysisCache { | 197 AnalysisCache get analysisCache { |
| 5675 fail("Unexpected invocation of analysisCache"); | 198 fail("Unexpected invocation of analysisCache"); |
| 5676 return null; | 199 return null; |
| 5677 } | 200 } |
| 5678 | 201 |
| 5679 @override | 202 @override |
| 5680 AnalysisOptions get analysisOptions { | 203 AnalysisOptions get analysisOptions { |
| 5681 fail("Unexpected invocation of getAnalysisOptions"); | 204 fail("Unexpected invocation of getAnalysisOptions"); |
| 5682 return null; | 205 return null; |
| 5683 } | 206 } |
| 5684 | 207 |
| 5685 @override | 208 @override |
| 5686 void set analysisOptions(AnalysisOptions options) { | 209 void set analysisOptions(AnalysisOptions options) { |
| 5687 fail("Unexpected invocation of setAnalysisOptions"); | 210 fail("Unexpected invocation of setAnalysisOptions"); |
| 5688 } | 211 } |
| 5689 | 212 |
| 5690 @override | 213 @override |
| 5691 void set analysisPriorityOrder(List<Source> sources) { | 214 void set analysisPriorityOrder(List<Source> sources) { |
| 5692 fail("Unexpected invocation of setAnalysisPriorityOrder"); | 215 fail("Unexpected invocation of setAnalysisPriorityOrder"); |
| 5693 } | 216 } |
| 5694 | 217 |
| 5695 @override | 218 @override |
| 219 CacheConsistencyValidator get cacheConsistencyValidator { |
| 220 fail("Unexpected invocation of cacheConsistencyValidator"); |
| 221 return null; |
| 222 } |
| 223 |
| 224 @override |
| 5696 set contentCache(ContentCache value) { | 225 set contentCache(ContentCache value) { |
| 5697 fail("Unexpected invocation of setContentCache"); | 226 fail("Unexpected invocation of setContentCache"); |
| 5698 } | 227 } |
| 5699 | 228 |
| 5700 @override | 229 @override |
| 5701 DeclaredVariables get declaredVariables { | 230 DeclaredVariables get declaredVariables { |
| 5702 fail("Unexpected invocation of getDeclaredVariables"); | 231 fail("Unexpected invocation of getDeclaredVariables"); |
| 5703 return null; | 232 return null; |
| 5704 } | 233 } |
| 5705 | 234 |
| 5706 @override | 235 @deprecated |
| 5707 List<newContext.AnalysisTarget> get explicitTargets { | 236 @override |
| 237 EmbedderYamlLocator get embedderYamlLocator { |
| 238 fail("Unexpected invocation of get embedderYamlLocator"); |
| 239 return null; |
| 240 } |
| 241 |
| 242 @override |
| 243 List<AnalysisTarget> get explicitTargets { |
| 5708 fail("Unexpected invocation of visitCacheItems"); | 244 fail("Unexpected invocation of visitCacheItems"); |
| 5709 return null; | 245 return null; |
| 5710 } | 246 } |
| 5711 | 247 |
| 5712 @override | 248 @override |
| 249 ResolverProvider get fileResolverProvider { |
| 250 fail("Unexpected invocation of fileResolverProvider"); |
| 251 return null; |
| 252 } |
| 253 |
| 254 @override |
| 255 void set fileResolverProvider(ResolverProvider resolverProvider) { |
| 256 fail("Unexpected invocation of fileResolverProvider"); |
| 257 } |
| 258 |
| 259 @override |
| 5713 List<Source> get htmlSources { | 260 List<Source> get htmlSources { |
| 5714 fail("Unexpected invocation of getHtmlSources"); | 261 fail("Unexpected invocation of getHtmlSources"); |
| 5715 return null; | 262 return null; |
| 5716 } | 263 } |
| 5717 | 264 |
| 5718 @override | 265 @override |
| 5719 Stream<ImplicitAnalysisEvent> get implicitAnalysisEvents { | 266 Stream<ImplicitAnalysisEvent> get implicitAnalysisEvents { |
| 5720 fail("Unexpected invocation of analyzedSources"); | 267 fail("Unexpected invocation of analyzedSources"); |
| 5721 return null; | 268 return null; |
| 5722 } | 269 } |
| 5723 | 270 |
| 271 bool get isActive { |
| 272 fail("Unexpected invocation of isActive"); |
| 273 return false; |
| 274 } |
| 275 |
| 276 void set isActive(bool isActive) { |
| 277 fail("Unexpected invocation of isActive"); |
| 278 } |
| 279 |
| 5724 @override | 280 @override |
| 5725 bool get isDisposed { | 281 bool get isDisposed { |
| 5726 fail("Unexpected invocation of isDisposed"); | 282 fail("Unexpected invocation of isDisposed"); |
| 5727 return false; | 283 return false; |
| 5728 } | 284 } |
| 5729 | 285 |
| 5730 @override | 286 @override |
| 5731 List<Source> get launchableClientLibrarySources { | 287 List<Source> get launchableClientLibrarySources { |
| 5732 fail("Unexpected invocation of getLaunchableClientLibrarySources"); | 288 fail("Unexpected invocation of getLaunchableClientLibrarySources"); |
| 5733 return null; | 289 return null; |
| 5734 } | 290 } |
| 5735 | 291 |
| 5736 @override | 292 @override |
| 5737 List<Source> get launchableServerLibrarySources { | 293 List<Source> get launchableServerLibrarySources { |
| 5738 fail("Unexpected invocation of getLaunchableServerLibrarySources"); | 294 fail("Unexpected invocation of getLaunchableServerLibrarySources"); |
| 5739 return null; | 295 return null; |
| 5740 } | 296 } |
| 5741 | 297 |
| 5742 @override | 298 @override |
| 5743 LibraryResolverFactory get libraryResolverFactory { | |
| 5744 fail("Unexpected invocation of getLibraryResolverFactory"); | |
| 5745 return null; | |
| 5746 } | |
| 5747 | |
| 5748 @override | |
| 5749 List<Source> get librarySources { | 299 List<Source> get librarySources { |
| 5750 fail("Unexpected invocation of getLibrarySources"); | 300 fail("Unexpected invocation of getLibrarySources"); |
| 5751 return null; | 301 return null; |
| 5752 } | 302 } |
| 5753 | 303 |
| 5754 @override | 304 @override |
| 5755 String get name { | 305 String get name { |
| 5756 fail("Unexpected invocation of name"); | 306 fail("Unexpected invocation of name"); |
| 5757 return null; | 307 return null; |
| 5758 } | 308 } |
| 5759 | 309 |
| 5760 @override | 310 @override |
| 5761 set name(String value) { | 311 set name(String value) { |
| 5762 fail("Unexpected invocation of name"); | 312 fail("Unexpected invocation of name"); |
| 5763 } | 313 } |
| 5764 | 314 |
| 5765 @override | 315 @override |
| 5766 Stream<SourcesChangedEvent> get onSourcesChanged { | 316 Stream<SourcesChangedEvent> get onSourcesChanged { |
| 5767 fail("Unexpected invocation of onSourcesChanged"); | 317 fail("Unexpected invocation of onSourcesChanged"); |
| 5768 return null; | 318 return null; |
| 5769 } | 319 } |
| 5770 | 320 |
| 5771 @override | 321 @override |
| 5772 List<Source> get prioritySources { | 322 List<Source> get prioritySources { |
| 5773 fail("Unexpected invocation of getPrioritySources"); | 323 fail("Unexpected invocation of getPrioritySources"); |
| 5774 return null; | 324 return null; |
| 5775 } | 325 } |
| 5776 | 326 |
| 5777 @override | 327 @override |
| 5778 List<newContext.AnalysisTarget> get priorityTargets { | 328 List<AnalysisTarget> get priorityTargets { |
| 5779 fail("Unexpected invocation of visitCacheItems"); | 329 fail("Unexpected invocation of visitCacheItems"); |
| 5780 return null; | 330 return null; |
| 5781 } | 331 } |
| 5782 | 332 |
| 5783 @override | 333 @override |
| 5784 CachePartition get privateAnalysisCachePartition { | 334 CachePartition get privateAnalysisCachePartition { |
| 5785 fail("Unexpected invocation of privateAnalysisCachePartition"); | 335 fail("Unexpected invocation of privateAnalysisCachePartition"); |
| 5786 return null; | 336 return null; |
| 5787 } | 337 } |
| 5788 | 338 |
| 5789 @override | 339 @override |
| 5790 ResolverVisitorFactory get resolverVisitorFactory { | |
| 5791 fail("Unexpected invocation of getResolverVisitorFactory"); | |
| 5792 return null; | |
| 5793 } | |
| 5794 | |
| 5795 @override | |
| 5796 SourceFactory get sourceFactory { | 340 SourceFactory get sourceFactory { |
| 5797 fail("Unexpected invocation of getSourceFactory"); | 341 fail("Unexpected invocation of getSourceFactory"); |
| 5798 return null; | 342 return null; |
| 5799 } | 343 } |
| 5800 | 344 |
| 5801 @override | 345 @override |
| 5802 void set sourceFactory(SourceFactory factory) { | 346 void set sourceFactory(SourceFactory factory) { |
| 5803 fail("Unexpected invocation of setSourceFactory"); | 347 fail("Unexpected invocation of setSourceFactory"); |
| 5804 } | 348 } |
| 5805 | 349 |
| 5806 @override | 350 @override |
| 5807 List<Source> get sources { | 351 List<Source> get sources { |
| 5808 fail("Unexpected invocation of sources"); | 352 fail("Unexpected invocation of sources"); |
| 5809 return null; | 353 return null; |
| 5810 } | 354 } |
| 5811 | 355 |
| 5812 @override | 356 @override |
| 5813 AnalysisContextStatistics get statistics { | |
| 5814 fail("Unexpected invocation of getStatistics"); | |
| 5815 return null; | |
| 5816 } | |
| 5817 | |
| 5818 @override | |
| 5819 TypeProvider get typeProvider { | 357 TypeProvider get typeProvider { |
| 5820 fail("Unexpected invocation of getTypeProvider"); | 358 fail("Unexpected invocation of getTypeProvider"); |
| 5821 return null; | 359 return null; |
| 5822 } | 360 } |
| 5823 | 361 |
| 5824 @override | 362 @override |
| 5825 void set typeProvider(TypeProvider typeProvider) { | 363 void set typeProvider(TypeProvider typeProvider) { |
| 5826 fail("Unexpected invocation of set typeProvider"); | 364 fail("Unexpected invocation of set typeProvider"); |
| 5827 } | 365 } |
| 5828 | 366 |
| 5829 @override | 367 @override |
| 5830 TypeResolverVisitorFactory get typeResolverVisitorFactory { | |
| 5831 fail("Unexpected invocation of getTypeResolverVisitorFactory"); | |
| 5832 return null; | |
| 5833 } | |
| 5834 | |
| 5835 @override | |
| 5836 TypeSystem get typeSystem { | 368 TypeSystem get typeSystem { |
| 5837 fail("Unexpected invocation of getTypeSystem"); | 369 fail("Unexpected invocation of getTypeSystem"); |
| 5838 return null; | 370 return null; |
| 5839 } | 371 } |
| 5840 | 372 |
| 5841 @override | 373 @override |
| 5842 List<newContext.WorkManager> get workManagers { | 374 List<WorkManager> get workManagers { |
| 5843 fail("Unexpected invocation of workManagers"); | 375 fail("Unexpected invocation of workManagers"); |
| 376 return null; |
| 377 } |
| 378 |
| 379 @override |
| 380 bool aboutToComputeResult(CacheEntry entry, ResultDescriptor result) { |
| 381 fail("Unexpected invocation of aboutToComputeResult"); |
| 382 return false; |
| 5844 } | 383 } |
| 5845 | 384 |
| 5846 @override | 385 @override |
| 5847 void addListener(AnalysisListener listener) { | 386 void addListener(AnalysisListener listener) { |
| 5848 fail("Unexpected invocation of addListener"); | 387 fail("Unexpected invocation of addListener"); |
| 5849 } | 388 } |
| 5850 | 389 |
| 5851 @override | 390 @override |
| 5852 void applyAnalysisDelta(AnalysisDelta delta) { | 391 void applyAnalysisDelta(AnalysisDelta delta) { |
| 5853 fail("Unexpected invocation of applyAnalysisDelta"); | 392 fail("Unexpected invocation of applyAnalysisDelta"); |
| 5854 } | 393 } |
| 5855 | 394 |
| 5856 @override | 395 @override |
| 5857 void applyChanges(ChangeSet changeSet) { | 396 void applyChanges(ChangeSet changeSet) { |
| 5858 fail("Unexpected invocation of applyChanges"); | 397 fail("Unexpected invocation of applyChanges"); |
| 398 return null; |
| 5859 } | 399 } |
| 5860 | 400 |
| 5861 @override | 401 @override |
| 5862 String computeDocumentationComment(Element element) { | 402 String computeDocumentationComment(Element element) { |
| 5863 fail("Unexpected invocation of computeDocumentationComment"); | 403 fail("Unexpected invocation of computeDocumentationComment"); |
| 5864 return null; | 404 return null; |
| 5865 } | 405 } |
| 5866 | 406 |
| 5867 @override | 407 @override |
| 5868 List<AnalysisError> computeErrors(Source source) { | 408 List<AnalysisError> computeErrors(Source source) { |
| 5869 fail("Unexpected invocation of computeErrors"); | 409 fail("Unexpected invocation of computeErrors"); |
| 5870 return null; | 410 return null; |
| 5871 } | 411 } |
| 5872 | 412 |
| 5873 @override | 413 @override |
| 5874 List<Source> computeExportedLibraries(Source source) { | 414 List<Source> computeExportedLibraries(Source source) { |
| 5875 fail("Unexpected invocation of computeExportedLibraries"); | 415 fail("Unexpected invocation of computeExportedLibraries"); |
| 5876 return null; | 416 return null; |
| 5877 } | 417 } |
| 5878 | 418 |
| 5879 @override | 419 @override |
| 5880 @deprecated | |
| 5881 HtmlElement computeHtmlElement(Source source) { | |
| 5882 fail("Unexpected invocation of computeHtmlElement"); | |
| 5883 return null; | |
| 5884 } | |
| 5885 | |
| 5886 @override | |
| 5887 List<Source> computeImportedLibraries(Source source) { | 420 List<Source> computeImportedLibraries(Source source) { |
| 5888 fail("Unexpected invocation of computeImportedLibraries"); | 421 fail("Unexpected invocation of computeImportedLibraries"); |
| 5889 return null; | 422 return null; |
| 5890 } | 423 } |
| 5891 | 424 |
| 5892 @override | 425 @override |
| 5893 SourceKind computeKindOf(Source source) { | 426 SourceKind computeKindOf(Source source) { |
| 5894 fail("Unexpected invocation of computeKindOf"); | 427 fail("Unexpected invocation of computeKindOf"); |
| 5895 return null; | 428 return null; |
| 5896 } | 429 } |
| 5897 | 430 |
| 5898 @override | 431 @override |
| 5899 LibraryElement computeLibraryElement(Source source) { | 432 LibraryElement computeLibraryElement(Source source) { |
| 5900 fail("Unexpected invocation of computeLibraryElement"); | 433 fail("Unexpected invocation of computeLibraryElement"); |
| 5901 return null; | 434 return null; |
| 5902 } | 435 } |
| 5903 | 436 |
| 5904 @override | 437 @override |
| 5905 LineInfo computeLineInfo(Source source) { | 438 LineInfo computeLineInfo(Source source) { |
| 5906 fail("Unexpected invocation of computeLineInfo"); | 439 fail("Unexpected invocation of computeLineInfo"); |
| 5907 return null; | 440 return null; |
| 5908 } | 441 } |
| 5909 | 442 |
| 5910 @override | 443 @override |
| 5911 CompilationUnit computeResolvableCompilationUnit(Source source) { | 444 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( |
| 5912 fail("Unexpected invocation of computeResolvableCompilationUnit"); | |
| 5913 return null; | |
| 5914 } | |
| 5915 | |
| 5916 @override | |
| 5917 Future<CompilationUnit> computeResolvedCompilationUnitAsync( | |
| 5918 Source source, Source librarySource) { | 445 Source source, Source librarySource) { |
| 5919 fail("Unexpected invocation of getResolvedCompilationUnitFuture"); | 446 fail("Unexpected invocation of getResolvedCompilationUnitFuture"); |
| 5920 return null; | 447 return null; |
| 5921 } | 448 } |
| 5922 | 449 |
| 5923 @override | 450 @override |
| 5924 Object computeResult( | 451 Object/*=V*/ computeResult/*<V>*/( |
| 5925 newContext.AnalysisTarget target, newContext.ResultDescriptor result) { | 452 AnalysisTarget target, ResultDescriptor/*<V>*/ result) { |
| 5926 fail("Unexpected invocation of computeResult"); | 453 fail("Unexpected invocation of computeResult"); |
| 5927 return null; | 454 return null; |
| 5928 } | 455 } |
| 5929 | 456 |
| 5930 @override | 457 @override |
| 5931 void dispose() { | 458 void dispose() { |
| 5932 fail("Unexpected invocation of dispose"); | 459 fail("Unexpected invocation of dispose"); |
| 5933 } | 460 } |
| 5934 | 461 |
| 5935 @override | 462 @override |
| 5936 List<CompilationUnit> ensureResolvedDartUnits(Source source) { | 463 List<CompilationUnit> ensureResolvedDartUnits(Source source) { |
| 5937 fail("Unexpected invocation of ensureResolvedDartUnits"); | 464 fail("Unexpected invocation of ensureResolvedDartUnits"); |
| 5938 return null; | 465 return null; |
| 5939 } | 466 } |
| 5940 | 467 |
| 5941 @override | 468 @override |
| 5942 bool exists(Source source) { | 469 bool exists(Source source) { |
| 5943 fail("Unexpected invocation of exists"); | 470 fail("Unexpected invocation of exists"); |
| 5944 return false; | 471 return false; |
| 5945 } | 472 } |
| 5946 | 473 |
| 5947 @override | 474 @override |
| 5948 CacheEntry getCacheEntry(newContext.AnalysisTarget target) { | 475 CacheEntry getCacheEntry(AnalysisTarget target) { |
| 5949 fail("Unexpected invocation of visitCacheItems"); | 476 fail("Unexpected invocation of visitCacheItems"); |
| 5950 return null; | 477 return null; |
| 5951 } | 478 } |
| 5952 | 479 |
| 5953 @override | 480 @override |
| 5954 CompilationUnitElement getCompilationUnitElement( | 481 CompilationUnitElement getCompilationUnitElement( |
| 5955 Source unitSource, Source librarySource) { | 482 Source unitSource, Source librarySource) { |
| 5956 fail("Unexpected invocation of getCompilationUnitElement"); | 483 fail("Unexpected invocation of getCompilationUnitElement"); |
| 5957 return null; | 484 return null; |
| 5958 } | 485 } |
| 5959 | 486 |
| 5960 @override | 487 @override |
| 5961 Object getConfigurationData(newContext.ResultDescriptor key) { | 488 Object/*=V*/ getConfigurationData/*<V>*/(ResultDescriptor/*<V>*/ key) { |
| 5962 fail("Unexpected invocation of getConfigurationData"); | 489 fail("Unexpected invocation of getConfigurationData"); |
| 490 return null; |
| 5963 } | 491 } |
| 5964 | 492 |
| 5965 @override | 493 @override |
| 5966 TimestampedData<String> getContents(Source source) { | 494 TimestampedData<String> getContents(Source source) { |
| 5967 fail("Unexpected invocation of getContents"); | 495 fail("Unexpected invocation of getContents"); |
| 5968 return null; | 496 return null; |
| 5969 } | 497 } |
| 5970 | 498 |
| 5971 @override | 499 @override |
| 5972 InternalAnalysisContext getContextFor(Source source) { | 500 InternalAnalysisContext getContextFor(Source source) { |
| 5973 fail("Unexpected invocation of getContextFor"); | 501 fail("Unexpected invocation of getContextFor"); |
| 5974 return null; | 502 return null; |
| 5975 } | 503 } |
| 5976 | 504 |
| 5977 @override | 505 @override |
| 5978 Element getElement(ElementLocation location) { | 506 Element getElement(ElementLocation location) { |
| 5979 fail("Unexpected invocation of getElement"); | 507 fail("Unexpected invocation of getElement"); |
| 5980 return null; | 508 return null; |
| 5981 } | 509 } |
| 5982 | 510 |
| 5983 @override | 511 @override |
| 5984 AnalysisErrorInfo getErrors(Source source) { | 512 AnalysisErrorInfo getErrors(Source source) { |
| 5985 fail("Unexpected invocation of getErrors"); | 513 fail("Unexpected invocation of getErrors"); |
| 5986 return null; | 514 return null; |
| 5987 } | 515 } |
| 5988 | 516 |
| 5989 @override | 517 @override |
| 5990 @deprecated | |
| 5991 HtmlElement getHtmlElement(Source source) { | |
| 5992 fail("Unexpected invocation of getHtmlElement"); | |
| 5993 return null; | |
| 5994 } | |
| 5995 | |
| 5996 @override | |
| 5997 List<Source> getHtmlFilesReferencing(Source source) { | 518 List<Source> getHtmlFilesReferencing(Source source) { |
| 5998 fail("Unexpected invocation of getHtmlFilesReferencing"); | 519 fail("Unexpected invocation of getHtmlFilesReferencing"); |
| 5999 return null; | 520 return null; |
| 6000 } | 521 } |
| 6001 | 522 |
| 6002 @override | 523 @override |
| 6003 SourceKind getKindOf(Source source) { | 524 SourceKind getKindOf(Source source) { |
| 6004 fail("Unexpected invocation of getKindOf"); | 525 fail("Unexpected invocation of getKindOf"); |
| 6005 return null; | 526 return null; |
| 6006 } | 527 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6061 } | 582 } |
| 6062 | 583 |
| 6063 @override | 584 @override |
| 6064 CompilationUnit getResolvedCompilationUnit2( | 585 CompilationUnit getResolvedCompilationUnit2( |
| 6065 Source unitSource, Source librarySource) { | 586 Source unitSource, Source librarySource) { |
| 6066 fail("Unexpected invocation of getResolvedCompilationUnit"); | 587 fail("Unexpected invocation of getResolvedCompilationUnit"); |
| 6067 return null; | 588 return null; |
| 6068 } | 589 } |
| 6069 | 590 |
| 6070 @override | 591 @override |
| 6071 @deprecated | 592 Object/*=V*/ getResult/*<V>*/( |
| 6072 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { | 593 AnalysisTarget target, ResultDescriptor/*<V>*/ result) { |
| 6073 fail("Unexpected invocation of getResolvedHtmlUnit"); | |
| 6074 return null; | |
| 6075 } | |
| 6076 | |
| 6077 @override | |
| 6078 Object getResult( | |
| 6079 newContext.AnalysisTarget target, newContext.ResultDescriptor result) { | |
| 6080 fail("Unexpected invocation of getResult"); | 594 fail("Unexpected invocation of getResult"); |
| 6081 return null; | 595 return null; |
| 6082 } | 596 } |
| 6083 | 597 |
| 6084 @override | 598 @override |
| 6085 List<Source> getSourcesWithFullName(String path) { | 599 List<Source> getSourcesWithFullName(String path) { |
| 6086 fail("Unexpected invocation of getSourcesWithFullName"); | 600 fail("Unexpected invocation of getSourcesWithFullName"); |
| 6087 return null; | 601 return null; |
| 6088 } | 602 } |
| 6089 | 603 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6105 return false; | 619 return false; |
| 6106 } | 620 } |
| 6107 | 621 |
| 6108 @override | 622 @override |
| 6109 bool isServerLibrary(Source librarySource) { | 623 bool isServerLibrary(Source librarySource) { |
| 6110 fail("Unexpected invocation of isServerLibrary"); | 624 fail("Unexpected invocation of isServerLibrary"); |
| 6111 return false; | 625 return false; |
| 6112 } | 626 } |
| 6113 | 627 |
| 6114 @override | 628 @override |
| 6115 Stream<ComputedResult> onResultComputed( | 629 Stream<ResultChangedEvent> onResultChanged(ResultDescriptor descriptor) { |
| 6116 newContext.ResultDescriptor descriptor) { | 630 fail("Unexpected invocation of onResultChanged"); |
| 631 return null; |
| 632 } |
| 633 |
| 634 @deprecated |
| 635 @override |
| 636 Stream<ComputedResult> onResultComputed(ResultDescriptor descriptor) { |
| 6117 fail("Unexpected invocation of onResultComputed"); | 637 fail("Unexpected invocation of onResultComputed"); |
| 6118 return null; | 638 return null; |
| 6119 } | 639 } |
| 6120 | 640 |
| 6121 @override | 641 @override |
| 6122 CompilationUnit parseCompilationUnit(Source source) { | 642 CompilationUnit parseCompilationUnit(Source source) { |
| 6123 fail("Unexpected invocation of parseCompilationUnit"); | 643 fail("Unexpected invocation of parseCompilationUnit"); |
| 6124 return null; | 644 return null; |
| 6125 } | 645 } |
| 6126 | 646 |
| 6127 @override | 647 @override |
| 6128 Document parseHtmlDocument(Source source) { | 648 Document parseHtmlDocument(Source source) { |
| 6129 fail("Unexpected invocation of parseHtmlDocument"); | 649 fail("Unexpected invocation of parseHtmlDocument"); |
| 6130 return null; | 650 return null; |
| 6131 } | 651 } |
| 6132 | 652 |
| 6133 @override | 653 @override |
| 6134 ht.HtmlUnit parseHtmlUnit(Source source) { | |
| 6135 fail("Unexpected invocation of parseHtmlUnit"); | |
| 6136 return null; | |
| 6137 } | |
| 6138 | |
| 6139 @override | |
| 6140 AnalysisResult performAnalysisTask() { | 654 AnalysisResult performAnalysisTask() { |
| 6141 fail("Unexpected invocation of performAnalysisTask"); | 655 fail("Unexpected invocation of performAnalysisTask"); |
| 6142 return null; | 656 return null; |
| 6143 } | 657 } |
| 6144 | 658 |
| 6145 @override | 659 @override |
| 6146 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | 660 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { |
| 6147 fail("Unexpected invocation of recordLibraryElements"); | 661 fail("Unexpected invocation of recordLibraryElements"); |
| 6148 } | 662 } |
| 6149 | 663 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6160 } | 674 } |
| 6161 | 675 |
| 6162 @override | 676 @override |
| 6163 CompilationUnit resolveCompilationUnit2( | 677 CompilationUnit resolveCompilationUnit2( |
| 6164 Source unitSource, Source librarySource) { | 678 Source unitSource, Source librarySource) { |
| 6165 fail("Unexpected invocation of resolveCompilationUnit"); | 679 fail("Unexpected invocation of resolveCompilationUnit"); |
| 6166 return null; | 680 return null; |
| 6167 } | 681 } |
| 6168 | 682 |
| 6169 @override | 683 @override |
| 6170 @deprecated | |
| 6171 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { | |
| 6172 fail("Unexpected invocation of resolveHtmlUnit"); | |
| 6173 return null; | |
| 6174 } | |
| 6175 | |
| 6176 @override | |
| 6177 void setChangedContents(Source source, String contents, int offset, | 684 void setChangedContents(Source source, String contents, int offset, |
| 6178 int oldLength, int newLength) { | 685 int oldLength, int newLength) { |
| 6179 fail("Unexpected invocation of setChangedContents"); | 686 fail("Unexpected invocation of setChangedContents"); |
| 6180 } | 687 } |
| 6181 | 688 |
| 6182 @override | 689 @override |
| 6183 void setConfigurationData(newContext.ResultDescriptor key, Object data) { | 690 void setConfigurationData(ResultDescriptor key, Object data) { |
| 6184 fail("Unexpected invocation of setConfigurationData"); | 691 fail("Unexpected invocation of setConfigurationData"); |
| 6185 } | 692 } |
| 6186 | 693 |
| 6187 @override | 694 @override |
| 6188 void setContents(Source source, String contents) { | 695 void setContents(Source source, String contents) { |
| 6189 fail("Unexpected invocation of setContents"); | 696 fail("Unexpected invocation of setContents"); |
| 6190 } | 697 } |
| 6191 | 698 |
| 6192 @override | 699 @override |
| 6193 bool shouldErrorsBeAnalyzed(Source source, Object entry) { | 700 bool shouldErrorsBeAnalyzed(Source source) { |
| 6194 fail("Unexpected invocation of shouldErrorsBeAnalyzed"); | 701 fail("Unexpected invocation of shouldErrorsBeAnalyzed"); |
| 6195 return false; | 702 return false; |
| 6196 } | 703 } |
| 6197 | 704 |
| 6198 @override | 705 @override |
| 6199 void test_flushAstStructures(Source source) { | 706 void test_flushAstStructures(Source source) { |
| 6200 fail("Unexpected invocation of test_flushAstStructures"); | 707 fail("Unexpected invocation of test_flushAstStructures"); |
| 6201 } | 708 } |
| 6202 | 709 |
| 6203 @override | 710 @override |
| 6204 bool validateCacheConsistency() { | |
| 6205 fail("Unexpected invocation of validateCacheConsistency"); | |
| 6206 return false; | |
| 6207 } | |
| 6208 | |
| 6209 @deprecated | |
| 6210 @override | |
| 6211 void visitCacheItems(void callback(Source source, SourceEntry dartEntry, | |
| 6212 DataDescriptor rowDesc, CacheState state)) { | |
| 6213 fail("Unexpected invocation of visitCacheItems"); | |
| 6214 } | |
| 6215 | |
| 6216 @override | |
| 6217 void visitContentCache(ContentCacheVisitor visitor) { | 711 void visitContentCache(ContentCacheVisitor visitor) { |
| 6218 fail("Unexpected invocation of visitContentCache"); | 712 fail("Unexpected invocation of visitContentCache"); |
| 6219 } | 713 } |
| 6220 } | 714 } |
| 6221 | |
| 6222 class TestAnalysisContext_test_applyChanges extends TestAnalysisContext { | |
| 6223 bool invoked = false; | |
| 6224 TestAnalysisContext_test_applyChanges(); | |
| 6225 @override | |
| 6226 void applyChanges(ChangeSet changeSet) { | |
| 6227 invoked = true; | |
| 6228 } | |
| 6229 } | |
| 6230 | |
| 6231 class TestAnalysisContext_test_computeDocumentationComment | |
| 6232 extends TestAnalysisContext { | |
| 6233 bool invoked = false; | |
| 6234 TestAnalysisContext_test_computeDocumentationComment(); | |
| 6235 @override | |
| 6236 String computeDocumentationComment(Element element) { | |
| 6237 invoked = true; | |
| 6238 return null; | |
| 6239 } | |
| 6240 } | |
| 6241 | |
| 6242 class TestAnalysisContext_test_computeErrors extends TestAnalysisContext { | |
| 6243 bool invoked = false; | |
| 6244 TestAnalysisContext_test_computeErrors(); | |
| 6245 @override | |
| 6246 List<AnalysisError> computeErrors(Source source) { | |
| 6247 invoked = true; | |
| 6248 return AnalysisError.NO_ERRORS; | |
| 6249 } | |
| 6250 } | |
| 6251 | |
| 6252 class TestAnalysisContext_test_computeExportedLibraries | |
| 6253 extends TestAnalysisContext { | |
| 6254 bool invoked = false; | |
| 6255 TestAnalysisContext_test_computeExportedLibraries(); | |
| 6256 @override | |
| 6257 List<Source> computeExportedLibraries(Source source) { | |
| 6258 invoked = true; | |
| 6259 return null; | |
| 6260 } | |
| 6261 } | |
| 6262 | |
| 6263 class TestAnalysisContext_test_computeHtmlElement extends TestAnalysisContext { | |
| 6264 bool invoked = false; | |
| 6265 TestAnalysisContext_test_computeHtmlElement(); | |
| 6266 @override | |
| 6267 @deprecated | |
| 6268 HtmlElement computeHtmlElement(Source source) { | |
| 6269 invoked = true; | |
| 6270 return null; | |
| 6271 } | |
| 6272 } | |
| 6273 | |
| 6274 class TestAnalysisContext_test_computeImportedLibraries | |
| 6275 extends TestAnalysisContext { | |
| 6276 bool invoked = false; | |
| 6277 TestAnalysisContext_test_computeImportedLibraries(); | |
| 6278 @override | |
| 6279 List<Source> computeImportedLibraries(Source source) { | |
| 6280 invoked = true; | |
| 6281 return null; | |
| 6282 } | |
| 6283 } | |
| 6284 | |
| 6285 class TestAnalysisContext_test_computeKindOf extends TestAnalysisContext { | |
| 6286 bool invoked = false; | |
| 6287 TestAnalysisContext_test_computeKindOf(); | |
| 6288 @override | |
| 6289 SourceKind computeKindOf(Source source) { | |
| 6290 invoked = true; | |
| 6291 return null; | |
| 6292 } | |
| 6293 } | |
| 6294 | |
| 6295 class TestAnalysisContext_test_computeLibraryElement | |
| 6296 extends TestAnalysisContext { | |
| 6297 bool invoked = false; | |
| 6298 TestAnalysisContext_test_computeLibraryElement(); | |
| 6299 @override | |
| 6300 LibraryElement computeLibraryElement(Source source) { | |
| 6301 invoked = true; | |
| 6302 return null; | |
| 6303 } | |
| 6304 } | |
| 6305 | |
| 6306 class TestAnalysisContext_test_computeLineInfo extends TestAnalysisContext { | |
| 6307 bool invoked = false; | |
| 6308 TestAnalysisContext_test_computeLineInfo(); | |
| 6309 @override | |
| 6310 LineInfo computeLineInfo(Source source) { | |
| 6311 invoked = true; | |
| 6312 return null; | |
| 6313 } | |
| 6314 } | |
| 6315 | |
| 6316 class TestAnalysisContext_test_computeResolvableCompilationUnit | |
| 6317 extends TestAnalysisContext { | |
| 6318 bool invoked = false; | |
| 6319 TestAnalysisContext_test_computeResolvableCompilationUnit(); | |
| 6320 @override | |
| 6321 CompilationUnit computeResolvableCompilationUnit(Source source) { | |
| 6322 invoked = true; | |
| 6323 return null; | |
| 6324 } | |
| 6325 } | |
| 6326 | |
| 6327 class TestAnalysisContext_test_dispose extends TestAnalysisContext { | |
| 6328 bool invoked = false; | |
| 6329 TestAnalysisContext_test_dispose(); | |
| 6330 @override | |
| 6331 void dispose() { | |
| 6332 invoked = true; | |
| 6333 } | |
| 6334 } | |
| 6335 | |
| 6336 class TestAnalysisContext_test_exists extends TestAnalysisContext { | |
| 6337 bool invoked = false; | |
| 6338 TestAnalysisContext_test_exists(); | |
| 6339 @override | |
| 6340 bool exists(Source source) { | |
| 6341 invoked = true; | |
| 6342 return false; | |
| 6343 } | |
| 6344 } | |
| 6345 | |
| 6346 class TestAnalysisContext_test_getAnalysisOptions extends TestAnalysisContext { | |
| 6347 bool invoked = false; | |
| 6348 TestAnalysisContext_test_getAnalysisOptions(); | |
| 6349 @override | |
| 6350 AnalysisOptions get analysisOptions { | |
| 6351 invoked = true; | |
| 6352 return null; | |
| 6353 } | |
| 6354 } | |
| 6355 | |
| 6356 class TestAnalysisContext_test_getCompilationUnitElement | |
| 6357 extends TestAnalysisContext { | |
| 6358 bool invoked = false; | |
| 6359 TestAnalysisContext_test_getCompilationUnitElement(); | |
| 6360 @override | |
| 6361 CompilationUnitElement getCompilationUnitElement( | |
| 6362 Source unitSource, Source librarySource) { | |
| 6363 invoked = true; | |
| 6364 return null; | |
| 6365 } | |
| 6366 } | |
| 6367 | |
| 6368 class TestAnalysisContext_test_getContents extends TestAnalysisContext { | |
| 6369 bool invoked = false; | |
| 6370 TestAnalysisContext_test_getContents(); | |
| 6371 @override | |
| 6372 TimestampedData<String> getContents(Source source) { | |
| 6373 invoked = true; | |
| 6374 return null; | |
| 6375 } | |
| 6376 } | |
| 6377 | |
| 6378 class TestAnalysisContext_test_getElement extends TestAnalysisContext { | |
| 6379 bool invoked = false; | |
| 6380 TestAnalysisContext_test_getElement(); | |
| 6381 @override | |
| 6382 Element getElement(ElementLocation location) { | |
| 6383 invoked = true; | |
| 6384 return null; | |
| 6385 } | |
| 6386 } | |
| 6387 | |
| 6388 class TestAnalysisContext_test_getErrors extends TestAnalysisContext { | |
| 6389 bool invoked = false; | |
| 6390 TestAnalysisContext_test_getErrors(); | |
| 6391 @override | |
| 6392 AnalysisErrorInfo getErrors(Source source) { | |
| 6393 invoked = true; | |
| 6394 return new AnalysisErrorInfoImpl(AnalysisError.NO_ERRORS, null); | |
| 6395 } | |
| 6396 } | |
| 6397 | |
| 6398 class TestAnalysisContext_test_getHtmlElement extends TestAnalysisContext { | |
| 6399 bool invoked = false; | |
| 6400 TestAnalysisContext_test_getHtmlElement(); | |
| 6401 @override | |
| 6402 @deprecated | |
| 6403 HtmlElement getHtmlElement(Source source) { | |
| 6404 invoked = true; | |
| 6405 return null; | |
| 6406 } | |
| 6407 } | |
| 6408 | |
| 6409 class TestAnalysisContext_test_getHtmlFilesReferencing | |
| 6410 extends TestAnalysisContext { | |
| 6411 bool invoked = false; | |
| 6412 TestAnalysisContext_test_getHtmlFilesReferencing(); | |
| 6413 @override | |
| 6414 List<Source> getHtmlFilesReferencing(Source source) { | |
| 6415 invoked = true; | |
| 6416 return Source.EMPTY_LIST; | |
| 6417 } | |
| 6418 } | |
| 6419 | |
| 6420 class TestAnalysisContext_test_getHtmlSources extends TestAnalysisContext { | |
| 6421 bool invoked = false; | |
| 6422 TestAnalysisContext_test_getHtmlSources(); | |
| 6423 @override | |
| 6424 List<Source> get htmlSources { | |
| 6425 invoked = true; | |
| 6426 return Source.EMPTY_LIST; | |
| 6427 } | |
| 6428 } | |
| 6429 | |
| 6430 class TestAnalysisContext_test_getKindOf extends TestAnalysisContext { | |
| 6431 bool invoked = false; | |
| 6432 TestAnalysisContext_test_getKindOf(); | |
| 6433 @override | |
| 6434 SourceKind getKindOf(Source source) { | |
| 6435 invoked = true; | |
| 6436 return null; | |
| 6437 } | |
| 6438 } | |
| 6439 | |
| 6440 class TestAnalysisContext_test_getLaunchableClientLibrarySources | |
| 6441 extends TestAnalysisContext { | |
| 6442 bool invoked = false; | |
| 6443 TestAnalysisContext_test_getLaunchableClientLibrarySources(); | |
| 6444 @override | |
| 6445 List<Source> get launchableClientLibrarySources { | |
| 6446 invoked = true; | |
| 6447 return Source.EMPTY_LIST; | |
| 6448 } | |
| 6449 } | |
| 6450 | |
| 6451 class TestAnalysisContext_test_getLaunchableServerLibrarySources | |
| 6452 extends TestAnalysisContext { | |
| 6453 bool invoked = false; | |
| 6454 TestAnalysisContext_test_getLaunchableServerLibrarySources(); | |
| 6455 @override | |
| 6456 List<Source> get launchableServerLibrarySources { | |
| 6457 invoked = true; | |
| 6458 return Source.EMPTY_LIST; | |
| 6459 } | |
| 6460 } | |
| 6461 | |
| 6462 class TestAnalysisContext_test_getLibrariesContaining | |
| 6463 extends TestAnalysisContext { | |
| 6464 bool invoked = false; | |
| 6465 TestAnalysisContext_test_getLibrariesContaining(); | |
| 6466 @override | |
| 6467 List<Source> getLibrariesContaining(Source source) { | |
| 6468 invoked = true; | |
| 6469 return Source.EMPTY_LIST; | |
| 6470 } | |
| 6471 } | |
| 6472 | |
| 6473 class TestAnalysisContext_test_getLibrariesDependingOn | |
| 6474 extends TestAnalysisContext { | |
| 6475 bool invoked = false; | |
| 6476 TestAnalysisContext_test_getLibrariesDependingOn(); | |
| 6477 @override | |
| 6478 List<Source> getLibrariesDependingOn(Source librarySource) { | |
| 6479 invoked = true; | |
| 6480 return Source.EMPTY_LIST; | |
| 6481 } | |
| 6482 } | |
| 6483 | |
| 6484 class TestAnalysisContext_test_getLibrariesReferencedFromHtml | |
| 6485 extends TestAnalysisContext { | |
| 6486 bool invoked = false; | |
| 6487 TestAnalysisContext_test_getLibrariesReferencedFromHtml(); | |
| 6488 @override | |
| 6489 List<Source> getLibrariesReferencedFromHtml(Source htmlSource) { | |
| 6490 invoked = true; | |
| 6491 return null; | |
| 6492 } | |
| 6493 } | |
| 6494 | |
| 6495 class TestAnalysisContext_test_getLibraryElement extends TestAnalysisContext { | |
| 6496 bool invoked = false; | |
| 6497 TestAnalysisContext_test_getLibraryElement(); | |
| 6498 @override | |
| 6499 LibraryElement getLibraryElement(Source source) { | |
| 6500 invoked = true; | |
| 6501 return null; | |
| 6502 } | |
| 6503 } | |
| 6504 | |
| 6505 class TestAnalysisContext_test_getLibrarySources extends TestAnalysisContext { | |
| 6506 bool invoked = false; | |
| 6507 TestAnalysisContext_test_getLibrarySources(); | |
| 6508 @override | |
| 6509 List<Source> get librarySources { | |
| 6510 invoked = true; | |
| 6511 return Source.EMPTY_LIST; | |
| 6512 } | |
| 6513 } | |
| 6514 | |
| 6515 class TestAnalysisContext_test_getLineInfo extends TestAnalysisContext { | |
| 6516 bool invoked = false; | |
| 6517 TestAnalysisContext_test_getLineInfo(); | |
| 6518 @override | |
| 6519 LineInfo getLineInfo(Source source) { | |
| 6520 invoked = true; | |
| 6521 return null; | |
| 6522 } | |
| 6523 } | |
| 6524 | |
| 6525 class TestAnalysisContext_test_getModificationStamp | |
| 6526 extends TestAnalysisContext { | |
| 6527 bool invoked = false; | |
| 6528 TestAnalysisContext_test_getModificationStamp(); | |
| 6529 @override | |
| 6530 int getModificationStamp(Source source) { | |
| 6531 invoked = true; | |
| 6532 return 0; | |
| 6533 } | |
| 6534 } | |
| 6535 | |
| 6536 class TestAnalysisContext_test_getPublicNamespace extends TestAnalysisContext { | |
| 6537 bool invoked = false; | |
| 6538 TestAnalysisContext_test_getPublicNamespace(); | |
| 6539 @override | |
| 6540 Namespace getPublicNamespace(LibraryElement library) { | |
| 6541 invoked = true; | |
| 6542 return null; | |
| 6543 } | |
| 6544 } | |
| 6545 | |
| 6546 class TestAnalysisContext_test_getResolvedCompilationUnit_element | |
| 6547 extends TestAnalysisContext { | |
| 6548 bool invoked = false; | |
| 6549 TestAnalysisContext_test_getResolvedCompilationUnit_element(); | |
| 6550 @override | |
| 6551 CompilationUnit getResolvedCompilationUnit( | |
| 6552 Source unitSource, LibraryElement library) { | |
| 6553 invoked = true; | |
| 6554 return null; | |
| 6555 } | |
| 6556 } | |
| 6557 | |
| 6558 class TestAnalysisContext_test_getResolvedCompilationUnit_source | |
| 6559 extends TestAnalysisContext { | |
| 6560 bool invoked = false; | |
| 6561 TestAnalysisContext_test_getResolvedCompilationUnit_source(); | |
| 6562 @override | |
| 6563 CompilationUnit getResolvedCompilationUnit2( | |
| 6564 Source unitSource, Source librarySource) { | |
| 6565 invoked = true; | |
| 6566 return null; | |
| 6567 } | |
| 6568 } | |
| 6569 | |
| 6570 class TestAnalysisContext_test_getResolvedHtmlUnit extends TestAnalysisContext { | |
| 6571 bool invoked = false; | |
| 6572 TestAnalysisContext_test_getResolvedHtmlUnit(); | |
| 6573 @override | |
| 6574 @deprecated | |
| 6575 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource) { | |
| 6576 invoked = true; | |
| 6577 return null; | |
| 6578 } | |
| 6579 } | |
| 6580 | |
| 6581 class TestAnalysisContext_test_getSourceFactory extends TestAnalysisContext { | |
| 6582 bool invoked = false; | |
| 6583 TestAnalysisContext_test_getSourceFactory(); | |
| 6584 @override | |
| 6585 SourceFactory get sourceFactory { | |
| 6586 invoked = true; | |
| 6587 return null; | |
| 6588 } | |
| 6589 } | |
| 6590 | |
| 6591 class TestAnalysisContext_test_getStatistics extends TestAnalysisContext { | |
| 6592 bool invoked = false; | |
| 6593 TestAnalysisContext_test_getStatistics(); | |
| 6594 @override | |
| 6595 AnalysisContextStatistics get statistics { | |
| 6596 invoked = true; | |
| 6597 return null; | |
| 6598 } | |
| 6599 } | |
| 6600 | |
| 6601 class TestAnalysisContext_test_getTypeProvider extends TestAnalysisContext { | |
| 6602 bool invoked = false; | |
| 6603 TestAnalysisContext_test_getTypeProvider(); | |
| 6604 @override | |
| 6605 TypeProvider get typeProvider { | |
| 6606 invoked = true; | |
| 6607 return null; | |
| 6608 } | |
| 6609 } | |
| 6610 | |
| 6611 class TestAnalysisContext_test_isClientLibrary extends TestAnalysisContext { | |
| 6612 bool invoked = false; | |
| 6613 TestAnalysisContext_test_isClientLibrary(); | |
| 6614 @override | |
| 6615 bool isClientLibrary(Source librarySource) { | |
| 6616 invoked = true; | |
| 6617 return false; | |
| 6618 } | |
| 6619 } | |
| 6620 | |
| 6621 class TestAnalysisContext_test_isDisposed extends TestAnalysisContext { | |
| 6622 bool invoked = false; | |
| 6623 TestAnalysisContext_test_isDisposed(); | |
| 6624 @override | |
| 6625 bool get isDisposed { | |
| 6626 invoked = true; | |
| 6627 return false; | |
| 6628 } | |
| 6629 } | |
| 6630 | |
| 6631 class TestAnalysisContext_test_isServerLibrary extends TestAnalysisContext { | |
| 6632 bool invoked = false; | |
| 6633 TestAnalysisContext_test_isServerLibrary(); | |
| 6634 @override | |
| 6635 bool isServerLibrary(Source librarySource) { | |
| 6636 invoked = true; | |
| 6637 return false; | |
| 6638 } | |
| 6639 } | |
| 6640 | |
| 6641 class TestAnalysisContext_test_parseCompilationUnit | |
| 6642 extends TestAnalysisContext { | |
| 6643 bool invoked = false; | |
| 6644 TestAnalysisContext_test_parseCompilationUnit(); | |
| 6645 @override | |
| 6646 CompilationUnit parseCompilationUnit(Source source) { | |
| 6647 invoked = true; | |
| 6648 return null; | |
| 6649 } | |
| 6650 } | |
| 6651 | |
| 6652 class TestAnalysisContext_test_parseHtmlUnit extends TestAnalysisContext { | |
| 6653 bool invoked = false; | |
| 6654 TestAnalysisContext_test_parseHtmlUnit(); | |
| 6655 @override | |
| 6656 ht.HtmlUnit parseHtmlUnit(Source source) { | |
| 6657 invoked = true; | |
| 6658 return null; | |
| 6659 } | |
| 6660 } | |
| 6661 | |
| 6662 class TestAnalysisContext_test_performAnalysisTask extends TestAnalysisContext { | |
| 6663 bool invoked = false; | |
| 6664 TestAnalysisContext_test_performAnalysisTask(); | |
| 6665 @override | |
| 6666 AnalysisResult performAnalysisTask() { | |
| 6667 invoked = true; | |
| 6668 return new AnalysisResult(new List<ChangeNotice>(0), 0, null, 0); | |
| 6669 } | |
| 6670 } | |
| 6671 | |
| 6672 class TestAnalysisContext_test_recordLibraryElements | |
| 6673 extends TestAnalysisContext { | |
| 6674 bool invoked = false; | |
| 6675 TestAnalysisContext_test_recordLibraryElements(); | |
| 6676 @override | |
| 6677 void recordLibraryElements(Map<Source, LibraryElement> elementMap) { | |
| 6678 invoked = true; | |
| 6679 } | |
| 6680 } | |
| 6681 | |
| 6682 class TestAnalysisContext_test_resolveCompilationUnit | |
| 6683 extends TestAnalysisContext { | |
| 6684 bool invoked = false; | |
| 6685 TestAnalysisContext_test_resolveCompilationUnit(); | |
| 6686 @override | |
| 6687 CompilationUnit resolveCompilationUnit2( | |
| 6688 Source unitSource, Source librarySource) { | |
| 6689 invoked = true; | |
| 6690 return null; | |
| 6691 } | |
| 6692 } | |
| 6693 | |
| 6694 class TestAnalysisContext_test_resolveCompilationUnit_element | |
| 6695 extends TestAnalysisContext { | |
| 6696 bool invoked = false; | |
| 6697 TestAnalysisContext_test_resolveCompilationUnit_element(); | |
| 6698 @override | |
| 6699 CompilationUnit resolveCompilationUnit( | |
| 6700 Source unitSource, LibraryElement library) { | |
| 6701 invoked = true; | |
| 6702 return null; | |
| 6703 } | |
| 6704 } | |
| 6705 | |
| 6706 class TestAnalysisContext_test_resolveHtmlUnit extends TestAnalysisContext { | |
| 6707 bool invoked = false; | |
| 6708 TestAnalysisContext_test_resolveHtmlUnit(); | |
| 6709 @override | |
| 6710 @deprecated | |
| 6711 ht.HtmlUnit resolveHtmlUnit(Source htmlSource) { | |
| 6712 invoked = true; | |
| 6713 return null; | |
| 6714 } | |
| 6715 } | |
| 6716 | |
| 6717 class TestAnalysisContext_test_setAnalysisOptions extends TestAnalysisContext { | |
| 6718 bool invoked = false; | |
| 6719 TestAnalysisContext_test_setAnalysisOptions(); | |
| 6720 @override | |
| 6721 void set analysisOptions(AnalysisOptions options) { | |
| 6722 invoked = true; | |
| 6723 } | |
| 6724 } | |
| 6725 | |
| 6726 class TestAnalysisContext_test_setAnalysisPriorityOrder | |
| 6727 extends TestAnalysisContext { | |
| 6728 bool invoked = false; | |
| 6729 TestAnalysisContext_test_setAnalysisPriorityOrder(); | |
| 6730 @override | |
| 6731 void set analysisPriorityOrder(List<Source> sources) { | |
| 6732 invoked = true; | |
| 6733 } | |
| 6734 } | |
| 6735 | |
| 6736 class TestAnalysisContext_test_setChangedContents extends TestAnalysisContext { | |
| 6737 bool invoked = false; | |
| 6738 TestAnalysisContext_test_setChangedContents(); | |
| 6739 @override | |
| 6740 void setChangedContents(Source source, String contents, int offset, | |
| 6741 int oldLength, int newLength) { | |
| 6742 invoked = true; | |
| 6743 } | |
| 6744 } | |
| 6745 | |
| 6746 class TestAnalysisContext_test_setContents extends TestAnalysisContext { | |
| 6747 bool invoked = false; | |
| 6748 TestAnalysisContext_test_setContents(); | |
| 6749 @override | |
| 6750 void setContents(Source source, String contents) { | |
| 6751 invoked = true; | |
| 6752 } | |
| 6753 } | |
| 6754 | |
| 6755 class TestAnalysisContext_test_setSourceFactory extends TestAnalysisContext { | |
| 6756 bool invoked = false; | |
| 6757 TestAnalysisContext_test_setSourceFactory(); | |
| 6758 @override | |
| 6759 void set sourceFactory(SourceFactory factory) { | |
| 6760 invoked = true; | |
| 6761 } | |
| 6762 } | |
| 6763 | |
| 6764 /** | |
| 6765 * Instances of the class `TestTaskVisitor` implement a task visitor that fails
if any of its | |
| 6766 * methods are invoked. Subclasses typically override the expected methods to no
t cause a test | |
| 6767 * failure. | |
| 6768 */ | |
| 6769 class TestTaskVisitor<E> implements AnalysisTaskVisitor<E> { | |
| 6770 @override | |
| 6771 E visitGenerateDartErrorsTask(GenerateDartErrorsTask task) { | |
| 6772 fail("Unexpectedly invoked visitGenerateDartErrorsTask"); | |
| 6773 return null; | |
| 6774 } | |
| 6775 | |
| 6776 @override | |
| 6777 E visitGenerateDartHintsTask(GenerateDartHintsTask task) { | |
| 6778 fail("Unexpectedly invoked visitGenerateDartHintsTask"); | |
| 6779 return null; | |
| 6780 } | |
| 6781 | |
| 6782 @override | |
| 6783 E visitGenerateDartLintsTask(GenerateDartLintsTask task) { | |
| 6784 fail("Unexpectedly invoked visitGenerateDartLintsTask"); | |
| 6785 return null; | |
| 6786 } | |
| 6787 | |
| 6788 @override | |
| 6789 E visitGetContentTask(GetContentTask task) { | |
| 6790 fail("Unexpectedly invoked visitGetContentsTask"); | |
| 6791 return null; | |
| 6792 } | |
| 6793 | |
| 6794 @override | |
| 6795 E visitIncrementalAnalysisTask( | |
| 6796 IncrementalAnalysisTask incrementalAnalysisTask) { | |
| 6797 fail("Unexpectedly invoked visitIncrementalAnalysisTask"); | |
| 6798 return null; | |
| 6799 } | |
| 6800 | |
| 6801 @override | |
| 6802 E visitParseDartTask(ParseDartTask task) { | |
| 6803 fail("Unexpectedly invoked visitParseDartTask"); | |
| 6804 return null; | |
| 6805 } | |
| 6806 | |
| 6807 @override | |
| 6808 E visitParseHtmlTask(ParseHtmlTask task) { | |
| 6809 fail("Unexpectedly invoked visitParseHtmlTask"); | |
| 6810 return null; | |
| 6811 } | |
| 6812 | |
| 6813 @override | |
| 6814 E visitResolveDartLibraryCycleTask(ResolveDartLibraryCycleTask task) { | |
| 6815 fail("Unexpectedly invoked visitResolveDartLibraryCycleTask"); | |
| 6816 return null; | |
| 6817 } | |
| 6818 | |
| 6819 @override | |
| 6820 E visitResolveDartLibraryTask(ResolveDartLibraryTask task) { | |
| 6821 fail("Unexpectedly invoked visitResolveDartLibraryTask"); | |
| 6822 return null; | |
| 6823 } | |
| 6824 | |
| 6825 @override | |
| 6826 E visitResolveDartUnitTask(ResolveDartUnitTask task) { | |
| 6827 fail("Unexpectedly invoked visitResolveDartUnitTask"); | |
| 6828 return null; | |
| 6829 } | |
| 6830 | |
| 6831 @override | |
| 6832 E visitResolveHtmlTask(ResolveHtmlTask task) { | |
| 6833 fail("Unexpectedly invoked visitResolveHtmlTask"); | |
| 6834 return null; | |
| 6835 } | |
| 6836 | |
| 6837 @override | |
| 6838 E visitScanDartTask(ScanDartTask task) { | |
| 6839 fail("Unexpectedly invoked visitScanDartTask"); | |
| 6840 return null; | |
| 6841 } | |
| 6842 } | |
| 6843 | |
| 6844 @reflectiveTest | |
| 6845 class UniversalCachePartitionTest extends EngineTestCase { | |
| 6846 void test_contains() { | |
| 6847 UniversalCachePartition partition = | |
| 6848 new UniversalCachePartition(null, 8, null); | |
| 6849 TestSource source = new TestSource(); | |
| 6850 expect(partition.contains(source), isTrue); | |
| 6851 } | |
| 6852 | |
| 6853 void test_creation() { | |
| 6854 expect(new UniversalCachePartition(null, 8, null), isNotNull); | |
| 6855 } | |
| 6856 | |
| 6857 void test_entrySet() { | |
| 6858 UniversalCachePartition partition = | |
| 6859 new UniversalCachePartition(null, 8, null); | |
| 6860 TestSource source = new TestSource(); | |
| 6861 DartEntry entry = new DartEntry(); | |
| 6862 partition.put(source, entry); | |
| 6863 Map<Source, SourceEntry> entryMap = partition.map; | |
| 6864 expect(entryMap.length, 1); | |
| 6865 Source entryKey = entryMap.keys.first; | |
| 6866 expect(entryKey, same(source)); | |
| 6867 expect(entryMap[entryKey], same(entry)); | |
| 6868 } | |
| 6869 | |
| 6870 void test_get() { | |
| 6871 UniversalCachePartition partition = | |
| 6872 new UniversalCachePartition(null, 8, null); | |
| 6873 TestSource source = new TestSource(); | |
| 6874 expect(partition.get(source), isNull); | |
| 6875 } | |
| 6876 | |
| 6877 void test_put_noFlush() { | |
| 6878 UniversalCachePartition partition = | |
| 6879 new UniversalCachePartition(null, 8, null); | |
| 6880 TestSource source = new TestSource(); | |
| 6881 DartEntry entry = new DartEntry(); | |
| 6882 partition.put(source, entry); | |
| 6883 expect(partition.get(source), same(entry)); | |
| 6884 } | |
| 6885 | |
| 6886 void test_remove() { | |
| 6887 UniversalCachePartition partition = | |
| 6888 new UniversalCachePartition(null, 8, null); | |
| 6889 TestSource source = new TestSource(); | |
| 6890 DartEntry entry = new DartEntry(); | |
| 6891 partition.put(source, entry); | |
| 6892 expect(partition.get(source), same(entry)); | |
| 6893 partition.remove(source); | |
| 6894 expect(partition.get(source), isNull); | |
| 6895 } | |
| 6896 | |
| 6897 void test_setMaxCacheSize() { | |
| 6898 UniversalCachePartition partition = new UniversalCachePartition( | |
| 6899 null, 8, new _UniversalCachePartitionTest_test_setMaxCacheSize()); | |
| 6900 int size = 6; | |
| 6901 for (int i = 0; i < size; i++) { | |
| 6902 Source source = new TestSource("/test$i.dart"); | |
| 6903 DartEntry entry = new DartEntry(); | |
| 6904 entry.setValue(DartEntry.PARSED_UNIT, null); | |
| 6905 partition.put(source, entry); | |
| 6906 partition.accessedAst(source); | |
| 6907 } | |
| 6908 _assertNonFlushedCount(size, partition); | |
| 6909 int newSize = size - 2; | |
| 6910 partition.maxCacheSize = newSize; | |
| 6911 _assertNonFlushedCount(newSize, partition); | |
| 6912 } | |
| 6913 | |
| 6914 void test_size() { | |
| 6915 UniversalCachePartition partition = | |
| 6916 new UniversalCachePartition(null, 8, null); | |
| 6917 int size = 4; | |
| 6918 for (int i = 0; i < size; i++) { | |
| 6919 Source source = new TestSource("/test$i.dart"); | |
| 6920 partition.put(source, new DartEntry()); | |
| 6921 partition.accessedAst(source); | |
| 6922 } | |
| 6923 expect(partition.size(), size); | |
| 6924 } | |
| 6925 | |
| 6926 void _assertNonFlushedCount( | |
| 6927 int expectedCount, UniversalCachePartition partition) { | |
| 6928 int nonFlushedCount = 0; | |
| 6929 Map<Source, SourceEntry> entryMap = partition.map; | |
| 6930 entryMap.values.forEach((SourceEntry value) { | |
| 6931 if (value.getState(DartEntry.PARSED_UNIT) != CacheState.FLUSHED) { | |
| 6932 nonFlushedCount++; | |
| 6933 } | |
| 6934 }); | |
| 6935 expect(nonFlushedCount, expectedCount); | |
| 6936 } | |
| 6937 } | |
| 6938 | |
| 6939 @reflectiveTest | |
| 6940 class WorkManagerTest extends EngineTestCase { | |
| 6941 void test_addFirst() { | |
| 6942 TestSource source1 = new TestSource("/f1.dart"); | |
| 6943 TestSource source2 = new TestSource("/f2.dart"); | |
| 6944 WorkManager manager = new WorkManager(); | |
| 6945 manager.add(source1, SourcePriority.UNKNOWN); | |
| 6946 manager.addFirst(source2, SourcePriority.UNKNOWN); | |
| 6947 WorkManager_WorkIterator iterator = manager.iterator(); | |
| 6948 expect(iterator.next(), same(source2)); | |
| 6949 expect(iterator.next(), same(source1)); | |
| 6950 } | |
| 6951 | |
| 6952 void test_creation() { | |
| 6953 expect(new WorkManager(), isNotNull); | |
| 6954 } | |
| 6955 | |
| 6956 void test_iterator_empty() { | |
| 6957 WorkManager manager = new WorkManager(); | |
| 6958 WorkManager_WorkIterator iterator = manager.iterator(); | |
| 6959 expect(iterator.hasNext, isFalse); | |
| 6960 try { | |
| 6961 iterator.next(); | |
| 6962 fail("Expected NoSuchElementException"); | |
| 6963 } on NoSuchElementException {} | |
| 6964 } | |
| 6965 | |
| 6966 void test_iterator_nonEmpty() { | |
| 6967 TestSource source = new TestSource(); | |
| 6968 WorkManager manager = new WorkManager(); | |
| 6969 manager.add(source, SourcePriority.UNKNOWN); | |
| 6970 WorkManager_WorkIterator iterator = manager.iterator(); | |
| 6971 expect(iterator.hasNext, isTrue); | |
| 6972 expect(iterator.next(), same(source)); | |
| 6973 } | |
| 6974 | |
| 6975 void test_remove() { | |
| 6976 TestSource source1 = new TestSource("/f1.dart"); | |
| 6977 TestSource source2 = new TestSource("/f2.dart"); | |
| 6978 TestSource source3 = new TestSource("/f3.dart"); | |
| 6979 WorkManager manager = new WorkManager(); | |
| 6980 manager.add(source1, SourcePriority.UNKNOWN); | |
| 6981 manager.add(source2, SourcePriority.UNKNOWN); | |
| 6982 manager.add(source3, SourcePriority.UNKNOWN); | |
| 6983 manager.remove(source2); | |
| 6984 WorkManager_WorkIterator iterator = manager.iterator(); | |
| 6985 expect(iterator.next(), same(source1)); | |
| 6986 expect(iterator.next(), same(source3)); | |
| 6987 } | |
| 6988 | |
| 6989 void test_toString_empty() { | |
| 6990 WorkManager manager = new WorkManager(); | |
| 6991 expect(manager.toString(), isNotNull); | |
| 6992 } | |
| 6993 | |
| 6994 void test_toString_nonEmpty() { | |
| 6995 WorkManager manager = new WorkManager(); | |
| 6996 manager.add(new TestSource(), SourcePriority.HTML); | |
| 6997 manager.add(new TestSource(), SourcePriority.LIBRARY); | |
| 6998 manager.add(new TestSource(), SourcePriority.NORMAL_PART); | |
| 6999 manager.add(new TestSource(), SourcePriority.PRIORITY_PART); | |
| 7000 manager.add(new TestSource(), SourcePriority.UNKNOWN); | |
| 7001 expect(manager.toString(), isNotNull); | |
| 7002 } | |
| 7003 } | |
| 7004 | |
| 7005 class _AnalysisCacheTest_test_setMaxCacheSize implements CacheRetentionPolicy { | |
| 7006 @override | |
| 7007 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => | |
| 7008 RetentionPriority.LOW; | |
| 7009 } | |
| 7010 | |
| 7011 class _AnalysisContext_sourceChangeDuringResolution | |
| 7012 extends AnalysisContextForTests { | |
| 7013 @override | |
| 7014 DartEntry recordResolveDartLibraryTaskResults(ResolveDartLibraryTask task) { | |
| 7015 ChangeSet changeSet = new ChangeSet(); | |
| 7016 changeSet.changedSource(task.librarySource); | |
| 7017 applyChanges(changeSet); | |
| 7018 return super.recordResolveDartLibraryTaskResults(task); | |
| 7019 } | |
| 7020 } | |
| 7021 | |
| 7022 class _AnalysisContextImplTest_test_applyChanges_removeContainer | |
| 7023 implements SourceContainer { | |
| 7024 Source libB; | |
| 7025 _AnalysisContextImplTest_test_applyChanges_removeContainer(this.libB); | |
| 7026 @override | |
| 7027 bool contains(Source source) => source == libB; | |
| 7028 } | |
| 7029 | |
| 7030 class _Source_getContent_throwException extends NonExistingSource { | |
| 7031 _Source_getContent_throwException(String name) | |
| 7032 : super(name, pathos.toUri(name), UriKind.FILE_URI); | |
| 7033 | |
| 7034 @override | |
| 7035 TimestampedData<String> get contents { | |
| 7036 throw 'Read error'; | |
| 7037 } | |
| 7038 | |
| 7039 @override | |
| 7040 bool exists() => true; | |
| 7041 } | |
| 7042 | |
| 7043 class _UniversalCachePartitionTest_test_setMaxCacheSize | |
| 7044 implements CacheRetentionPolicy { | |
| 7045 @override | |
| 7046 RetentionPriority getAstPriority(Source source, SourceEntry sourceEntry) => | |
| 7047 RetentionPriority.LOW; | |
| 7048 } | |
| OLD | NEW |