| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.src.serialization.elements_test; | 5 library test.src.serialization.elements_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/element.dart'; | 7 import 'package:analyzer/src/generated/element.dart'; |
| 8 import 'package:analyzer/src/generated/element_handle.dart'; | 8 import 'package:analyzer/src/generated/element_handle.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/resolver.dart' | 10 import 'package:analyzer/src/generated/resolver.dart' |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // TODO(paulberry): test metadata. | 85 // TODO(paulberry): test metadata. |
| 86 } | 86 } |
| 87 | 87 |
| 88 void compareClassElements( | 88 void compareClassElements( |
| 89 ClassElementImpl resynthesized, ClassElementImpl original, String desc) { | 89 ClassElementImpl resynthesized, ClassElementImpl original, String desc) { |
| 90 compareElements(resynthesized, original, desc); | 90 compareElements(resynthesized, original, desc); |
| 91 expect(resynthesized.fields.length, original.fields.length, | 91 expect(resynthesized.fields.length, original.fields.length, |
| 92 reason: '$desc fields.length'); | 92 reason: '$desc fields.length'); |
| 93 for (int i = 0; i < resynthesized.fields.length; i++) { | 93 for (int i = 0; i < resynthesized.fields.length; i++) { |
| 94 String name = original.fields[i].name; | 94 String name = original.fields[i].name; |
| 95 compareFieldElements(resynthesized.getField(name), original.fields[i], | 95 compareFieldElements( |
| 96 '$desc.field $name'); | 96 resynthesized.fields[i], original.fields[i], '$desc.field $name'); |
| 97 } | 97 } |
| 98 compareTypes( | 98 compareTypes( |
| 99 resynthesized.supertype, original.supertype, '$desc supertype'); | 99 resynthesized.supertype, original.supertype, '$desc supertype'); |
| 100 expect(resynthesized.interfaces.length, original.interfaces.length); | 100 expect(resynthesized.interfaces.length, original.interfaces.length); |
| 101 for (int i = 0; i < resynthesized.interfaces.length; i++) { | 101 for (int i = 0; i < resynthesized.interfaces.length; i++) { |
| 102 compareTypes(resynthesized.interfaces[i], original.interfaces[i], | 102 compareTypes(resynthesized.interfaces[i], original.interfaces[i], |
| 103 '$desc interface ${original.interfaces[i].name}'); | 103 '$desc interface ${original.interfaces[i].name}'); |
| 104 } | 104 } |
| 105 expect(resynthesized.mixins.length, original.mixins.length); | 105 expect(resynthesized.mixins.length, original.mixins.length); |
| 106 for (int i = 0; i < resynthesized.mixins.length; i++) { | 106 for (int i = 0; i < resynthesized.mixins.length; i++) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 117 expect(resynthesized.constructors.length, original.constructors.length, | 117 expect(resynthesized.constructors.length, original.constructors.length, |
| 118 reason: '$desc constructors.length'); | 118 reason: '$desc constructors.length'); |
| 119 for (int i = 0; i < resynthesized.constructors.length; i++) { | 119 for (int i = 0; i < resynthesized.constructors.length; i++) { |
| 120 compareConstructorElements( | 120 compareConstructorElements( |
| 121 resynthesized.constructors[i], | 121 resynthesized.constructors[i], |
| 122 original.constructors[i], | 122 original.constructors[i], |
| 123 '$desc constructor ${original.constructors[i].name}'); | 123 '$desc constructor ${original.constructors[i].name}'); |
| 124 } | 124 } |
| 125 expect(resynthesized.accessors.length, original.accessors.length); | 125 expect(resynthesized.accessors.length, original.accessors.length); |
| 126 for (int i = 0; i < resynthesized.accessors.length; i++) { | 126 for (int i = 0; i < resynthesized.accessors.length; i++) { |
| 127 String name = original.accessors[i].name; | 127 comparePropertyAccessorElements( |
| 128 if (name.endsWith('=')) { | 128 resynthesized.accessors[i], |
| 129 comparePropertyAccessorElements( | 129 original.accessors[i], |
| 130 resynthesized.getSetter(name), | 130 '$desc accessor ${original.accessors[i].name}'); |
| 131 original.accessors[i], | |
| 132 '$desc setter ${original.accessors[i].name}'); | |
| 133 } else { | |
| 134 comparePropertyAccessorElements( | |
| 135 resynthesized.getGetter(name), | |
| 136 original.accessors[i], | |
| 137 '$desc getter ${original.accessors[i].name}'); | |
| 138 } | |
| 139 } | 131 } |
| 140 expect(resynthesized.methods.length, original.methods.length); | 132 expect(resynthesized.methods.length, original.methods.length); |
| 141 for (int i = 0; i < resynthesized.methods.length; i++) { | 133 for (int i = 0; i < resynthesized.methods.length; i++) { |
| 142 compareMethodElements(resynthesized.methods[i], original.methods[i], | 134 compareMethodElements(resynthesized.methods[i], original.methods[i], |
| 143 '$desc.${original.methods[i].name}'); | 135 '$desc.${original.methods[i].name}'); |
| 144 } | 136 } |
| 145 compareTypes(resynthesized.type, original.type, desc); | 137 compareTypes(resynthesized.type, original.type, desc); |
| 146 } | 138 } |
| 147 | 139 |
| 148 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, | 140 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 709 } |
| 718 | 710 |
| 719 test_class_constructor_field_formal_dynamic_typed() { | 711 test_class_constructor_field_formal_dynamic_typed() { |
| 720 checkLibrary('class C { dynamic x; C(int this.x); }'); | 712 checkLibrary('class C { dynamic x; C(int this.x); }'); |
| 721 } | 713 } |
| 722 | 714 |
| 723 test_class_constructor_field_formal_dynamic_untyped() { | 715 test_class_constructor_field_formal_dynamic_untyped() { |
| 724 checkLibrary('class C { dynamic x; C(this.x); }'); | 716 checkLibrary('class C { dynamic x; C(this.x); }'); |
| 725 } | 717 } |
| 726 | 718 |
| 719 test_class_constructor_field_formal_multiple_matching_fields() { |
| 720 // This is a compile-time error but it should still analyze consistently. |
| 721 checkLibrary('class C { C(this.x); int x; String x; }', allowErrors: true); |
| 722 } |
| 723 |
| 724 test_class_constructor_field_formal_no_matching_field() { |
| 725 // This is a compile-time error but it should still analyze consistently. |
| 726 checkLibrary('class C { C(this.x); }', allowErrors: true); |
| 727 } |
| 728 |
| 727 test_class_constructor_field_formal_typed_dynamic() { | 729 test_class_constructor_field_formal_typed_dynamic() { |
| 728 checkLibrary('class C { num x; C(dynamic this.x); }'); | 730 checkLibrary('class C { num x; C(dynamic this.x); }'); |
| 729 } | 731 } |
| 730 | 732 |
| 731 test_class_constructor_field_formal_typed_typed() { | 733 test_class_constructor_field_formal_typed_typed() { |
| 732 checkLibrary('class C { num x; C(int this.x); }'); | 734 checkLibrary('class C { num x; C(int this.x); }'); |
| 733 } | 735 } |
| 734 | 736 |
| 735 test_class_constructor_field_formal_typed_untyped() { | 737 test_class_constructor_field_formal_typed_untyped() { |
| 736 checkLibrary('class C { num x; C(this.x); }'); | 738 checkLibrary('class C { num x; C(this.x); }'); |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 fail('Unexpectedly tried to get unlinked summary for $uri'); | 1607 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 1606 } | 1608 } |
| 1607 return serializedUnit; | 1609 return serializedUnit; |
| 1608 } | 1610 } |
| 1609 | 1611 |
| 1610 @override | 1612 @override |
| 1611 bool hasLibrarySummary(String uri) { | 1613 bool hasLibrarySummary(String uri) { |
| 1612 return true; | 1614 return true; |
| 1613 } | 1615 } |
| 1614 } | 1616 } |
| OLD | NEW |