| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library analyzer.test.generated.inheritance_manager_test; |
| 6 |
| 7 import 'dart:collection'; |
| 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; |
| 15 import 'package:analyzer/src/error/codes.dart'; |
| 16 import 'package:analyzer/src/generated/engine.dart'; |
| 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 18 import 'package:analyzer/src/generated/source_io.dart'; |
| 19 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 20 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 21 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 22 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 23 import 'package:analyzer/src/source/source_resource.dart'; |
| 24 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 25 import 'package:unittest/unittest.dart'; |
| 26 |
| 27 import '../utils.dart'; |
| 28 import 'analysis_context_factory.dart'; |
| 29 import 'test_support.dart'; |
| 30 |
| 31 main() { |
| 32 initializeTestEnvironment(); |
| 33 defineReflectiveTests(InheritanceManagerTest); |
| 34 } |
| 35 |
| 36 @reflectiveTest |
| 37 class InheritanceManagerTest { |
| 38 /** |
| 39 * The type provider used to access the types. |
| 40 */ |
| 41 TestTypeProvider _typeProvider; |
| 42 |
| 43 /** |
| 44 * The library containing the code being resolved. |
| 45 */ |
| 46 LibraryElementImpl _definingLibrary; |
| 47 |
| 48 /** |
| 49 * The inheritance manager being tested. |
| 50 */ |
| 51 InheritanceManager _inheritanceManager; |
| 52 |
| 53 /** |
| 54 * The number of members that Object implements (as determined by [TestTypePro
vider]). |
| 55 */ |
| 56 int _numOfMembersInObject = 0; |
| 57 |
| 58 void setUp() { |
| 59 _typeProvider = new TestTypeProvider(); |
| 60 _inheritanceManager = _createInheritanceManager(); |
| 61 InterfaceType objectType = _typeProvider.objectType; |
| 62 _numOfMembersInObject = |
| 63 objectType.methods.length + objectType.accessors.length; |
| 64 } |
| 65 |
| 66 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { |
| 67 // class A { int get g; } |
| 68 // class B extends A {} |
| 69 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 70 String getterName = "g"; |
| 71 PropertyAccessorElement getterG = |
| 72 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 73 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 74 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 75 Map<String, ExecutableElement> mapB = |
| 76 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 77 Map<String, ExecutableElement> mapA = |
| 78 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 79 expect(mapA.length, _numOfMembersInObject); |
| 80 expect(mapB.length, _numOfMembersInObject + 1); |
| 81 expect(mapB[getterName], same(getterG)); |
| 82 _assertNoErrors(classA); |
| 83 _assertNoErrors(classB); |
| 84 } |
| 85 |
| 86 void test_getMapOfMembersInheritedFromClasses_accessor_implements() { |
| 87 // class A { int get g; } |
| 88 // class B implements A {} |
| 89 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 90 String getterName = "g"; |
| 91 PropertyAccessorElement getterG = |
| 92 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 93 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 94 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 95 classB.interfaces = <InterfaceType>[classA.type]; |
| 96 Map<String, ExecutableElement> mapB = |
| 97 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 98 Map<String, ExecutableElement> mapA = |
| 99 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 100 expect(mapA.length, _numOfMembersInObject); |
| 101 expect(mapB.length, _numOfMembersInObject); |
| 102 expect(mapB[getterName], isNull); |
| 103 _assertNoErrors(classA); |
| 104 _assertNoErrors(classB); |
| 105 } |
| 106 |
| 107 void test_getMapOfMembersInheritedFromClasses_accessor_with() { |
| 108 // class A { int get g; } |
| 109 // class B extends Object with A {} |
| 110 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 111 String getterName = "g"; |
| 112 PropertyAccessorElement getterG = |
| 113 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 114 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 115 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 116 classB.mixins = <InterfaceType>[classA.type]; |
| 117 Map<String, ExecutableElement> mapB = |
| 118 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 119 Map<String, ExecutableElement> mapA = |
| 120 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 121 expect(mapA.length, _numOfMembersInObject); |
| 122 expect(mapB.length, _numOfMembersInObject + 1); |
| 123 expect(mapB[getterName], same(getterG)); |
| 124 _assertNoErrors(classA); |
| 125 _assertNoErrors(classB); |
| 126 } |
| 127 |
| 128 void test_getMapOfMembersInheritedFromClasses_implicitExtends() { |
| 129 // class A {} |
| 130 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 131 Map<String, ExecutableElement> mapA = |
| 132 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 133 expect(mapA.length, _numOfMembersInObject); |
| 134 _assertNoErrors(classA); |
| 135 } |
| 136 |
| 137 void test_getMapOfMembersInheritedFromClasses_method_extends() { |
| 138 // class A { int g(); } |
| 139 // class B extends A {} |
| 140 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 141 String methodName = "m"; |
| 142 MethodElement methodM = |
| 143 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 144 classA.methods = <MethodElement>[methodM]; |
| 145 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 146 classB.supertype = classA.type; |
| 147 Map<String, ExecutableElement> mapB = |
| 148 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 149 Map<String, ExecutableElement> mapA = |
| 150 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 151 expect(mapA.length, _numOfMembersInObject); |
| 152 expect(mapB.length, _numOfMembersInObject + 1); |
| 153 expect(mapB[methodName], same(methodM)); |
| 154 _assertNoErrors(classA); |
| 155 _assertNoErrors(classB); |
| 156 } |
| 157 |
| 158 void test_getMapOfMembersInheritedFromClasses_method_implements() { |
| 159 // class A { int g(); } |
| 160 // class B implements A {} |
| 161 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 162 String methodName = "m"; |
| 163 MethodElement methodM = |
| 164 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 165 classA.methods = <MethodElement>[methodM]; |
| 166 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 167 classB.interfaces = <InterfaceType>[classA.type]; |
| 168 Map<String, ExecutableElement> mapB = |
| 169 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 170 Map<String, ExecutableElement> mapA = |
| 171 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 172 expect(mapA.length, _numOfMembersInObject); |
| 173 expect(mapB.length, _numOfMembersInObject); |
| 174 expect(mapB[methodName], isNull); |
| 175 _assertNoErrors(classA); |
| 176 _assertNoErrors(classB); |
| 177 } |
| 178 |
| 179 void test_getMapOfMembersInheritedFromClasses_method_with() { |
| 180 // class A { int g(); } |
| 181 // class B extends Object with A {} |
| 182 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 183 String methodName = "m"; |
| 184 MethodElement methodM = |
| 185 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 186 classA.methods = <MethodElement>[methodM]; |
| 187 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 188 classB.mixins = <InterfaceType>[classA.type]; |
| 189 Map<String, ExecutableElement> mapB = |
| 190 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 191 Map<String, ExecutableElement> mapA = |
| 192 _inheritanceManager.getMembersInheritedFromClasses(classA); |
| 193 expect(mapA.length, _numOfMembersInObject); |
| 194 expect(mapB.length, _numOfMembersInObject + 1); |
| 195 expect(mapB[methodName], same(methodM)); |
| 196 _assertNoErrors(classA); |
| 197 _assertNoErrors(classB); |
| 198 } |
| 199 |
| 200 void test_getMapOfMembersInheritedFromClasses_method_with_two_mixins() { |
| 201 // class A1 { int m(); } |
| 202 // class A2 { int m(); } |
| 203 // class B extends Object with A1, A2 {} |
| 204 ClassElementImpl classA1 = ElementFactory.classElement2("A1"); |
| 205 String methodName = "m"; |
| 206 MethodElement methodA1M = |
| 207 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 208 classA1.methods = <MethodElement>[methodA1M]; |
| 209 ClassElementImpl classA2 = ElementFactory.classElement2("A2"); |
| 210 MethodElement methodA2M = |
| 211 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 212 classA2.methods = <MethodElement>[methodA2M]; |
| 213 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 214 classB.mixins = <InterfaceType>[classA1.type, classA2.type]; |
| 215 Map<String, ExecutableElement> mapB = |
| 216 _inheritanceManager.getMembersInheritedFromClasses(classB); |
| 217 expect(mapB[methodName], same(methodA2M)); |
| 218 _assertNoErrors(classA1); |
| 219 _assertNoErrors(classA2); |
| 220 _assertNoErrors(classB); |
| 221 } |
| 222 |
| 223 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() { |
| 224 // class A { int get g; } |
| 225 // class B extends A {} |
| 226 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 227 String getterName = "g"; |
| 228 PropertyAccessorElement getterG = |
| 229 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 230 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 231 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 232 Map<String, ExecutableElement> mapB = |
| 233 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 234 Map<String, ExecutableElement> mapA = |
| 235 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 236 expect(mapA.length, _numOfMembersInObject); |
| 237 expect(mapB.length, _numOfMembersInObject + 1); |
| 238 expect(mapB[getterName], same(getterG)); |
| 239 _assertNoErrors(classA); |
| 240 _assertNoErrors(classB); |
| 241 } |
| 242 |
| 243 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() { |
| 244 // class A { int get g; } |
| 245 // class B implements A {} |
| 246 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 247 String getterName = "g"; |
| 248 PropertyAccessorElement getterG = |
| 249 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 250 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 251 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 252 classB.interfaces = <InterfaceType>[classA.type]; |
| 253 Map<String, ExecutableElement> mapB = |
| 254 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 255 Map<String, ExecutableElement> mapA = |
| 256 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 257 expect(mapA.length, _numOfMembersInObject); |
| 258 expect(mapB.length, _numOfMembersInObject + 1); |
| 259 expect(mapB[getterName], same(getterG)); |
| 260 _assertNoErrors(classA); |
| 261 _assertNoErrors(classB); |
| 262 } |
| 263 |
| 264 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() { |
| 265 // class A { int get g; } |
| 266 // class B extends Object with A {} |
| 267 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 268 String getterName = "g"; |
| 269 PropertyAccessorElement getterG = |
| 270 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 271 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 272 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 273 classB.mixins = <InterfaceType>[classA.type]; |
| 274 Map<String, ExecutableElement> mapB = |
| 275 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 276 Map<String, ExecutableElement> mapA = |
| 277 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 278 expect(mapA.length, _numOfMembersInObject); |
| 279 expect(mapB.length, _numOfMembersInObject + 1); |
| 280 expect(mapB[getterName], same(getterG)); |
| 281 _assertNoErrors(classA); |
| 282 _assertNoErrors(classB); |
| 283 } |
| 284 |
| 285 void test_getMapOfMembersInheritedFromInterfaces_field_indirectWith() { |
| 286 // class A { int f; } |
| 287 // class B extends A {} |
| 288 // class C extends Object with B {} |
| 289 ClassElementImpl classA = ElementFactory.classElement2('A'); |
| 290 String fieldName = "f"; |
| 291 FieldElement fieldF = ElementFactory.fieldElement( |
| 292 fieldName, false, false, false, _typeProvider.intType); |
| 293 classA.fields = <FieldElement>[fieldF]; |
| 294 classA.accessors = <PropertyAccessorElement>[fieldF.getter, fieldF.setter]; |
| 295 |
| 296 ClassElementImpl classB = ElementFactory.classElement('B', classA.type); |
| 297 |
| 298 ClassElementImpl classC = ElementFactory.classElement2('C'); |
| 299 classC.mixins = <InterfaceType>[classB.type]; |
| 300 |
| 301 Map<String, ExecutableElement> mapC = |
| 302 _inheritanceManager.getMembersInheritedFromInterfaces(classC); |
| 303 expect(mapC, hasLength(_numOfMembersInObject + 2)); |
| 304 expect(mapC[fieldName], same(fieldF.getter)); |
| 305 expect(mapC['$fieldName='], same(fieldF.setter)); |
| 306 _assertNoErrors(classA); |
| 307 _assertNoErrors(classB); |
| 308 _assertNoErrors(classC); |
| 309 } |
| 310 |
| 311 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() { |
| 312 // class A {} |
| 313 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 314 Map<String, ExecutableElement> mapA = |
| 315 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 316 expect(mapA.length, _numOfMembersInObject); |
| 317 _assertNoErrors(classA); |
| 318 } |
| 319 |
| 320 void |
| 321 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_
getter_method() { |
| 322 // class I1 { int m(); } |
| 323 // class I2 { int get m; } |
| 324 // class A implements I2, I1 {} |
| 325 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 326 String methodName = "m"; |
| 327 MethodElement methodM = |
| 328 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 329 classI1.methods = <MethodElement>[methodM]; |
| 330 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 331 PropertyAccessorElement getter = |
| 332 ElementFactory.getterElement(methodName, false, _typeProvider.intType); |
| 333 classI2.accessors = <PropertyAccessorElement>[getter]; |
| 334 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 335 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; |
| 336 Map<String, ExecutableElement> mapA = |
| 337 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 338 expect(mapA.length, _numOfMembersInObject); |
| 339 expect(mapA[methodName], isNull); |
| 340 _assertErrors(classA, |
| 341 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); |
| 342 } |
| 343 |
| 344 void |
| 345 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_
int_str() { |
| 346 // class I1 { int m(); } |
| 347 // class I2 { String m(); } |
| 348 // class A implements I1, I2 {} |
| 349 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 350 String methodName = "m"; |
| 351 MethodElement methodM1 = |
| 352 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); |
| 353 classI1.methods = <MethodElement>[methodM1]; |
| 354 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 355 MethodElement methodM2 = ElementFactory |
| 356 .methodElement(methodName, null, [_typeProvider.stringType]); |
| 357 classI2.methods = <MethodElement>[methodM2]; |
| 358 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 359 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 360 Map<String, ExecutableElement> mapA = |
| 361 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 362 expect(mapA.length, _numOfMembersInObject); |
| 363 expect(mapA[methodName], isNull); |
| 364 _assertErrors( |
| 365 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
| 366 } |
| 367 |
| 368 void |
| 369 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_
method_getter() { |
| 370 // class I1 { int m(); } |
| 371 // class I2 { int get m; } |
| 372 // class A implements I1, I2 {} |
| 373 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 374 String methodName = "m"; |
| 375 MethodElement methodM = |
| 376 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 377 classI1.methods = <MethodElement>[methodM]; |
| 378 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 379 PropertyAccessorElement getter = |
| 380 ElementFactory.getterElement(methodName, false, _typeProvider.intType); |
| 381 classI2.accessors = <PropertyAccessorElement>[getter]; |
| 382 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 383 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 384 Map<String, ExecutableElement> mapA = |
| 385 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 386 expect(mapA.length, _numOfMembersInObject); |
| 387 expect(mapA[methodName], isNull); |
| 388 _assertErrors(classA, |
| 389 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]); |
| 390 } |
| 391 |
| 392 void |
| 393 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_
numOfRequiredParams() { |
| 394 // class I1 { dynamic m(int, [int]); } |
| 395 // class I2 { dynamic m(int, int, int); } |
| 396 // class A implements I1, I2 {} |
| 397 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 398 String methodName = "m"; |
| 399 MethodElementImpl methodM1 = |
| 400 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 401 ParameterElementImpl parameter1 = |
| 402 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); |
| 403 parameter1.type = _typeProvider.intType; |
| 404 parameter1.parameterKind = ParameterKind.REQUIRED; |
| 405 ParameterElementImpl parameter2 = |
| 406 new ParameterElementImpl.forNode(AstFactory.identifier3("a2")); |
| 407 parameter2.type = _typeProvider.intType; |
| 408 parameter2.parameterKind = ParameterKind.POSITIONAL; |
| 409 methodM1.parameters = <ParameterElement>[parameter1, parameter2]; |
| 410 classI1.methods = <MethodElement>[methodM1]; |
| 411 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 412 MethodElementImpl methodM2 = |
| 413 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 414 ParameterElementImpl parameter3 = |
| 415 new ParameterElementImpl.forNode(AstFactory.identifier3("a3")); |
| 416 parameter3.type = _typeProvider.intType; |
| 417 parameter3.parameterKind = ParameterKind.REQUIRED; |
| 418 ParameterElementImpl parameter4 = |
| 419 new ParameterElementImpl.forNode(AstFactory.identifier3("a4")); |
| 420 parameter4.type = _typeProvider.intType; |
| 421 parameter4.parameterKind = ParameterKind.REQUIRED; |
| 422 ParameterElementImpl parameter5 = |
| 423 new ParameterElementImpl.forNode(AstFactory.identifier3("a5")); |
| 424 parameter5.type = _typeProvider.intType; |
| 425 parameter5.parameterKind = ParameterKind.REQUIRED; |
| 426 methodM2.parameters = <ParameterElement>[ |
| 427 parameter3, |
| 428 parameter4, |
| 429 parameter5 |
| 430 ]; |
| 431 classI2.methods = <MethodElement>[methodM2]; |
| 432 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 433 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 434 Map<String, ExecutableElement> mapA = |
| 435 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 436 expect(mapA.length, _numOfMembersInObject); |
| 437 expect(mapA[methodName], isNull); |
| 438 _assertErrors( |
| 439 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
| 440 } |
| 441 |
| 442 void |
| 443 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_
str_int() { |
| 444 // class I1 { int m(); } |
| 445 // class I2 { String m(); } |
| 446 // class A implements I2, I1 {} |
| 447 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 448 String methodName = "m"; |
| 449 MethodElement methodM1 = ElementFactory |
| 450 .methodElement(methodName, null, [_typeProvider.stringType]); |
| 451 classI1.methods = <MethodElement>[methodM1]; |
| 452 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 453 MethodElement methodM2 = |
| 454 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]); |
| 455 classI2.methods = <MethodElement>[methodM2]; |
| 456 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 457 classA.interfaces = <InterfaceType>[classI2.type, classI1.type]; |
| 458 Map<String, ExecutableElement> mapA = |
| 459 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 460 expect(mapA.length, _numOfMembersInObject); |
| 461 expect(mapA[methodName], isNull); |
| 462 _assertErrors( |
| 463 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]); |
| 464 } |
| 465 |
| 466 void test_getMapOfMembersInheritedFromInterfaces_method_extends() { |
| 467 // class A { int g(); } |
| 468 // class B extends A {} |
| 469 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 470 String methodName = "m"; |
| 471 MethodElement methodM = |
| 472 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 473 classA.methods = <MethodElement>[methodM]; |
| 474 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 475 Map<String, ExecutableElement> mapB = |
| 476 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 477 Map<String, ExecutableElement> mapA = |
| 478 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 479 expect(mapA.length, _numOfMembersInObject); |
| 480 expect(mapB.length, _numOfMembersInObject + 1); |
| 481 expect(mapB[methodName], same(methodM)); |
| 482 _assertNoErrors(classA); |
| 483 _assertNoErrors(classB); |
| 484 } |
| 485 |
| 486 void test_getMapOfMembersInheritedFromInterfaces_method_implements() { |
| 487 // class A { int g(); } |
| 488 // class B implements A {} |
| 489 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 490 String methodName = "m"; |
| 491 MethodElement methodM = |
| 492 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 493 classA.methods = <MethodElement>[methodM]; |
| 494 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 495 classB.interfaces = <InterfaceType>[classA.type]; |
| 496 Map<String, ExecutableElement> mapB = |
| 497 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 498 Map<String, ExecutableElement> mapA = |
| 499 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 500 expect(mapA.length, _numOfMembersInObject); |
| 501 expect(mapB.length, _numOfMembersInObject + 1); |
| 502 expect(mapB[methodName], same(methodM)); |
| 503 _assertNoErrors(classA); |
| 504 _assertNoErrors(classB); |
| 505 } |
| 506 |
| 507 void test_getMapOfMembersInheritedFromInterfaces_method_with() { |
| 508 // class A { int g(); } |
| 509 // class B extends Object with A {} |
| 510 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 511 String methodName = "m"; |
| 512 MethodElement methodM = |
| 513 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 514 classA.methods = <MethodElement>[methodM]; |
| 515 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 516 classB.mixins = <InterfaceType>[classA.type]; |
| 517 Map<String, ExecutableElement> mapB = |
| 518 _inheritanceManager.getMembersInheritedFromInterfaces(classB); |
| 519 Map<String, ExecutableElement> mapA = |
| 520 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 521 expect(mapA.length, _numOfMembersInObject); |
| 522 expect(mapB.length, _numOfMembersInObject + 1); |
| 523 expect(mapB[methodName], same(methodM)); |
| 524 _assertNoErrors(classA); |
| 525 _assertNoErrors(classB); |
| 526 } |
| 527 |
| 528 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() { |
| 529 // class I1 { int m1(); } |
| 530 // class I2 { int m2(); } |
| 531 // class A implements I1, I2 {} |
| 532 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 533 String methodName1 = "m1"; |
| 534 MethodElement methodM1 = |
| 535 ElementFactory.methodElement(methodName1, _typeProvider.intType); |
| 536 classI1.methods = <MethodElement>[methodM1]; |
| 537 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 538 String methodName2 = "m2"; |
| 539 MethodElement methodM2 = |
| 540 ElementFactory.methodElement(methodName2, _typeProvider.intType); |
| 541 classI2.methods = <MethodElement>[methodM2]; |
| 542 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 543 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 544 Map<String, ExecutableElement> mapA = |
| 545 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 546 expect(mapA.length, _numOfMembersInObject + 2); |
| 547 expect(mapA[methodName1], same(methodM1)); |
| 548 expect(mapA[methodName2], same(methodM2)); |
| 549 _assertNoErrors(classA); |
| 550 } |
| 551 |
| 552 void |
| 553 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gette
rs() { |
| 554 // class I1 { int get g; } |
| 555 // class I2 { num get g; } |
| 556 // class A implements I1, I2 {} |
| 557 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 558 String accessorName = "g"; |
| 559 PropertyAccessorElement getter1 = ElementFactory.getterElement( |
| 560 accessorName, false, _typeProvider.intType); |
| 561 classI1.accessors = <PropertyAccessorElement>[getter1]; |
| 562 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 563 PropertyAccessorElement getter2 = ElementFactory.getterElement( |
| 564 accessorName, false, _typeProvider.numType); |
| 565 classI2.accessors = <PropertyAccessorElement>[getter2]; |
| 566 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 567 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 568 Map<String, ExecutableElement> mapA = |
| 569 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 570 expect(mapA.length, _numOfMembersInObject + 1); |
| 571 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement( |
| 572 accessorName, false, _typeProvider.dynamicType); |
| 573 expect(mapA[accessorName].type, syntheticAccessor.type); |
| 574 _assertNoErrors(classA); |
| 575 } |
| 576 |
| 577 void |
| 578 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_metho
ds() { |
| 579 // class I1 { dynamic m(int); } |
| 580 // class I2 { dynamic m(num); } |
| 581 // class A implements I1, I2 {} |
| 582 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 583 String methodName = "m"; |
| 584 MethodElementImpl methodM1 = |
| 585 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 586 ParameterElementImpl parameter1 = |
| 587 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); |
| 588 parameter1.type = _typeProvider.intType; |
| 589 parameter1.parameterKind = ParameterKind.REQUIRED; |
| 590 methodM1.parameters = <ParameterElement>[parameter1]; |
| 591 classI1.methods = <MethodElement>[methodM1]; |
| 592 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 593 MethodElementImpl methodM2 = |
| 594 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 595 ParameterElementImpl parameter2 = |
| 596 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); |
| 597 parameter2.type = _typeProvider.numType; |
| 598 parameter2.parameterKind = ParameterKind.REQUIRED; |
| 599 methodM2.parameters = <ParameterElement>[parameter2]; |
| 600 classI2.methods = <MethodElement>[methodM2]; |
| 601 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 602 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 603 Map<String, ExecutableElement> mapA = |
| 604 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 605 expect(mapA.length, _numOfMembersInObject + 1); |
| 606 MethodElement syntheticMethod = ElementFactory.methodElement( |
| 607 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]); |
| 608 expect(mapA[methodName].type, syntheticMethod.type); |
| 609 _assertNoErrors(classA); |
| 610 } |
| 611 |
| 612 void |
| 613 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sette
rs() { |
| 614 // class I1 { set s(int); } |
| 615 // class I2 { set s(num); } |
| 616 // class A implements I1, I2 {} |
| 617 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 618 String accessorName = "s"; |
| 619 PropertyAccessorElement setter1 = ElementFactory.setterElement( |
| 620 accessorName, false, _typeProvider.intType); |
| 621 classI1.accessors = <PropertyAccessorElement>[setter1]; |
| 622 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 623 PropertyAccessorElement setter2 = ElementFactory.setterElement( |
| 624 accessorName, false, _typeProvider.numType); |
| 625 classI2.accessors = <PropertyAccessorElement>[setter2]; |
| 626 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 627 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 628 Map<String, ExecutableElement> mapA = |
| 629 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 630 expect(mapA.length, _numOfMembersInObject + 1); |
| 631 PropertyAccessorElementImpl syntheticAccessor = ElementFactory |
| 632 .setterElement(accessorName, false, _typeProvider.dynamicType); |
| 633 syntheticAccessor.returnType = _typeProvider.dynamicType; |
| 634 expect(mapA["$accessorName="].type, syntheticAccessor.type); |
| 635 _assertNoErrors(classA); |
| 636 } |
| 637 |
| 638 void |
| 639 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gette
rs() { |
| 640 // class A {} |
| 641 // class B extends A {} |
| 642 // class C extends B {} |
| 643 // class I1 { A get g; } |
| 644 // class I2 { B get g; } |
| 645 // class I3 { C get g; } |
| 646 // class D implements I1, I2, I3 {} |
| 647 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 648 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 649 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); |
| 650 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 651 String accessorName = "g"; |
| 652 PropertyAccessorElement getter1 = |
| 653 ElementFactory.getterElement(accessorName, false, classA.type); |
| 654 classI1.accessors = <PropertyAccessorElement>[getter1]; |
| 655 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 656 PropertyAccessorElement getter2 = |
| 657 ElementFactory.getterElement(accessorName, false, classB.type); |
| 658 classI2.accessors = <PropertyAccessorElement>[getter2]; |
| 659 ClassElementImpl classI3 = ElementFactory.classElement2("I3"); |
| 660 PropertyAccessorElement getter3 = |
| 661 ElementFactory.getterElement(accessorName, false, classC.type); |
| 662 classI3.accessors = <PropertyAccessorElement>[getter3]; |
| 663 ClassElementImpl classD = ElementFactory.classElement2("D"); |
| 664 classD.interfaces = <InterfaceType>[ |
| 665 classI1.type, |
| 666 classI2.type, |
| 667 classI3.type |
| 668 ]; |
| 669 Map<String, ExecutableElement> mapD = |
| 670 _inheritanceManager.getMembersInheritedFromInterfaces(classD); |
| 671 expect(mapD.length, _numOfMembersInObject + 1); |
| 672 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement( |
| 673 accessorName, false, _typeProvider.dynamicType); |
| 674 expect(mapD[accessorName].type, syntheticAccessor.type); |
| 675 _assertNoErrors(classD); |
| 676 } |
| 677 |
| 678 void |
| 679 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_metho
ds() { |
| 680 // class A {} |
| 681 // class B extends A {} |
| 682 // class C extends B {} |
| 683 // class I1 { dynamic m(A a); } |
| 684 // class I2 { dynamic m(B b); } |
| 685 // class I3 { dynamic m(C c); } |
| 686 // class D implements I1, I2, I3 {} |
| 687 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 688 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 689 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); |
| 690 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 691 String methodName = "m"; |
| 692 MethodElementImpl methodM1 = |
| 693 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 694 ParameterElementImpl parameter1 = |
| 695 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); |
| 696 parameter1.type = classA.type; |
| 697 parameter1.parameterKind = ParameterKind.REQUIRED; |
| 698 methodM1.parameters = <ParameterElement>[parameter1]; |
| 699 classI1.methods = <MethodElement>[methodM1]; |
| 700 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 701 MethodElementImpl methodM2 = |
| 702 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 703 ParameterElementImpl parameter2 = |
| 704 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); |
| 705 parameter2.type = classB.type; |
| 706 parameter2.parameterKind = ParameterKind.REQUIRED; |
| 707 methodM2.parameters = <ParameterElement>[parameter2]; |
| 708 classI2.methods = <MethodElement>[methodM2]; |
| 709 ClassElementImpl classI3 = ElementFactory.classElement2("I3"); |
| 710 MethodElementImpl methodM3 = |
| 711 ElementFactory.methodElement(methodName, _typeProvider.dynamicType); |
| 712 ParameterElementImpl parameter3 = |
| 713 new ParameterElementImpl.forNode(AstFactory.identifier3("a0")); |
| 714 parameter3.type = classC.type; |
| 715 parameter3.parameterKind = ParameterKind.REQUIRED; |
| 716 methodM3.parameters = <ParameterElement>[parameter3]; |
| 717 classI3.methods = <MethodElement>[methodM3]; |
| 718 ClassElementImpl classD = ElementFactory.classElement2("D"); |
| 719 classD.interfaces = <InterfaceType>[ |
| 720 classI1.type, |
| 721 classI2.type, |
| 722 classI3.type |
| 723 ]; |
| 724 Map<String, ExecutableElement> mapD = |
| 725 _inheritanceManager.getMembersInheritedFromInterfaces(classD); |
| 726 expect(mapD.length, _numOfMembersInObject + 1); |
| 727 MethodElement syntheticMethod = ElementFactory.methodElement( |
| 728 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]); |
| 729 expect(mapD[methodName].type, syntheticMethod.type); |
| 730 _assertNoErrors(classD); |
| 731 } |
| 732 |
| 733 void |
| 734 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sette
rs() { |
| 735 // class A {} |
| 736 // class B extends A {} |
| 737 // class C extends B {} |
| 738 // class I1 { set s(A); } |
| 739 // class I2 { set s(B); } |
| 740 // class I3 { set s(C); } |
| 741 // class D implements I1, I2, I3 {} |
| 742 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 743 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 744 ClassElementImpl classC = ElementFactory.classElement("C", classB.type); |
| 745 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 746 String accessorName = "s"; |
| 747 PropertyAccessorElement setter1 = |
| 748 ElementFactory.setterElement(accessorName, false, classA.type); |
| 749 classI1.accessors = <PropertyAccessorElement>[setter1]; |
| 750 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 751 PropertyAccessorElement setter2 = |
| 752 ElementFactory.setterElement(accessorName, false, classB.type); |
| 753 classI2.accessors = <PropertyAccessorElement>[setter2]; |
| 754 ClassElementImpl classI3 = ElementFactory.classElement2("I3"); |
| 755 PropertyAccessorElement setter3 = |
| 756 ElementFactory.setterElement(accessorName, false, classC.type); |
| 757 classI3.accessors = <PropertyAccessorElement>[setter3]; |
| 758 ClassElementImpl classD = ElementFactory.classElement2("D"); |
| 759 classD.interfaces = <InterfaceType>[ |
| 760 classI1.type, |
| 761 classI2.type, |
| 762 classI3.type |
| 763 ]; |
| 764 Map<String, ExecutableElement> mapD = |
| 765 _inheritanceManager.getMembersInheritedFromInterfaces(classD); |
| 766 expect(mapD.length, _numOfMembersInObject + 1); |
| 767 PropertyAccessorElementImpl syntheticAccessor = ElementFactory |
| 768 .setterElement(accessorName, false, _typeProvider.dynamicType); |
| 769 syntheticAccessor.returnType = _typeProvider.dynamicType; |
| 770 expect(mapD["$accessorName="].type, syntheticAccessor.type); |
| 771 _assertNoErrors(classD); |
| 772 } |
| 773 |
| 774 void |
| 775 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() { |
| 776 // class I1 { int m(); } |
| 777 // class I2 { int m([int]); } |
| 778 // class A implements I1, I2 {} |
| 779 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 780 String methodName = "m"; |
| 781 MethodElement methodM1 = |
| 782 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 783 classI1.methods = <MethodElement>[methodM1]; |
| 784 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 785 MethodElementImpl methodM2 = |
| 786 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 787 ParameterElementImpl parameter1 = |
| 788 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); |
| 789 parameter1.type = _typeProvider.intType; |
| 790 parameter1.parameterKind = ParameterKind.POSITIONAL; |
| 791 methodM2.parameters = <ParameterElement>[parameter1]; |
| 792 classI2.methods = <MethodElement>[methodM2]; |
| 793 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 794 classA.interfaces = <InterfaceType>[classI1.type, classI2.type]; |
| 795 Map<String, ExecutableElement> mapA = |
| 796 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 797 expect(mapA.length, _numOfMembersInObject + 1); |
| 798 expect(mapA[methodName], same(methodM2)); |
| 799 _assertNoErrors(classA); |
| 800 } |
| 801 |
| 802 void |
| 803 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() { |
| 804 // class I1 { int m(); } |
| 805 // class I2 { int m([int]); } |
| 806 // class I3 { int m([int, int]); } |
| 807 // class A implements I1, I2, I3 {} |
| 808 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 809 String methodName = "m"; |
| 810 MethodElementImpl methodM1 = |
| 811 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 812 classI1.methods = <MethodElement>[methodM1]; |
| 813 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 814 MethodElementImpl methodM2 = |
| 815 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 816 ParameterElementImpl parameter1 = |
| 817 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); |
| 818 parameter1.type = _typeProvider.intType; |
| 819 parameter1.parameterKind = ParameterKind.POSITIONAL; |
| 820 methodM1.parameters = <ParameterElement>[parameter1]; |
| 821 classI2.methods = <MethodElement>[methodM2]; |
| 822 ClassElementImpl classI3 = ElementFactory.classElement2("I3"); |
| 823 MethodElementImpl methodM3 = |
| 824 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 825 ParameterElementImpl parameter2 = |
| 826 new ParameterElementImpl.forNode(AstFactory.identifier3("a2")); |
| 827 parameter2.type = _typeProvider.intType; |
| 828 parameter2.parameterKind = ParameterKind.POSITIONAL; |
| 829 ParameterElementImpl parameter3 = |
| 830 new ParameterElementImpl.forNode(AstFactory.identifier3("a3")); |
| 831 parameter3.type = _typeProvider.intType; |
| 832 parameter3.parameterKind = ParameterKind.POSITIONAL; |
| 833 methodM3.parameters = <ParameterElement>[parameter2, parameter3]; |
| 834 classI3.methods = <MethodElement>[methodM3]; |
| 835 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 836 classA.interfaces = <InterfaceType>[ |
| 837 classI1.type, |
| 838 classI2.type, |
| 839 classI3.type |
| 840 ]; |
| 841 Map<String, ExecutableElement> mapA = |
| 842 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 843 expect(mapA.length, _numOfMembersInObject + 1); |
| 844 expect(mapA[methodName], same(methodM3)); |
| 845 _assertNoErrors(classA); |
| 846 } |
| 847 |
| 848 void |
| 849 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() { |
| 850 // class I1 { int m(); } |
| 851 // class I2 { int m(); } |
| 852 // class I3 { int m([int]); } |
| 853 // class I4 { int m([int, int]); } |
| 854 // class A implements I1, I2, I3, I4 {} |
| 855 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 856 String methodName = "m"; |
| 857 MethodElement methodM1 = |
| 858 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 859 classI1.methods = <MethodElement>[methodM1]; |
| 860 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 861 MethodElement methodM2 = |
| 862 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 863 classI2.methods = <MethodElement>[methodM2]; |
| 864 ClassElementImpl classI3 = ElementFactory.classElement2("I3"); |
| 865 MethodElementImpl methodM3 = |
| 866 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 867 ParameterElementImpl parameter1 = |
| 868 new ParameterElementImpl.forNode(AstFactory.identifier3("a1")); |
| 869 parameter1.type = _typeProvider.intType; |
| 870 parameter1.parameterKind = ParameterKind.POSITIONAL; |
| 871 methodM3.parameters = <ParameterElement>[parameter1]; |
| 872 classI3.methods = <MethodElement>[methodM3]; |
| 873 ClassElementImpl classI4 = ElementFactory.classElement2("I4"); |
| 874 MethodElementImpl methodM4 = |
| 875 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 876 ParameterElementImpl parameter2 = |
| 877 new ParameterElementImpl.forNode(AstFactory.identifier3("a2")); |
| 878 parameter2.type = _typeProvider.intType; |
| 879 parameter2.parameterKind = ParameterKind.POSITIONAL; |
| 880 ParameterElementImpl parameter3 = |
| 881 new ParameterElementImpl.forNode(AstFactory.identifier3("a3")); |
| 882 parameter3.type = _typeProvider.intType; |
| 883 parameter3.parameterKind = ParameterKind.POSITIONAL; |
| 884 methodM4.parameters = <ParameterElement>[parameter2, parameter3]; |
| 885 classI4.methods = <MethodElement>[methodM4]; |
| 886 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 887 classA.interfaces = <InterfaceType>[ |
| 888 classI1.type, |
| 889 classI2.type, |
| 890 classI3.type, |
| 891 classI4.type |
| 892 ]; |
| 893 Map<String, ExecutableElement> mapA = |
| 894 _inheritanceManager.getMembersInheritedFromInterfaces(classA); |
| 895 expect(mapA.length, _numOfMembersInObject + 1); |
| 896 expect(mapA[methodName], same(methodM4)); |
| 897 _assertNoErrors(classA); |
| 898 } |
| 899 |
| 900 void test_getMembersInheritedFromClasses_field_indirectWith() { |
| 901 // class A { int f; } |
| 902 // class B extends A {} |
| 903 // class C extends Object with B {} |
| 904 ClassElementImpl classA = ElementFactory.classElement2('A'); |
| 905 String fieldName = "f"; |
| 906 FieldElement fieldF = ElementFactory.fieldElement( |
| 907 fieldName, false, false, false, _typeProvider.intType); |
| 908 classA.fields = <FieldElement>[fieldF]; |
| 909 classA.accessors = <PropertyAccessorElement>[fieldF.getter, fieldF.setter]; |
| 910 |
| 911 ClassElementImpl classB = ElementFactory.classElement('B', classA.type); |
| 912 |
| 913 ClassElementImpl classC = ElementFactory.classElement2('C'); |
| 914 classC.mixins = <InterfaceType>[classB.type]; |
| 915 |
| 916 Map<String, ExecutableElement> mapC = |
| 917 _inheritanceManager.getMembersInheritedFromClasses(classC); |
| 918 expect(mapC, hasLength(_numOfMembersInObject)); |
| 919 _assertNoErrors(classA); |
| 920 _assertNoErrors(classB); |
| 921 _assertNoErrors(classC); |
| 922 } |
| 923 |
| 924 void test_lookupInheritance_interface_getter() { |
| 925 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 926 String getterName = "g"; |
| 927 PropertyAccessorElement getterG = |
| 928 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 929 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 930 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 931 classB.interfaces = <InterfaceType>[classA.type]; |
| 932 expect(_inheritanceManager.lookupInheritance(classB, getterName), |
| 933 same(getterG)); |
| 934 _assertNoErrors(classA); |
| 935 _assertNoErrors(classB); |
| 936 } |
| 937 |
| 938 void test_lookupInheritance_interface_method() { |
| 939 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 940 String methodName = "m"; |
| 941 MethodElement methodM = |
| 942 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 943 classA.methods = <MethodElement>[methodM]; |
| 944 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 945 classB.interfaces = <InterfaceType>[classA.type]; |
| 946 expect(_inheritanceManager.lookupInheritance(classB, methodName), |
| 947 same(methodM)); |
| 948 _assertNoErrors(classA); |
| 949 _assertNoErrors(classB); |
| 950 } |
| 951 |
| 952 void test_lookupInheritance_interface_setter() { |
| 953 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 954 String setterName = "s"; |
| 955 PropertyAccessorElement setterS = |
| 956 ElementFactory.setterElement(setterName, false, _typeProvider.intType); |
| 957 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 958 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 959 classB.interfaces = <InterfaceType>[classA.type]; |
| 960 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), |
| 961 same(setterS)); |
| 962 _assertNoErrors(classA); |
| 963 _assertNoErrors(classB); |
| 964 } |
| 965 |
| 966 void test_lookupInheritance_interface_staticMember() { |
| 967 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 968 String methodName = "m"; |
| 969 MethodElement methodM = |
| 970 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 971 (methodM as MethodElementImpl).static = true; |
| 972 classA.methods = <MethodElement>[methodM]; |
| 973 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 974 classB.interfaces = <InterfaceType>[classA.type]; |
| 975 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 976 _assertNoErrors(classA); |
| 977 _assertNoErrors(classB); |
| 978 } |
| 979 |
| 980 void test_lookupInheritance_interfaces_infiniteLoop() { |
| 981 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 982 classA.interfaces = <InterfaceType>[classA.type]; |
| 983 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 984 _assertNoErrors(classA); |
| 985 } |
| 986 |
| 987 void test_lookupInheritance_interfaces_infiniteLoop2() { |
| 988 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 989 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 990 classA.interfaces = <InterfaceType>[classB.type]; |
| 991 classB.interfaces = <InterfaceType>[classA.type]; |
| 992 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 993 _assertNoErrors(classA); |
| 994 _assertNoErrors(classB); |
| 995 } |
| 996 |
| 997 void test_lookupInheritance_interfaces_union2() { |
| 998 ClassElementImpl classI1 = ElementFactory.classElement2("I1"); |
| 999 String methodName1 = "m1"; |
| 1000 MethodElement methodM1 = |
| 1001 ElementFactory.methodElement(methodName1, _typeProvider.intType); |
| 1002 classI1.methods = <MethodElement>[methodM1]; |
| 1003 ClassElementImpl classI2 = ElementFactory.classElement2("I2"); |
| 1004 String methodName2 = "m2"; |
| 1005 MethodElement methodM2 = |
| 1006 ElementFactory.methodElement(methodName2, _typeProvider.intType); |
| 1007 classI2.methods = <MethodElement>[methodM2]; |
| 1008 classI2.interfaces = <InterfaceType>[classI1.type]; |
| 1009 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1010 classA.interfaces = <InterfaceType>[classI2.type]; |
| 1011 expect(_inheritanceManager.lookupInheritance(classA, methodName1), |
| 1012 same(methodM1)); |
| 1013 expect(_inheritanceManager.lookupInheritance(classA, methodName2), |
| 1014 same(methodM2)); |
| 1015 _assertNoErrors(classI1); |
| 1016 _assertNoErrors(classI2); |
| 1017 _assertNoErrors(classA); |
| 1018 } |
| 1019 |
| 1020 void test_lookupInheritance_mixin_getter() { |
| 1021 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1022 String getterName = "g"; |
| 1023 PropertyAccessorElement getterG = |
| 1024 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 1025 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 1026 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1027 classB.mixins = <InterfaceType>[classA.type]; |
| 1028 expect(_inheritanceManager.lookupInheritance(classB, getterName), |
| 1029 same(getterG)); |
| 1030 _assertNoErrors(classA); |
| 1031 _assertNoErrors(classB); |
| 1032 } |
| 1033 |
| 1034 void test_lookupInheritance_mixin_method() { |
| 1035 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1036 String methodName = "m"; |
| 1037 MethodElement methodM = |
| 1038 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1039 classA.methods = <MethodElement>[methodM]; |
| 1040 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1041 classB.mixins = <InterfaceType>[classA.type]; |
| 1042 expect(_inheritanceManager.lookupInheritance(classB, methodName), |
| 1043 same(methodM)); |
| 1044 _assertNoErrors(classA); |
| 1045 _assertNoErrors(classB); |
| 1046 } |
| 1047 |
| 1048 void test_lookupInheritance_mixin_setter() { |
| 1049 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1050 String setterName = "s"; |
| 1051 PropertyAccessorElement setterS = |
| 1052 ElementFactory.setterElement(setterName, false, _typeProvider.intType); |
| 1053 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 1054 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1055 classB.mixins = <InterfaceType>[classA.type]; |
| 1056 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), |
| 1057 same(setterS)); |
| 1058 _assertNoErrors(classA); |
| 1059 _assertNoErrors(classB); |
| 1060 } |
| 1061 |
| 1062 void test_lookupInheritance_mixin_staticMember() { |
| 1063 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1064 String methodName = "m"; |
| 1065 MethodElement methodM = |
| 1066 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1067 (methodM as MethodElementImpl).static = true; |
| 1068 classA.methods = <MethodElement>[methodM]; |
| 1069 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1070 classB.mixins = <InterfaceType>[classA.type]; |
| 1071 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 1072 _assertNoErrors(classA); |
| 1073 _assertNoErrors(classB); |
| 1074 } |
| 1075 |
| 1076 void test_lookupInheritance_noMember() { |
| 1077 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1078 expect(_inheritanceManager.lookupInheritance(classA, "a"), isNull); |
| 1079 _assertNoErrors(classA); |
| 1080 } |
| 1081 |
| 1082 void test_lookupInheritance_superclass_getter() { |
| 1083 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1084 String getterName = "g"; |
| 1085 PropertyAccessorElement getterG = |
| 1086 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 1087 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 1088 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 1089 expect(_inheritanceManager.lookupInheritance(classB, getterName), |
| 1090 same(getterG)); |
| 1091 _assertNoErrors(classA); |
| 1092 _assertNoErrors(classB); |
| 1093 } |
| 1094 |
| 1095 void test_lookupInheritance_superclass_infiniteLoop() { |
| 1096 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1097 classA.supertype = classA.type; |
| 1098 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 1099 _assertNoErrors(classA); |
| 1100 } |
| 1101 |
| 1102 void test_lookupInheritance_superclass_infiniteLoop2() { |
| 1103 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1104 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1105 classA.supertype = classB.type; |
| 1106 classB.supertype = classA.type; |
| 1107 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 1108 _assertNoErrors(classA); |
| 1109 _assertNoErrors(classB); |
| 1110 } |
| 1111 |
| 1112 void test_lookupInheritance_superclass_method() { |
| 1113 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1114 String methodName = "m"; |
| 1115 MethodElement methodM = |
| 1116 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1117 classA.methods = <MethodElement>[methodM]; |
| 1118 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 1119 expect(_inheritanceManager.lookupInheritance(classB, methodName), |
| 1120 same(methodM)); |
| 1121 _assertNoErrors(classA); |
| 1122 _assertNoErrors(classB); |
| 1123 } |
| 1124 |
| 1125 void test_lookupInheritance_superclass_setter() { |
| 1126 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1127 String setterName = "s"; |
| 1128 PropertyAccessorElement setterS = |
| 1129 ElementFactory.setterElement(setterName, false, _typeProvider.intType); |
| 1130 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 1131 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 1132 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), |
| 1133 same(setterS)); |
| 1134 _assertNoErrors(classA); |
| 1135 _assertNoErrors(classB); |
| 1136 } |
| 1137 |
| 1138 void test_lookupInheritance_superclass_staticMember() { |
| 1139 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1140 String methodName = "m"; |
| 1141 MethodElement methodM = |
| 1142 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1143 (methodM as MethodElementImpl).static = true; |
| 1144 classA.methods = <MethodElement>[methodM]; |
| 1145 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 1146 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 1147 _assertNoErrors(classA); |
| 1148 _assertNoErrors(classB); |
| 1149 } |
| 1150 |
| 1151 void test_lookupMember_getter() { |
| 1152 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1153 String getterName = "g"; |
| 1154 PropertyAccessorElement getterG = |
| 1155 ElementFactory.getterElement(getterName, false, _typeProvider.intType); |
| 1156 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 1157 expect(_inheritanceManager.lookupMember(classA, getterName), same(getterG)); |
| 1158 _assertNoErrors(classA); |
| 1159 } |
| 1160 |
| 1161 void test_lookupMember_getter_static() { |
| 1162 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1163 String getterName = "g"; |
| 1164 PropertyAccessorElement getterG = |
| 1165 ElementFactory.getterElement(getterName, true, _typeProvider.intType); |
| 1166 classA.accessors = <PropertyAccessorElement>[getterG]; |
| 1167 expect(_inheritanceManager.lookupMember(classA, getterName), isNull); |
| 1168 _assertNoErrors(classA); |
| 1169 } |
| 1170 |
| 1171 void test_lookupMember_method() { |
| 1172 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1173 String methodName = "m"; |
| 1174 MethodElement methodM = |
| 1175 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1176 classA.methods = <MethodElement>[methodM]; |
| 1177 expect(_inheritanceManager.lookupMember(classA, methodName), same(methodM)); |
| 1178 _assertNoErrors(classA); |
| 1179 } |
| 1180 |
| 1181 void test_lookupMember_method_static() { |
| 1182 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1183 String methodName = "m"; |
| 1184 MethodElement methodM = |
| 1185 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1186 (methodM as MethodElementImpl).static = true; |
| 1187 classA.methods = <MethodElement>[methodM]; |
| 1188 expect(_inheritanceManager.lookupMember(classA, methodName), isNull); |
| 1189 _assertNoErrors(classA); |
| 1190 } |
| 1191 |
| 1192 void test_lookupMember_noMember() { |
| 1193 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1194 expect(_inheritanceManager.lookupMember(classA, "a"), isNull); |
| 1195 _assertNoErrors(classA); |
| 1196 } |
| 1197 |
| 1198 void test_lookupMember_setter() { |
| 1199 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1200 String setterName = "s"; |
| 1201 PropertyAccessorElement setterS = |
| 1202 ElementFactory.setterElement(setterName, false, _typeProvider.intType); |
| 1203 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 1204 expect(_inheritanceManager.lookupMember(classA, "$setterName="), |
| 1205 same(setterS)); |
| 1206 _assertNoErrors(classA); |
| 1207 } |
| 1208 |
| 1209 void test_lookupMember_setter_static() { |
| 1210 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1211 String setterName = "s"; |
| 1212 PropertyAccessorElement setterS = |
| 1213 ElementFactory.setterElement(setterName, true, _typeProvider.intType); |
| 1214 classA.accessors = <PropertyAccessorElement>[setterS]; |
| 1215 expect(_inheritanceManager.lookupMember(classA, setterName), isNull); |
| 1216 _assertNoErrors(classA); |
| 1217 } |
| 1218 |
| 1219 void test_lookupOverrides_noParentClasses() { |
| 1220 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1221 String methodName = "m"; |
| 1222 MethodElementImpl methodM = |
| 1223 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1224 classA.methods = <MethodElement>[methodM]; |
| 1225 expect( |
| 1226 _inheritanceManager.lookupOverrides(classA, methodName), hasLength(0)); |
| 1227 _assertNoErrors(classA); |
| 1228 } |
| 1229 |
| 1230 void test_lookupOverrides_overrideBaseClass() { |
| 1231 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1232 String methodName = "m"; |
| 1233 MethodElementImpl methodMinA = |
| 1234 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1235 classA.methods = <MethodElement>[methodMinA]; |
| 1236 ClassElementImpl classB = ElementFactory.classElement("B", classA.type); |
| 1237 MethodElementImpl methodMinB = |
| 1238 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1239 classB.methods = <MethodElement>[methodMinB]; |
| 1240 List<ExecutableElement> overrides = |
| 1241 _inheritanceManager.lookupOverrides(classB, methodName); |
| 1242 expect(overrides, unorderedEquals([methodMinA])); |
| 1243 _assertNoErrors(classA); |
| 1244 _assertNoErrors(classB); |
| 1245 } |
| 1246 |
| 1247 void test_lookupOverrides_overrideInterface() { |
| 1248 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1249 String methodName = "m"; |
| 1250 MethodElementImpl methodMinA = |
| 1251 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1252 classA.methods = <MethodElement>[methodMinA]; |
| 1253 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1254 classB.interfaces = <InterfaceType>[classA.type]; |
| 1255 MethodElementImpl methodMinB = |
| 1256 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1257 classB.methods = <MethodElement>[methodMinB]; |
| 1258 List<ExecutableElement> overrides = |
| 1259 _inheritanceManager.lookupOverrides(classB, methodName); |
| 1260 expect(overrides, unorderedEquals([methodMinA])); |
| 1261 _assertNoErrors(classA); |
| 1262 _assertNoErrors(classB); |
| 1263 } |
| 1264 |
| 1265 void test_lookupOverrides_overrideTwoInterfaces() { |
| 1266 ClassElementImpl classA = ElementFactory.classElement2("A"); |
| 1267 String methodName = "m"; |
| 1268 MethodElementImpl methodMinA = |
| 1269 ElementFactory.methodElement(methodName, _typeProvider.intType); |
| 1270 classA.methods = <MethodElement>[methodMinA]; |
| 1271 ClassElementImpl classB = ElementFactory.classElement2("B"); |
| 1272 MethodElementImpl methodMinB = |
| 1273 ElementFactory.methodElement(methodName, _typeProvider.doubleType); |
| 1274 classB.methods = <MethodElement>[methodMinB]; |
| 1275 ClassElementImpl classC = ElementFactory.classElement2("C"); |
| 1276 classC.interfaces = <InterfaceType>[classA.type, classB.type]; |
| 1277 MethodElementImpl methodMinC = |
| 1278 ElementFactory.methodElement(methodName, _typeProvider.numType); |
| 1279 classC.methods = <MethodElement>[methodMinC]; |
| 1280 List<ExecutableElement> overrides = |
| 1281 _inheritanceManager.lookupOverrides(classC, methodName); |
| 1282 expect(overrides, unorderedEquals([methodMinA, methodMinB])); |
| 1283 _assertNoErrors(classA); |
| 1284 _assertNoErrors(classB); |
| 1285 _assertNoErrors(classC); |
| 1286 } |
| 1287 |
| 1288 void _assertErrors(ClassElement classElt, |
| 1289 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { |
| 1290 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 1291 HashSet<AnalysisError> actualErrors = |
| 1292 _inheritanceManager.getErrors(classElt); |
| 1293 if (actualErrors != null) { |
| 1294 for (AnalysisError error in actualErrors) { |
| 1295 errorListener.onError(error); |
| 1296 } |
| 1297 } |
| 1298 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
| 1299 } |
| 1300 |
| 1301 void _assertNoErrors(ClassElement classElt) { |
| 1302 _assertErrors(classElt); |
| 1303 } |
| 1304 |
| 1305 /** |
| 1306 * Create the inheritance manager used by the tests. |
| 1307 * |
| 1308 * @return the inheritance manager that was created |
| 1309 */ |
| 1310 InheritanceManager _createInheritanceManager() { |
| 1311 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 1312 AnalysisContext context = AnalysisContextFactory.contextWithCore( |
| 1313 resourceProvider: resourceProvider); |
| 1314 Source source = new FileSource(resourceProvider.getFile("/test.dart")); |
| 1315 CompilationUnitElementImpl definingCompilationUnit = |
| 1316 new CompilationUnitElementImpl("test.dart"); |
| 1317 definingCompilationUnit.librarySource = |
| 1318 definingCompilationUnit.source = source; |
| 1319 _definingLibrary = ElementFactory.library(context, "test"); |
| 1320 _definingLibrary.definingCompilationUnit = definingCompilationUnit; |
| 1321 return new InheritanceManager(_definingLibrary); |
| 1322 } |
| 1323 } |
| OLD | NEW |