Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1569633003: Fix resynthesis of variables/fields with implicit types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/source.dart'; 8 import 'package:analyzer/src/generated/source.dart';
9 import 'package:analyzer/src/summary/base.dart'; 9 import 'package:analyzer/src/summary/base.dart';
10 import 'package:analyzer/src/summary/format.dart'; 10 import 'package:analyzer/src/summary/format.dart';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 for (int i = 0; i < resynthesized.constructors.length; i++) { 100 for (int i = 0; i < resynthesized.constructors.length; i++) {
101 compareConstructorElements( 101 compareConstructorElements(
102 resynthesized.constructors[i], 102 resynthesized.constructors[i],
103 original.constructors[i], 103 original.constructors[i],
104 '$desc constructor ${original.constructors[i].name}'); 104 '$desc constructor ${original.constructors[i].name}');
105 } 105 }
106 expect(resynthesized.accessors.length, original.accessors.length); 106 expect(resynthesized.accessors.length, original.accessors.length);
107 for (int i = 0; i < resynthesized.accessors.length; i++) { 107 for (int i = 0; i < resynthesized.accessors.length; i++) {
108 String name = original.accessors[i].name; 108 String name = original.accessors[i].name;
109 if (name.endsWith('=')) { 109 if (name.endsWith('=')) {
110 comparePropertyAccessorElements(resynthesized.getSetter(name), 110 comparePropertyAccessorElements(
111 original.accessors[i], '$desc.${original.accessors[i].name}='); 111 resynthesized.getSetter(name),
112 original.accessors[i],
113 '$desc setter ${original.accessors[i].name}');
112 } else { 114 } else {
113 comparePropertyAccessorElements(resynthesized.getGetter(name), 115 comparePropertyAccessorElements(
114 original.accessors[i], '$desc.${original.accessors[i].name}'); 116 resynthesized.getGetter(name),
117 original.accessors[i],
118 '$desc getter ${original.accessors[i].name}');
115 } 119 }
116 } 120 }
117 expect(resynthesized.methods.length, original.methods.length); 121 expect(resynthesized.methods.length, original.methods.length);
118 for (int i = 0; i < resynthesized.methods.length; i++) { 122 for (int i = 0; i < resynthesized.methods.length; i++) {
119 compareMethodElements(resynthesized.methods[i], original.methods[i], 123 compareMethodElements(resynthesized.methods[i], original.methods[i],
120 '$desc.${original.methods[i].name}'); 124 '$desc.${original.methods[i].name}');
121 } 125 }
122 compareTypes(resynthesized.type, original.type, desc); 126 compareTypes(resynthesized.type, original.type, desc);
123 } 127 }
124 128
125 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized, 129 void compareCompilationUnitElements(CompilationUnitElementImpl resynthesized,
126 CompilationUnitElementImpl original) { 130 CompilationUnitElementImpl original) {
127 compareUriReferencedElements(resynthesized, original, '(compilation unit)'); 131 compareUriReferencedElements(resynthesized, original, '(compilation unit)');
128 expect(resynthesized.source, original.source); 132 expect(resynthesized.source, original.source);
129 expect(resynthesized.librarySource, original.librarySource); 133 expect(resynthesized.librarySource, original.librarySource);
130 expect(resynthesized.types.length, original.types.length); 134 expect(resynthesized.types.length, original.types.length);
131 for (int i = 0; i < resynthesized.types.length; i++) { 135 for (int i = 0; i < resynthesized.types.length; i++) {
132 compareClassElements( 136 compareClassElements(
133 resynthesized.types[i], original.types[i], original.types[i].name); 137 resynthesized.types[i], original.types[i], original.types[i].name);
134 } 138 }
135 expect(resynthesized.topLevelVariables.length, 139 expect(resynthesized.topLevelVariables.length,
136 original.topLevelVariables.length); 140 original.topLevelVariables.length);
137 for (int i = 0; i < resynthesized.topLevelVariables.length; i++) { 141 for (int i = 0; i < resynthesized.topLevelVariables.length; i++) {
138 compareTopLevelVariableElements(resynthesized.topLevelVariables[i], 142 compareTopLevelVariableElements(
139 original.topLevelVariables[i], original.topLevelVariables[i].name); 143 resynthesized.topLevelVariables[i],
144 original.topLevelVariables[i],
145 'variable ${original.topLevelVariables[i].name}');
140 } 146 }
141 expect(resynthesized.functions.length, original.functions.length); 147 expect(resynthesized.functions.length, original.functions.length);
142 for (int i = 0; i < resynthesized.functions.length; i++) { 148 for (int i = 0; i < resynthesized.functions.length; i++) {
143 compareFunctionElements(resynthesized.functions[i], original.functions[i], 149 compareFunctionElements(resynthesized.functions[i], original.functions[i],
144 original.functions[i].name); 150 'function ${original.functions[i].name}');
145 } 151 }
146 expect(resynthesized.functionTypeAliases.length, 152 expect(resynthesized.functionTypeAliases.length,
147 original.functionTypeAliases.length); 153 original.functionTypeAliases.length);
148 for (int i = 0; i < resynthesized.functionTypeAliases.length; i++) { 154 for (int i = 0; i < resynthesized.functionTypeAliases.length; i++) {
149 compareFunctionTypeAliasElements( 155 compareFunctionTypeAliasElements(
150 resynthesized.functionTypeAliases[i], 156 resynthesized.functionTypeAliases[i],
151 original.functionTypeAliases[i], 157 original.functionTypeAliases[i],
152 original.functionTypeAliases[i].name); 158 original.functionTypeAliases[i].name);
153 } 159 }
154 expect(resynthesized.enums.length, original.enums.length); 160 expect(resynthesized.enums.length, original.enums.length);
155 for (int i = 0; i < resynthesized.enums.length; i++) { 161 for (int i = 0; i < resynthesized.enums.length; i++) {
156 compareClassElements( 162 compareClassElements(
157 resynthesized.enums[i], original.enums[i], original.enums[i].name); 163 resynthesized.enums[i], original.enums[i], original.enums[i].name);
158 } 164 }
159 expect(resynthesized.accessors.length, original.accessors.length); 165 expect(resynthesized.accessors.length, original.accessors.length);
160 for (int i = 0; i < resynthesized.accessors.length; i++) { 166 for (int i = 0; i < resynthesized.accessors.length; i++) {
161 comparePropertyAccessorElements(resynthesized.accessors[i], 167 if (original.accessors[i].isGetter) {
162 original.accessors[i], original.accessors[i].name); 168 comparePropertyAccessorElements(resynthesized.accessors[i],
169 original.accessors[i], 'getter ${original.accessors[i].name}');
170 } else {
171 comparePropertyAccessorElements(resynthesized.accessors[i],
172 original.accessors[i], 'setter ${original.accessors[i].name}');
173 }
163 } 174 }
164 // TODO(paulberry): test metadata and offsetToElementMap. 175 // TODO(paulberry): test metadata and offsetToElementMap.
165 } 176 }
166 177
167 void compareConstructorElements(ConstructorElementImpl resynthesized, 178 void compareConstructorElements(ConstructorElementImpl resynthesized,
168 ConstructorElementImpl original, String desc) { 179 ConstructorElementImpl original, String desc) {
169 compareExecutableElements(resynthesized, original, desc); 180 compareExecutableElements(resynthesized, original, desc);
170 // TODO(paulberry): test redirectedConstructor and constantInitializers 181 // TODO(paulberry): test redirectedConstructor and constantInitializers
171 } 182 }
172 183
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 607 }
597 608
598 test_class_constructors() { 609 test_class_constructors() {
599 checkLibrary('class C { C.foo(); C.bar(); }'); 610 checkLibrary('class C { C.foo(); C.bar(); }');
600 } 611 }
601 612
602 test_class_field_const() { 613 test_class_field_const() {
603 checkLibrary('class C { static const int i = 0; }'); 614 checkLibrary('class C { static const int i = 0; }');
604 } 615 }
605 616
617 test_class_field_implicit_type() {
618 checkLibrary('class C { var x; }');
619 }
620
606 test_class_field_static() { 621 test_class_field_static() {
607 checkLibrary('class C { static int i; }'); 622 checkLibrary('class C { static int i; }');
608 } 623 }
609 624
610 test_class_fields() { 625 test_class_fields() {
611 checkLibrary('class C { int i; int j; }'); 626 checkLibrary('class C { int i; int j; }');
612 } 627 }
613 628
614 test_class_getter_external() { 629 test_class_getter_external() {
615 checkLibrary('class C { external int get x; }'); 630 checkLibrary('class C { external int get x; }');
616 } 631 }
617 632
633 test_class_getter_implicit_return_type() {
634 checkLibrary('class C { get x => null; }');
635 }
636
618 test_class_getter_static() { 637 test_class_getter_static() {
619 checkLibrary('class C { static int get x => null; }'); 638 checkLibrary('class C { static int get x => null; }');
620 } 639 }
621 640
622 test_class_getters() { 641 test_class_getters() {
623 checkLibrary('class C { int get x => null; get y => null; }'); 642 checkLibrary('class C { int get x => null; get y => null; }');
624 } 643 }
625 644
626 test_class_implicitField_getterFirst() { 645 test_class_implicitField_getterFirst() {
627 checkLibrary('class C { int get x => 0; void set x(int value) {} }'); 646 checkLibrary('class C { int get x => 0; void set x(int value) {} }');
(...skipping 24 matching lines...) Expand all
652 } 671 }
653 672
654 test_class_mixins() { 673 test_class_mixins() {
655 checkLibrary('class C extends Object with D, E {} class D {} class E {}'); 674 checkLibrary('class C extends Object with D, E {} class D {} class E {}');
656 } 675 }
657 676
658 test_class_setter_external() { 677 test_class_setter_external() {
659 checkLibrary('class C { external void set x(int value); }'); 678 checkLibrary('class C { external void set x(int value); }');
660 } 679 }
661 680
681 test_class_setter_implicit_param_type() {
682 checkLibrary('class C { void set x(value) {} }');
683 }
684
685 test_class_setter_implicit_return_type() {
686 checkLibrary('class C { set x(int value) {} }');
687 }
688
662 test_class_setter_static() { 689 test_class_setter_static() {
663 checkLibrary('class C { static void set x(int value) {} }'); 690 checkLibrary('class C { static void set x(int value) {} }');
664 } 691 }
665 692
666 test_class_setters() { 693 test_class_setters() {
667 checkLibrary('class C { void set x(int value) {} set y(value) {} }'); 694 checkLibrary('class C { void set x(int value) {} set y(value) {} }');
668 } 695 }
669 696
670 test_class_supertype() { 697 test_class_supertype() {
671 checkLibrary('class C extends D {} class D {}'); 698 checkLibrary('class C extends D {} class D {}');
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 } 1101 }
1075 1102
1076 test_typedefs() { 1103 test_typedefs() {
1077 checkLibrary('f() {} g() {}'); 1104 checkLibrary('f() {} g() {}');
1078 } 1105 }
1079 1106
1080 test_variable_const() { 1107 test_variable_const() {
1081 checkLibrary('const int i = 0;'); 1108 checkLibrary('const int i = 0;');
1082 } 1109 }
1083 1110
1111 test_variable_implicit_type() {
1112 checkLibrary('var x;');
1113 }
1114
1084 test_variables() { 1115 test_variables() {
1085 checkLibrary('int i; int j;'); 1116 checkLibrary('int i; int j;');
1086 } 1117 }
1087 } 1118 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698