| 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 test.src.context.context_test; | 5 library test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| 11 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/generated/ast.dart'; | 12 import 'package:analyzer/src/generated/ast.dart'; |
| 13 import 'package:analyzer/src/generated/element.dart'; | 13 import 'package:analyzer/src/generated/element.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart' | 14 import 'package:analyzer/src/generated/engine.dart' |
| 15 show | 15 show |
| 16 AnalysisContext, | 16 AnalysisContext, |
| 17 AnalysisContextStatistics, | 17 AnalysisContextStatistics, |
| 18 AnalysisDelta, | 18 AnalysisDelta, |
| 19 AnalysisEngine, | 19 AnalysisEngine, |
| 20 AnalysisErrorInfo, | 20 AnalysisErrorInfo, |
| 21 AnalysisLevel, | 21 AnalysisLevel, |
| 22 AnalysisNotScheduledError, | 22 AnalysisNotScheduledError, |
| 23 AnalysisOptions, | 23 AnalysisOptions, |
| 24 AnalysisOptionsImpl, | 24 AnalysisOptionsImpl, |
| 25 AnalysisResult, | 25 AnalysisResult, |
| 26 CacheState, |
| 26 ChangeNotice, | 27 ChangeNotice, |
| 27 ChangeSet, | 28 ChangeSet, |
| 28 IncrementalAnalysisCache, | 29 IncrementalAnalysisCache, |
| 29 TimestampedData; | 30 TimestampedData; |
| 30 import 'package:analyzer/src/generated/error.dart'; | 31 import 'package:analyzer/src/generated/error.dart'; |
| 31 import 'package:analyzer/src/generated/html.dart' as ht; | 32 import 'package:analyzer/src/generated/html.dart' as ht; |
| 32 import 'package:analyzer/src/generated/java_engine.dart'; | 33 import 'package:analyzer/src/generated/java_engine.dart'; |
| 33 import 'package:analyzer/src/generated/java_engine_io.dart'; | 34 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 34 import 'package:analyzer/src/generated/resolver.dart'; | 35 import 'package:analyzer/src/generated/resolver.dart'; |
| 35 import 'package:analyzer/src/generated/scanner.dart'; | 36 import 'package:analyzer/src/generated/scanner.dart'; |
| 36 import 'package:analyzer/src/generated/sdk.dart'; | 37 import 'package:analyzer/src/generated/sdk.dart'; |
| 37 import 'package:analyzer/src/generated/sdk_io.dart'; | 38 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 38 import 'package:analyzer/src/generated/source.dart'; | 39 import 'package:analyzer/src/generated/source.dart'; |
| 39 import 'package:analyzer/src/generated/source_io.dart'; | 40 import 'package:analyzer/src/generated/source_io.dart'; |
| 40 import 'package:analyzer/src/plugin/engine_plugin.dart'; | 41 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
| 42 import 'package:analyzer/task/dart.dart'; |
| 41 import 'package:plugin/manager.dart'; | 43 import 'package:plugin/manager.dart'; |
| 42 import 'package:unittest/unittest.dart'; | 44 import 'package:unittest/unittest.dart'; |
| 43 import 'package:watcher/src/utils.dart'; | 45 import 'package:watcher/src/utils.dart'; |
| 44 | 46 |
| 45 import '../../generated/engine_test.dart'; | 47 import '../../generated/engine_test.dart'; |
| 46 import '../../generated/test_support.dart'; | 48 import '../../generated/test_support.dart'; |
| 47 import '../../reflective_tests.dart'; | 49 import '../../reflective_tests.dart'; |
| 48 import '../mock_sdk.dart'; | 50 import '../mock_sdk.dart'; |
| 49 | 51 |
| 50 main() { | 52 main() { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 void fail_computeImportedLibraries_some() { | 277 void fail_computeImportedLibraries_some() { |
| 276 // This is failing because computeImportedLibraries now always includes | 278 // This is failing because computeImportedLibraries now always includes |
| 277 // dart:core, and we don't have any way of knowing whether it was explicit. | 279 // dart:core, and we don't have any way of knowing whether it was explicit. |
| 278 // addSource("/lib1.dart", "library lib1;"); | 280 // addSource("/lib1.dart", "library lib1;"); |
| 279 // addSource("/lib2.dart", "library lib2;"); | 281 // addSource("/lib2.dart", "library lib2;"); |
| 280 Source source = _addSource( | 282 Source source = _addSource( |
| 281 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | 283 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
| 282 expect(_context.computeImportedLibraries(source), hasLength(2)); | 284 expect(_context.computeImportedLibraries(source), hasLength(2)); |
| 283 } | 285 } |
| 284 | 286 |
| 285 void test_computeKindOf_html() { | |
| 286 Source source = _addSource("/test.html", ""); | |
| 287 expect(_context.computeKindOf(source), same(SourceKind.HTML)); | |
| 288 } | |
| 289 | |
| 290 void fail_computeResolvableCompilationUnit_dart_exception() { | 287 void fail_computeResolvableCompilationUnit_dart_exception() { |
| 291 TestSource source = _addSourceWithException("/test.dart"); | 288 TestSource source = _addSourceWithException("/test.dart"); |
| 292 try { | 289 try { |
| 293 _context.computeResolvableCompilationUnit(source); | 290 _context.computeResolvableCompilationUnit(source); |
| 294 fail("Expected AnalysisException"); | 291 fail("Expected AnalysisException"); |
| 295 } on AnalysisException { | 292 } on AnalysisException { |
| 296 // Expected | 293 // Expected |
| 297 } | 294 } |
| 298 } | 295 } |
| 299 | 296 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 317 expect(resolvedUnit, same(parsedUnit)); | 314 expect(resolvedUnit, same(parsedUnit)); |
| 318 } | 315 } |
| 319 | 316 |
| 320 Future fail_computeResolvedCompilationUnitAsync_dispose() { | 317 Future fail_computeResolvedCompilationUnitAsync_dispose() { |
| 321 _context = contextWithCore(); | 318 _context = contextWithCore(); |
| 322 _sourceFactory = _context.sourceFactory; | 319 _sourceFactory = _context.sourceFactory; |
| 323 Source source = _addSource("/lib.dart", "library lib;"); | 320 Source source = _addSource("/lib.dart", "library lib;"); |
| 324 // Complete all pending analysis tasks and flush the AST so that it won't | 321 // Complete all pending analysis tasks and flush the AST so that it won't |
| 325 // be available immediately. | 322 // be available immediately. |
| 326 _performPendingAnalysisTasks(); | 323 _performPendingAnalysisTasks(); |
| 327 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); | 324 _flushAst(source); |
| 328 entry.flushAstStructures(); | |
| 329 CancelableFuture<CompilationUnit> future = | 325 CancelableFuture<CompilationUnit> future = |
| 330 _context.computeResolvedCompilationUnitAsync(source, source); | 326 _context.computeResolvedCompilationUnitAsync(source, source); |
| 331 bool completed = false; | 327 bool completed = false; |
| 332 future.then((CompilationUnit unit) { | 328 future.then((CompilationUnit unit) { |
| 333 fail('Future should have completed with error'); | 329 fail('Future should have completed with error'); |
| 334 }, onError: (error) { | 330 }, onError: (error) { |
| 335 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); | 331 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); |
| 336 completed = true; | 332 completed = true; |
| 337 }); | 333 }); |
| 338 expect(completed, isFalse); | 334 expect(completed, isFalse); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 void fail_getHtmlSources() { | 501 void fail_getHtmlSources() { |
| 506 List<Source> sources = _context.htmlSources; | 502 List<Source> sources = _context.htmlSources; |
| 507 expect(sources, hasLength(0)); | 503 expect(sources, hasLength(0)); |
| 508 Source source = _addSource("/test.html", ""); | 504 Source source = _addSource("/test.html", ""); |
| 509 _context.computeKindOf(source); | 505 _context.computeKindOf(source); |
| 510 sources = _context.htmlSources; | 506 sources = _context.htmlSources; |
| 511 expect(sources, hasLength(1)); | 507 expect(sources, hasLength(1)); |
| 512 expect(sources[0], source); | 508 expect(sources[0], source); |
| 513 } | 509 } |
| 514 | 510 |
| 515 void test_getKindOf_html() { | |
| 516 Source source = _addSource("/test.html", ""); | |
| 517 expect(_context.getKindOf(source), same(SourceKind.HTML)); | |
| 518 } | |
| 519 | |
| 520 void test_getLibrariesContaining() { | |
| 521 _context = contextWithCore(); | |
| 522 _sourceFactory = _context.sourceFactory; | |
| 523 Source librarySource = _addSource("/lib.dart", r''' | |
| 524 library lib; | |
| 525 part 'part.dart';'''); | |
| 526 Source partSource = _addSource("/part.dart", "part of lib;"); | |
| 527 _context.computeLibraryElement(librarySource); | |
| 528 List<Source> result = _context.getLibrariesContaining(librarySource); | |
| 529 expect(result, hasLength(1)); | |
| 530 expect(result[0], librarySource); | |
| 531 result = _context.getLibrariesContaining(partSource); | |
| 532 expect(result, hasLength(1)); | |
| 533 expect(result[0], librarySource); | |
| 534 } | |
| 535 | |
| 536 void fail_getLibrariesReferencedFromHtml() { | 511 void fail_getLibrariesReferencedFromHtml() { |
| 537 _context = contextWithCore(); | 512 _context = contextWithCore(); |
| 538 _sourceFactory = _context.sourceFactory; | 513 _sourceFactory = _context.sourceFactory; |
| 539 Source htmlSource = _addSource("/test.html", r''' | 514 Source htmlSource = _addSource("/test.html", r''' |
| 540 <html><head> | 515 <html><head> |
| 541 <script type='application/dart' src='test.dart'/> | 516 <script type='application/dart' src='test.dart'/> |
| 542 <script type='application/dart' src='test.js'/> | 517 <script type='application/dart' src='test.js'/> |
| 543 </head></html>'''); | 518 </head></html>'''); |
| 544 Source librarySource = _addSource("/test.dart", "library lib;"); | 519 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 545 _context.computeLibraryElement(librarySource); | 520 _context.computeLibraryElement(librarySource); |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), | 1085 new DartUriResolver(DirectoryBasedDartSdk.defaultSdk), |
| 1111 new FileUriResolver() | 1086 new FileUriResolver() |
| 1112 ]); | 1087 ]); |
| 1113 _context.sourceFactory = _sourceFactory; | 1088 _context.sourceFactory = _sourceFactory; |
| 1114 AnalysisOptionsImpl options = | 1089 AnalysisOptionsImpl options = |
| 1115 new AnalysisOptionsImpl.con1(_context.analysisOptions); | 1090 new AnalysisOptionsImpl.con1(_context.analysisOptions); |
| 1116 options.cacheSize = 256; | 1091 options.cacheSize = 256; |
| 1117 _context.analysisOptions = options; | 1092 _context.analysisOptions = options; |
| 1118 } | 1093 } |
| 1119 | 1094 |
| 1095 void test_applyChanges_change_flush_element() { |
| 1096 _context = contextWithCore(); |
| 1097 _sourceFactory = _context.sourceFactory; |
| 1098 Source librarySource = _addSource("/lib.dart", r''' |
| 1099 library lib; |
| 1100 int a = 0;'''); |
| 1101 expect(_context.computeLibraryElement(librarySource), isNotNull); |
| 1102 _context.setContents(librarySource, r''' |
| 1103 library lib; |
| 1104 int aa = 0;'''); |
| 1105 expect(_context.getLibraryElement(librarySource), isNull); |
| 1106 } |
| 1107 |
| 1120 @override | 1108 @override |
| 1121 void tearDown() { | 1109 void tearDown() { |
| 1122 _context = null; | 1110 _context = null; |
| 1123 _sourceFactory = null; | 1111 _sourceFactory = null; |
| 1124 super.tearDown(); | 1112 super.tearDown(); |
| 1125 } | 1113 } |
| 1126 | 1114 |
| 1127 Future test_applyChanges_add() { | 1115 Future test_applyChanges_add() { |
| 1128 SourcesChangedListener listener = new SourcesChangedListener(); | 1116 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1129 _context.onSourcesChanged.listen(listener.onData); | 1117 _context.onSourcesChanged.listen(listener.onData); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 changeSet2.addedSource(source2); | 1167 changeSet2.addedSource(source2); |
| 1180 changeSet2.changedContent(source, 'library test;'); | 1168 changeSet2.changedContent(source, 'library test;'); |
| 1181 _context.applyChanges(changeSet2); | 1169 _context.applyChanges(changeSet2); |
| 1182 return pumpEventQueue().then((_) { | 1170 return pumpEventQueue().then((_) { |
| 1183 listener.assertEvent(wereSourcesAdded: true); | 1171 listener.assertEvent(wereSourcesAdded: true); |
| 1184 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 1172 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
| 1185 listener.assertNoMoreEvents(); | 1173 listener.assertNoMoreEvents(); |
| 1186 }); | 1174 }); |
| 1187 } | 1175 } |
| 1188 | 1176 |
| 1189 void test_applyChanges_change_flush_element() { | |
| 1190 _context = contextWithCore(); | |
| 1191 _sourceFactory = _context.sourceFactory; | |
| 1192 Source librarySource = _addSource("/lib.dart", r''' | |
| 1193 library lib; | |
| 1194 int a = 0;'''); | |
| 1195 expect(_context.computeLibraryElement(librarySource), isNotNull); | |
| 1196 _context.setContents(librarySource, r''' | |
| 1197 library lib; | |
| 1198 int aa = 0;'''); | |
| 1199 expect(_context.getLibraryElement(librarySource), isNull); | |
| 1200 } | |
| 1201 | |
| 1202 Future test_applyChanges_change_multiple() { | 1177 Future test_applyChanges_change_multiple() { |
| 1203 _context = contextWithCore(); | 1178 _context = contextWithCore(); |
| 1204 SourcesChangedListener listener = new SourcesChangedListener(); | 1179 SourcesChangedListener listener = new SourcesChangedListener(); |
| 1205 _context.onSourcesChanged.listen(listener.onData); | 1180 _context.onSourcesChanged.listen(listener.onData); |
| 1206 _sourceFactory = _context.sourceFactory; | 1181 _sourceFactory = _context.sourceFactory; |
| 1207 String libraryContents1 = r''' | 1182 String libraryContents1 = r''' |
| 1208 library lib; | 1183 library lib; |
| 1209 part 'part.dart'; | 1184 part 'part.dart'; |
| 1210 int a = 0;'''; | 1185 int a = 0;'''; |
| 1211 Source librarySource = _addSource("/lib.dart", libraryContents1); | 1186 Source librarySource = _addSource("/lib.dart", libraryContents1); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 Source source = _addSource( | 1314 Source source = _addSource( |
| 1340 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); | 1315 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); |
| 1341 expect(_context.computeExportedLibraries(source), hasLength(2)); | 1316 expect(_context.computeExportedLibraries(source), hasLength(2)); |
| 1342 } | 1317 } |
| 1343 | 1318 |
| 1344 void test_computeHtmlElement_nonHtml() { | 1319 void test_computeHtmlElement_nonHtml() { |
| 1345 Source source = _addSource("/test.dart", "library test;"); | 1320 Source source = _addSource("/test.dart", "library test;"); |
| 1346 expect(_context.computeHtmlElement(source), isNull); | 1321 expect(_context.computeHtmlElement(source), isNull); |
| 1347 } | 1322 } |
| 1348 | 1323 |
| 1324 void test_computeKindOf_html() { |
| 1325 Source source = _addSource("/test.html", ""); |
| 1326 expect(_context.computeKindOf(source), same(SourceKind.HTML)); |
| 1327 } |
| 1328 |
| 1349 void test_computeKindOf_library() { | 1329 void test_computeKindOf_library() { |
| 1350 Source source = _addSource("/test.dart", "library lib;"); | 1330 Source source = _addSource("/test.dart", "library lib;"); |
| 1351 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); | 1331 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); |
| 1352 } | 1332 } |
| 1353 | 1333 |
| 1354 void test_computeKindOf_libraryAndPart() { | 1334 void test_computeKindOf_libraryAndPart() { |
| 1355 Source source = _addSource("/test.dart", "library lib; part of lib;"); | 1335 Source source = _addSource("/test.dart", "library lib; part of lib;"); |
| 1356 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); | 1336 expect(_context.computeKindOf(source), same(SourceKind.LIBRARY)); |
| 1357 } | 1337 } |
| 1358 | 1338 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1389 expect(info, isNotNull); | 1369 expect(info, isNotNull); |
| 1390 } | 1370 } |
| 1391 | 1371 |
| 1392 Future test_computeResolvedCompilationUnitAsync_afterDispose() { | 1372 Future test_computeResolvedCompilationUnitAsync_afterDispose() { |
| 1393 _context = contextWithCore(); | 1373 _context = contextWithCore(); |
| 1394 _sourceFactory = _context.sourceFactory; | 1374 _sourceFactory = _context.sourceFactory; |
| 1395 Source source = _addSource("/lib.dart", "library lib;"); | 1375 Source source = _addSource("/lib.dart", "library lib;"); |
| 1396 // Complete all pending analysis tasks and flush the AST so that it won't | 1376 // Complete all pending analysis tasks and flush the AST so that it won't |
| 1397 // be available immediately. | 1377 // be available immediately. |
| 1398 _performPendingAnalysisTasks(); | 1378 _performPendingAnalysisTasks(); |
| 1399 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); | 1379 _flushAst(source); |
| 1400 entry.flushAstStructures(); | |
| 1401 // Dispose of the context. | 1380 // Dispose of the context. |
| 1402 _context.dispose(); | 1381 _context.dispose(); |
| 1403 // Any attempt to start an asynchronous computation should return a future | 1382 // Any attempt to start an asynchronous computation should return a future |
| 1404 // which completes with error. | 1383 // which completes with error. |
| 1405 CancelableFuture<CompilationUnit> future = | 1384 CancelableFuture<CompilationUnit> future = |
| 1406 _context.computeResolvedCompilationUnitAsync(source, source); | 1385 _context.computeResolvedCompilationUnitAsync(source, source); |
| 1407 bool completed = false; | 1386 bool completed = false; |
| 1408 future.then((CompilationUnit unit) { | 1387 future.then((CompilationUnit unit) { |
| 1409 fail('Future should have completed with error'); | 1388 fail('Future should have completed with error'); |
| 1410 }, onError: (error) { | 1389 }, onError: (error) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 Source librarySource = _addSource("/test.dart", "library lib;"); | 1487 Source librarySource = _addSource("/test.dart", "library lib;"); |
| 1509 Source secondHtmlSource = _addSource("/test.html", "<html></html>"); | 1488 Source secondHtmlSource = _addSource("/test.html", "<html></html>"); |
| 1510 _context.computeLibraryElement(librarySource); | 1489 _context.computeLibraryElement(librarySource); |
| 1511 List<Source> result = _context.getHtmlFilesReferencing(secondHtmlSource); | 1490 List<Source> result = _context.getHtmlFilesReferencing(secondHtmlSource); |
| 1512 expect(result, hasLength(0)); | 1491 expect(result, hasLength(0)); |
| 1513 _context.parseHtmlUnit(htmlSource); | 1492 _context.parseHtmlUnit(htmlSource); |
| 1514 result = _context.getHtmlFilesReferencing(secondHtmlSource); | 1493 result = _context.getHtmlFilesReferencing(secondHtmlSource); |
| 1515 expect(result, hasLength(0)); | 1494 expect(result, hasLength(0)); |
| 1516 } | 1495 } |
| 1517 | 1496 |
| 1497 void test_getKindOf_html() { |
| 1498 Source source = _addSource("/test.html", ""); |
| 1499 expect(_context.getKindOf(source), same(SourceKind.HTML)); |
| 1500 } |
| 1501 |
| 1518 void test_getKindOf_library() { | 1502 void test_getKindOf_library() { |
| 1519 Source source = _addSource("/test.dart", "library lib;"); | 1503 Source source = _addSource("/test.dart", "library lib;"); |
| 1520 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); | 1504 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| 1521 _context.computeKindOf(source); | 1505 _context.computeKindOf(source); |
| 1522 expect(_context.getKindOf(source), same(SourceKind.LIBRARY)); | 1506 expect(_context.getKindOf(source), same(SourceKind.LIBRARY)); |
| 1523 } | 1507 } |
| 1524 | 1508 |
| 1525 void test_getKindOf_part() { | 1509 void test_getKindOf_part() { |
| 1526 Source source = _addSource("/test.dart", "part of lib;"); | 1510 Source source = _addSource("/test.dart", "part of lib;"); |
| 1527 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); | 1511 expect(_context.getKindOf(source), same(SourceKind.UNKNOWN)); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1623 } | 1607 } |
| 1624 | 1608 |
| 1625 void test_getLaunchableServerLibrarySources_noMain() { | 1609 void test_getLaunchableServerLibrarySources_noMain() { |
| 1626 _context = contextWithCore(); | 1610 _context = contextWithCore(); |
| 1627 _sourceFactory = _context.sourceFactory; | 1611 _sourceFactory = _context.sourceFactory; |
| 1628 Source source = _addSource("/test.dart", ''); | 1612 Source source = _addSource("/test.dart", ''); |
| 1629 _context.computeLibraryElement(source); | 1613 _context.computeLibraryElement(source); |
| 1630 expect(_context.launchableServerLibrarySources, isEmpty); | 1614 expect(_context.launchableServerLibrarySources, isEmpty); |
| 1631 } | 1615 } |
| 1632 | 1616 |
| 1617 void test_getLibrariesContaining() { |
| 1618 _context = contextWithCore(); |
| 1619 _sourceFactory = _context.sourceFactory; |
| 1620 Source librarySource = _addSource("/lib.dart", r''' |
| 1621 library lib; |
| 1622 part 'part.dart';'''); |
| 1623 Source partSource = _addSource("/part.dart", "part of lib;"); |
| 1624 _context.computeLibraryElement(librarySource); |
| 1625 List<Source> result = _context.getLibrariesContaining(librarySource); |
| 1626 expect(result, hasLength(1)); |
| 1627 expect(result[0], librarySource); |
| 1628 result = _context.getLibrariesContaining(partSource); |
| 1629 expect(result, hasLength(1)); |
| 1630 expect(result[0], librarySource); |
| 1631 } |
| 1632 |
| 1633 void test_getLibrariesDependingOn() { | 1633 void test_getLibrariesDependingOn() { |
| 1634 _context = contextWithCore(); | 1634 _context = contextWithCore(); |
| 1635 _sourceFactory = _context.sourceFactory; | 1635 _sourceFactory = _context.sourceFactory; |
| 1636 Source libASource = _addSource("/libA.dart", "library libA;"); | 1636 Source libASource = _addSource("/libA.dart", "library libA;"); |
| 1637 _addSource("/libB.dart", "library libB;"); | 1637 _addSource("/libB.dart", "library libB;"); |
| 1638 Source lib1Source = _addSource("/lib1.dart", r''' | 1638 Source lib1Source = _addSource("/lib1.dart", r''' |
| 1639 library lib1; | 1639 library lib1; |
| 1640 import 'libA.dart'; | 1640 import 'libA.dart'; |
| 1641 export 'libB.dart';'''); | 1641 export 'libB.dart';'''); |
| 1642 Source lib2Source = _addSource("/lib2.dart", r''' | 1642 Source lib2Source = _addSource("/lib2.dart", r''' |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 | 1853 |
| 1854 void test_parseCompilationUnit_noErrors() { | 1854 void test_parseCompilationUnit_noErrors() { |
| 1855 Source source = _addSource("/lib.dart", "library lib;"); | 1855 Source source = _addSource("/lib.dart", "library lib;"); |
| 1856 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); | 1856 CompilationUnit compilationUnit = _context.parseCompilationUnit(source); |
| 1857 expect(compilationUnit, isNotNull); | 1857 expect(compilationUnit, isNotNull); |
| 1858 AnalysisErrorInfo errorInfo = _context.getErrors(source); | 1858 AnalysisErrorInfo errorInfo = _context.getErrors(source); |
| 1859 expect(errorInfo, isNotNull); | 1859 expect(errorInfo, isNotNull); |
| 1860 expect(errorInfo.errors, hasLength(0)); | 1860 expect(errorInfo.errors, hasLength(0)); |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { | |
| 1864 // _context = new _AnalysisContext_sourceChangeDuringResolution(); | |
| 1865 // AnalysisContextFactory.initContextWithCore(_context); | |
| 1866 // _sourceFactory = _context.sourceFactory; | |
| 1867 // Source source = _addSource("/lib.dart", "library lib;"); | |
| 1868 // CompilationUnit compilationUnit = | |
| 1869 // _context.resolveCompilationUnit2(source, source); | |
| 1870 // expect(compilationUnit, isNotNull); | |
| 1871 // expect(_context.getLineInfo(source), isNotNull); | |
| 1872 // } | |
| 1873 | |
| 1874 void test_parseCompilationUnit_nonExistentSource() { | 1863 void test_parseCompilationUnit_nonExistentSource() { |
| 1875 Source source = | 1864 Source source = |
| 1876 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); | 1865 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); |
| 1877 try { | 1866 try { |
| 1878 _context.parseCompilationUnit(source); | 1867 _context.parseCompilationUnit(source); |
| 1879 fail("Expected AnalysisException because file does not exist"); | 1868 fail("Expected AnalysisException because file does not exist"); |
| 1880 } on AnalysisException { | 1869 } on AnalysisException { |
| 1881 // Expected result | 1870 // Expected result |
| 1882 } | 1871 } |
| 1883 } | 1872 } |
| 1884 | 1873 |
| 1874 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { |
| 1875 // _context = new _AnalysisContext_sourceChangeDuringResolution(); |
| 1876 // AnalysisContextFactory.initContextWithCore(_context); |
| 1877 // _sourceFactory = _context.sourceFactory; |
| 1878 // Source source = _addSource("/lib.dart", "library lib;"); |
| 1879 // CompilationUnit compilationUnit = |
| 1880 // _context.resolveCompilationUnit2(source, source); |
| 1881 // expect(compilationUnit, isNotNull); |
| 1882 // expect(_context.getLineInfo(source), isNotNull); |
| 1883 // } |
| 1884 |
| 1885 void test_performAnalysisTask_modifiedAfterParse() { | 1885 void test_performAnalysisTask_modifiedAfterParse() { |
| 1886 // TODO(scheglov) no threads in Dart | 1886 // TODO(scheglov) no threads in Dart |
| 1887 // Source source = _addSource("/test.dart", "library lib;"); | 1887 // Source source = _addSource("/test.dart", "library lib;"); |
| 1888 // int initialTime = _context.getModificationStamp(source); | 1888 // int initialTime = _context.getModificationStamp(source); |
| 1889 // List<Source> sources = new List<Source>(); | 1889 // List<Source> sources = new List<Source>(); |
| 1890 // sources.add(source); | 1890 // sources.add(source); |
| 1891 // _context.analysisPriorityOrder = sources; | 1891 // _context.analysisPriorityOrder = sources; |
| 1892 // _context.parseCompilationUnit(source); | 1892 // _context.parseCompilationUnit(source); |
| 1893 // while (initialTime == JavaSystem.currentTimeMillis()) { | 1893 // while (initialTime == JavaSystem.currentTimeMillis()) { |
| 1894 // Thread.sleep(1); | 1894 // Thread.sleep(1); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); | 2037 expect(_context.sourcesNeedingProcessing.contains(source), isFalse); |
| 2038 } | 2038 } |
| 2039 | 2039 |
| 2040 Future xtest_computeResolvedCompilationUnitAsync() { | 2040 Future xtest_computeResolvedCompilationUnitAsync() { |
| 2041 _context = contextWithCore(); | 2041 _context = contextWithCore(); |
| 2042 _sourceFactory = _context.sourceFactory; | 2042 _sourceFactory = _context.sourceFactory; |
| 2043 Source source = _addSource("/lib.dart", "library lib;"); | 2043 Source source = _addSource("/lib.dart", "library lib;"); |
| 2044 // Complete all pending analysis tasks and flush the AST so that it won't | 2044 // Complete all pending analysis tasks and flush the AST so that it won't |
| 2045 // be available immediately. | 2045 // be available immediately. |
| 2046 _performPendingAnalysisTasks(); | 2046 _performPendingAnalysisTasks(); |
| 2047 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); | 2047 _flushAst(source); |
| 2048 entry.flushAstStructures(); | |
| 2049 bool completed = false; | 2048 bool completed = false; |
| 2050 _context | 2049 _context |
| 2051 .computeResolvedCompilationUnitAsync(source, source) | 2050 .computeResolvedCompilationUnitAsync(source, source) |
| 2052 .then((CompilationUnit unit) { | 2051 .then((CompilationUnit unit) { |
| 2053 expect(unit, isNotNull); | 2052 expect(unit, isNotNull); |
| 2054 completed = true; | 2053 completed = true; |
| 2055 }); | 2054 }); |
| 2056 return pumpEventQueue().then((_) { | 2055 return pumpEventQueue().then((_) { |
| 2057 expect(completed, isFalse); | 2056 expect(completed, isFalse); |
| 2058 _performPendingAnalysisTasks(); | 2057 _performPendingAnalysisTasks(); |
| 2059 }).then((_) => pumpEventQueue()).then((_) { | 2058 }).then((_) => pumpEventQueue()).then((_) { |
| 2060 expect(completed, isTrue); | 2059 expect(completed, isTrue); |
| 2061 }); | 2060 }); |
| 2062 } | 2061 } |
| 2063 | 2062 |
| 2064 Future xtest_computeResolvedCompilationUnitAsync_cancel() { | 2063 Future xtest_computeResolvedCompilationUnitAsync_cancel() { |
| 2065 _context = contextWithCore(); | 2064 _context = contextWithCore(); |
| 2066 _sourceFactory = _context.sourceFactory; | 2065 _sourceFactory = _context.sourceFactory; |
| 2067 Source source = _addSource("/lib.dart", "library lib;"); | 2066 Source source = _addSource("/lib.dart", "library lib;"); |
| 2068 // Complete all pending analysis tasks and flush the AST so that it won't | 2067 // Complete all pending analysis tasks and flush the AST so that it won't |
| 2069 // be available immediately. | 2068 // be available immediately. |
| 2070 _performPendingAnalysisTasks(); | 2069 _performPendingAnalysisTasks(); |
| 2071 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); | 2070 _flushAst(source); |
| 2072 entry.flushAstStructures(); | |
| 2073 CancelableFuture<CompilationUnit> future = | 2071 CancelableFuture<CompilationUnit> future = |
| 2074 _context.computeResolvedCompilationUnitAsync(source, source); | 2072 _context.computeResolvedCompilationUnitAsync(source, source); |
| 2075 bool completed = false; | 2073 bool completed = false; |
| 2076 future.then((CompilationUnit unit) { | 2074 future.then((CompilationUnit unit) { |
| 2077 fail('Future should have been canceled'); | 2075 fail('Future should have been canceled'); |
| 2078 }, onError: (error) { | 2076 }, onError: (error) { |
| 2079 expect(error, new isInstanceOf<FutureCanceledError>()); | 2077 expect(error, new isInstanceOf<FutureCanceledError>()); |
| 2080 completed = true; | 2078 completed = true; |
| 2081 }); | 2079 }); |
| 2082 expect(completed, isFalse); | 2080 expect(completed, isFalse); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2181 */ | 2179 */ |
| 2182 ClassElement _findClass(CompilationUnitElement unit, String className) { | 2180 ClassElement _findClass(CompilationUnitElement unit, String className) { |
| 2183 for (ClassElement classElement in unit.types) { | 2181 for (ClassElement classElement in unit.types) { |
| 2184 if (classElement.displayName == className) { | 2182 if (classElement.displayName == className) { |
| 2185 return classElement; | 2183 return classElement; |
| 2186 } | 2184 } |
| 2187 } | 2185 } |
| 2188 return null; | 2186 return null; |
| 2189 } | 2187 } |
| 2190 | 2188 |
| 2189 void _flushAst(Source source) { |
| 2190 CacheEntry entry = _context.getReadableSourceEntryOrNull(source); |
| 2191 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 2192 } |
| 2193 |
| 2191 IncrementalAnalysisCache _getIncrementalAnalysisCache( | 2194 IncrementalAnalysisCache _getIncrementalAnalysisCache( |
| 2192 AnalysisContextImpl context2) { | 2195 AnalysisContextImpl context2) { |
| 2193 return context2.test_incrementalAnalysisCache; | 2196 return context2.test_incrementalAnalysisCache; |
| 2194 } | 2197 } |
| 2195 | 2198 |
| 2196 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { | 2199 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { |
| 2197 return context2.test_priorityOrder; | 2200 return context2.test_priorityOrder; |
| 2198 } | 2201 } |
| 2199 | 2202 |
| 2200 void _performPendingAnalysisTasks([int maxTasks = 20]) { | 2203 void _performPendingAnalysisTasks([int maxTasks = 20]) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 : super(name, UriKind.FILE_URI); | 2272 : super(name, UriKind.FILE_URI); |
| 2270 | 2273 |
| 2271 @override | 2274 @override |
| 2272 TimestampedData<String> get contents { | 2275 TimestampedData<String> get contents { |
| 2273 throw 'Read error'; | 2276 throw 'Read error'; |
| 2274 } | 2277 } |
| 2275 | 2278 |
| 2276 @override | 2279 @override |
| 2277 bool exists() => true; | 2280 bool exists() => true; |
| 2278 } | 2281 } |
| OLD | NEW |