OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:analysis_server/src/services/correction/status.dart'; | 5 import 'package:analysis_server/src/services/correction/status.dart'; |
6 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 6 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
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_plugin/protocol/protocol_common.dart'; | 9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
10 import 'package:test/test.dart'; | 10 import 'package:test/test.dart'; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 93 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
94 expectedMessage: | 94 expectedMessage: |
95 "Class 'A' already declares method with name 'newName'.", | 95 "Class 'A' already declares method with name 'newName'.", |
96 expectedContextSearch: 'newName() {} // existing'); | 96 expectedContextSearch: 'newName() {} // existing'); |
97 } | 97 } |
98 | 98 |
99 test_createChange_add() async { | 99 test_createChange_add() async { |
100 await indexTestUnit(''' | 100 await indexTestUnit(''' |
101 class A { | 101 class A { |
102 A() {} // marker | 102 A() {} // marker |
| 103 factory A._() = A; |
103 } | 104 } |
104 class B extends A { | 105 class B extends A { |
105 B() : super() {} | 106 B() : super() {} |
106 factory B._() = A; | |
107 } | 107 } |
108 main() { | 108 main() { |
109 new A(); | 109 new A(); |
110 } | 110 } |
111 '''); | 111 '''); |
112 // configure refactoring | 112 // configure refactoring |
113 _createConstructorDeclarationRefactoring('() {} // marker'); | 113 _createConstructorDeclarationRefactoring('() {} // marker'); |
114 expect(refactoring.refactoringName, 'Rename Constructor'); | 114 expect(refactoring.refactoringName, 'Rename Constructor'); |
115 expect(refactoring.elementKindName, 'constructor'); | 115 expect(refactoring.elementKindName, 'constructor'); |
116 expect(refactoring.oldName, ''); | 116 expect(refactoring.oldName, ''); |
117 // validate change | 117 // validate change |
118 refactoring.newName = 'newName'; | 118 refactoring.newName = 'newName'; |
119 return assertSuccessfulRefactoring(''' | 119 return assertSuccessfulRefactoring(''' |
120 class A { | 120 class A { |
121 A.newName() {} // marker | 121 A.newName() {} // marker |
| 122 factory A._() = A.newName; |
122 } | 123 } |
123 class B extends A { | 124 class B extends A { |
124 B() : super.newName() {} | 125 B() : super.newName() {} |
125 factory B._() = A.newName; | |
126 } | 126 } |
127 main() { | 127 main() { |
128 new A.newName(); | 128 new A.newName(); |
129 } | 129 } |
130 '''); | 130 '''); |
131 } | 131 } |
132 | 132 |
133 test_createChange_add_toSynthetic() async { | 133 test_createChange_add_toSynthetic() async { |
134 await indexTestUnit(''' | 134 await indexTestUnit(''' |
135 class A { | 135 class A { |
136 } | 136 } |
137 class B extends A { | 137 class B extends A { |
138 B() : super() {} | 138 B() : super() {} |
139 factory B._() = A; | |
140 } | 139 } |
141 main() { | 140 main() { |
142 new A(); | 141 new A(); |
143 } | 142 } |
144 '''); | 143 '''); |
145 // configure refactoring | 144 // configure refactoring |
146 _createConstructorInvocationRefactoring('new A();'); | 145 _createConstructorInvocationRefactoring('new A();'); |
147 expect(refactoring.refactoringName, 'Rename Constructor'); | 146 expect(refactoring.refactoringName, 'Rename Constructor'); |
148 expect(refactoring.elementKindName, 'constructor'); | 147 expect(refactoring.elementKindName, 'constructor'); |
149 expect(refactoring.oldName, ''); | 148 expect(refactoring.oldName, ''); |
150 // validate change | 149 // validate change |
151 refactoring.newName = 'newName'; | 150 refactoring.newName = 'newName'; |
152 return assertSuccessfulRefactoring(''' | 151 return assertSuccessfulRefactoring(''' |
153 class A { | 152 class A { |
154 A.newName(); | 153 A.newName(); |
155 } | 154 } |
156 class B extends A { | 155 class B extends A { |
157 B() : super.newName() {} | 156 B() : super.newName() {} |
158 factory B._() = A.newName; | |
159 } | 157 } |
160 main() { | 158 main() { |
161 new A.newName(); | 159 new A.newName(); |
162 } | 160 } |
163 '''); | 161 '''); |
164 } | 162 } |
165 | 163 |
166 test_createChange_change() async { | 164 test_createChange_change() async { |
167 await indexTestUnit(''' | 165 await indexTestUnit(''' |
168 class A { | 166 class A { |
169 A.test() {} // marker | 167 A.test() {} // marker |
| 168 factory A._() = A.test; |
170 } | 169 } |
171 class B extends A { | 170 class B extends A { |
172 B() : super.test() {} | 171 B() : super.test() {} |
173 factory B._() = A.test; | |
174 } | 172 } |
175 main() { | 173 main() { |
176 new A.test(); | 174 new A.test(); |
177 } | 175 } |
178 '''); | 176 '''); |
179 // configure refactoring | 177 // configure refactoring |
180 _createConstructorDeclarationRefactoring('test() {} // marker'); | 178 _createConstructorDeclarationRefactoring('test() {} // marker'); |
181 expect(refactoring.refactoringName, 'Rename Constructor'); | 179 expect(refactoring.refactoringName, 'Rename Constructor'); |
182 expect(refactoring.elementKindName, 'constructor'); | 180 expect(refactoring.elementKindName, 'constructor'); |
183 expect(refactoring.oldName, 'test'); | 181 expect(refactoring.oldName, 'test'); |
184 // validate change | 182 // validate change |
185 refactoring.newName = 'newName'; | 183 refactoring.newName = 'newName'; |
186 return assertSuccessfulRefactoring(''' | 184 return assertSuccessfulRefactoring(''' |
187 class A { | 185 class A { |
188 A.newName() {} // marker | 186 A.newName() {} // marker |
| 187 factory A._() = A.newName; |
189 } | 188 } |
190 class B extends A { | 189 class B extends A { |
191 B() : super.newName() {} | 190 B() : super.newName() {} |
192 factory B._() = A.newName; | |
193 } | 191 } |
194 main() { | 192 main() { |
195 new A.newName(); | 193 new A.newName(); |
196 } | 194 } |
197 '''); | 195 '''); |
198 } | 196 } |
199 | 197 |
200 test_createChange_remove() async { | 198 test_createChange_remove() async { |
201 await indexTestUnit(''' | 199 await indexTestUnit(''' |
202 class A { | 200 class A { |
203 A.test() {} // marker | 201 A.test() {} // marker |
| 202 factory A._() = A.test; |
204 } | 203 } |
205 class B extends A { | 204 class B extends A { |
206 B() : super.test() {} | 205 B() : super.test() {} |
207 factory B._() = A.test; | |
208 } | 206 } |
209 main() { | 207 main() { |
210 new A.test(); | 208 new A.test(); |
211 } | 209 } |
212 '''); | 210 '''); |
213 // configure refactoring | 211 // configure refactoring |
214 _createConstructorDeclarationRefactoring('test() {} // marker'); | 212 _createConstructorDeclarationRefactoring('test() {} // marker'); |
215 expect(refactoring.refactoringName, 'Rename Constructor'); | 213 expect(refactoring.refactoringName, 'Rename Constructor'); |
216 expect(refactoring.elementKindName, 'constructor'); | 214 expect(refactoring.elementKindName, 'constructor'); |
217 expect(refactoring.oldName, 'test'); | 215 expect(refactoring.oldName, 'test'); |
218 // validate change | 216 // validate change |
219 refactoring.newName = ''; | 217 refactoring.newName = ''; |
220 return assertSuccessfulRefactoring(''' | 218 return assertSuccessfulRefactoring(''' |
221 class A { | 219 class A { |
222 A() {} // marker | 220 A() {} // marker |
| 221 factory A._() = A; |
223 } | 222 } |
224 class B extends A { | 223 class B extends A { |
225 B() : super() {} | 224 B() : super() {} |
226 factory B._() = A; | |
227 } | 225 } |
228 main() { | 226 main() { |
229 new A(); | 227 new A(); |
230 } | 228 } |
231 '''); | 229 '''); |
232 } | 230 } |
233 | 231 |
234 test_newInstance_nullElement() async { | 232 test_newInstance_nullElement() async { |
235 RenameRefactoring refactoring = | 233 RenameRefactoring refactoring = |
236 new RenameRefactoring(searchEngine, null, null); | 234 new RenameRefactoring(searchEngine, null, null); |
237 expect(refactoring, isNull); | 235 expect(refactoring, isNull); |
238 } | 236 } |
239 | 237 |
240 void _createConstructorDeclarationRefactoring(String search) { | 238 void _createConstructorDeclarationRefactoring(String search) { |
241 ConstructorElement element = findNodeElementAtString( | 239 ConstructorElement element = findNodeElementAtString( |
242 search, (node) => node is ConstructorDeclaration); | 240 search, (node) => node is ConstructorDeclaration); |
243 createRenameRefactoringForElement(element); | 241 createRenameRefactoringForElement(element); |
244 } | 242 } |
245 | 243 |
246 void _createConstructorInvocationRefactoring(String search) { | 244 void _createConstructorInvocationRefactoring(String search) { |
247 ConstructorElement element = findNodeElementAtString( | 245 ConstructorElement element = findNodeElementAtString( |
248 search, (node) => node is InstanceCreationExpression); | 246 search, (node) => node is InstanceCreationExpression); |
249 createRenameRefactoringForElement(element); | 247 createRenameRefactoringForElement(element); |
250 } | 248 } |
251 } | 249 } |
OLD | NEW |