OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:kernel/ast.dart'; | 5 import 'package:kernel/ast.dart'; |
6 import 'package:kernel/class_hierarchy.dart'; | 6 import 'package:kernel/class_hierarchy.dart'; |
7 import 'package:kernel/core_types.dart'; | 7 import 'package:kernel/core_types.dart'; |
8 import 'package:kernel/src/incremental_class_hierarchy.dart'; | 8 import 'package:kernel/src/incremental_class_hierarchy.dart'; |
9 import 'package:kernel/testing/mock_sdk_program.dart'; | 9 import 'package:kernel/testing/mock_sdk_program.dart'; |
10 import 'package:kernel/text/ast_to_text.dart'; | 10 import 'package:kernel/text/ast_to_text.dart'; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 /// [implements_] the given classes. | 122 /// [implements_] the given classes. |
123 Class addImplementsClass(String name, List<Class> implements_) { | 123 Class addImplementsClass(String name, List<Class> implements_) { |
124 return addClass(new Class( | 124 return addClass(new Class( |
125 name: name, | 125 name: name, |
126 supertype: objectSuper, | 126 supertype: objectSuper, |
127 implementedTypes: implements_.map((c) => c.asThisSupertype).toList())); | 127 implementedTypes: implements_.map((c) => c.asThisSupertype).toList())); |
128 } | 128 } |
129 | 129 |
130 ClassHierarchy createClassHierarchy(Program program); | 130 ClassHierarchy createClassHierarchy(Program program); |
131 | 131 |
132 Procedure newEmptyGetter(String name, | |
133 {DartType returnType: const DynamicType()}) { | |
134 var body = new Block([new ReturnStatement(new NullLiteral())]); | |
135 return new Procedure(new Name(name), ProcedureKind.Getter, | |
136 new FunctionNode(body, returnType: returnType)); | |
137 } | |
138 | |
132 Procedure newEmptyMethod(String name, {bool isAbstract: false}) { | 139 Procedure newEmptyMethod(String name, {bool isAbstract: false}) { |
133 var body = isAbstract ? null : new Block([]); | 140 var body = isAbstract ? null : new Block([]); |
134 return new Procedure(new Name(name), ProcedureKind.Method, | 141 return new Procedure(new Name(name), ProcedureKind.Method, |
135 new FunctionNode(body, returnType: const VoidType()), | 142 new FunctionNode(body, returnType: const VoidType()), |
136 isAbstract: isAbstract); | 143 isAbstract: isAbstract); |
137 } | 144 } |
138 | 145 |
139 Procedure newEmptySetter(String name, {bool abstract: false}) { | 146 Procedure newEmptySetter(String name, |
147 {bool abstract: false, DartType type: const DynamicType()}) { | |
140 var body = abstract ? null : new Block([]); | 148 var body = abstract ? null : new Block([]); |
141 return new Procedure( | 149 return new Procedure( |
142 new Name(name), | 150 new Name(name), |
143 ProcedureKind.Setter, | 151 ProcedureKind.Setter, |
144 new FunctionNode(body, | 152 new FunctionNode(body, |
145 returnType: const VoidType(), | 153 returnType: const VoidType(), |
146 positionalParameters: [new VariableDeclaration('_')])); | 154 positionalParameters: [new VariableDeclaration('_', type: type)])); |
147 } | 155 } |
148 | 156 |
149 void setUp() { | 157 void setUp() { |
150 // Start with mock SDK libraries. | 158 // Start with mock SDK libraries. |
151 program = createMockSdkProgram(); | 159 program = createMockSdkProgram(); |
152 coreTypes = new CoreTypes(program); | 160 coreTypes = new CoreTypes(program); |
153 | 161 |
154 // Add the test library. | 162 // Add the test library. |
155 library = new Library(Uri.parse('org-dartlang:///test.dart'), name: 'test'); | 163 library = new Library(Uri.parse('org-dartlang:///test.dart'), name: 'test'); |
156 library.parent = program; | 164 library.parent = program; |
157 program.libraries.add(library); | 165 program.libraries.add(library); |
158 } | 166 } |
159 | 167 |
168 void test_forEachOverridePair_crossGetterSetter_super() { | |
169 var int = coreTypes.intClass.rawType; | |
170 var a = addClass(new Class(name: 'A', supertype: objectSuper, procedures: [ | |
171 newEmptySetter('foo', type: int), | |
172 newEmptyGetter('bar', returnType: int) | |
173 ])); | |
174 var b = addClass(new Class( | |
175 name: 'B', | |
176 supertype: a.asThisSupertype, | |
177 procedures: [newEmptyGetter('foo'), newEmptySetter('bar')])); | |
178 | |
179 _assertTestLibraryText(''' | |
180 class A { | |
181 set foo(core::int _) → void {} | |
182 get bar() → core::int { | |
183 return null; | |
184 } | |
185 } | |
186 class B extends self::A { | |
187 get foo() → dynamic { | |
188 return null; | |
189 } | |
190 set bar(dynamic _) → void {} | |
191 } | |
192 '''); | |
193 | |
194 _assertOverridePairs(b, [ | |
195 'test::B::foo overrides test::A::foo=', | |
196 'test::B::bar= overrides test::A::bar' | |
197 ]); | |
Paul Berry
2017/06/16 22:05:11
We should also test that if `crossGettersSetters:
| |
198 } | |
199 | |
160 /// 2. A non-abstract member is inherited from a superclass, and in the | 200 /// 2. A non-abstract member is inherited from a superclass, and in the |
161 /// context of this class, it overrides an abstract member inheritable through | 201 /// context of this class, it overrides an abstract member inheritable through |
162 /// one of its superinterfaces. | 202 /// one of its superinterfaces. |
163 void test_forEachOverridePair_supertypeOverridesInterface() { | 203 void test_forEachOverridePair_supertypeOverridesInterface() { |
164 var a = addClass(new Class( | 204 var a = addClass(new Class( |
165 name: 'A', | 205 name: 'A', |
166 supertype: objectSuper, | 206 supertype: objectSuper, |
167 procedures: [newEmptyMethod('foo'), newEmptyMethod('bar')])); | 207 procedures: [newEmptyMethod('foo'), newEmptyMethod('bar')])); |
168 var b = addClass(new Class( | 208 var b = addClass(new Class( |
169 name: 'B', | 209 name: 'B', |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 var b_int = new InterfaceType(b, [int]); | 938 var b_int = new InterfaceType(b, [int]); |
899 expect(hierarchy.getTypeAsInstanceOf(b_int, a), | 939 expect(hierarchy.getTypeAsInstanceOf(b_int, a), |
900 new InterfaceType(a, [int, bool])); | 940 new InterfaceType(a, [int, bool])); |
901 expect(hierarchy.getTypeAsInstanceOf(b_int, objectClass), | 941 expect(hierarchy.getTypeAsInstanceOf(b_int, objectClass), |
902 new InterfaceType(objectClass)); | 942 new InterfaceType(objectClass)); |
903 } | 943 } |
904 | 944 |
905 void _assertOverridePairs(Class class_, List<String> expected) { | 945 void _assertOverridePairs(Class class_, List<String> expected) { |
906 List<String> overrideDescriptions = []; | 946 List<String> overrideDescriptions = []; |
907 hierarchy.forEachOverridePair(class_, | 947 hierarchy.forEachOverridePair(class_, |
908 (Member declaredMember, Member interfaceMember, bool isSetter) { | 948 (Member declaredMember, Member interfaceMember, bool isSetter_) { |
Paul Berry
2017/06/16 22:05:11
We are no longer checking that forEachOverridePair
scheglov
2017/06/16 23:49:41
Done.
| |
909 String declaredName = '$declaredMember${isSetter ? '=': ''}'; | 949 String declaredSuffix = _isSetter(declaredMember) ? '=' : ''; |
910 String interfaceName = '$interfaceMember${isSetter ? '=': ''}'; | 950 String interfaceSuffix = _isSetter(interfaceMember) ? '=' : ''; |
951 String declaredName = '$declaredMember$declaredSuffix'; | |
952 String interfaceName = '$interfaceMember$interfaceSuffix'; | |
911 var desc = '$declaredName overrides $interfaceName'; | 953 var desc = '$declaredName overrides $interfaceName'; |
912 overrideDescriptions.add(desc); | 954 overrideDescriptions.add(desc); |
913 }); | 955 }, crossGettersSetters: true); |
914 expect(overrideDescriptions, unorderedEquals(expected)); | 956 expect(overrideDescriptions, unorderedEquals(expected)); |
915 } | 957 } |
916 | 958 |
917 /// Assert that the test [library] has the [expectedText] presentation. | 959 /// Assert that the test [library] has the [expectedText] presentation. |
918 /// The presentation is close, but not identical to the normal Kernel one. | 960 /// The presentation is close, but not identical to the normal Kernel one. |
919 void _assertTestLibraryText(String expectedText) { | 961 void _assertTestLibraryText(String expectedText) { |
920 StringBuffer sb = new StringBuffer(); | 962 StringBuffer sb = new StringBuffer(); |
921 Printer printer = new Printer(sb); | 963 Printer printer = new Printer(sb); |
922 printer.writeLibraryFile(library); | 964 printer.writeLibraryFile(library); |
923 | 965 |
(...skipping 12 matching lines...) Expand all Loading... | |
936 actualText = actualText.replaceAll('{\n}', '{}'); | 978 actualText = actualText.replaceAll('{\n}', '{}'); |
937 actualText = actualText.replaceAll(' extends core::Object', ''); | 979 actualText = actualText.replaceAll(' extends core::Object', ''); |
938 | 980 |
939 // if (actualText != expectedText) { | 981 // if (actualText != expectedText) { |
940 // print('-------- Actual --------'); | 982 // print('-------- Actual --------'); |
941 // print(actualText + '------------------------'); | 983 // print(actualText + '------------------------'); |
942 // } | 984 // } |
943 | 985 |
944 expect(actualText, expectedText); | 986 expect(actualText, expectedText); |
945 } | 987 } |
988 | |
989 static bool _isSetter(Member member) { | |
990 return member is Procedure && member.kind == ProcedureKind.Setter; | |
991 } | |
946 } | 992 } |
OLD | NEW |