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 analyzer.test.src.context.context_test; | 5 library analyzer.test.src.context.context_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
(...skipping 1404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 // must be in the "async" library - main context | 1415 // must be in the "async" library - main context |
1416 { | 1416 { |
1417 List<Source> coreLibraries = context.getLibrariesContaining(intSource); | 1417 List<Source> coreLibraries = context.getLibrariesContaining(intSource); |
1418 expect(coreLibraries, hasLength(1)); | 1418 expect(coreLibraries, hasLength(1)); |
1419 Source coreSource = coreLibraries[0]; | 1419 Source coreSource = coreLibraries[0]; |
1420 expect(coreSource.isInSystemLibrary, isTrue); | 1420 expect(coreSource.isInSystemLibrary, isTrue); |
1421 expect(coreSource.shortName, 'async.dart'); | 1421 expect(coreSource.shortName, 'async.dart'); |
1422 } | 1422 } |
1423 } | 1423 } |
1424 | 1424 |
| 1425 void test_getLibrarySpecificUnit_definingCU_different() { |
| 1426 Source source1 = newSource('/lib1.dart'); |
| 1427 Source source2 = newSource('/lib2.dart'); |
| 1428 context.applyChanges( |
| 1429 new ChangeSet()..addedSource(source1)..addedSource(source2)); |
| 1430 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(source1, source1); |
| 1431 expect(lsu1, isNotNull); |
| 1432 expect(lsu1.library, same(source1)); |
| 1433 expect(lsu1.unit, same(source1)); |
| 1434 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(source2, source2); |
| 1435 expect(lsu2, isNotNull); |
| 1436 expect(lsu2.library, same(source2)); |
| 1437 expect(lsu2.unit, same(source2)); |
| 1438 } |
| 1439 |
| 1440 void test_getLibrarySpecificUnit_definingCU_explicit() { |
| 1441 Source source = newSource('/test.dart'); |
| 1442 context.applyChanges(new ChangeSet()..addedSource(source)); |
| 1443 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(source, source); |
| 1444 expect(lsu1, isNotNull); |
| 1445 expect(lsu1.library, same(source)); |
| 1446 expect(lsu1.unit, same(source)); |
| 1447 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(source, source); |
| 1448 expect(lsu2, same(lsu1)); |
| 1449 } |
| 1450 |
| 1451 void test_getLibrarySpecificUnit_definingCU_implicit() { |
| 1452 Source source = newSource('/test.dart'); |
| 1453 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(source, source); |
| 1454 expect(lsu1, isNotNull); |
| 1455 expect(lsu1.library, same(source)); |
| 1456 expect(lsu1.unit, same(source)); |
| 1457 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(source, source); |
| 1458 expect(lsu2, equals(lsu1)); |
| 1459 } |
| 1460 |
| 1461 void test_getLibrarySpecificUnit_part_differentLibraries() { |
| 1462 Source library1 = newSource('/lib1.dart'); |
| 1463 Source library2 = newSource('/lib2.dart'); |
| 1464 Source part = newSource('/part.dart'); |
| 1465 context.applyChanges(new ChangeSet() |
| 1466 ..addedSource(library1) |
| 1467 ..addedSource(library2) |
| 1468 ..addedSource(part)); |
| 1469 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(library1, part); |
| 1470 expect(lsu1, isNotNull); |
| 1471 expect(lsu1.library, same(library1)); |
| 1472 expect(lsu1.unit, same(part)); |
| 1473 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(library2, part); |
| 1474 expect(lsu2, isNotNull); |
| 1475 expect(lsu2.library, same(library2)); |
| 1476 expect(lsu2.unit, same(part)); |
| 1477 } |
| 1478 |
| 1479 void test_getLibrarySpecificUnit_part_differentParts() { |
| 1480 Source library = newSource('/lib.dart'); |
| 1481 Source part1 = newSource('/part1.dart'); |
| 1482 Source part2 = newSource('/part2.dart'); |
| 1483 context.applyChanges(new ChangeSet() |
| 1484 ..addedSource(library) |
| 1485 ..addedSource(part1) |
| 1486 ..addedSource(part2)); |
| 1487 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(library, part1); |
| 1488 expect(lsu1, isNotNull); |
| 1489 expect(lsu1.library, same(library)); |
| 1490 expect(lsu1.unit, same(part1)); |
| 1491 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(library, part2); |
| 1492 expect(lsu2, isNotNull); |
| 1493 expect(lsu2.library, same(library)); |
| 1494 expect(lsu2.unit, same(part2)); |
| 1495 } |
| 1496 |
| 1497 void test_getLibrarySpecificUnit_part_explicit() { |
| 1498 Source library = newSource('/lib.dart'); |
| 1499 Source part = newSource('/part.dart'); |
| 1500 context |
| 1501 .applyChanges(new ChangeSet()..addedSource(library)..addedSource(part)); |
| 1502 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(library, part); |
| 1503 expect(lsu1, isNotNull); |
| 1504 expect(lsu1.library, same(library)); |
| 1505 expect(lsu1.unit, same(part)); |
| 1506 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(library, part); |
| 1507 expect(lsu2, same(lsu1)); |
| 1508 } |
| 1509 |
| 1510 void test_getLibrarySpecificUnit_part_implicit() { |
| 1511 Source library = newSource('/lib.dart'); |
| 1512 Source part = newSource('/part.dart'); |
| 1513 LibrarySpecificUnit lsu1 = context.getLibrarySpecificUnit(library, part); |
| 1514 expect(lsu1, isNotNull); |
| 1515 expect(lsu1.library, same(library)); |
| 1516 expect(lsu1.unit, same(part)); |
| 1517 LibrarySpecificUnit lsu2 = context.getLibrarySpecificUnit(library, part); |
| 1518 expect(lsu2, isNotNull); |
| 1519 expect(lsu2.library, same(library)); |
| 1520 expect(lsu2.unit, same(part)); |
| 1521 } |
| 1522 |
1425 void test_getLineInfo() { | 1523 void test_getLineInfo() { |
1426 Source source = addSource( | 1524 Source source = addSource( |
1427 "/test.dart", | 1525 "/test.dart", |
1428 r''' | 1526 r''' |
1429 library lib; | 1527 library lib; |
1430 | 1528 |
1431 main() {}'''); | 1529 main() {}'''); |
1432 LineInfo info = context.getLineInfo(source); | 1530 LineInfo info = context.getLineInfo(source); |
1433 expect(info, isNull); | 1531 expect(info, isNull); |
1434 context.parseCompilationUnit(source); | 1532 context.parseCompilationUnit(source); |
(...skipping 2540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3975 * Initialize the visitor. | 4073 * Initialize the visitor. |
3976 */ | 4074 */ |
3977 _ElementGatherer(); | 4075 _ElementGatherer(); |
3978 | 4076 |
3979 @override | 4077 @override |
3980 void visitElement(Element element) { | 4078 void visitElement(Element element) { |
3981 elements[element] = element; | 4079 elements[element] = element; |
3982 super.visitElement(element); | 4080 super.visitElement(element); |
3983 } | 4081 } |
3984 } | 4082 } |
OLD | NEW |