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 analyzer.test.src.task.incremental_element_builder_test; | 5 library analyzer.test.src.task.incremental_element_builder_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
9 import 'package:analyzer/src/dart/ast/utilities.dart'; | 9 import 'package:analyzer/src/dart/ast/utilities.dart'; |
10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 // nodes | 59 // nodes |
60 ClassMember newConstructorNode = helper.newMembers[0]; | 60 ClassMember newConstructorNode = helper.newMembers[0]; |
61 // elements | 61 // elements |
62 ConstructorElement newConstructorElement = newConstructorNode.element; | 62 ConstructorElement newConstructorElement = newConstructorNode.element; |
63 expect(newConstructorElement, isNotNull); | 63 expect(newConstructorElement, isNotNull); |
64 expect(newConstructorElement.name, 'a'); | 64 expect(newConstructorElement.name, 'a'); |
65 // classElement.constructors | 65 // classElement.constructors |
66 ClassElement classElement = helper.element; | 66 ClassElement classElement = helper.element; |
67 expect(classElement.constructors, unorderedEquals([newConstructorElement])); | 67 expect(classElement.constructors, unorderedEquals([newConstructorElement])); |
68 // verify delta | 68 // verify delta |
| 69 expect(helper.delta.hasUnnamedConstructorChange, isTrue); |
69 expect(helper.delta.addedConstructors, | 70 expect(helper.delta.addedConstructors, |
70 unorderedEquals([newConstructorElement])); | 71 unorderedEquals([newConstructorElement])); |
71 expect(helper.delta.removedConstructors, | 72 expect(helper.delta.removedConstructors, |
72 unorderedEquals([oldConstructorElement])); | 73 unorderedEquals([oldConstructorElement])); |
73 expect(helper.delta.addedAccessors, isEmpty); | 74 expect(helper.delta.addedAccessors, isEmpty); |
74 expect(helper.delta.removedAccessors, isEmpty); | 75 expect(helper.delta.removedAccessors, isEmpty); |
75 expect(helper.delta.addedMethods, isEmpty); | 76 expect(helper.delta.addedMethods, isEmpty); |
76 expect(helper.delta.removedMethods, isEmpty); | 77 expect(helper.delta.removedMethods, isEmpty); |
77 } | 78 } |
78 | 79 |
(...skipping 13 matching lines...) Expand all Loading... |
92 helper.initNew(newUnit, unitDelta); | 93 helper.initNew(newUnit, unitDelta); |
93 // classElement.constructors | 94 // classElement.constructors |
94 ClassElement classElement = helper.element; | 95 ClassElement classElement = helper.element; |
95 { | 96 { |
96 List<ConstructorElement> constructors = classElement.constructors; | 97 List<ConstructorElement> constructors = classElement.constructors; |
97 expect(constructors, hasLength(1)); | 98 expect(constructors, hasLength(1)); |
98 expect(constructors[0].isDefaultConstructor, isTrue); | 99 expect(constructors[0].isDefaultConstructor, isTrue); |
99 expect(constructors[0].isSynthetic, isTrue); | 100 expect(constructors[0].isSynthetic, isTrue); |
100 } | 101 } |
101 // verify delta | 102 // verify delta |
102 expect(helper.delta.addedConstructors, unorderedEquals([])); | 103 expect(helper.delta.hasUnnamedConstructorChange, isTrue); |
| 104 expect(helper.delta.addedConstructors, |
| 105 unorderedEquals([classElement.unnamedConstructor])); |
103 expect(helper.delta.removedConstructors, unorderedEquals([oldElementA])); | 106 expect(helper.delta.removedConstructors, unorderedEquals([oldElementA])); |
104 expect(helper.delta.addedAccessors, isEmpty); | 107 expect(helper.delta.addedAccessors, isEmpty); |
105 expect(helper.delta.removedAccessors, isEmpty); | 108 expect(helper.delta.removedAccessors, isEmpty); |
106 expect(helper.delta.addedMethods, isEmpty); | 109 expect(helper.delta.addedMethods, isEmpty); |
107 expect(helper.delta.removedMethods, isEmpty); | 110 expect(helper.delta.removedMethods, isEmpty); |
108 } | 111 } |
109 | 112 |
| 113 test_classDelta_constructor_1to1_unnamed_addParameter() { |
| 114 var helper = new _ClassDeltaHelper('A'); |
| 115 _buildOldUnit(r''' |
| 116 class A { |
| 117 A(); |
| 118 } |
| 119 '''); |
| 120 helper.initOld(oldUnit); |
| 121 ConstructorElement oldConstructor = helper.element.unnamedConstructor; |
| 122 _buildNewUnit(r''' |
| 123 class A { |
| 124 A(int p); |
| 125 } |
| 126 '''); |
| 127 helper.initNew(newUnit, unitDelta); |
| 128 ClassElement classElement = helper.element; |
| 129 ConstructorElement newConstructor = classElement.unnamedConstructor; |
| 130 expect(classElement.constructors, [newConstructor]); |
| 131 // verify delta |
| 132 expect(helper.delta.hasUnnamedConstructorChange, isTrue); |
| 133 expect(helper.delta.addedConstructors, unorderedEquals([newConstructor])); |
| 134 expect(helper.delta.removedConstructors, unorderedEquals([oldConstructor])); |
| 135 expect(helper.delta.addedAccessors, isEmpty); |
| 136 expect(helper.delta.removedAccessors, isEmpty); |
| 137 expect(helper.delta.addedMethods, isEmpty); |
| 138 expect(helper.delta.removedMethods, isEmpty); |
| 139 } |
| 140 |
| 141 test_classDelta_constructor_1to1_unnamed_removeParameter() { |
| 142 var helper = new _ClassDeltaHelper('A'); |
| 143 _buildOldUnit(r''' |
| 144 class A { |
| 145 final int a; |
| 146 final int b; |
| 147 A(this.a, this.b); |
| 148 } |
| 149 '''); |
| 150 helper.initOld(oldUnit); |
| 151 ConstructorElement oldConstructor = helper.element.unnamedConstructor; |
| 152 _buildNewUnit(r''' |
| 153 class A { |
| 154 final int a; |
| 155 final int b; |
| 156 A(this.a); |
| 157 } |
| 158 '''); |
| 159 helper.initNew(newUnit, unitDelta); |
| 160 ClassElement classElement = helper.element; |
| 161 ConstructorElement newConstructor = classElement.unnamedConstructor; |
| 162 expect(classElement.constructors, [newConstructor]); |
| 163 // verify delta |
| 164 expect(helper.delta.hasUnnamedConstructorChange, isTrue); |
| 165 expect(helper.delta.addedConstructors, unorderedEquals([newConstructor])); |
| 166 expect(helper.delta.removedConstructors, unorderedEquals([oldConstructor])); |
| 167 expect(helper.delta.addedAccessors, isEmpty); |
| 168 expect(helper.delta.removedAccessors, isEmpty); |
| 169 expect(helper.delta.addedMethods, isEmpty); |
| 170 expect(helper.delta.removedMethods, isEmpty); |
| 171 } |
| 172 |
110 test_classDelta_constructor_1to2() { | 173 test_classDelta_constructor_1to2() { |
111 var helper = new _ClassDeltaHelper('A'); | 174 var helper = new _ClassDeltaHelper('A'); |
112 _buildOldUnit(r''' | 175 _buildOldUnit(r''' |
113 class A { | 176 class A { |
114 A.a(); | 177 A.a(); |
115 } | 178 } |
116 '''); | 179 '''); |
117 helper.initOld(oldUnit); | 180 helper.initOld(oldUnit); |
118 _buildNewUnit(r''' | 181 _buildNewUnit(r''' |
119 class A { | 182 class A { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 217 } |
155 '''); | 218 '''); |
156 helper.initOld(oldUnit); | 219 helper.initOld(oldUnit); |
157 ConstructorElement oldElementA = helper.element.getNamedConstructor('a'); | 220 ConstructorElement oldElementA = helper.element.getNamedConstructor('a'); |
158 _buildNewUnit(r''' | 221 _buildNewUnit(r''' |
159 class A { | 222 class A { |
160 A.b(); | 223 A.b(); |
161 } | 224 } |
162 '''); | 225 '''); |
163 helper.initNew(newUnit, unitDelta); | 226 helper.initNew(newUnit, unitDelta); |
| 227 expect(helper.delta.hasUnnamedConstructorChange, isFalse); |
164 // nodes | 228 // nodes |
165 ClassMember nodeB = helper.newMembers[0]; | 229 ClassMember nodeB = helper.newMembers[0]; |
166 expect(nodeB, same(helper.oldMembers[1])); | 230 expect(nodeB, same(helper.oldMembers[1])); |
167 // elements | 231 // elements |
168 ConstructorElement elementB = nodeB.element; | 232 ConstructorElement elementB = nodeB.element; |
169 expect(elementB, isNotNull); | 233 expect(elementB, isNotNull); |
170 expect(elementB.name, 'b'); | 234 expect(elementB.name, 'b'); |
171 // classElement.constructors | 235 // classElement.constructors |
172 ClassElement classElement = helper.element; | 236 ClassElement classElement = helper.element; |
173 expect(classElement.constructors, unorderedEquals([elementB])); | 237 expect(classElement.constructors, unorderedEquals([elementB])); |
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 expect(oldClass, isNotNull); | 1959 expect(oldClass, isNotNull); |
1896 element = oldClass.element; | 1960 element = oldClass.element; |
1897 oldVersion = element.version; | 1961 oldVersion = element.version; |
1898 oldMembers = oldClass.members.toList(); | 1962 oldMembers = oldClass.members.toList(); |
1899 } | 1963 } |
1900 | 1964 |
1901 ClassDeclaration _findClassNode(CompilationUnit unit, String name) => | 1965 ClassDeclaration _findClassNode(CompilationUnit unit, String name) => |
1902 unit.declarations.singleWhere((unitMember) => | 1966 unit.declarations.singleWhere((unitMember) => |
1903 unitMember is ClassDeclaration && unitMember.name.name == name); | 1967 unitMember is ClassDeclaration && unitMember.name.name == name); |
1904 } | 1968 } |
OLD | NEW |