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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.element_test; | 8 library engine.element_test; |
9 | 9 |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
11 import 'package:analyzer/src/generated/element.dart'; | 11 import 'package:analyzer/src/generated/element.dart'; |
12 import 'package:analyzer/src/generated/engine.dart' | 12 import 'package:analyzer/src/generated/engine.dart' |
13 show AnalysisContext, AnalysisOptionsImpl; | 13 show AnalysisContext, AnalysisOptionsImpl; |
14 import 'package:analyzer/src/generated/java_core.dart'; | 14 import 'package:analyzer/src/generated/java_core.dart'; |
15 import 'package:analyzer/src/generated/source_io.dart'; | 15 import 'package:analyzer/src/generated/source_io.dart'; |
16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
17 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 17 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
18 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 18 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
19 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
20 | 20 |
21 import '../reflective_tests.dart'; | 21 import '../reflective_tests.dart'; |
| 22 import '../utils.dart'; |
22 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper; | 23 import 'resolver_test.dart' show TestTypeProvider, AnalysisContextHelper; |
23 import 'test_support.dart'; | 24 import 'test_support.dart'; |
24 | 25 |
25 main() { | 26 main() { |
26 groupSep = ' | '; | 27 initializeTestEnvironment(); |
27 runReflectiveTests(ElementKindTest); | 28 runReflectiveTests(ElementKindTest); |
28 runReflectiveTests(FieldElementImplTest); | 29 runReflectiveTests(FieldElementImplTest); |
29 runReflectiveTests(FunctionTypeImplTest); | 30 runReflectiveTests(FunctionTypeImplTest); |
30 runReflectiveTests(InterfaceTypeImplTest); | 31 runReflectiveTests(InterfaceTypeImplTest); |
31 runReflectiveTests(TypeParameterTypeImplTest); | 32 runReflectiveTests(TypeParameterTypeImplTest); |
32 runReflectiveTests(VoidTypeImplTest); | 33 runReflectiveTests(VoidTypeImplTest); |
33 runReflectiveTests(ClassElementImplTest); | 34 runReflectiveTests(ClassElementImplTest); |
34 runReflectiveTests(CompilationUnitElementImplTest); | 35 runReflectiveTests(CompilationUnitElementImplTest); |
35 runReflectiveTests(ElementLocationImplTest); | 36 runReflectiveTests(ElementLocationImplTest); |
36 runReflectiveTests(ElementImplTest); | 37 runReflectiveTests(ElementImplTest); |
37 runReflectiveTests(HtmlElementImplTest); | 38 runReflectiveTests(HtmlElementImplTest); |
38 runReflectiveTests(LibraryElementImplTest); | 39 runReflectiveTests(LibraryElementImplTest); |
39 runReflectiveTests(MethodElementImplTest); | 40 runReflectiveTests(MethodElementImplTest); |
40 runReflectiveTests(MultiplyDefinedElementImplTest); | 41 runReflectiveTests(MultiplyDefinedElementImplTest); |
41 runReflectiveTests(ParameterElementImplTest); | 42 runReflectiveTests(ParameterElementImplTest); |
42 } | 43 } |
43 | 44 |
44 @reflectiveTest | 45 @reflectiveTest |
45 class ClassElementImplTest extends EngineTestCase { | 46 class ClassElementImplTest extends EngineTestCase { |
46 void test_computeNode_ClassDeclaration() { | 47 void test_computeNode_ClassDeclaration() { |
47 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 48 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
48 AnalysisContext context = contextHelper.context; | 49 AnalysisContext context = contextHelper.context; |
49 Source source = contextHelper.addSource("/test.dart", r''' | 50 Source source = contextHelper.addSource( |
| 51 "/test.dart", |
| 52 r''' |
50 class A {} | 53 class A {} |
51 @deprecated class B {} | 54 @deprecated class B {} |
52 enum C {C1, C2, C3} | 55 enum C {C1, C2, C3} |
53 @deprecated enum D {D1, D2, D3}'''); | 56 @deprecated enum D {D1, D2, D3}'''); |
54 // prepare CompilationUnitElement | 57 // prepare CompilationUnitElement |
55 LibraryElement libraryElement = context.computeLibraryElement(source); | 58 LibraryElement libraryElement = context.computeLibraryElement(source); |
56 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 59 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
57 // A | 60 // A |
58 { | 61 { |
59 ClassElement elementA = unitElement.getType("A"); | 62 ClassElement elementA = unitElement.getType("A"); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 EnumDeclaration nodeC = elementD.computeNode(); | 95 EnumDeclaration nodeC = elementD.computeNode(); |
93 expect(nodeC, isNotNull); | 96 expect(nodeC, isNotNull); |
94 expect(nodeC.name.name, "D"); | 97 expect(nodeC.name.name, "D"); |
95 expect(nodeC.element, same(elementD)); | 98 expect(nodeC.element, same(elementD)); |
96 } | 99 } |
97 } | 100 } |
98 | 101 |
99 void test_computeNode_ClassTypeAlias() { | 102 void test_computeNode_ClassTypeAlias() { |
100 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 103 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
101 AnalysisContext context = contextHelper.context; | 104 AnalysisContext context = contextHelper.context; |
102 Source source = contextHelper.addSource("/test.dart", r''' | 105 Source source = contextHelper.addSource( |
| 106 "/test.dart", |
| 107 r''' |
103 abstract class A<K, V> = Object with MapMixin<K, V>; | 108 abstract class A<K, V> = Object with MapMixin<K, V>; |
104 '''); | 109 '''); |
105 // prepare CompilationUnitElement | 110 // prepare CompilationUnitElement |
106 LibraryElement libraryElement = context.computeLibraryElement(source); | 111 LibraryElement libraryElement = context.computeLibraryElement(source); |
107 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 112 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
108 // A | 113 // A |
109 { | 114 { |
110 ClassElement elementA = unitElement.getType("A"); | 115 ClassElement elementA = unitElement.getType("A"); |
111 ClassTypeAlias nodeA = elementA.computeNode(); | 116 ClassTypeAlias nodeA = elementA.computeNode(); |
112 expect(nodeA, isNotNull); | 117 expect(nodeA, isNotNull); |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 expect(element.enclosingElement, mainElement); | 988 expect(element.enclosingElement, mainElement); |
984 expect(element.name, 'localVar'); | 989 expect(element.name, 'localVar'); |
985 } | 990 } |
986 // null | 991 // null |
987 expect(unitElement.getElementAt(1000), isNull); | 992 expect(unitElement.getElementAt(1000), isNull); |
988 } | 993 } |
989 | 994 |
990 void test_getElementAt_multipleUnitsInLibrary() { | 995 void test_getElementAt_multipleUnitsInLibrary() { |
991 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 996 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
992 AnalysisContext context = contextHelper.context; | 997 AnalysisContext context = contextHelper.context; |
993 Source libSource = contextHelper.addSource("/my_lib.dart", r''' | 998 Source libSource = contextHelper.addSource( |
| 999 "/my_lib.dart", |
| 1000 r''' |
994 library my_lib; | 1001 library my_lib; |
995 part 'unit_a.dart'; | 1002 part 'unit_a.dart'; |
996 part 'unit_b.dart'; | 1003 part 'unit_b.dart'; |
997 '''); | 1004 '''); |
998 Source unitSourceA = | 1005 Source unitSourceA = |
999 contextHelper.addSource("/unit_a.dart", 'part of my_lib;class A {}'); | 1006 contextHelper.addSource("/unit_a.dart", 'part of my_lib;class A {}'); |
1000 Source unitSourceB = | 1007 Source unitSourceB = |
1001 contextHelper.addSource("/unit_b.dart", 'part of my_lib;class B {}'); | 1008 contextHelper.addSource("/unit_b.dart", 'part of my_lib;class B {}'); |
1002 int offset = 'part of my_lib;class A {}'.indexOf('A {}'); | 1009 int offset = 'part of my_lib;class A {}'.indexOf('A {}'); |
1003 // prepare library/unit elements | 1010 // prepare library/unit elements |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 ElementLocationImpl second = new ElementLocationImpl.con2(encoding); | 1241 ElementLocationImpl second = new ElementLocationImpl.con2(encoding); |
1235 expect(first.hashCode == second.hashCode, isTrue); | 1242 expect(first.hashCode == second.hashCode, isTrue); |
1236 } | 1243 } |
1237 } | 1244 } |
1238 | 1245 |
1239 @reflectiveTest | 1246 @reflectiveTest |
1240 class FieldElementImplTest extends EngineTestCase { | 1247 class FieldElementImplTest extends EngineTestCase { |
1241 void test_computeNode() { | 1248 void test_computeNode() { |
1242 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 1249 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
1243 AnalysisContext context = contextHelper.context; | 1250 AnalysisContext context = contextHelper.context; |
1244 Source source = contextHelper.addSource("/test.dart", r''' | 1251 Source source = contextHelper.addSource( |
| 1252 "/test.dart", |
| 1253 r''' |
1245 class A { | 1254 class A { |
1246 int a; | 1255 int a; |
1247 } | 1256 } |
1248 enum B {B1, B2, B3}'''); | 1257 enum B {B1, B2, B3}'''); |
1249 // prepare CompilationUnitElement | 1258 // prepare CompilationUnitElement |
1250 LibraryElement libraryElement = context.computeLibraryElement(source); | 1259 LibraryElement libraryElement = context.computeLibraryElement(source); |
1251 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 1260 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
1252 // A | 1261 // A |
1253 { | 1262 { |
1254 FieldElement elementA = unitElement.getType("A").getField('a'); | 1263 FieldElement elementA = unitElement.getType("A").getField('a'); |
1255 VariableDeclaration nodeA = elementA.computeNode(); | 1264 VariableDeclaration nodeA = elementA.computeNode(); |
1256 expect(nodeA, isNotNull); | 1265 expect(nodeA, isNotNull); |
1257 expect(nodeA.name.name, "a"); | 1266 expect(nodeA.name.name, "a"); |
1258 expect(nodeA.element, same(elementA)); | 1267 expect(nodeA.element, same(elementA)); |
1259 } | 1268 } |
1260 // B | 1269 // B |
1261 { | 1270 { |
1262 FieldElement elementB = unitElement.getEnum("B").getField('B2'); | 1271 FieldElement elementB = unitElement.getEnum("B").getField('B2'); |
1263 EnumConstantDeclaration nodeB = elementB.computeNode(); | 1272 EnumConstantDeclaration nodeB = elementB.computeNode(); |
1264 expect(nodeB, isNotNull); | 1273 expect(nodeB, isNotNull); |
1265 expect(nodeB.name.name, "B2"); | 1274 expect(nodeB.name.name, "B2"); |
1266 expect(nodeB.element, same(elementB)); | 1275 expect(nodeB.element, same(elementB)); |
1267 } | 1276 } |
1268 } | 1277 } |
1269 } | 1278 } |
1270 | 1279 |
1271 @reflectiveTest | 1280 @reflectiveTest |
1272 class FunctionTypeImplTest extends EngineTestCase { | 1281 class FunctionTypeImplTest extends EngineTestCase { |
1273 void test_creation() { | 1282 void test_creation() { |
1274 expect(new FunctionTypeImpl( | 1283 expect( |
| 1284 new FunctionTypeImpl( |
1275 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))), | 1285 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))), |
1276 isNotNull); | 1286 isNotNull); |
1277 } | 1287 } |
1278 | 1288 |
1279 void test_equality_recursive() { | 1289 void test_equality_recursive() { |
1280 FunctionTypeAliasElementImpl s = | 1290 FunctionTypeAliasElementImpl s = |
1281 ElementFactory.functionTypeAliasElement('s'); | 1291 ElementFactory.functionTypeAliasElement('s'); |
1282 FunctionTypeAliasElementImpl t = | 1292 FunctionTypeAliasElementImpl t = |
1283 ElementFactory.functionTypeAliasElement('t'); | 1293 ElementFactory.functionTypeAliasElement('t'); |
1284 FunctionTypeAliasElementImpl u = | 1294 FunctionTypeAliasElementImpl u = |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1408 FunctionType t = ElementFactory.functionElement4( | 1418 FunctionType t = ElementFactory.functionElement4( |
1409 "t", null, null, <String>["name"], <ClassElement>[a]).type; | 1419 "t", null, null, <String>["name"], <ClassElement>[a]).type; |
1410 FunctionType s = ElementFactory.functionElement4( | 1420 FunctionType s = ElementFactory.functionElement4( |
1411 "s", null, null, <String>["name"], <ClassElement>[b]).type; | 1421 "s", null, null, <String>["name"], <ClassElement>[b]).type; |
1412 expect(t.isSubtypeOf(s), isTrue); | 1422 expect(t.isSubtypeOf(s), isTrue); |
1413 expect(s.isSubtypeOf(t), isTrue); | 1423 expect(s.isSubtypeOf(t), isTrue); |
1414 } | 1424 } |
1415 | 1425 |
1416 void test_isSubtypeOf_namedParameters_isNotAssignable() { | 1426 void test_isSubtypeOf_namedParameters_isNotAssignable() { |
1417 // ! ({name: A}) -> void <: ({name: B}) -> void | 1427 // ! ({name: A}) -> void <: ({name: B}) -> void |
1418 FunctionType t = ElementFactory.functionElement4("t", null, null, | 1428 FunctionType t = ElementFactory.functionElement4( |
| 1429 "t", |
| 1430 null, |
| 1431 null, |
1419 <String>["name"], | 1432 <String>["name"], |
1420 <ClassElement>[ElementFactory.classElement2("A")]).type; | 1433 <ClassElement>[ElementFactory.classElement2("A")]).type; |
1421 FunctionType s = ElementFactory.functionElement4("s", null, null, | 1434 FunctionType s = ElementFactory.functionElement4( |
| 1435 "s", |
| 1436 null, |
| 1437 null, |
1422 <String>["name"], | 1438 <String>["name"], |
1423 <ClassElement>[ElementFactory.classElement2("B")]).type; | 1439 <ClassElement>[ElementFactory.classElement2("B")]).type; |
1424 expect(t.isSubtypeOf(s), isFalse); | 1440 expect(t.isSubtypeOf(s), isFalse); |
1425 } | 1441 } |
1426 | 1442 |
1427 void test_isSubtypeOf_namedParameters_namesDifferent() { | 1443 void test_isSubtypeOf_namedParameters_namesDifferent() { |
1428 // B extends A | 1444 // B extends A |
1429 // void t({A name}) {} | 1445 // void t({A name}) {} |
1430 // void s({A diff}) {} | 1446 // void s({A diff}) {} |
1431 // ! t <: s | 1447 // ! t <: s |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; | 1523 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; |
1508 FunctionType s = | 1524 FunctionType s = |
1509 ElementFactory.functionElement5("s", <ClassElement>[a]).type; | 1525 ElementFactory.functionElement5("s", <ClassElement>[a]).type; |
1510 expect(t.isSubtypeOf(s), isTrue); | 1526 expect(t.isSubtypeOf(s), isTrue); |
1511 expect(s.isSubtypeOf(t), isFalse); | 1527 expect(s.isSubtypeOf(t), isFalse); |
1512 } | 1528 } |
1513 | 1529 |
1514 void test_isSubtypeOf_normalAndPositionalArgs_2() { | 1530 void test_isSubtypeOf_normalAndPositionalArgs_2() { |
1515 // (a, [a]) -> void <: (a) -> void | 1531 // (a, [a]) -> void <: (a) -> void |
1516 ClassElement a = ElementFactory.classElement2("A"); | 1532 ClassElement a = ElementFactory.classElement2("A"); |
1517 FunctionType t = ElementFactory.functionElement6( | 1533 FunctionType t = ElementFactory |
1518 "t", <ClassElement>[a], <ClassElement>[a]).type; | 1534 .functionElement6("t", <ClassElement>[a], <ClassElement>[a]).type; |
1519 FunctionType s = | 1535 FunctionType s = |
1520 ElementFactory.functionElement5("s", <ClassElement>[a]).type; | 1536 ElementFactory.functionElement5("s", <ClassElement>[a]).type; |
1521 expect(t.isSubtypeOf(s), isTrue); | 1537 expect(t.isSubtypeOf(s), isTrue); |
1522 expect(s.isSubtypeOf(t), isFalse); | 1538 expect(s.isSubtypeOf(t), isFalse); |
1523 } | 1539 } |
1524 | 1540 |
1525 void test_isSubtypeOf_normalAndPositionalArgs_3() { | 1541 void test_isSubtypeOf_normalAndPositionalArgs_3() { |
1526 // ([a]) -> void <: () -> void | 1542 // ([a]) -> void <: () -> void |
1527 ClassElement a = ElementFactory.classElement2("A"); | 1543 ClassElement a = ElementFactory.classElement2("A"); |
1528 FunctionType t = | 1544 FunctionType t = |
1529 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; | 1545 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; |
1530 FunctionType s = ElementFactory.functionElement("s").type; | 1546 FunctionType s = ElementFactory.functionElement("s").type; |
1531 expect(t.isSubtypeOf(s), isTrue); | 1547 expect(t.isSubtypeOf(s), isTrue); |
1532 expect(s.isSubtypeOf(t), isFalse); | 1548 expect(s.isSubtypeOf(t), isFalse); |
1533 } | 1549 } |
1534 | 1550 |
1535 void test_isSubtypeOf_normalAndPositionalArgs_4() { | 1551 void test_isSubtypeOf_normalAndPositionalArgs_4() { |
1536 // (a, b, [c, d, e]) -> void <: (a, b, c, [d]) -> void | 1552 // (a, b, [c, d, e]) -> void <: (a, b, c, [d]) -> void |
1537 ClassElement a = ElementFactory.classElement2("A"); | 1553 ClassElement a = ElementFactory.classElement2("A"); |
1538 ClassElement b = ElementFactory.classElement2("B"); | 1554 ClassElement b = ElementFactory.classElement2("B"); |
1539 ClassElement c = ElementFactory.classElement2("C"); | 1555 ClassElement c = ElementFactory.classElement2("C"); |
1540 ClassElement d = ElementFactory.classElement2("D"); | 1556 ClassElement d = ElementFactory.classElement2("D"); |
1541 ClassElement e = ElementFactory.classElement2("E"); | 1557 ClassElement e = ElementFactory.classElement2("E"); |
1542 FunctionType t = ElementFactory.functionElement6( | 1558 FunctionType t = ElementFactory.functionElement6( |
1543 "t", <ClassElement>[a, b], <ClassElement>[c, d, e]).type; | 1559 "t", <ClassElement>[a, b], <ClassElement>[c, d, e]).type; |
1544 FunctionType s = ElementFactory.functionElement6( | 1560 FunctionType s = ElementFactory |
1545 "s", <ClassElement>[a, b, c], <ClassElement>[d]).type; | 1561 .functionElement6("s", <ClassElement>[a, b, c], <ClassElement>[d]).type; |
1546 expect(t.isSubtypeOf(s), isTrue); | 1562 expect(t.isSubtypeOf(s), isTrue); |
1547 expect(s.isSubtypeOf(t), isFalse); | 1563 expect(s.isSubtypeOf(t), isFalse); |
1548 } | 1564 } |
1549 | 1565 |
1550 void test_isSubtypeOf_normalParameters_isAssignable() { | 1566 void test_isSubtypeOf_normalParameters_isAssignable() { |
1551 // B extends A | 1567 // B extends A |
1552 // (a) -> void <: (b) -> void | 1568 // (a) -> void <: (b) -> void |
1553 // (b) -> void <: (a) -> void | 1569 // (b) -> void <: (a) -> void |
1554 ClassElement a = ElementFactory.classElement2("A"); | 1570 ClassElement a = ElementFactory.classElement2("A"); |
1555 ClassElement b = ElementFactory.classElement("B", a.type); | 1571 ClassElement b = ElementFactory.classElement("B", a.type); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 ClassElement a = ElementFactory.classElement2("A"); | 1683 ClassElement a = ElementFactory.classElement2("A"); |
1668 ClassElement b = ElementFactory.classElement("B", a.type); | 1684 ClassElement b = ElementFactory.classElement("B", a.type); |
1669 FunctionType t = ElementFactory.functionElement2("t", a).type; | 1685 FunctionType t = ElementFactory.functionElement2("t", a).type; |
1670 FunctionType s = ElementFactory.functionElement2("s", b).type; | 1686 FunctionType s = ElementFactory.functionElement2("s", b).type; |
1671 expect(t.isSubtypeOf(s), isTrue); | 1687 expect(t.isSubtypeOf(s), isTrue); |
1672 expect(s.isSubtypeOf(t), isTrue); | 1688 expect(s.isSubtypeOf(t), isTrue); |
1673 } | 1689 } |
1674 | 1690 |
1675 void test_isSubtypeOf_returnType_tNotAssignableToS() { | 1691 void test_isSubtypeOf_returnType_tNotAssignableToS() { |
1676 // ! () -> A <: () -> B | 1692 // ! () -> A <: () -> B |
1677 FunctionType t = ElementFactory.functionElement2( | 1693 FunctionType t = ElementFactory |
1678 "t", ElementFactory.classElement2("A")).type; | 1694 .functionElement2("t", ElementFactory.classElement2("A")) |
1679 FunctionType s = ElementFactory.functionElement2( | 1695 .type; |
1680 "s", ElementFactory.classElement2("B")).type; | 1696 FunctionType s = ElementFactory |
| 1697 .functionElement2("s", ElementFactory.classElement2("B")) |
| 1698 .type; |
1681 expect(t.isSubtypeOf(s), isFalse); | 1699 expect(t.isSubtypeOf(s), isFalse); |
1682 } | 1700 } |
1683 | 1701 |
1684 void test_isSubtypeOf_typeParameters_matchesBounds() { | 1702 void test_isSubtypeOf_typeParameters_matchesBounds() { |
1685 TestTypeProvider provider = new TestTypeProvider(); | 1703 TestTypeProvider provider = new TestTypeProvider(); |
1686 InterfaceType boolType = provider.boolType; | 1704 InterfaceType boolType = provider.boolType; |
1687 InterfaceType stringType = provider.stringType; | 1705 InterfaceType stringType = provider.stringType; |
1688 TypeParameterElementImpl parameterB = | 1706 TypeParameterElementImpl parameterB = |
1689 new TypeParameterElementImpl.forNode(AstFactory.identifier3("B")); | 1707 new TypeParameterElementImpl.forNode(AstFactory.identifier3("B")); |
1690 parameterB.bound = boolType; | 1708 parameterB.bound = boolType; |
(...skipping 23 matching lines...) Expand all Loading... |
1714 functionElement.type = functionType; | 1732 functionElement.type = functionType; |
1715 expect(functionType.isAssignableTo(functionAliasType), isTrue); | 1733 expect(functionType.isAssignableTo(functionAliasType), isTrue); |
1716 } | 1734 } |
1717 | 1735 |
1718 void test_isSubtypeOf_wrongFunctionType_normal_named() { | 1736 void test_isSubtypeOf_wrongFunctionType_normal_named() { |
1719 // ! (a) -> void <: ({name: A}) -> void | 1737 // ! (a) -> void <: ({name: A}) -> void |
1720 // ! ({name: A}) -> void <: (a) -> void | 1738 // ! ({name: A}) -> void <: (a) -> void |
1721 ClassElement a = ElementFactory.classElement2("A"); | 1739 ClassElement a = ElementFactory.classElement2("A"); |
1722 FunctionType t = | 1740 FunctionType t = |
1723 ElementFactory.functionElement5("t", <ClassElement>[a]).type; | 1741 ElementFactory.functionElement5("t", <ClassElement>[a]).type; |
1724 FunctionType s = ElementFactory.functionElement7( | 1742 FunctionType s = ElementFactory |
1725 "s", null, <String>["name"], <ClassElement>[a]).type; | 1743 .functionElement7("s", null, <String>["name"], <ClassElement>[a]).type; |
1726 expect(t.isSubtypeOf(s), isFalse); | 1744 expect(t.isSubtypeOf(s), isFalse); |
1727 expect(s.isSubtypeOf(t), isFalse); | 1745 expect(s.isSubtypeOf(t), isFalse); |
1728 } | 1746 } |
1729 | 1747 |
1730 void test_isSubtypeOf_wrongFunctionType_optional_named() { | 1748 void test_isSubtypeOf_wrongFunctionType_optional_named() { |
1731 // ! ([a]) -> void <: ({name: A}) -> void | 1749 // ! ([a]) -> void <: ({name: A}) -> void |
1732 // ! ({name: A}) -> void <: ([a]) -> void | 1750 // ! ({name: A}) -> void <: ([a]) -> void |
1733 ClassElement a = ElementFactory.classElement2("A"); | 1751 ClassElement a = ElementFactory.classElement2("A"); |
1734 FunctionType t = | 1752 FunctionType t = |
1735 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; | 1753 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; |
1736 FunctionType s = ElementFactory.functionElement7( | 1754 FunctionType s = ElementFactory |
1737 "s", null, <String>["name"], <ClassElement>[a]).type; | 1755 .functionElement7("s", null, <String>["name"], <ClassElement>[a]).type; |
1738 expect(t.isSubtypeOf(s), isFalse); | 1756 expect(t.isSubtypeOf(s), isFalse); |
1739 expect(s.isSubtypeOf(t), isFalse); | 1757 expect(s.isSubtypeOf(t), isFalse); |
1740 } | 1758 } |
1741 | 1759 |
1742 void test_namedParameterTypes_pruned_no_type_arguments() { | 1760 void test_namedParameterTypes_pruned_no_type_arguments() { |
1743 FunctionTypeAliasElementImpl f = | 1761 FunctionTypeAliasElementImpl f = |
1744 ElementFactory.functionTypeAliasElement('f'); | 1762 ElementFactory.functionTypeAliasElement('f'); |
1745 FunctionTypeAliasElementImpl g = | 1763 FunctionTypeAliasElementImpl g = |
1746 ElementFactory.functionTypeAliasElement('g'); | 1764 ElementFactory.functionTypeAliasElement('g'); |
1747 f.parameters = [ElementFactory.namedParameter2('x', g.type)]; | 1765 f.parameters = [ElementFactory.namedParameter2('x', g.type)]; |
(...skipping 1384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3132 // void f(String s) {} | 3150 // void f(String s) {} |
3133 // class A { | 3151 // class A { |
3134 // void call(String s) {} | 3152 // void call(String s) {} |
3135 // } | 3153 // } |
3136 // | 3154 // |
3137 InterfaceType stringType = _typeProvider.stringType; | 3155 InterfaceType stringType = _typeProvider.stringType; |
3138 ClassElementImpl classA = ElementFactory.classElement2("A"); | 3156 ClassElementImpl classA = ElementFactory.classElement2("A"); |
3139 classA.methods = <MethodElement>[ | 3157 classA.methods = <MethodElement>[ |
3140 ElementFactory.methodElement("call", VoidTypeImpl.instance, [stringType]) | 3158 ElementFactory.methodElement("call", VoidTypeImpl.instance, [stringType]) |
3141 ]; | 3159 ]; |
3142 FunctionType functionType = ElementFactory.functionElement5( | 3160 FunctionType functionType = ElementFactory |
3143 "f", <ClassElement>[stringType.element]).type; | 3161 .functionElement5("f", <ClassElement>[stringType.element]).type; |
3144 expect(classA.type.isSubtypeOf(functionType), isTrue); | 3162 expect(classA.type.isSubtypeOf(functionType), isTrue); |
3145 } | 3163 } |
3146 | 3164 |
3147 void test_isSubtypeOf_generic() { | 3165 void test_isSubtypeOf_generic() { |
3148 ClassElement classA = ElementFactory.classElement2("A", ["E"]); | 3166 ClassElement classA = ElementFactory.classElement2("A", ["E"]); |
3149 ClassElement classB = ElementFactory.classElement2("B"); | 3167 ClassElement classB = ElementFactory.classElement2("B"); |
3150 DartType dynamicType = DynamicTypeImpl.instance; | 3168 DartType dynamicType = DynamicTypeImpl.instance; |
3151 InterfaceType typeAOfDynamic = | 3169 InterfaceType typeAOfDynamic = |
3152 classA.type.substitute4(<DartType>[dynamicType]); | 3170 classA.type.substitute4(<DartType>[dynamicType]); |
3153 InterfaceType typeAOfB = classA.type.substitute4(<DartType>[classB.type]); | 3171 InterfaceType typeAOfB = classA.type.substitute4(<DartType>[classB.type]); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3710 expect(result.element, classA); | 3728 expect(result.element, classA); |
3711 List<DartType> resultArguments = result.typeArguments; | 3729 List<DartType> resultArguments = result.typeArguments; |
3712 expect(resultArguments, hasLength(1)); | 3730 expect(resultArguments, hasLength(1)); |
3713 expect(resultArguments[0], parameter); | 3731 expect(resultArguments[0], parameter); |
3714 } | 3732 } |
3715 } | 3733 } |
3716 | 3734 |
3717 @reflectiveTest | 3735 @reflectiveTest |
3718 class LibraryElementImplTest extends EngineTestCase { | 3736 class LibraryElementImplTest extends EngineTestCase { |
3719 void test_creation() { | 3737 void test_creation() { |
3720 expect(new LibraryElementImpl.forNode( | 3738 expect( |
| 3739 new LibraryElementImpl.forNode( |
3721 createAnalysisContext(), AstFactory.libraryIdentifier2(["l"])), | 3740 createAnalysisContext(), AstFactory.libraryIdentifier2(["l"])), |
3722 isNotNull); | 3741 isNotNull); |
3723 } | 3742 } |
3724 | 3743 |
3725 void test_getImportedLibraries() { | 3744 void test_getImportedLibraries() { |
3726 AnalysisContext context = createAnalysisContext(); | 3745 AnalysisContext context = createAnalysisContext(); |
3727 LibraryElementImpl library1 = ElementFactory.library(context, "l1"); | 3746 LibraryElementImpl library1 = ElementFactory.library(context, "l1"); |
3728 LibraryElementImpl library2 = ElementFactory.library(context, "l2"); | 3747 LibraryElementImpl library2 = ElementFactory.library(context, "l2"); |
3729 LibraryElementImpl library3 = ElementFactory.library(context, "l3"); | 3748 LibraryElementImpl library3 = ElementFactory.library(context, "l3"); |
3730 LibraryElementImpl library4 = ElementFactory.library(context, "l4"); | 3749 LibraryElementImpl library4 = ElementFactory.library(context, "l4"); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3781 ElementFactory.compilationUnit("unit_b.dart", unitLib.source); | 3800 ElementFactory.compilationUnit("unit_b.dart", unitLib.source); |
3782 library.parts = <CompilationUnitElement>[unitA, unitB]; | 3801 library.parts = <CompilationUnitElement>[unitA, unitB]; |
3783 expect(library.units, | 3802 expect(library.units, |
3784 unorderedEquals(<CompilationUnitElement>[unitLib, unitA, unitB])); | 3803 unorderedEquals(<CompilationUnitElement>[unitLib, unitA, unitB])); |
3785 } | 3804 } |
3786 | 3805 |
3787 void test_getVisibleLibraries_cycle() { | 3806 void test_getVisibleLibraries_cycle() { |
3788 AnalysisContext context = createAnalysisContext(); | 3807 AnalysisContext context = createAnalysisContext(); |
3789 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3808 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3790 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); | 3809 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); |
3791 libraryA.imports = | 3810 libraryA.imports = <ImportElementImpl>[ |
3792 <ImportElementImpl>[ElementFactory.importFor(library, null)]; | 3811 ElementFactory.importFor(library, null) |
3793 library.imports = | 3812 ]; |
3794 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)]; | 3813 library.imports = <ImportElementImpl>[ |
| 3814 ElementFactory.importFor(libraryA, null) |
| 3815 ]; |
3795 List<LibraryElement> libraries = library.visibleLibraries; | 3816 List<LibraryElement> libraries = library.visibleLibraries; |
3796 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); | 3817 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); |
3797 } | 3818 } |
3798 | 3819 |
3799 void test_getVisibleLibraries_directExports() { | 3820 void test_getVisibleLibraries_directExports() { |
3800 AnalysisContext context = createAnalysisContext(); | 3821 AnalysisContext context = createAnalysisContext(); |
3801 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3822 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3802 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); | 3823 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); |
3803 library.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryA)]; | 3824 library.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryA)]; |
3804 List<LibraryElement> libraries = library.visibleLibraries; | 3825 List<LibraryElement> libraries = library.visibleLibraries; |
3805 expect(libraries, unorderedEquals(<LibraryElement>[library])); | 3826 expect(libraries, unorderedEquals(<LibraryElement>[library])); |
3806 } | 3827 } |
3807 | 3828 |
3808 void test_getVisibleLibraries_directImports() { | 3829 void test_getVisibleLibraries_directImports() { |
3809 AnalysisContext context = createAnalysisContext(); | 3830 AnalysisContext context = createAnalysisContext(); |
3810 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3831 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3811 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); | 3832 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); |
3812 library.imports = | 3833 library.imports = <ImportElementImpl>[ |
3813 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)]; | 3834 ElementFactory.importFor(libraryA, null) |
| 3835 ]; |
3814 List<LibraryElement> libraries = library.visibleLibraries; | 3836 List<LibraryElement> libraries = library.visibleLibraries; |
3815 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); | 3837 expect(libraries, unorderedEquals(<LibraryElement>[library, libraryA])); |
3816 } | 3838 } |
3817 | 3839 |
3818 void test_getVisibleLibraries_indirectExports() { | 3840 void test_getVisibleLibraries_indirectExports() { |
3819 AnalysisContext context = createAnalysisContext(); | 3841 AnalysisContext context = createAnalysisContext(); |
3820 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3842 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3821 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); | 3843 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); |
3822 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); | 3844 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); |
3823 libraryA.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryAA)]; | 3845 libraryA.exports = <ExportElementImpl>[ElementFactory.exportFor(libraryAA)]; |
3824 library.imports = | 3846 library.imports = <ImportElementImpl>[ |
3825 <ImportElementImpl>[ElementFactory.importFor(libraryA, null)]; | 3847 ElementFactory.importFor(libraryA, null) |
| 3848 ]; |
3826 List<LibraryElement> libraries = library.visibleLibraries; | 3849 List<LibraryElement> libraries = library.visibleLibraries; |
3827 expect(libraries, | 3850 expect(libraries, |
3828 unorderedEquals(<LibraryElement>[library, libraryA, libraryAA])); | 3851 unorderedEquals(<LibraryElement>[library, libraryA, libraryAA])); |
3829 } | 3852 } |
3830 | 3853 |
3831 void test_getVisibleLibraries_indirectImports() { | 3854 void test_getVisibleLibraries_indirectImports() { |
3832 AnalysisContext context = createAnalysisContext(); | 3855 AnalysisContext context = createAnalysisContext(); |
3833 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3856 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3834 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); | 3857 LibraryElementImpl libraryA = ElementFactory.library(context, "A"); |
3835 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); | 3858 LibraryElementImpl libraryAA = ElementFactory.library(context, "AA"); |
3836 LibraryElementImpl libraryB = ElementFactory.library(context, "B"); | 3859 LibraryElementImpl libraryB = ElementFactory.library(context, "B"); |
3837 libraryA.imports = | 3860 libraryA.imports = <ImportElementImpl>[ |
3838 <ImportElementImpl>[ElementFactory.importFor(libraryAA, null)]; | 3861 ElementFactory.importFor(libraryAA, null) |
| 3862 ]; |
3839 library.imports = <ImportElementImpl>[ | 3863 library.imports = <ImportElementImpl>[ |
3840 ElementFactory.importFor(libraryA, null), | 3864 ElementFactory.importFor(libraryA, null), |
3841 ElementFactory.importFor(libraryB, null) | 3865 ElementFactory.importFor(libraryB, null) |
3842 ]; | 3866 ]; |
3843 List<LibraryElement> libraries = library.visibleLibraries; | 3867 List<LibraryElement> libraries = library.visibleLibraries; |
3844 expect(libraries, unorderedEquals( | 3868 expect( |
3845 <LibraryElement>[library, libraryA, libraryAA, libraryB])); | 3869 libraries, |
| 3870 unorderedEquals( |
| 3871 <LibraryElement>[library, libraryA, libraryAA, libraryB])); |
3846 } | 3872 } |
3847 | 3873 |
3848 void test_getVisibleLibraries_noImports() { | 3874 void test_getVisibleLibraries_noImports() { |
3849 AnalysisContext context = createAnalysisContext(); | 3875 AnalysisContext context = createAnalysisContext(); |
3850 LibraryElementImpl library = ElementFactory.library(context, "app"); | 3876 LibraryElementImpl library = ElementFactory.library(context, "app"); |
3851 expect( | 3877 expect( |
3852 library.visibleLibraries, unorderedEquals(<LibraryElement>[library])); | 3878 library.visibleLibraries, unorderedEquals(<LibraryElement>[library])); |
3853 } | 3879 } |
3854 | 3880 |
3855 void test_isUpToDate() { | 3881 void test_isUpToDate() { |
(...skipping 23 matching lines...) Expand all Loading... |
3879 expect(actualImports[i], same(expectedImports[i])); | 3905 expect(actualImports[i], same(expectedImports[i])); |
3880 } | 3906 } |
3881 } | 3907 } |
3882 } | 3908 } |
3883 | 3909 |
3884 @reflectiveTest | 3910 @reflectiveTest |
3885 class MethodElementImplTest extends EngineTestCase { | 3911 class MethodElementImplTest extends EngineTestCase { |
3886 void test_computeNode() { | 3912 void test_computeNode() { |
3887 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 3913 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
3888 AnalysisContext context = contextHelper.context; | 3914 AnalysisContext context = contextHelper.context; |
3889 Source source = contextHelper.addSource("/test.dart", r''' | 3915 Source source = contextHelper.addSource( |
| 3916 "/test.dart", |
| 3917 r''' |
3890 abstract class A { | 3918 abstract class A { |
3891 String m1() => null; | 3919 String m1() => null; |
3892 m2(); | 3920 m2(); |
3893 } | 3921 } |
3894 '''); | 3922 '''); |
3895 // prepare CompilationUnitElement | 3923 // prepare CompilationUnitElement |
3896 LibraryElement libraryElement = context.computeLibraryElement(source); | 3924 LibraryElement libraryElement = context.computeLibraryElement(source); |
3897 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 3925 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
3898 // m1 | 3926 // m1 |
3899 { | 3927 { |
(...skipping 11 matching lines...) Expand all Loading... |
3911 expect(m2Node.name.name, "m2"); | 3939 expect(m2Node.name.name, "m2"); |
3912 expect(m2Node.element, same(m2Element)); | 3940 expect(m2Node.element, same(m2Element)); |
3913 } | 3941 } |
3914 } | 3942 } |
3915 | 3943 |
3916 void test_computeNode_withoutFunctionBody() { | 3944 void test_computeNode_withoutFunctionBody() { |
3917 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 3945 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
3918 options.analyzeFunctionBodies = false; | 3946 options.analyzeFunctionBodies = false; |
3919 AnalysisContextHelper contextHelper = new AnalysisContextHelper(options); | 3947 AnalysisContextHelper contextHelper = new AnalysisContextHelper(options); |
3920 AnalysisContext context = contextHelper.context; | 3948 AnalysisContext context = contextHelper.context; |
3921 Source source = contextHelper.addSource("/test.dart", r''' | 3949 Source source = contextHelper.addSource( |
| 3950 "/test.dart", |
| 3951 r''' |
3922 abstract class A { | 3952 abstract class A { |
3923 String m1() => null; | 3953 String m1() => null; |
3924 m2(); | 3954 m2(); |
3925 } | 3955 } |
3926 '''); | 3956 '''); |
3927 // prepare CompilationUnitElement | 3957 // prepare CompilationUnitElement |
3928 LibraryElement libraryElement = context.computeLibraryElement(source); | 3958 LibraryElement libraryElement = context.computeLibraryElement(source); |
3929 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 3959 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
3930 // m1 | 3960 // m1 |
3931 { | 3961 { |
(...skipping 29 matching lines...) Expand all Loading... |
3961 for (int i = 0; i < elements.length; i++) { | 3991 for (int i = 0; i < elements.length; i++) { |
3962 EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement, | 3992 EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement, |
3963 LocalVariableElement, elements[i]); | 3993 LocalVariableElement, elements[i]); |
3964 } | 3994 } |
3965 } | 3995 } |
3966 | 3996 |
3967 void test_fromElements_multiple() { | 3997 void test_fromElements_multiple() { |
3968 Element firstElement = ElementFactory.localVariableElement2("xx"); | 3998 Element firstElement = ElementFactory.localVariableElement2("xx"); |
3969 Element secondElement = ElementFactory.localVariableElement2("yy"); | 3999 Element secondElement = ElementFactory.localVariableElement2("yy"); |
3970 Element thirdElement = ElementFactory.localVariableElement2("zz"); | 4000 Element thirdElement = ElementFactory.localVariableElement2("zz"); |
3971 Element result = MultiplyDefinedElementImpl.fromElements(null, | 4001 Element result = MultiplyDefinedElementImpl.fromElements( |
| 4002 null, |
3972 MultiplyDefinedElementImpl.fromElements( | 4003 MultiplyDefinedElementImpl.fromElements( |
3973 null, firstElement, secondElement), thirdElement); | 4004 null, firstElement, secondElement), |
| 4005 thirdElement); |
3974 EngineTestCase.assertInstanceOf( | 4006 EngineTestCase.assertInstanceOf( |
3975 (obj) => obj is MultiplyDefinedElement, MultiplyDefinedElement, result); | 4007 (obj) => obj is MultiplyDefinedElement, MultiplyDefinedElement, result); |
3976 List<Element> elements = | 4008 List<Element> elements = |
3977 (result as MultiplyDefinedElement).conflictingElements; | 4009 (result as MultiplyDefinedElement).conflictingElements; |
3978 expect(elements, hasLength(3)); | 4010 expect(elements, hasLength(3)); |
3979 for (int i = 0; i < elements.length; i++) { | 4011 for (int i = 0; i < elements.length; i++) { |
3980 EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement, | 4012 EngineTestCase.assertInstanceOf((obj) => obj is LocalVariableElement, |
3981 LocalVariableElement, elements[i]); | 4013 LocalVariableElement, elements[i]); |
3982 } | 4014 } |
3983 } | 4015 } |
3984 | 4016 |
3985 void test_fromElements_nonConflicting() { | 4017 void test_fromElements_nonConflicting() { |
3986 Element element = ElementFactory.localVariableElement2("xx"); | 4018 Element element = ElementFactory.localVariableElement2("xx"); |
3987 expect(MultiplyDefinedElementImpl.fromElements(null, element, element), | 4019 expect(MultiplyDefinedElementImpl.fromElements(null, element, element), |
3988 same(element)); | 4020 same(element)); |
3989 } | 4021 } |
3990 } | 4022 } |
3991 | 4023 |
3992 @reflectiveTest | 4024 @reflectiveTest |
3993 class ParameterElementImplTest extends EngineTestCase { | 4025 class ParameterElementImplTest extends EngineTestCase { |
3994 void test_computeNode_DefaultFormalParameter() { | 4026 void test_computeNode_DefaultFormalParameter() { |
3995 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 4027 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
3996 AnalysisContext context = contextHelper.context; | 4028 AnalysisContext context = contextHelper.context; |
3997 Source source = contextHelper.addSource("/test.dart", r''' | 4029 Source source = contextHelper.addSource( |
| 4030 "/test.dart", |
| 4031 r''' |
3998 main([int p = 42]) { | 4032 main([int p = 42]) { |
3999 }'''); | 4033 }'''); |
4000 // prepare CompilationUnitElement | 4034 // prepare CompilationUnitElement |
4001 LibraryElement libraryElement = context.computeLibraryElement(source); | 4035 LibraryElement libraryElement = context.computeLibraryElement(source); |
4002 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 4036 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
4003 // p | 4037 // p |
4004 { | 4038 { |
4005 ParameterElement element = unitElement.functions[0].parameters[0]; | 4039 ParameterElement element = unitElement.functions[0].parameters[0]; |
4006 DefaultFormalParameter node = element.computeNode(); | 4040 DefaultFormalParameter node = element.computeNode(); |
4007 expect(node, isNotNull); | 4041 expect(node, isNotNull); |
4008 expect(node.identifier.name, 'p'); | 4042 expect(node.identifier.name, 'p'); |
4009 expect(node.element, same(element)); | 4043 expect(node.element, same(element)); |
4010 } | 4044 } |
4011 } | 4045 } |
4012 | 4046 |
4013 void test_computeNode_FieldFormalParameter() { | 4047 void test_computeNode_FieldFormalParameter() { |
4014 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 4048 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
4015 AnalysisContext context = contextHelper.context; | 4049 AnalysisContext context = contextHelper.context; |
4016 Source source = contextHelper.addSource("/test.dart", r''' | 4050 Source source = contextHelper.addSource( |
| 4051 "/test.dart", |
| 4052 r''' |
4017 class A { | 4053 class A { |
4018 int p; | 4054 int p; |
4019 A(this.p) { | 4055 A(this.p) { |
4020 } | 4056 } |
4021 }'''); | 4057 }'''); |
4022 // prepare CompilationUnitElement | 4058 // prepare CompilationUnitElement |
4023 LibraryElement libraryElement = context.computeLibraryElement(source); | 4059 LibraryElement libraryElement = context.computeLibraryElement(source); |
4024 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 4060 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
4025 // p | 4061 // p |
4026 { | 4062 { |
4027 ClassElement classA = unitElement.types[0]; | 4063 ClassElement classA = unitElement.types[0]; |
4028 ConstructorElement constructorA = classA.constructors[0]; | 4064 ConstructorElement constructorA = classA.constructors[0]; |
4029 FieldFormalParameterElement element = constructorA.parameters[0]; | 4065 FieldFormalParameterElement element = constructorA.parameters[0]; |
4030 FieldFormalParameter node = element.computeNode(); | 4066 FieldFormalParameter node = element.computeNode(); |
4031 expect(node, isNotNull); | 4067 expect(node, isNotNull); |
4032 expect(node.identifier.name, 'p'); | 4068 expect(node.identifier.name, 'p'); |
4033 expect(node.element, same(element)); | 4069 expect(node.element, same(element)); |
4034 } | 4070 } |
4035 } | 4071 } |
4036 | 4072 |
4037 void test_computeNode_FunctionTypedFormalParameter() { | 4073 void test_computeNode_FunctionTypedFormalParameter() { |
4038 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 4074 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
4039 AnalysisContext context = contextHelper.context; | 4075 AnalysisContext context = contextHelper.context; |
4040 Source source = contextHelper.addSource("/test.dart", r''' | 4076 Source source = contextHelper.addSource( |
| 4077 "/test.dart", |
| 4078 r''' |
4041 main(p(int a, int b)) { | 4079 main(p(int a, int b)) { |
4042 }'''); | 4080 }'''); |
4043 // prepare CompilationUnitElement | 4081 // prepare CompilationUnitElement |
4044 LibraryElement libraryElement = context.computeLibraryElement(source); | 4082 LibraryElement libraryElement = context.computeLibraryElement(source); |
4045 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 4083 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
4046 // p | 4084 // p |
4047 { | 4085 { |
4048 ParameterElement element = unitElement.functions[0].parameters[0]; | 4086 ParameterElement element = unitElement.functions[0].parameters[0]; |
4049 FunctionTypedFormalParameter node = element.computeNode(); | 4087 FunctionTypedFormalParameter node = element.computeNode(); |
4050 expect(node, isNotNull); | 4088 expect(node, isNotNull); |
4051 expect(node.identifier.name, 'p'); | 4089 expect(node.identifier.name, 'p'); |
4052 expect(node.element, same(element)); | 4090 expect(node.element, same(element)); |
4053 } | 4091 } |
4054 } | 4092 } |
4055 | 4093 |
4056 void test_computeNode_SimpleFormalParameter() { | 4094 void test_computeNode_SimpleFormalParameter() { |
4057 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); | 4095 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); |
4058 AnalysisContext context = contextHelper.context; | 4096 AnalysisContext context = contextHelper.context; |
4059 Source source = contextHelper.addSource("/test.dart", r''' | 4097 Source source = contextHelper.addSource( |
| 4098 "/test.dart", |
| 4099 r''' |
4060 main(int p) { | 4100 main(int p) { |
4061 }'''); | 4101 }'''); |
4062 // prepare CompilationUnitElement | 4102 // prepare CompilationUnitElement |
4063 LibraryElement libraryElement = context.computeLibraryElement(source); | 4103 LibraryElement libraryElement = context.computeLibraryElement(source); |
4064 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; | 4104 CompilationUnitElement unitElement = libraryElement.definingCompilationUnit; |
4065 // p | 4105 // p |
4066 { | 4106 { |
4067 ParameterElement element = unitElement.functions[0].parameters[0]; | 4107 ParameterElement element = unitElement.functions[0].parameters[0]; |
4068 SimpleFormalParameter node = element.computeNode(); | 4108 SimpleFormalParameter node = element.computeNode(); |
4069 expect(node, isNotNull); | 4109 expect(node, isNotNull); |
4070 expect(node.identifier.name, 'p'); | 4110 expect(node.identifier.name, 'p'); |
4071 expect(node.element, same(element)); | 4111 expect(node.element, same(element)); |
4072 } | 4112 } |
4073 } | 4113 } |
4074 } | 4114 } |
4075 | 4115 |
4076 @reflectiveTest | 4116 @reflectiveTest |
4077 class TypeParameterTypeImplTest extends EngineTestCase { | 4117 class TypeParameterTypeImplTest extends EngineTestCase { |
4078 void test_creation() { | 4118 void test_creation() { |
4079 expect(new TypeParameterTypeImpl( | 4119 expect( |
| 4120 new TypeParameterTypeImpl( |
4080 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"))), | 4121 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E"))), |
4081 isNotNull); | 4122 isNotNull); |
4082 } | 4123 } |
4083 | 4124 |
4084 void test_getElement() { | 4125 void test_getElement() { |
4085 TypeParameterElementImpl element = | 4126 TypeParameterElementImpl element = |
4086 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")); | 4127 new TypeParameterElementImpl.forNode(AstFactory.identifier3("E")); |
4087 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); | 4128 TypeParameterTypeImpl type = new TypeParameterTypeImpl(element); |
4088 expect(type.element, element); | 4129 expect(type.element, element); |
4089 } | 4130 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4238 } | 4279 } |
4239 | 4280 |
4240 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction | 4281 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction |
4241 extends InterfaceTypeImpl { | 4282 extends InterfaceTypeImpl { |
4242 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) | 4283 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) |
4243 : super(arg0); | 4284 : super(arg0); |
4244 | 4285 |
4245 @override | 4286 @override |
4246 bool get isDartCoreFunction => true; | 4287 bool get isDartCoreFunction => true; |
4247 } | 4288 } |
OLD | NEW |