| 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 library test.services.refactoring.extract_method; | 5 library test.services.refactoring.extract_method; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| 11 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; | 11 import 'package:analysis_server/src/services/refactoring/extract_method.dart'; |
| 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 | 15 |
| 16 import 'abstract_refactoring.dart'; | 16 import 'abstract_refactoring.dart'; |
| 17 | 17 |
| 18 main() { | 18 main() { |
| 19 defineReflectiveSuite(() { | 19 defineReflectiveSuite(() { |
| 20 defineReflectiveTests(ExtractMethodTest); | 20 defineReflectiveTests(ExtractMethodTest); |
| 21 }); | 21 }); |
| 22 } | 22 } |
| 23 | 23 |
| 24 @reflectiveTest | 24 @reflectiveTest |
| 25 class ExtractMethodTest extends RefactoringTest { | 25 class ExtractMethodTest extends RefactoringTest { |
| 26 ExtractMethodRefactoringImpl refactoring; | 26 ExtractMethodRefactoringImpl refactoring; |
| 27 | 27 |
| 28 test_bad_assignmentLeftHandSide() { | 28 test_bad_assignmentLeftHandSide() async { |
| 29 indexTestUnit(''' | 29 await indexTestUnit(''' |
| 30 main() { | 30 main() { |
| 31 int aaa; | 31 int aaa; |
| 32 aaa = 0; | 32 aaa = 0; |
| 33 } | 33 } |
| 34 '''); | 34 '''); |
| 35 _createRefactoringForString('aaa '); | 35 _createRefactoringForString('aaa '); |
| 36 return _assertConditionsFatal( | 36 return _assertConditionsFatal( |
| 37 'Cannot extract the left-hand side of an assignment.'); | 37 'Cannot extract the left-hand side of an assignment.'); |
| 38 } | 38 } |
| 39 | 39 |
| 40 test_bad_comment_selectionEndsInside() { | 40 test_bad_comment_selectionEndsInside() async { |
| 41 indexTestUnit(''' | 41 await indexTestUnit(''' |
| 42 main() { | 42 main() { |
| 43 // start | 43 // start |
| 44 print(0); | 44 print(0); |
| 45 /* | 45 /* |
| 46 // end | 46 // end |
| 47 */ | 47 */ |
| 48 } | 48 } |
| 49 '''); | 49 '''); |
| 50 _createRefactoringForStartEndComments(); | 50 _createRefactoringForStartEndComments(); |
| 51 return _assertConditionsFatal('Selection ends inside a comment.'); | 51 return _assertConditionsFatal('Selection ends inside a comment.'); |
| 52 } | 52 } |
| 53 | 53 |
| 54 test_bad_comment_selectionStartsInside() { | 54 test_bad_comment_selectionStartsInside() async { |
| 55 indexTestUnit(''' | 55 await indexTestUnit(''' |
| 56 main() { | 56 main() { |
| 57 /* | 57 /* |
| 58 // start | 58 // start |
| 59 */ | 59 */ |
| 60 print(0); | 60 print(0); |
| 61 // end | 61 // end |
| 62 } | 62 } |
| 63 '''); | 63 '''); |
| 64 _createRefactoringForStartEndComments(); | 64 _createRefactoringForStartEndComments(); |
| 65 return _assertConditionsFatal('Selection begins inside a comment.'); | 65 return _assertConditionsFatal('Selection begins inside a comment.'); |
| 66 } | 66 } |
| 67 | 67 |
| 68 test_bad_conflict_method_alreadyDeclaresMethod() { | 68 test_bad_conflict_method_alreadyDeclaresMethod() async { |
| 69 indexTestUnit(''' | 69 await indexTestUnit(''' |
| 70 class A { | 70 class A { |
| 71 void res() {} | 71 void res() {} |
| 72 main() { | 72 main() { |
| 73 // start | 73 // start |
| 74 print(0); | 74 print(0); |
| 75 // end | 75 // end |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 '''); | 78 '''); |
| 79 _createRefactoringForStartEndComments(); | 79 _createRefactoringForStartEndComments(); |
| 80 return _assertConditionsError( | 80 return _assertConditionsError( |
| 81 "Class 'A' already declares method with name 'res'."); | 81 "Class 'A' already declares method with name 'res'."); |
| 82 } | 82 } |
| 83 | 83 |
| 84 test_bad_conflict_method_shadowsSuperDeclaration() { | 84 test_bad_conflict_method_shadowsSuperDeclaration() async { |
| 85 indexTestUnit(''' | 85 await indexTestUnit(''' |
| 86 class A { | 86 class A { |
| 87 void res() {} // marker | 87 void res() {} // marker |
| 88 } | 88 } |
| 89 class B extends A { | 89 class B extends A { |
| 90 main() { | 90 main() { |
| 91 res(); | 91 res(); |
| 92 // start | 92 // start |
| 93 print(0); | 93 print(0); |
| 94 // end | 94 // end |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 '''); | 97 '''); |
| 98 _createRefactoringForStartEndComments(); | 98 _createRefactoringForStartEndComments(); |
| 99 return _assertConditionsError("Created method will shadow method 'A.res'."); | 99 return _assertConditionsError("Created method will shadow method 'A.res'."); |
| 100 } | 100 } |
| 101 | 101 |
| 102 test_bad_conflict_topLevel_alreadyDeclaresFunction() { | 102 test_bad_conflict_topLevel_alreadyDeclaresFunction() async { |
| 103 indexTestUnit(''' | 103 await indexTestUnit(''' |
| 104 library my.lib; | 104 library my.lib; |
| 105 | 105 |
| 106 void res() {} | 106 void res() {} |
| 107 main() { | 107 main() { |
| 108 // start | 108 // start |
| 109 print(0); | 109 print(0); |
| 110 // end | 110 // end |
| 111 } | 111 } |
| 112 '''); | 112 '''); |
| 113 _createRefactoringForStartEndComments(); | 113 _createRefactoringForStartEndComments(); |
| 114 return _assertConditionsError( | 114 return _assertConditionsError( |
| 115 "Library already declares function with name 'res'."); | 115 "Library already declares function with name 'res'."); |
| 116 } | 116 } |
| 117 | 117 |
| 118 test_bad_conflict_topLevel_willHideInheritedMemberUsage() { | 118 test_bad_conflict_topLevel_willHideInheritedMemberUsage() async { |
| 119 indexTestUnit(''' | 119 await indexTestUnit(''' |
| 120 class A { | 120 class A { |
| 121 void res() {} | 121 void res() {} |
| 122 } | 122 } |
| 123 class B extends A { | 123 class B extends A { |
| 124 foo() { | 124 foo() { |
| 125 res(); // marker | 125 res(); // marker |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 main() { | 128 main() { |
| 129 // start | 129 // start |
| 130 print(0); | 130 print(0); |
| 131 // end | 131 // end |
| 132 } | 132 } |
| 133 '''); | 133 '''); |
| 134 _createRefactoringForStartEndComments(); | 134 _createRefactoringForStartEndComments(); |
| 135 return _assertConditionsError( | 135 return _assertConditionsError( |
| 136 "Created function will shadow method 'A.res'."); | 136 "Created function will shadow method 'A.res'."); |
| 137 } | 137 } |
| 138 | 138 |
| 139 test_bad_constructor_initializer() { | 139 test_bad_constructor_initializer() async { |
| 140 indexTestUnit(''' | 140 await indexTestUnit(''' |
| 141 class A { | 141 class A { |
| 142 int f; | 142 int f; |
| 143 A() : f = 0 {} | 143 A() : f = 0 {} |
| 144 } | 144 } |
| 145 '''); | 145 '''); |
| 146 _createRefactoringForString('f = 0'); | 146 _createRefactoringForString('f = 0'); |
| 147 return _assertConditionsFatal( | 147 return _assertConditionsFatal( |
| 148 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); | 148 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); |
| 149 } | 149 } |
| 150 | 150 |
| 151 test_bad_constructor_redirectingConstructor() { | 151 test_bad_constructor_redirectingConstructor() async { |
| 152 indexTestUnit(''' | 152 await indexTestUnit(''' |
| 153 class A { | 153 class A { |
| 154 A() : this.named(); | 154 A() : this.named(); |
| 155 A.named() {} | 155 A.named() {} |
| 156 } | 156 } |
| 157 '''); | 157 '''); |
| 158 _createRefactoringForString('this.named()'); | 158 _createRefactoringForString('this.named()'); |
| 159 return _assertConditionsFatal( | 159 return _assertConditionsFatal( |
| 160 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); | 160 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); |
| 161 } | 161 } |
| 162 | 162 |
| 163 test_bad_constructor_superConstructor() { | 163 test_bad_constructor_superConstructor() async { |
| 164 indexTestUnit(''' | 164 await indexTestUnit(''' |
| 165 class A {} | 165 class A {} |
| 166 class B extends A { | 166 class B extends A { |
| 167 B() : super(); | 167 B() : super(); |
| 168 } | 168 } |
| 169 '''); | 169 '''); |
| 170 _createRefactoringForString('super()'); | 170 _createRefactoringForString('super()'); |
| 171 return _assertConditionsFatal( | 171 return _assertConditionsFatal( |
| 172 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); | 172 'Cannot extract a constructor initializer. Select expression part of ini
tializer.'); |
| 173 } | 173 } |
| 174 | 174 |
| 175 test_bad_doWhile_body() { | 175 test_bad_doWhile_body() async { |
| 176 indexTestUnit(''' | 176 await indexTestUnit(''' |
| 177 main() { | 177 main() { |
| 178 do | 178 do |
| 179 // start | 179 // start |
| 180 { | 180 { |
| 181 } | 181 } |
| 182 // end | 182 // end |
| 183 while (true); | 183 while (true); |
| 184 } | 184 } |
| 185 '''); | 185 '''); |
| 186 _createRefactoringForStartEndComments(); | 186 _createRefactoringForStartEndComments(); |
| 187 return _assertConditionsFatal( | 187 return _assertConditionsFatal( |
| 188 "Operation not applicable to a 'do' statement's body and expression."); | 188 "Operation not applicable to a 'do' statement's body and expression."); |
| 189 } | 189 } |
| 190 | 190 |
| 191 test_bad_emptySelection() { | 191 test_bad_emptySelection() async { |
| 192 indexTestUnit(''' | 192 await indexTestUnit(''' |
| 193 main() { | 193 main() { |
| 194 // start | 194 // start |
| 195 // end | 195 // end |
| 196 print(0); | 196 print(0); |
| 197 } | 197 } |
| 198 '''); | 198 '''); |
| 199 _createRefactoringForStartEndComments(); | 199 _createRefactoringForStartEndComments(); |
| 200 return _assertConditionsFatal( | 200 return _assertConditionsFatal( |
| 201 "Can only extract a single expression or a set of statements."); | 201 "Can only extract a single expression or a set of statements."); |
| 202 } | 202 } |
| 203 | 203 |
| 204 test_bad_forLoop_conditionAndUpdaters() { | 204 test_bad_forLoop_conditionAndUpdaters() async { |
| 205 indexTestUnit(''' | 205 await indexTestUnit(''' |
| 206 main() { | 206 main() { |
| 207 for ( | 207 for ( |
| 208 int i = 0; | 208 int i = 0; |
| 209 // start | 209 // start |
| 210 i < 10; | 210 i < 10; |
| 211 i++ | 211 i++ |
| 212 // end | 212 // end |
| 213 ) {} | 213 ) {} |
| 214 } | 214 } |
| 215 '''); | 215 '''); |
| 216 _createRefactoringForStartEndComments(); | 216 _createRefactoringForStartEndComments(); |
| 217 return _assertConditionsFatal( | 217 return _assertConditionsFatal( |
| 218 "Operation not applicable to a 'for' statement's condition and updaters.
"); | 218 "Operation not applicable to a 'for' statement's condition and updaters.
"); |
| 219 } | 219 } |
| 220 | 220 |
| 221 test_bad_forLoop_init() { | 221 test_bad_forLoop_init() async { |
| 222 indexTestUnit(''' | 222 await indexTestUnit(''' |
| 223 main() { | 223 main() { |
| 224 for ( | 224 for ( |
| 225 // start | 225 // start |
| 226 int i = 0 | 226 int i = 0 |
| 227 // end | 227 // end |
| 228 ; i < 10; | 228 ; i < 10; |
| 229 i++ | 229 i++ |
| 230 ) {} | 230 ) {} |
| 231 } | 231 } |
| 232 '''); | 232 '''); |
| 233 _createRefactoringForStartEndComments(); | 233 _createRefactoringForStartEndComments(); |
| 234 return _assertConditionsFatal( | 234 return _assertConditionsFatal( |
| 235 "Cannot extract initialization part of a 'for' statement."); | 235 "Cannot extract initialization part of a 'for' statement."); |
| 236 } | 236 } |
| 237 | 237 |
| 238 test_bad_forLoop_initAndCondition() { | 238 test_bad_forLoop_initAndCondition() async { |
| 239 indexTestUnit(''' | 239 await indexTestUnit(''' |
| 240 main() { | 240 main() { |
| 241 for ( | 241 for ( |
| 242 // start | 242 // start |
| 243 int i = 0; | 243 int i = 0; |
| 244 i < 10; | 244 i < 10; |
| 245 // end | 245 // end |
| 246 i++ | 246 i++ |
| 247 ) {} | 247 ) {} |
| 248 } | 248 } |
| 249 '''); | 249 '''); |
| 250 _createRefactoringForStartEndComments(); | 250 _createRefactoringForStartEndComments(); |
| 251 return _assertConditionsFatal( | 251 return _assertConditionsFatal( |
| 252 "Operation not applicable to a 'for' statement's initializer and conditi
on."); | 252 "Operation not applicable to a 'for' statement's initializer and conditi
on."); |
| 253 } | 253 } |
| 254 | 254 |
| 255 test_bad_forLoop_updaters() { | 255 test_bad_forLoop_updaters() async { |
| 256 indexTestUnit(''' | 256 await indexTestUnit(''' |
| 257 main() { | 257 main() { |
| 258 for ( | 258 for ( |
| 259 int i = 0; | 259 int i = 0; |
| 260 i < 10; | 260 i < 10; |
| 261 // start | 261 // start |
| 262 i++ | 262 i++ |
| 263 // end | 263 // end |
| 264 ) {} | 264 ) {} |
| 265 } | 265 } |
| 266 '''); | 266 '''); |
| 267 _createRefactoringForStartEndComments(); | 267 _createRefactoringForStartEndComments(); |
| 268 return _assertConditionsFatal( | 268 return _assertConditionsFatal( |
| 269 "Cannot extract increment part of a 'for' statement."); | 269 "Cannot extract increment part of a 'for' statement."); |
| 270 } | 270 } |
| 271 | 271 |
| 272 test_bad_forLoop_updatersAndBody() { | 272 test_bad_forLoop_updatersAndBody() async { |
| 273 indexTestUnit(''' | 273 await indexTestUnit(''' |
| 274 main() { | 274 main() { |
| 275 for ( | 275 for ( |
| 276 int i = 0; | 276 int i = 0; |
| 277 i < 10; | 277 i < 10; |
| 278 // start | 278 // start |
| 279 i++ | 279 i++ |
| 280 ) {} | 280 ) {} |
| 281 // end | 281 // end |
| 282 } | 282 } |
| 283 '''); | 283 '''); |
| 284 _createRefactoringForStartEndComments(); | 284 _createRefactoringForStartEndComments(); |
| 285 return _assertConditionsFatal( | 285 return _assertConditionsFatal( |
| 286 "Operation not applicable to a 'for' statement's updaters and body."); | 286 "Operation not applicable to a 'for' statement's updaters and body."); |
| 287 } | 287 } |
| 288 | 288 |
| 289 test_bad_methodName_reference() { | 289 test_bad_methodName_reference() async { |
| 290 indexTestUnit(''' | 290 await indexTestUnit(''' |
| 291 main() { | 291 main() { |
| 292 main(); | 292 main(); |
| 293 } | 293 } |
| 294 '''); | 294 '''); |
| 295 _createRefactoringWithSuffix('main', '();'); | 295 _createRefactoringWithSuffix('main', '();'); |
| 296 return _assertConditionsFatal("Cannot extract a single method name."); | 296 return _assertConditionsFatal("Cannot extract a single method name."); |
| 297 } | 297 } |
| 298 | 298 |
| 299 test_bad_namePartOfDeclaration_function() { | 299 test_bad_namePartOfDeclaration_function() async { |
| 300 indexTestUnit(''' | 300 await indexTestUnit(''' |
| 301 main() { | 301 main() { |
| 302 } | 302 } |
| 303 '''); | 303 '''); |
| 304 _createRefactoringForString('main'); | 304 _createRefactoringForString('main'); |
| 305 return _assertConditionsFatal( | 305 return _assertConditionsFatal( |
| 306 "Cannot extract the name part of a declaration."); | 306 "Cannot extract the name part of a declaration."); |
| 307 } | 307 } |
| 308 | 308 |
| 309 test_bad_namePartOfDeclaration_variable() { | 309 test_bad_namePartOfDeclaration_variable() async { |
| 310 indexTestUnit(''' | 310 await indexTestUnit(''' |
| 311 main() { | 311 main() { |
| 312 int vvv = 0; | 312 int vvv = 0; |
| 313 } | 313 } |
| 314 '''); | 314 '''); |
| 315 _createRefactoringForString('vvv'); | 315 _createRefactoringForString('vvv'); |
| 316 return _assertConditionsFatal( | 316 return _assertConditionsFatal( |
| 317 "Cannot extract the name part of a declaration."); | 317 "Cannot extract the name part of a declaration."); |
| 318 } | 318 } |
| 319 | 319 |
| 320 test_bad_namePartOfQualified() { | 320 test_bad_namePartOfQualified() async { |
| 321 indexTestUnit(''' | 321 await indexTestUnit(''' |
| 322 class A { | 322 class A { |
| 323 var fff; | 323 var fff; |
| 324 } | 324 } |
| 325 main() { | 325 main() { |
| 326 A a; | 326 A a; |
| 327 a.fff = 1; | 327 a.fff = 1; |
| 328 } | 328 } |
| 329 '''); | 329 '''); |
| 330 _createRefactoringWithSuffix('fff', ' = 1'); | 330 _createRefactoringWithSuffix('fff', ' = 1'); |
| 331 return _assertConditionsFatal( | 331 return _assertConditionsFatal( |
| 332 "Can not extract name part of a property access."); | 332 "Can not extract name part of a property access."); |
| 333 } | 333 } |
| 334 | 334 |
| 335 test_bad_newMethodName_notIdentifier() { | 335 test_bad_newMethodName_notIdentifier() async { |
| 336 indexTestUnit(''' | 336 await indexTestUnit(''' |
| 337 main() { | 337 main() { |
| 338 // start | 338 // start |
| 339 print(0); | 339 print(0); |
| 340 // end | 340 // end |
| 341 } | 341 } |
| 342 '''); | 342 '''); |
| 343 _createRefactoringForStartEndComments(); | 343 _createRefactoringForStartEndComments(); |
| 344 refactoring.name = 'bad-name'; | 344 refactoring.name = 'bad-name'; |
| 345 // check conditions | 345 // check conditions |
| 346 return _assertConditionsFatal("Method name must not contain '-'."); | 346 return _assertConditionsFatal("Method name must not contain '-'."); |
| 347 } | 347 } |
| 348 | 348 |
| 349 test_bad_notSameParent() { | 349 test_bad_notSameParent() async { |
| 350 indexTestUnit(''' | 350 await indexTestUnit(''' |
| 351 main() { | 351 main() { |
| 352 while (false) | 352 while (false) |
| 353 // start | 353 // start |
| 354 { | 354 { |
| 355 } | 355 } |
| 356 print(0); | 356 print(0); |
| 357 // end | 357 // end |
| 358 } | 358 } |
| 359 '''); | 359 '''); |
| 360 _createRefactoringForStartEndComments(); | 360 _createRefactoringForStartEndComments(); |
| 361 return _assertConditionsFatal( | 361 return _assertConditionsFatal( |
| 362 'Not all selected statements are enclosed by the same parent statement.'
); | 362 'Not all selected statements are enclosed by the same parent statement.'
); |
| 363 } | 363 } |
| 364 | 364 |
| 365 test_bad_parameterName_duplicate() async { | 365 test_bad_parameterName_duplicate() async { |
| 366 indexTestUnit(''' | 366 await indexTestUnit(''' |
| 367 main() { | 367 main() { |
| 368 int v1 = 1; | 368 int v1 = 1; |
| 369 int v2 = 2; | 369 int v2 = 2; |
| 370 // start | 370 // start |
| 371 int a = v1 + v2; // marker | 371 int a = v1 + v2; // marker |
| 372 // end | 372 // end |
| 373 } | 373 } |
| 374 '''); | 374 '''); |
| 375 _createRefactoringForStartEndComments(); | 375 _createRefactoringForStartEndComments(); |
| 376 // update parameters | 376 // update parameters |
| 377 await refactoring.checkInitialConditions(); | 377 await refactoring.checkInitialConditions(); |
| 378 { | 378 { |
| 379 List<RefactoringMethodParameter> parameters = _getParametersCopy(); | 379 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 380 expect(parameters, hasLength(2)); | 380 expect(parameters, hasLength(2)); |
| 381 parameters[0].name = 'dup'; | 381 parameters[0].name = 'dup'; |
| 382 parameters[1].name = 'dup'; | 382 parameters[1].name = 'dup'; |
| 383 refactoring.parameters = parameters; | 383 refactoring.parameters = parameters; |
| 384 } | 384 } |
| 385 return _assertFinalConditionsError("Parameter 'dup' already exists"); | 385 return _assertFinalConditionsError("Parameter 'dup' already exists"); |
| 386 } | 386 } |
| 387 | 387 |
| 388 test_bad_parameterName_inUse_function() async { | 388 test_bad_parameterName_inUse_function() async { |
| 389 indexTestUnit(''' | 389 await indexTestUnit(''' |
| 390 main() { | 390 main() { |
| 391 int v1 = 1; | 391 int v1 = 1; |
| 392 int v2 = 2; | 392 int v2 = 2; |
| 393 // start | 393 // start |
| 394 f(v1, v2); | 394 f(v1, v2); |
| 395 // end | 395 // end |
| 396 } | 396 } |
| 397 f(a, b) {} | 397 f(a, b) {} |
| 398 '''); | 398 '''); |
| 399 _createRefactoringForStartEndComments(); | 399 _createRefactoringForStartEndComments(); |
| 400 // update parameters | 400 // update parameters |
| 401 await refactoring.checkInitialConditions(); | 401 await refactoring.checkInitialConditions(); |
| 402 { | 402 { |
| 403 List<RefactoringMethodParameter> parameters = _getParametersCopy(); | 403 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 404 expect(parameters, hasLength(2)); | 404 expect(parameters, hasLength(2)); |
| 405 parameters[0].name = 'f'; | 405 parameters[0].name = 'f'; |
| 406 refactoring.parameters = parameters; | 406 refactoring.parameters = parameters; |
| 407 } | 407 } |
| 408 return _assertFinalConditionsError( | 408 return _assertFinalConditionsError( |
| 409 "'f' is already used as a name in the selected code"); | 409 "'f' is already used as a name in the selected code"); |
| 410 } | 410 } |
| 411 | 411 |
| 412 test_bad_parameterName_inUse_localVariable() async { | 412 test_bad_parameterName_inUse_localVariable() async { |
| 413 indexTestUnit(''' | 413 await indexTestUnit(''' |
| 414 main() { | 414 main() { |
| 415 int v1 = 1; | 415 int v1 = 1; |
| 416 int v2 = 2; | 416 int v2 = 2; |
| 417 // start | 417 // start |
| 418 int a = v1 + v2; // marker | 418 int a = v1 + v2; // marker |
| 419 // end | 419 // end |
| 420 } | 420 } |
| 421 '''); | 421 '''); |
| 422 _createRefactoringForStartEndComments(); | 422 _createRefactoringForStartEndComments(); |
| 423 // update parameters | 423 // update parameters |
| 424 await refactoring.checkInitialConditions(); | 424 await refactoring.checkInitialConditions(); |
| 425 { | 425 { |
| 426 List<RefactoringMethodParameter> parameters = _getParametersCopy(); | 426 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 427 expect(parameters, hasLength(2)); | 427 expect(parameters, hasLength(2)); |
| 428 parameters[0].name = 'a'; | 428 parameters[0].name = 'a'; |
| 429 refactoring.parameters = parameters; | 429 refactoring.parameters = parameters; |
| 430 } | 430 } |
| 431 return _assertFinalConditionsError( | 431 return _assertFinalConditionsError( |
| 432 "'a' is already used as a name in the selected code"); | 432 "'a' is already used as a name in the selected code"); |
| 433 } | 433 } |
| 434 | 434 |
| 435 test_bad_parameterName_inUse_method() async { | 435 test_bad_parameterName_inUse_method() async { |
| 436 indexTestUnit(''' | 436 await indexTestUnit(''' |
| 437 class A { | 437 class A { |
| 438 main() { | 438 main() { |
| 439 int v1 = 1; | 439 int v1 = 1; |
| 440 int v2 = 2; | 440 int v2 = 2; |
| 441 // start | 441 // start |
| 442 m(v1, v2); | 442 m(v1, v2); |
| 443 // end | 443 // end |
| 444 } | 444 } |
| 445 m(a, b) {} | 445 m(a, b) {} |
| 446 } | 446 } |
| 447 '''); | 447 '''); |
| 448 _createRefactoringForStartEndComments(); | 448 _createRefactoringForStartEndComments(); |
| 449 // update parameters | 449 // update parameters |
| 450 await refactoring.checkInitialConditions(); | 450 await refactoring.checkInitialConditions(); |
| 451 { | 451 { |
| 452 List<RefactoringMethodParameter> parameters = _getParametersCopy(); | 452 List<RefactoringMethodParameter> parameters = _getParametersCopy(); |
| 453 expect(parameters, hasLength(2)); | 453 expect(parameters, hasLength(2)); |
| 454 parameters[0].name = 'm'; | 454 parameters[0].name = 'm'; |
| 455 refactoring.parameters = parameters; | 455 refactoring.parameters = parameters; |
| 456 } | 456 } |
| 457 return _assertFinalConditionsError( | 457 return _assertFinalConditionsError( |
| 458 "'m' is already used as a name in the selected code"); | 458 "'m' is already used as a name in the selected code"); |
| 459 } | 459 } |
| 460 | 460 |
| 461 test_bad_selectionEndsInSomeNode() { | 461 test_bad_selectionEndsInSomeNode() async { |
| 462 indexTestUnit(''' | 462 await indexTestUnit(''' |
| 463 main() { | 463 main() { |
| 464 // start | 464 // start |
| 465 print(0); | 465 print(0); |
| 466 print(1); | 466 print(1); |
| 467 // end | 467 // end |
| 468 } | 468 } |
| 469 '''); | 469 '''); |
| 470 _createRefactoringForStartEndString('print(0', 'rint(1)'); | 470 _createRefactoringForStartEndString('print(0', 'rint(1)'); |
| 471 return _assertConditionsFatal( | 471 return _assertConditionsFatal( |
| 472 "The selection does not cover a set of statements or an expression. " | 472 "The selection does not cover a set of statements or an expression. " |
| 473 "Extend selection to a valid range."); | 473 "Extend selection to a valid range."); |
| 474 } | 474 } |
| 475 | 475 |
| 476 test_bad_statements_exit_notAllExecutionFlows() { | 476 test_bad_statements_exit_notAllExecutionFlows() async { |
| 477 indexTestUnit(''' | 477 await indexTestUnit(''' |
| 478 main(int p) { | 478 main(int p) { |
| 479 // start | 479 // start |
| 480 if (p == 0) { | 480 if (p == 0) { |
| 481 return; | 481 return; |
| 482 } | 482 } |
| 483 // end | 483 // end |
| 484 print(p); | 484 print(p); |
| 485 } | 485 } |
| 486 '''); | 486 '''); |
| 487 _createRefactoringForStartEndComments(); | 487 _createRefactoringForStartEndComments(); |
| 488 return _assertConditionsError(ExtractMethodRefactoringImpl.ERROR_EXITS); | 488 return _assertConditionsError(ExtractMethodRefactoringImpl.ERROR_EXITS); |
| 489 } | 489 } |
| 490 | 490 |
| 491 test_bad_statements_return_andAssignsVariable() { | 491 test_bad_statements_return_andAssignsVariable() async { |
| 492 indexTestUnit(''' | 492 await indexTestUnit(''' |
| 493 main() { | 493 main() { |
| 494 // start | 494 // start |
| 495 var v = 0; | 495 var v = 0; |
| 496 return 42; | 496 return 42; |
| 497 // end | 497 // end |
| 498 print(v); | 498 print(v); |
| 499 } | 499 } |
| 500 '''); | 500 '''); |
| 501 _createRefactoringForStartEndComments(); | 501 _createRefactoringForStartEndComments(); |
| 502 return _assertConditionsFatal( | 502 return _assertConditionsFatal( |
| 503 "Ambiguous return value: Selected block contains assignment(s) to " | 503 "Ambiguous return value: Selected block contains assignment(s) to " |
| 504 "local variables and return statement."); | 504 "local variables and return statement."); |
| 505 } | 505 } |
| 506 | 506 |
| 507 test_bad_switchCase() { | 507 test_bad_switchCase() async { |
| 508 indexTestUnit(''' | 508 await indexTestUnit(''' |
| 509 main() { | 509 main() { |
| 510 switch (1) { | 510 switch (1) { |
| 511 // start | 511 // start |
| 512 case 0: break; | 512 case 0: break; |
| 513 // end | 513 // end |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 '''); | 516 '''); |
| 517 _createRefactoringForStartEndComments(); | 517 _createRefactoringForStartEndComments(); |
| 518 return _assertConditionsFatal( | 518 return _assertConditionsFatal( |
| 519 "Selection must either cover whole switch statement " | 519 "Selection must either cover whole switch statement " |
| 520 "or parts of a single case block."); | 520 "or parts of a single case block."); |
| 521 } | 521 } |
| 522 | 522 |
| 523 test_bad_tokensBetweenLastNodeAndSelectionEnd() { | 523 test_bad_tokensBetweenLastNodeAndSelectionEnd() async { |
| 524 indexTestUnit(''' | 524 await indexTestUnit(''' |
| 525 main() { | 525 main() { |
| 526 // start | 526 // start |
| 527 print(0); | 527 print(0); |
| 528 print(1); | 528 print(1); |
| 529 } | 529 } |
| 530 // end | 530 // end |
| 531 '''); | 531 '''); |
| 532 _createRefactoringForStartEndComments(); | 532 _createRefactoringForStartEndComments(); |
| 533 return _assertConditionsFatal( | 533 return _assertConditionsFatal( |
| 534 "The end of the selection contains characters that do not belong to a st
atement."); | 534 "The end of the selection contains characters that do not belong to a st
atement."); |
| 535 } | 535 } |
| 536 | 536 |
| 537 test_bad_tokensBetweenSelectionStartAndFirstNode() { | 537 test_bad_tokensBetweenSelectionStartAndFirstNode() async { |
| 538 indexTestUnit(''' | 538 await indexTestUnit(''' |
| 539 main() { | 539 main() { |
| 540 // start | 540 // start |
| 541 print(0); // marker | 541 print(0); // marker |
| 542 print(1); | 542 print(1); |
| 543 // end | 543 // end |
| 544 } | 544 } |
| 545 '''); | 545 '''); |
| 546 _createRefactoringForStartEndString('); // marker', '// end'); | 546 _createRefactoringForStartEndString('); // marker', '// end'); |
| 547 return _assertConditionsFatal( | 547 return _assertConditionsFatal( |
| 548 "The beginning of the selection contains characters that do not belong t
o a statement."); | 548 "The beginning of the selection contains characters that do not belong t
o a statement."); |
| 549 } | 549 } |
| 550 | 550 |
| 551 test_bad_try_catchBlock_block() { | 551 test_bad_try_catchBlock_block() async { |
| 552 indexTestUnit(''' | 552 await indexTestUnit(''' |
| 553 main() { | 553 main() { |
| 554 try | 554 try |
| 555 {} | 555 {} |
| 556 catch (e) | 556 catch (e) |
| 557 // start | 557 // start |
| 558 {} | 558 {} |
| 559 // end | 559 // end |
| 560 } | 560 } |
| 561 '''); | 561 '''); |
| 562 _createRefactoringForStartEndComments(); | 562 _createRefactoringForStartEndComments(); |
| 563 return _assertConditionsFatal( | 563 return _assertConditionsFatal( |
| 564 "Selection must either cover whole try statement or " | 564 "Selection must either cover whole try statement or " |
| 565 "parts of try, catch, or finally block."); | 565 "parts of try, catch, or finally block."); |
| 566 } | 566 } |
| 567 | 567 |
| 568 test_bad_try_catchBlock_complete() { | 568 test_bad_try_catchBlock_complete() async { |
| 569 indexTestUnit(''' | 569 await indexTestUnit(''' |
| 570 main() { | 570 main() { |
| 571 try | 571 try |
| 572 {} | 572 {} |
| 573 // start | 573 // start |
| 574 catch (e) | 574 catch (e) |
| 575 {} | 575 {} |
| 576 // end | 576 // end |
| 577 } | 577 } |
| 578 '''); | 578 '''); |
| 579 _createRefactoringForStartEndComments(); | 579 _createRefactoringForStartEndComments(); |
| 580 return _assertConditionsFatal( | 580 return _assertConditionsFatal( |
| 581 "Selection must either cover whole try statement or " | 581 "Selection must either cover whole try statement or " |
| 582 "parts of try, catch, or finally block."); | 582 "parts of try, catch, or finally block."); |
| 583 } | 583 } |
| 584 | 584 |
| 585 test_bad_try_catchBlock_exception() { | 585 test_bad_try_catchBlock_exception() async { |
| 586 indexTestUnit(''' | 586 await indexTestUnit(''' |
| 587 main() { | 587 main() { |
| 588 try { | 588 try { |
| 589 } catch ( | 589 } catch ( |
| 590 // start | 590 // start |
| 591 e | 591 e |
| 592 // end | 592 // end |
| 593 ) { | 593 ) { |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 '''); | 596 '''); |
| 597 _createRefactoringForStartEndComments(); | 597 _createRefactoringForStartEndComments(); |
| 598 return _assertConditionsFatal( | 598 return _assertConditionsFatal( |
| 599 'Cannot extract the name part of a declaration.'); | 599 'Cannot extract the name part of a declaration.'); |
| 600 } | 600 } |
| 601 | 601 |
| 602 test_bad_try_finallyBlock() { | 602 test_bad_try_finallyBlock() async { |
| 603 indexTestUnit(''' | 603 await indexTestUnit(''' |
| 604 main() { | 604 main() { |
| 605 try | 605 try |
| 606 {} | 606 {} |
| 607 finally | 607 finally |
| 608 // start | 608 // start |
| 609 {} | 609 {} |
| 610 // end | 610 // end |
| 611 } | 611 } |
| 612 '''); | 612 '''); |
| 613 _createRefactoringForStartEndComments(); | 613 _createRefactoringForStartEndComments(); |
| 614 return _assertConditionsFatal( | 614 return _assertConditionsFatal( |
| 615 "Selection must either cover whole try statement or " | 615 "Selection must either cover whole try statement or " |
| 616 "parts of try, catch, or finally block."); | 616 "parts of try, catch, or finally block."); |
| 617 } | 617 } |
| 618 | 618 |
| 619 test_bad_try_tryBlock() { | 619 test_bad_try_tryBlock() async { |
| 620 indexTestUnit(''' | 620 await indexTestUnit(''' |
| 621 main() { | 621 main() { |
| 622 try | 622 try |
| 623 // start | 623 // start |
| 624 {} | 624 {} |
| 625 // end | 625 // end |
| 626 finally | 626 finally |
| 627 {} | 627 {} |
| 628 } | 628 } |
| 629 '''); | 629 '''); |
| 630 _createRefactoringForStartEndComments(); | 630 _createRefactoringForStartEndComments(); |
| 631 return _assertConditionsFatal( | 631 return _assertConditionsFatal( |
| 632 "Selection must either cover whole try statement or " | 632 "Selection must either cover whole try statement or " |
| 633 "parts of try, catch, or finally block."); | 633 "parts of try, catch, or finally block."); |
| 634 } | 634 } |
| 635 | 635 |
| 636 test_bad_typeReference() { | 636 test_bad_typeReference() async { |
| 637 indexTestUnit(''' | 637 await indexTestUnit(''' |
| 638 main() { | 638 main() { |
| 639 int a = 0; | 639 int a = 0; |
| 640 } | 640 } |
| 641 '''); | 641 '''); |
| 642 _createRefactoringForString("int"); | 642 _createRefactoringForString("int"); |
| 643 return _assertConditionsFatal("Cannot extract a single type reference."); | 643 return _assertConditionsFatal("Cannot extract a single type reference."); |
| 644 } | 644 } |
| 645 | 645 |
| 646 test_bad_variableDeclarationFragment() { | 646 test_bad_variableDeclarationFragment() async { |
| 647 indexTestUnit(''' | 647 await indexTestUnit(''' |
| 648 main() { | 648 main() { |
| 649 int | 649 int |
| 650 // start | 650 // start |
| 651 a = 1 | 651 a = 1 |
| 652 // end | 652 // end |
| 653 ,b = 2; | 653 ,b = 2; |
| 654 } | 654 } |
| 655 '''); | 655 '''); |
| 656 _createRefactoringForStartEndComments(); | 656 _createRefactoringForStartEndComments(); |
| 657 return _assertConditionsFatal( | 657 return _assertConditionsFatal( |
| 658 "Cannot extract a variable declaration fragment. Select whole declaratio
n statement."); | 658 "Cannot extract a variable declaration fragment. Select whole declaratio
n statement."); |
| 659 } | 659 } |
| 660 | 660 |
| 661 test_bad_while_conditionAndBody() { | 661 test_bad_while_conditionAndBody() async { |
| 662 indexTestUnit(''' | 662 await indexTestUnit(''' |
| 663 main() { | 663 main() { |
| 664 while | 664 while |
| 665 // start | 665 // start |
| 666 (false) | 666 (false) |
| 667 { | 667 { |
| 668 } | 668 } |
| 669 // end | 669 // end |
| 670 } | 670 } |
| 671 '''); | 671 '''); |
| 672 _createRefactoringForStartEndComments(); | 672 _createRefactoringForStartEndComments(); |
| 673 return _assertConditionsFatal( | 673 return _assertConditionsFatal( |
| 674 "Operation not applicable to a while statement's expression and body."); | 674 "Operation not applicable to a while statement's expression and body."); |
| 675 } | 675 } |
| 676 | 676 |
| 677 test_canExtractGetter_false_closure() async { | 677 test_canExtractGetter_false_closure() async { |
| 678 indexTestUnit(''' | 678 await indexTestUnit(''' |
| 679 main() { | 679 main() { |
| 680 useFunction((_) => true); | 680 useFunction((_) => true); |
| 681 } | 681 } |
| 682 useFunction(filter(String p)) {} | 682 useFunction(filter(String p)) {} |
| 683 '''); | 683 '''); |
| 684 _createRefactoringForString('(_) => true'); | 684 _createRefactoringForString('(_) => true'); |
| 685 // apply refactoring | 685 // apply refactoring |
| 686 await assertRefactoringConditionsOK(); | 686 await assertRefactoringConditionsOK(); |
| 687 expect(refactoring.canCreateGetter, false); | 687 expect(refactoring.canCreateGetter, false); |
| 688 expect(refactoring.createGetter, false); | 688 expect(refactoring.createGetter, false); |
| 689 } | 689 } |
| 690 | 690 |
| 691 test_canExtractGetter_false_fieldAssignment() async { | 691 test_canExtractGetter_false_fieldAssignment() async { |
| 692 indexTestUnit(''' | 692 await indexTestUnit(''' |
| 693 class A { | 693 class A { |
| 694 var f; | 694 var f; |
| 695 main() { | 695 main() { |
| 696 // start | 696 // start |
| 697 f = 1; | 697 f = 1; |
| 698 // end | 698 // end |
| 699 } | 699 } |
| 700 } | 700 } |
| 701 '''); | 701 '''); |
| 702 _createRefactoringForStartEndComments(); | 702 _createRefactoringForStartEndComments(); |
| 703 // apply refactoring | 703 // apply refactoring |
| 704 await assertRefactoringConditionsOK(); | 704 await assertRefactoringConditionsOK(); |
| 705 expect(refactoring.canCreateGetter, false); | 705 expect(refactoring.canCreateGetter, false); |
| 706 expect(refactoring.createGetter, false); | 706 expect(refactoring.createGetter, false); |
| 707 } | 707 } |
| 708 | 708 |
| 709 test_canExtractGetter_false_hasParameters() async { | 709 test_canExtractGetter_false_hasParameters() async { |
| 710 indexTestUnit(''' | 710 await indexTestUnit(''' |
| 711 main(int p) { | 711 main(int p) { |
| 712 int a = p + 1; | 712 int a = p + 1; |
| 713 } | 713 } |
| 714 '''); | 714 '''); |
| 715 _createRefactoringForString('p + 1'); | 715 _createRefactoringForString('p + 1'); |
| 716 // apply refactoring | 716 // apply refactoring |
| 717 await assertRefactoringConditionsOK(); | 717 await assertRefactoringConditionsOK(); |
| 718 expect(refactoring.canCreateGetter, false); | 718 expect(refactoring.canCreateGetter, false); |
| 719 expect(refactoring.createGetter, false); | 719 expect(refactoring.createGetter, false); |
| 720 } | 720 } |
| 721 | 721 |
| 722 test_canExtractGetter_false_returnNotUsed_assignment() async { | 722 test_canExtractGetter_false_returnNotUsed_assignment() async { |
| 723 indexTestUnit(''' | 723 await indexTestUnit(''' |
| 724 var topVar = 0; | 724 var topVar = 0; |
| 725 f(int p) { | 725 f(int p) { |
| 726 topVar = 5; | 726 topVar = 5; |
| 727 } | 727 } |
| 728 '''); | 728 '''); |
| 729 _createRefactoringForString('topVar = 5'); | 729 _createRefactoringForString('topVar = 5'); |
| 730 // apply refactoring | 730 // apply refactoring |
| 731 await assertRefactoringConditionsOK(); | 731 await assertRefactoringConditionsOK(); |
| 732 expect(refactoring.canCreateGetter, false); | 732 expect(refactoring.canCreateGetter, false); |
| 733 expect(refactoring.createGetter, false); | 733 expect(refactoring.createGetter, false); |
| 734 } | 734 } |
| 735 | 735 |
| 736 test_canExtractGetter_false_returnNotUsed_noReturn() async { | 736 test_canExtractGetter_false_returnNotUsed_noReturn() async { |
| 737 indexTestUnit(''' | 737 await indexTestUnit(''' |
| 738 var topVar = 0; | 738 var topVar = 0; |
| 739 main() { | 739 main() { |
| 740 // start | 740 // start |
| 741 int a = 1; | 741 int a = 1; |
| 742 int b = 2; | 742 int b = 2; |
| 743 topVar = a + b; | 743 topVar = a + b; |
| 744 // end | 744 // end |
| 745 } | 745 } |
| 746 '''); | 746 '''); |
| 747 _createRefactoringForStartEndComments(); | 747 _createRefactoringForStartEndComments(); |
| 748 // apply refactoring | 748 // apply refactoring |
| 749 await assertRefactoringConditionsOK(); | 749 await assertRefactoringConditionsOK(); |
| 750 expect(refactoring.canCreateGetter, false); | 750 expect(refactoring.canCreateGetter, false); |
| 751 expect(refactoring.createGetter, false); | 751 expect(refactoring.createGetter, false); |
| 752 } | 752 } |
| 753 | 753 |
| 754 test_canExtractGetter_true() async { | 754 test_canExtractGetter_true() async { |
| 755 indexTestUnit(''' | 755 await indexTestUnit(''' |
| 756 main() { | 756 main() { |
| 757 int a = 1 + 2; | 757 int a = 1 + 2; |
| 758 } | 758 } |
| 759 '''); | 759 '''); |
| 760 _createRefactoringForString('1 + 2'); | 760 _createRefactoringForString('1 + 2'); |
| 761 // apply refactoring | 761 // apply refactoring |
| 762 await assertRefactoringConditionsOK(); | 762 await assertRefactoringConditionsOK(); |
| 763 expect(refactoring.canCreateGetter, true); | 763 expect(refactoring.canCreateGetter, true); |
| 764 expect(refactoring.createGetter, true); | 764 expect(refactoring.createGetter, true); |
| 765 } | 765 } |
| 766 | 766 |
| 767 test_checkName() { | 767 test_checkName() async { |
| 768 indexTestUnit(''' | 768 await indexTestUnit(''' |
| 769 main() { | 769 main() { |
| 770 int a = 1 + 2; | 770 int a = 1 + 2; |
| 771 } | 771 } |
| 772 '''); | 772 '''); |
| 773 _createRefactoringForString('1 + 2'); | 773 _createRefactoringForString('1 + 2'); |
| 774 // null | 774 // null |
| 775 refactoring.name = null; | 775 refactoring.name = null; |
| 776 assertRefactoringStatus( | 776 assertRefactoringStatus( |
| 777 refactoring.checkName(), RefactoringProblemSeverity.FATAL, | 777 refactoring.checkName(), RefactoringProblemSeverity.FATAL, |
| 778 expectedMessage: "Method name must not be null."); | 778 expectedMessage: "Method name must not be null."); |
| 779 // empty | 779 // empty |
| 780 refactoring.name = ''; | 780 refactoring.name = ''; |
| 781 assertRefactoringStatus( | 781 assertRefactoringStatus( |
| 782 refactoring.checkName(), RefactoringProblemSeverity.FATAL, | 782 refactoring.checkName(), RefactoringProblemSeverity.FATAL, |
| 783 expectedMessage: "Method name must not be empty."); | 783 expectedMessage: "Method name must not be empty."); |
| 784 // OK | 784 // OK |
| 785 refactoring.name = 'res'; | 785 refactoring.name = 'res'; |
| 786 assertRefactoringStatusOK(refactoring.checkName()); | 786 assertRefactoringStatusOK(refactoring.checkName()); |
| 787 } | 787 } |
| 788 | 788 |
| 789 test_closure_asFunction_singleExpression() { | 789 test_closure_asFunction_singleExpression() async { |
| 790 indexTestUnit(''' | 790 await indexTestUnit(''' |
| 791 process(f(x)) {} | 791 process(f(x)) {} |
| 792 main() { | 792 main() { |
| 793 process((x) => x * 2); | 793 process((x) => x * 2); |
| 794 } | 794 } |
| 795 '''); | 795 '''); |
| 796 _createRefactoringForString('(x) => x * 2'); | 796 _createRefactoringForString('(x) => x * 2'); |
| 797 // apply refactoring | 797 // apply refactoring |
| 798 return _assertSuccessfulRefactoring(''' | 798 return _assertSuccessfulRefactoring(''' |
| 799 process(f(x)) {} | 799 process(f(x)) {} |
| 800 main() { | 800 main() { |
| 801 process(res); | 801 process(res); |
| 802 } | 802 } |
| 803 | 803 |
| 804 res(x) => x * 2; | 804 res(x) => x * 2; |
| 805 '''); | 805 '''); |
| 806 } | 806 } |
| 807 | 807 |
| 808 test_closure_asFunction_statements() { | 808 test_closure_asFunction_statements() async { |
| 809 indexTestUnit(''' | 809 await indexTestUnit(''' |
| 810 process(f(x)) {} | 810 process(f(x)) {} |
| 811 main() { | 811 main() { |
| 812 process((x) { | 812 process((x) { |
| 813 print(x); | 813 print(x); |
| 814 return x * 2; | 814 return x * 2; |
| 815 }); // marker | 815 }); // marker |
| 816 } | 816 } |
| 817 '''); | 817 '''); |
| 818 _createRefactoringForStartEndString('(x) {', '); // marker'); | 818 _createRefactoringForStartEndString('(x) {', '); // marker'); |
| 819 // apply refactoring | 819 // apply refactoring |
| 820 return _assertSuccessfulRefactoring(''' | 820 return _assertSuccessfulRefactoring(''' |
| 821 process(f(x)) {} | 821 process(f(x)) {} |
| 822 main() { | 822 main() { |
| 823 process(res); // marker | 823 process(res); // marker |
| 824 } | 824 } |
| 825 | 825 |
| 826 res(x) { | 826 res(x) { |
| 827 print(x); | 827 print(x); |
| 828 return x * 2; | 828 return x * 2; |
| 829 } | 829 } |
| 830 '''); | 830 '''); |
| 831 } | 831 } |
| 832 | 832 |
| 833 test_closure_asMethod_statements() { | 833 test_closure_asMethod_statements() async { |
| 834 indexTestUnit(''' | 834 await indexTestUnit(''' |
| 835 process(f(x)) {} | 835 process(f(x)) {} |
| 836 class A { | 836 class A { |
| 837 int k = 2; | 837 int k = 2; |
| 838 main() { | 838 main() { |
| 839 process((x) { | 839 process((x) { |
| 840 print(x); | 840 print(x); |
| 841 return x * k; | 841 return x * k; |
| 842 }); // marker | 842 }); // marker |
| 843 } | 843 } |
| 844 } | 844 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 855 | 855 |
| 856 res(x) { | 856 res(x) { |
| 857 print(x); | 857 print(x); |
| 858 return x * k; | 858 return x * k; |
| 859 } | 859 } |
| 860 } | 860 } |
| 861 '''); | 861 '''); |
| 862 } | 862 } |
| 863 | 863 |
| 864 test_closure_bad_referencesLocalVariable() async { | 864 test_closure_bad_referencesLocalVariable() async { |
| 865 indexTestUnit(''' | 865 await indexTestUnit(''' |
| 866 process(f(x)) {} | 866 process(f(x)) {} |
| 867 main() { | 867 main() { |
| 868 int k = 2; | 868 int k = 2; |
| 869 process((x) => x * k); | 869 process((x) => x * k); |
| 870 } | 870 } |
| 871 '''); | 871 '''); |
| 872 _createRefactoringForString('(x) => x * k'); | 872 _createRefactoringForString('(x) => x * k'); |
| 873 // check | 873 // check |
| 874 RefactoringStatus status = await refactoring.checkInitialConditions(); | 874 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 875 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 875 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 876 expectedMessage: | 876 expectedMessage: |
| 877 'Cannot extract closure as method, it references 1 external variable
(s).'); | 877 'Cannot extract closure as method, it references 1 external variable
(s).'); |
| 878 } | 878 } |
| 879 | 879 |
| 880 test_closure_bad_referencesParameter() async { | 880 test_closure_bad_referencesParameter() async { |
| 881 indexTestUnit(''' | 881 await indexTestUnit(''' |
| 882 process(f(x)) {} | 882 process(f(x)) {} |
| 883 main(int k) { | 883 main(int k) { |
| 884 process((x) => x * k); | 884 process((x) => x * k); |
| 885 } | 885 } |
| 886 '''); | 886 '''); |
| 887 _createRefactoringForString('(x) => x * k'); | 887 _createRefactoringForString('(x) => x * k'); |
| 888 // check | 888 // check |
| 889 RefactoringStatus status = await refactoring.checkInitialConditions(); | 889 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 890 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 890 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 891 expectedMessage: | 891 expectedMessage: |
| 892 'Cannot extract closure as method, it references 1 external variable
(s).'); | 892 'Cannot extract closure as method, it references 1 external variable
(s).'); |
| 893 } | 893 } |
| 894 | 894 |
| 895 test_fromTopLevelVariableInitializerClosure() { | 895 test_fromTopLevelVariableInitializerClosure() async { |
| 896 indexTestUnit(''' | 896 await indexTestUnit(''' |
| 897 var X = 1; | 897 var X = 1; |
| 898 | 898 |
| 899 var Y = () { | 899 var Y = () { |
| 900 return 1 + X; | 900 return 1 + X; |
| 901 }; | 901 }; |
| 902 '''); | 902 '''); |
| 903 _createRefactoringForString('1 + X'); | 903 _createRefactoringForString('1 + X'); |
| 904 // apply refactoring | 904 // apply refactoring |
| 905 return _assertSuccessfulRefactoring(''' | 905 return _assertSuccessfulRefactoring(''' |
| 906 var X = 1; | 906 var X = 1; |
| 907 | 907 |
| 908 var Y = () { | 908 var Y = () { |
| 909 return res(); | 909 return res(); |
| 910 }; | 910 }; |
| 911 | 911 |
| 912 num res() => 1 + X; | 912 num res() => 1 + X; |
| 913 '''); | 913 '''); |
| 914 } | 914 } |
| 915 | 915 |
| 916 test_getExtractGetter_expression_true_binaryExpression() async { | 916 test_getExtractGetter_expression_true_binaryExpression() async { |
| 917 indexTestUnit(''' | 917 await indexTestUnit(''' |
| 918 main() { | 918 main() { |
| 919 print(1 + 2); | 919 print(1 + 2); |
| 920 } | 920 } |
| 921 '''); | 921 '''); |
| 922 _createRefactoringForString('1 + 2'); | 922 _createRefactoringForString('1 + 2'); |
| 923 // apply refactoring | 923 // apply refactoring |
| 924 await assertRefactoringConditionsOK(); | 924 await assertRefactoringConditionsOK(); |
| 925 expect(refactoring.createGetter, true); | 925 expect(refactoring.createGetter, true); |
| 926 } | 926 } |
| 927 | 927 |
| 928 test_getExtractGetter_expression_true_literal() async { | 928 test_getExtractGetter_expression_true_literal() async { |
| 929 indexTestUnit(''' | 929 await indexTestUnit(''' |
| 930 main() { | 930 main() { |
| 931 print(42); | 931 print(42); |
| 932 } | 932 } |
| 933 '''); | 933 '''); |
| 934 _createRefactoringForString('42'); | 934 _createRefactoringForString('42'); |
| 935 // apply refactoring | 935 // apply refactoring |
| 936 await assertRefactoringConditionsOK(); | 936 await assertRefactoringConditionsOK(); |
| 937 expect(refactoring.createGetter, true); | 937 expect(refactoring.createGetter, true); |
| 938 } | 938 } |
| 939 | 939 |
| 940 test_getExtractGetter_expression_true_prefixedExpression() async { | 940 test_getExtractGetter_expression_true_prefixedExpression() async { |
| 941 indexTestUnit(''' | 941 await indexTestUnit(''' |
| 942 main() { | 942 main() { |
| 943 print(!true); | 943 print(!true); |
| 944 } | 944 } |
| 945 '''); | 945 '''); |
| 946 _createRefactoringForString('!true'); | 946 _createRefactoringForString('!true'); |
| 947 // apply refactoring | 947 // apply refactoring |
| 948 await assertRefactoringConditionsOK(); | 948 await assertRefactoringConditionsOK(); |
| 949 expect(refactoring.createGetter, true); | 949 expect(refactoring.createGetter, true); |
| 950 } | 950 } |
| 951 | 951 |
| 952 test_getExtractGetter_expression_true_prefixedIdentifier() async { | 952 test_getExtractGetter_expression_true_prefixedIdentifier() async { |
| 953 indexTestUnit(''' | 953 await indexTestUnit(''' |
| 954 main() { | 954 main() { |
| 955 print(myValue.isEven); | 955 print(myValue.isEven); |
| 956 } | 956 } |
| 957 int get myValue => 42; | 957 int get myValue => 42; |
| 958 '''); | 958 '''); |
| 959 _createRefactoringForString('myValue.isEven'); | 959 _createRefactoringForString('myValue.isEven'); |
| 960 // apply refactoring | 960 // apply refactoring |
| 961 await assertRefactoringConditionsOK(); | 961 await assertRefactoringConditionsOK(); |
| 962 expect(refactoring.createGetter, true); | 962 expect(refactoring.createGetter, true); |
| 963 } | 963 } |
| 964 | 964 |
| 965 test_getExtractGetter_expression_true_propertyAccess() async { | 965 test_getExtractGetter_expression_true_propertyAccess() async { |
| 966 indexTestUnit(''' | 966 await indexTestUnit(''' |
| 967 main() { | 967 main() { |
| 968 print(1.isEven); | 968 print(1.isEven); |
| 969 } | 969 } |
| 970 '''); | 970 '''); |
| 971 _createRefactoringForString('1.isEven'); | 971 _createRefactoringForString('1.isEven'); |
| 972 // apply refactoring | 972 // apply refactoring |
| 973 await assertRefactoringConditionsOK(); | 973 await assertRefactoringConditionsOK(); |
| 974 expect(refactoring.createGetter, true); | 974 expect(refactoring.createGetter, true); |
| 975 } | 975 } |
| 976 | 976 |
| 977 test_getExtractGetter_statements() async { | 977 test_getExtractGetter_statements() async { |
| 978 indexTestUnit(''' | 978 await indexTestUnit(''' |
| 979 main() { | 979 main() { |
| 980 // start | 980 // start |
| 981 int v = 0; | 981 int v = 0; |
| 982 // end | 982 // end |
| 983 print(v); | 983 print(v); |
| 984 } | 984 } |
| 985 '''); | 985 '''); |
| 986 _createRefactoringForStartEndComments(); | 986 _createRefactoringForStartEndComments(); |
| 987 // apply refactoring | 987 // apply refactoring |
| 988 await assertRefactoringConditionsOK(); | 988 await assertRefactoringConditionsOK(); |
| 989 expect(refactoring.createGetter, false); | 989 expect(refactoring.createGetter, false); |
| 990 } | 990 } |
| 991 | 991 |
| 992 test_getRefactoringName_function() { | 992 test_getRefactoringName_function() async { |
| 993 indexTestUnit(''' | 993 await indexTestUnit(''' |
| 994 main() { | 994 main() { |
| 995 print(1 + 2); | 995 print(1 + 2); |
| 996 } | 996 } |
| 997 '''); | 997 '''); |
| 998 _createRefactoringForString('1 + 2'); | 998 _createRefactoringForString('1 + 2'); |
| 999 expect(refactoring.refactoringName, 'Extract Function'); | 999 expect(refactoring.refactoringName, 'Extract Function'); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 test_getRefactoringName_method() { | 1002 test_getRefactoringName_method() async { |
| 1003 indexTestUnit(''' | 1003 await indexTestUnit(''' |
| 1004 class A { | 1004 class A { |
| 1005 main() { | 1005 main() { |
| 1006 print(1 + 2); | 1006 print(1 + 2); |
| 1007 } | 1007 } |
| 1008 } | 1008 } |
| 1009 '''); | 1009 '''); |
| 1010 _createRefactoringForString('1 + 2'); | 1010 _createRefactoringForString('1 + 2'); |
| 1011 expect(refactoring.refactoringName, 'Extract Method'); | 1011 expect(refactoring.refactoringName, 'Extract Method'); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 test_names_singleExpression() async { | 1014 test_names_singleExpression() async { |
| 1015 indexTestUnit(''' | 1015 await indexTestUnit(''' |
| 1016 class TreeItem {} | 1016 class TreeItem {} |
| 1017 TreeItem getSelectedItem() => null; | 1017 TreeItem getSelectedItem() => null; |
| 1018 process(my) {} | 1018 process(my) {} |
| 1019 main() { | 1019 main() { |
| 1020 process(getSelectedItem()); // marker | 1020 process(getSelectedItem()); // marker |
| 1021 int treeItem = 0; | 1021 int treeItem = 0; |
| 1022 } | 1022 } |
| 1023 '''); | 1023 '''); |
| 1024 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); | 1024 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); |
| 1025 // check names | 1025 // check names |
| 1026 await refactoring.checkInitialConditions(); | 1026 await refactoring.checkInitialConditions(); |
| 1027 expect(refactoring.names, | 1027 expect(refactoring.names, |
| 1028 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem2'])); | 1028 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem2'])); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 test_offsets_lengths() async { | 1031 test_offsets_lengths() async { |
| 1032 indexTestUnit(''' | 1032 await indexTestUnit(''' |
| 1033 main() { | 1033 main() { |
| 1034 int a = 1 + 2; | 1034 int a = 1 + 2; |
| 1035 int b = 1 + 2; | 1035 int b = 1 + 2; |
| 1036 } | 1036 } |
| 1037 '''); | 1037 '''); |
| 1038 _createRefactoringForString('1 + 2'); | 1038 _createRefactoringForString('1 + 2'); |
| 1039 // apply refactoring | 1039 // apply refactoring |
| 1040 await refactoring.checkInitialConditions(); | 1040 await refactoring.checkInitialConditions(); |
| 1041 expect(refactoring.offsets, | 1041 expect(refactoring.offsets, |
| 1042 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')])); | 1042 unorderedEquals([findOffset('1 + 2'), findOffset('1 + 2')])); |
| 1043 expect(refactoring.lengths, unorderedEquals([5, 6])); | 1043 expect(refactoring.lengths, unorderedEquals([5, 6])); |
| 1044 } | 1044 } |
| 1045 | 1045 |
| 1046 test_returnType_closure() async { | 1046 test_returnType_closure() async { |
| 1047 indexTestUnit(''' | 1047 await indexTestUnit(''' |
| 1048 process(f(x)) {} | 1048 process(f(x)) {} |
| 1049 main() { | 1049 main() { |
| 1050 process((x) => x * 2); | 1050 process((x) => x * 2); |
| 1051 } | 1051 } |
| 1052 '''); | 1052 '''); |
| 1053 _createRefactoringForString('(x) => x * 2'); | 1053 _createRefactoringForString('(x) => x * 2'); |
| 1054 // do check | 1054 // do check |
| 1055 await refactoring.checkInitialConditions(); | 1055 await refactoring.checkInitialConditions(); |
| 1056 expect(refactoring.returnType, ''); | 1056 expect(refactoring.returnType, ''); |
| 1057 } | 1057 } |
| 1058 | 1058 |
| 1059 test_returnType_expression() async { | 1059 test_returnType_expression() async { |
| 1060 indexTestUnit(''' | 1060 await indexTestUnit(''' |
| 1061 main() { | 1061 main() { |
| 1062 int a = 1 + 2; | 1062 int a = 1 + 2; |
| 1063 } | 1063 } |
| 1064 '''); | 1064 '''); |
| 1065 _createRefactoringForString('1 + 2'); | 1065 _createRefactoringForString('1 + 2'); |
| 1066 // do check | 1066 // do check |
| 1067 await refactoring.checkInitialConditions(); | 1067 await refactoring.checkInitialConditions(); |
| 1068 expect(refactoring.returnType, 'int'); | 1068 expect(refactoring.returnType, 'int'); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 test_returnType_mixInterfaceFunction() async { | 1071 test_returnType_mixInterfaceFunction() async { |
| 1072 indexTestUnit(''' | 1072 await indexTestUnit(''' |
| 1073 main() { | 1073 main() { |
| 1074 // start | 1074 // start |
| 1075 if (true) { | 1075 if (true) { |
| 1076 return 1; | 1076 return 1; |
| 1077 } else { | 1077 } else { |
| 1078 return () {}; | 1078 return () {}; |
| 1079 } | 1079 } |
| 1080 // end | 1080 // end |
| 1081 } | 1081 } |
| 1082 '''); | 1082 '''); |
| 1083 _createRefactoringForStartEndComments(); | 1083 _createRefactoringForStartEndComments(); |
| 1084 // do check | 1084 // do check |
| 1085 await refactoring.checkInitialConditions(); | 1085 await refactoring.checkInitialConditions(); |
| 1086 expect(refactoring.returnType, 'Object'); | 1086 expect(refactoring.returnType, 'Object'); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 test_returnType_statements() async { | 1089 test_returnType_statements() async { |
| 1090 indexTestUnit(''' | 1090 await indexTestUnit(''' |
| 1091 main() { | 1091 main() { |
| 1092 // start | 1092 // start |
| 1093 double v = 5.0; | 1093 double v = 5.0; |
| 1094 // end | 1094 // end |
| 1095 print(v); | 1095 print(v); |
| 1096 } | 1096 } |
| 1097 '''); | 1097 '''); |
| 1098 _createRefactoringForStartEndComments(); | 1098 _createRefactoringForStartEndComments(); |
| 1099 // do check | 1099 // do check |
| 1100 await refactoring.checkInitialConditions(); | 1100 await refactoring.checkInitialConditions(); |
| 1101 expect(refactoring.returnType, 'double'); | 1101 expect(refactoring.returnType, 'double'); |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 test_returnType_statements_nullMix() async { | 1104 test_returnType_statements_nullMix() async { |
| 1105 indexTestUnit(''' | 1105 await indexTestUnit(''' |
| 1106 main(bool p) { | 1106 main(bool p) { |
| 1107 // start | 1107 // start |
| 1108 if (p) { | 1108 if (p) { |
| 1109 return 42; | 1109 return 42; |
| 1110 } | 1110 } |
| 1111 return null; | 1111 return null; |
| 1112 // end | 1112 // end |
| 1113 } | 1113 } |
| 1114 '''); | 1114 '''); |
| 1115 _createRefactoringForStartEndComments(); | 1115 _createRefactoringForStartEndComments(); |
| 1116 // do check | 1116 // do check |
| 1117 await refactoring.checkInitialConditions(); | 1117 await refactoring.checkInitialConditions(); |
| 1118 expect(refactoring.returnType, 'int'); | 1118 expect(refactoring.returnType, 'int'); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 test_returnType_statements_void() async { | 1121 test_returnType_statements_void() async { |
| 1122 indexTestUnit(''' | 1122 await indexTestUnit(''' |
| 1123 main() { | 1123 main() { |
| 1124 // start | 1124 // start |
| 1125 print(42); | 1125 print(42); |
| 1126 // end | 1126 // end |
| 1127 } | 1127 } |
| 1128 '''); | 1128 '''); |
| 1129 _createRefactoringForStartEndComments(); | 1129 _createRefactoringForStartEndComments(); |
| 1130 // do check | 1130 // do check |
| 1131 await refactoring.checkInitialConditions(); | 1131 await refactoring.checkInitialConditions(); |
| 1132 expect(refactoring.returnType, 'void'); | 1132 expect(refactoring.returnType, 'void'); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 test_setExtractGetter() async { | 1135 test_setExtractGetter() async { |
| 1136 indexTestUnit(''' | 1136 await indexTestUnit(''' |
| 1137 main() { | 1137 main() { |
| 1138 int a = 1 + 2; | 1138 int a = 1 + 2; |
| 1139 } | 1139 } |
| 1140 '''); | 1140 '''); |
| 1141 _createRefactoringForString('1 + 2'); | 1141 _createRefactoringForString('1 + 2'); |
| 1142 // apply refactoring | 1142 // apply refactoring |
| 1143 await assertRefactoringConditionsOK(); | 1143 await assertRefactoringConditionsOK(); |
| 1144 expect(refactoring.canCreateGetter, true); | 1144 expect(refactoring.canCreateGetter, true); |
| 1145 expect(refactoring.createGetter, true); | 1145 expect(refactoring.createGetter, true); |
| 1146 refactoringChange = await refactoring.createChange(); | 1146 refactoringChange = await refactoring.createChange(); |
| 1147 assertTestChangeResult(''' | 1147 assertTestChangeResult(''' |
| 1148 main() { | 1148 main() { |
| 1149 int a = res; | 1149 int a = res; |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 int get res => 1 + 2; | 1152 int get res => 1 + 2; |
| 1153 '''); | 1153 '''); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 test_singleExpression() { | 1156 test_singleExpression() async { |
| 1157 indexTestUnit(''' | 1157 await indexTestUnit(''' |
| 1158 main() { | 1158 main() { |
| 1159 int a = 1 + 2; | 1159 int a = 1 + 2; |
| 1160 } | 1160 } |
| 1161 '''); | 1161 '''); |
| 1162 _createRefactoringForString('1 + 2'); | 1162 _createRefactoringForString('1 + 2'); |
| 1163 // apply refactoring | 1163 // apply refactoring |
| 1164 return _assertSuccessfulRefactoring(''' | 1164 return _assertSuccessfulRefactoring(''' |
| 1165 main() { | 1165 main() { |
| 1166 int a = res(); | 1166 int a = res(); |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 int res() => 1 + 2; | 1169 int res() => 1 + 2; |
| 1170 '''); | 1170 '''); |
| 1171 } | 1171 } |
| 1172 | 1172 |
| 1173 test_singleExpression_cascade() { | 1173 test_singleExpression_cascade() async { |
| 1174 indexTestUnit(''' | 1174 await indexTestUnit(''' |
| 1175 main() { | 1175 main() { |
| 1176 String s = ''; | 1176 String s = ''; |
| 1177 var v = s..length; | 1177 var v = s..length; |
| 1178 } | 1178 } |
| 1179 '''); | 1179 '''); |
| 1180 _createRefactoringForString('s..length'); | 1180 _createRefactoringForString('s..length'); |
| 1181 // apply refactoring | 1181 // apply refactoring |
| 1182 return _assertSuccessfulRefactoring(''' | 1182 return _assertSuccessfulRefactoring(''' |
| 1183 main() { | 1183 main() { |
| 1184 String s = ''; | 1184 String s = ''; |
| 1185 var v = res(s); | 1185 var v = res(s); |
| 1186 } | 1186 } |
| 1187 | 1187 |
| 1188 String res(String s) => s..length; | 1188 String res(String s) => s..length; |
| 1189 '''); | 1189 '''); |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 test_singleExpression_dynamic() { | 1192 test_singleExpression_dynamic() async { |
| 1193 indexTestUnit(''' | 1193 await indexTestUnit(''' |
| 1194 dynaFunction() {} | 1194 dynaFunction() {} |
| 1195 main() { | 1195 main() { |
| 1196 var v = dynaFunction(); // marker | 1196 var v = dynaFunction(); // marker |
| 1197 } | 1197 } |
| 1198 '''); | 1198 '''); |
| 1199 _createRefactoringWithSuffix('dynaFunction()', '; // marker'); | 1199 _createRefactoringWithSuffix('dynaFunction()', '; // marker'); |
| 1200 // apply refactoring | 1200 // apply refactoring |
| 1201 return _assertSuccessfulRefactoring(''' | 1201 return _assertSuccessfulRefactoring(''' |
| 1202 dynaFunction() {} | 1202 dynaFunction() {} |
| 1203 main() { | 1203 main() { |
| 1204 var v = res(); // marker | 1204 var v = res(); // marker |
| 1205 } | 1205 } |
| 1206 | 1206 |
| 1207 res() => dynaFunction(); | 1207 res() => dynaFunction(); |
| 1208 '''); | 1208 '''); |
| 1209 } | 1209 } |
| 1210 | 1210 |
| 1211 test_singleExpression_hasAwait() { | 1211 test_singleExpression_hasAwait() async { |
| 1212 indexTestUnit(''' | 1212 await indexTestUnit(''' |
| 1213 import 'dart:async'; | 1213 import 'dart:async'; |
| 1214 Future<int> getValue() => 42; | 1214 Future<int> getValue() => 42; |
| 1215 main() async { | 1215 main() async { |
| 1216 int v = await getValue(); | 1216 int v = await getValue(); |
| 1217 print(v); | 1217 print(v); |
| 1218 } | 1218 } |
| 1219 '''); | 1219 '''); |
| 1220 _createRefactoringForString('await getValue()'); | 1220 _createRefactoringForString('await getValue()'); |
| 1221 // apply refactoring | 1221 // apply refactoring |
| 1222 return _assertSuccessfulRefactoring(''' | 1222 return _assertSuccessfulRefactoring(''' |
| 1223 import 'dart:async'; | 1223 import 'dart:async'; |
| 1224 Future<int> getValue() => 42; | 1224 Future<int> getValue() => 42; |
| 1225 main() async { | 1225 main() async { |
| 1226 int v = await res(); | 1226 int v = await res(); |
| 1227 print(v); | 1227 print(v); |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 Future<int> res() async => await getValue(); | 1230 Future<int> res() async => await getValue(); |
| 1231 '''); | 1231 '''); |
| 1232 } | 1232 } |
| 1233 | 1233 |
| 1234 test_singleExpression_ignore_assignmentLeftHandSize() { | 1234 test_singleExpression_ignore_assignmentLeftHandSize() async { |
| 1235 indexTestUnit(''' | 1235 await indexTestUnit(''' |
| 1236 main() { | 1236 main() { |
| 1237 getButton().text = 'txt'; | 1237 getButton().text = 'txt'; |
| 1238 print(getButton().text); // marker | 1238 print(getButton().text); // marker |
| 1239 } | 1239 } |
| 1240 getButton() {} | 1240 getButton() {} |
| 1241 '''); | 1241 '''); |
| 1242 _createRefactoringWithSuffix('getButton().text', '); // marker'); | 1242 _createRefactoringWithSuffix('getButton().text', '); // marker'); |
| 1243 // apply refactoring | 1243 // apply refactoring |
| 1244 return _assertSuccessfulRefactoring(''' | 1244 return _assertSuccessfulRefactoring(''' |
| 1245 main() { | 1245 main() { |
| 1246 getButton().text = 'txt'; | 1246 getButton().text = 'txt'; |
| 1247 print(res()); // marker | 1247 print(res()); // marker |
| 1248 } | 1248 } |
| 1249 | 1249 |
| 1250 res() => getButton().text; | 1250 res() => getButton().text; |
| 1251 getButton() {} | 1251 getButton() {} |
| 1252 '''); | 1252 '''); |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 test_singleExpression_occurrences() { | 1255 test_singleExpression_occurrences() async { |
| 1256 indexTestUnit(''' | 1256 await indexTestUnit(''' |
| 1257 main() { | 1257 main() { |
| 1258 int v1 = 1; | 1258 int v1 = 1; |
| 1259 int v2 = 2; | 1259 int v2 = 2; |
| 1260 int v3 = 3; | 1260 int v3 = 3; |
| 1261 int positiveA = v1 + v2; // marker | 1261 int positiveA = v1 + v2; // marker |
| 1262 int positiveB = v2 + v3; | 1262 int positiveB = v2 + v3; |
| 1263 int positiveC = v1 + v2; | 1263 int positiveC = v1 + v2; |
| 1264 int positiveD = v1/*abc*/ + v2; | 1264 int positiveD = v1/*abc*/ + v2; |
| 1265 int negA = 1 + 2; | 1265 int negA = 1 + 2; |
| 1266 int negB = 1 + v2; | 1266 int negB = 1 + v2; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1282 int negA = 1 + 2; | 1282 int negA = 1 + 2; |
| 1283 int negB = 1 + v2; | 1283 int negB = 1 + v2; |
| 1284 int negC = v1 + 2; | 1284 int negC = v1 + 2; |
| 1285 int negD = v1 * v2; | 1285 int negD = v1 * v2; |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 int res(int v1, int v2) => v1 + v2; | 1288 int res(int v1, int v2) => v1 + v2; |
| 1289 '''); | 1289 '''); |
| 1290 } | 1290 } |
| 1291 | 1291 |
| 1292 test_singleExpression_occurrences_disabled() { | 1292 test_singleExpression_occurrences_disabled() async { |
| 1293 indexTestUnit(''' | 1293 await indexTestUnit(''' |
| 1294 main() { | 1294 main() { |
| 1295 int v1 = 1; | 1295 int v1 = 1; |
| 1296 int v2 = 2; | 1296 int v2 = 2; |
| 1297 int v3 = 3; | 1297 int v3 = 3; |
| 1298 int a = v1 + v2; // marker | 1298 int a = v1 + v2; // marker |
| 1299 int b = v2 + v3; | 1299 int b = v2 + v3; |
| 1300 } | 1300 } |
| 1301 '''); | 1301 '''); |
| 1302 _createRefactoringWithSuffix('v1 + v2', '; // marker'); | 1302 _createRefactoringWithSuffix('v1 + v2', '; // marker'); |
| 1303 refactoring.extractAll = false; | 1303 refactoring.extractAll = false; |
| 1304 // apply refactoring | 1304 // apply refactoring |
| 1305 return _assertSuccessfulRefactoring(''' | 1305 return _assertSuccessfulRefactoring(''' |
| 1306 main() { | 1306 main() { |
| 1307 int v1 = 1; | 1307 int v1 = 1; |
| 1308 int v2 = 2; | 1308 int v2 = 2; |
| 1309 int v3 = 3; | 1309 int v3 = 3; |
| 1310 int a = res(v1, v2); // marker | 1310 int a = res(v1, v2); // marker |
| 1311 int b = v2 + v3; | 1311 int b = v2 + v3; |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 int res(int v1, int v2) => v1 + v2; | 1314 int res(int v1, int v2) => v1 + v2; |
| 1315 '''); | 1315 '''); |
| 1316 } | 1316 } |
| 1317 | 1317 |
| 1318 test_singleExpression_occurrences_inClassOnly() { | 1318 test_singleExpression_occurrences_inClassOnly() async { |
| 1319 indexTestUnit(''' | 1319 await indexTestUnit(''' |
| 1320 class A { | 1320 class A { |
| 1321 myMethod() { | 1321 myMethod() { |
| 1322 int v1 = 1; | 1322 int v1 = 1; |
| 1323 int v2 = 2; | 1323 int v2 = 2; |
| 1324 int positiveA = v1 + v2; // marker | 1324 int positiveA = v1 + v2; // marker |
| 1325 } | 1325 } |
| 1326 } | 1326 } |
| 1327 main() { | 1327 main() { |
| 1328 int v1 = 1; | 1328 int v1 = 1; |
| 1329 int v2 = 2; | 1329 int v2 = 2; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1343 int res(int v1, int v2) => v1 + v2; | 1343 int res(int v1, int v2) => v1 + v2; |
| 1344 } | 1344 } |
| 1345 main() { | 1345 main() { |
| 1346 int v1 = 1; | 1346 int v1 = 1; |
| 1347 int v2 = 2; | 1347 int v2 = 2; |
| 1348 int negA = v1 + v2; | 1348 int negA = v1 + v2; |
| 1349 } | 1349 } |
| 1350 '''); | 1350 '''); |
| 1351 } | 1351 } |
| 1352 | 1352 |
| 1353 test_singleExpression_occurrences_incompatibleTypes() { | 1353 test_singleExpression_occurrences_incompatibleTypes() async { |
| 1354 indexTestUnit(''' | 1354 await indexTestUnit(''' |
| 1355 main() { | 1355 main() { |
| 1356 int x = 1; | 1356 int x = 1; |
| 1357 String y = 'foo'; | 1357 String y = 'foo'; |
| 1358 print(x.toString()); | 1358 print(x.toString()); |
| 1359 print(y.toString()); | 1359 print(y.toString()); |
| 1360 } | 1360 } |
| 1361 '''); | 1361 '''); |
| 1362 _createRefactoringForString('x.toString()'); | 1362 _createRefactoringForString('x.toString()'); |
| 1363 // apply refactoring | 1363 // apply refactoring |
| 1364 return _assertSuccessfulRefactoring(''' | 1364 return _assertSuccessfulRefactoring(''' |
| 1365 main() { | 1365 main() { |
| 1366 int x = 1; | 1366 int x = 1; |
| 1367 String y = 'foo'; | 1367 String y = 'foo'; |
| 1368 print(res(x)); | 1368 print(res(x)); |
| 1369 print(y.toString()); | 1369 print(y.toString()); |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 String res(int x) => x.toString(); | 1372 String res(int x) => x.toString(); |
| 1373 '''); | 1373 '''); |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 test_singleExpression_occurrences_inWholeUnit() { | 1376 test_singleExpression_occurrences_inWholeUnit() async { |
| 1377 indexTestUnit(''' | 1377 await indexTestUnit(''' |
| 1378 main() { | 1378 main() { |
| 1379 int v1 = 1; | 1379 int v1 = 1; |
| 1380 int v2 = 2; | 1380 int v2 = 2; |
| 1381 int positiveA = v1 + v2; // marker | 1381 int positiveA = v1 + v2; // marker |
| 1382 } | 1382 } |
| 1383 class A { | 1383 class A { |
| 1384 myMethod() { | 1384 myMethod() { |
| 1385 int v1 = 1; | 1385 int v1 = 1; |
| 1386 int v2 = 2; | 1386 int v2 = 2; |
| 1387 int positiveB = v1 + v2; | 1387 int positiveB = v1 + v2; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1401 class A { | 1401 class A { |
| 1402 myMethod() { | 1402 myMethod() { |
| 1403 int v1 = 1; | 1403 int v1 = 1; |
| 1404 int v2 = 2; | 1404 int v2 = 2; |
| 1405 int positiveB = res(v1, v2); | 1405 int positiveB = res(v1, v2); |
| 1406 } | 1406 } |
| 1407 } | 1407 } |
| 1408 '''); | 1408 '''); |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 test_singleExpression_parameter_functionTypeAlias() { | 1411 test_singleExpression_parameter_functionTypeAlias() async { |
| 1412 indexTestUnit(''' | 1412 await indexTestUnit(''' |
| 1413 typedef R Foo<S, R>(S s); | 1413 typedef R Foo<S, R>(S s); |
| 1414 void main(Foo<String, int> foo, String s) { | 1414 void main(Foo<String, int> foo, String s) { |
| 1415 int a = foo(s); | 1415 int a = foo(s); |
| 1416 } | 1416 } |
| 1417 '''); | 1417 '''); |
| 1418 _createRefactoringForString('foo(s)'); | 1418 _createRefactoringForString('foo(s)'); |
| 1419 // apply refactoring | 1419 // apply refactoring |
| 1420 return _assertSuccessfulRefactoring(''' | 1420 return _assertSuccessfulRefactoring(''' |
| 1421 typedef R Foo<S, R>(S s); | 1421 typedef R Foo<S, R>(S s); |
| 1422 void main(Foo<String, int> foo, String s) { | 1422 void main(Foo<String, int> foo, String s) { |
| 1423 int a = res(foo, s); | 1423 int a = res(foo, s); |
| 1424 } | 1424 } |
| 1425 | 1425 |
| 1426 int res(Foo<String, int> foo, String s) => foo(s); | 1426 int res(Foo<String, int> foo, String s) => foo(s); |
| 1427 '''); | 1427 '''); |
| 1428 } | 1428 } |
| 1429 | 1429 |
| 1430 test_singleExpression_returnType_importLibrary() async { | 1430 test_singleExpression_returnType_importLibrary() async { |
| 1431 _addLibraryReturningAsync(); | 1431 _addLibraryReturningAsync(); |
| 1432 indexTestUnit(''' | 1432 await indexTestUnit(''' |
| 1433 import 'asyncLib.dart'; | 1433 import 'asyncLib.dart'; |
| 1434 main() { | 1434 main() { |
| 1435 var a = newFuture(); | 1435 var a = newFuture(); |
| 1436 } | 1436 } |
| 1437 '''); | 1437 '''); |
| 1438 _createRefactoringForString('newFuture()'); | 1438 _createRefactoringForString('newFuture()'); |
| 1439 // apply refactoring | 1439 // apply refactoring |
| 1440 return _assertSuccessfulRefactoring(''' | 1440 return _assertSuccessfulRefactoring(''' |
| 1441 import 'asyncLib.dart'; | 1441 import 'asyncLib.dart'; |
| 1442 import 'dart:async'; | 1442 import 'dart:async'; |
| 1443 main() { | 1443 main() { |
| 1444 var a = res(); | 1444 var a = res(); |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 Future<int> res() => newFuture(); | 1447 Future<int> res() => newFuture(); |
| 1448 '''); | 1448 '''); |
| 1449 } | 1449 } |
| 1450 | 1450 |
| 1451 test_singleExpression_returnTypeGeneric() { | 1451 test_singleExpression_returnTypeGeneric() async { |
| 1452 indexTestUnit(''' | 1452 await indexTestUnit(''' |
| 1453 main() { | 1453 main() { |
| 1454 var v = new List<String>(); | 1454 var v = new List<String>(); |
| 1455 } | 1455 } |
| 1456 '''); | 1456 '''); |
| 1457 _createRefactoringForString('new List<String>()'); | 1457 _createRefactoringForString('new List<String>()'); |
| 1458 // apply refactoring | 1458 // apply refactoring |
| 1459 return _assertSuccessfulRefactoring(''' | 1459 return _assertSuccessfulRefactoring(''' |
| 1460 main() { | 1460 main() { |
| 1461 var v = res(); | 1461 var v = res(); |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 List<String> res() => new List<String>(); | 1464 List<String> res() => new List<String>(); |
| 1465 '''); | 1465 '''); |
| 1466 } | 1466 } |
| 1467 | 1467 |
| 1468 test_singleExpression_returnTypePrefix() { | 1468 test_singleExpression_returnTypePrefix() async { |
| 1469 indexTestUnit(''' | 1469 await indexTestUnit(''' |
| 1470 import 'dart:math' as pref; | 1470 import 'dart:math' as pref; |
| 1471 main() { | 1471 main() { |
| 1472 var v = new pref.Random(); | 1472 var v = new pref.Random(); |
| 1473 } | 1473 } |
| 1474 '''); | 1474 '''); |
| 1475 _createRefactoringForString('new pref.Random()'); | 1475 _createRefactoringForString('new pref.Random()'); |
| 1476 // apply refactoring | 1476 // apply refactoring |
| 1477 return _assertSuccessfulRefactoring(''' | 1477 return _assertSuccessfulRefactoring(''' |
| 1478 import 'dart:math' as pref; | 1478 import 'dart:math' as pref; |
| 1479 main() { | 1479 main() { |
| 1480 var v = res(); | 1480 var v = res(); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 pref.Random res() => new pref.Random(); | 1483 pref.Random res() => new pref.Random(); |
| 1484 '''); | 1484 '''); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 test_singleExpression_staticContext_extractFromInitializer() { | 1487 test_singleExpression_staticContext_extractFromInitializer() async { |
| 1488 indexTestUnit(''' | 1488 await indexTestUnit(''' |
| 1489 class A { | 1489 class A { |
| 1490 A(int v) {} | 1490 A(int v) {} |
| 1491 } | 1491 } |
| 1492 class B extends A { | 1492 class B extends A { |
| 1493 B() : super(1 + 2) {} | 1493 B() : super(1 + 2) {} |
| 1494 } | 1494 } |
| 1495 '''); | 1495 '''); |
| 1496 _createRefactoringForString('1 + 2'); | 1496 _createRefactoringForString('1 + 2'); |
| 1497 // apply refactoring | 1497 // apply refactoring |
| 1498 return _assertSuccessfulRefactoring(''' | 1498 return _assertSuccessfulRefactoring(''' |
| 1499 class A { | 1499 class A { |
| 1500 A(int v) {} | 1500 A(int v) {} |
| 1501 } | 1501 } |
| 1502 class B extends A { | 1502 class B extends A { |
| 1503 B() : super(res()) {} | 1503 B() : super(res()) {} |
| 1504 | 1504 |
| 1505 static int res() => 1 + 2; | 1505 static int res() => 1 + 2; |
| 1506 } | 1506 } |
| 1507 '''); | 1507 '''); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 test_singleExpression_staticContext_extractFromInstance() { | 1510 test_singleExpression_staticContext_extractFromInstance() async { |
| 1511 indexTestUnit(''' | 1511 await indexTestUnit(''' |
| 1512 class A { | 1512 class A { |
| 1513 instanceMethodA() { | 1513 instanceMethodA() { |
| 1514 int v1 = 1; | 1514 int v1 = 1; |
| 1515 int v2 = 2; | 1515 int v2 = 2; |
| 1516 int positiveA = v1 + v2; // marker | 1516 int positiveA = v1 + v2; // marker |
| 1517 } | 1517 } |
| 1518 instanceMethodB() { | 1518 instanceMethodB() { |
| 1519 int v1 = 1; | 1519 int v1 = 1; |
| 1520 int v2 = 2; | 1520 int v2 = 2; |
| 1521 int positiveB = v1 + v2; | 1521 int positiveB = v1 + v2; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1545 } | 1545 } |
| 1546 static staticMethodA() { | 1546 static staticMethodA() { |
| 1547 int v1 = 1; | 1547 int v1 = 1; |
| 1548 int v2 = 2; | 1548 int v2 = 2; |
| 1549 int positiveA = res(v1, v2); | 1549 int positiveA = res(v1, v2); |
| 1550 } | 1550 } |
| 1551 } | 1551 } |
| 1552 '''); | 1552 '''); |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 test_singleExpression_staticContext_extractFromStatic() { | 1555 test_singleExpression_staticContext_extractFromStatic() async { |
| 1556 indexTestUnit(''' | 1556 await indexTestUnit(''' |
| 1557 class A { | 1557 class A { |
| 1558 static staticMethodA() { | 1558 static staticMethodA() { |
| 1559 int v1 = 1; | 1559 int v1 = 1; |
| 1560 int v2 = 2; | 1560 int v2 = 2; |
| 1561 int positiveA = v1 + v2; // marker | 1561 int positiveA = v1 + v2; // marker |
| 1562 } | 1562 } |
| 1563 static staticMethodB() { | 1563 static staticMethodB() { |
| 1564 int v1 = 1; | 1564 int v1 = 1; |
| 1565 int v2 = 2; | 1565 int v2 = 2; |
| 1566 int positiveB = v1 + v2; | 1566 int positiveB = v1 + v2; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1590 } | 1590 } |
| 1591 instanceMethodA() { | 1591 instanceMethodA() { |
| 1592 int v1 = 1; | 1592 int v1 = 1; |
| 1593 int v2 = 2; | 1593 int v2 = 2; |
| 1594 int positiveA = res(v1, v2); | 1594 int positiveA = res(v1, v2); |
| 1595 } | 1595 } |
| 1596 } | 1596 } |
| 1597 '''); | 1597 '''); |
| 1598 } | 1598 } |
| 1599 | 1599 |
| 1600 test_singleExpression_staticContext_hasInInitializer() { | 1600 test_singleExpression_staticContext_hasInInitializer() async { |
| 1601 indexTestUnit(''' | 1601 await indexTestUnit(''' |
| 1602 class A { | 1602 class A { |
| 1603 A(int v) {} | 1603 A(int v) {} |
| 1604 } | 1604 } |
| 1605 class B extends A { | 1605 class B extends A { |
| 1606 B() : super(1 + 2) {} | 1606 B() : super(1 + 2) {} |
| 1607 foo() { | 1607 foo() { |
| 1608 print(1 + 2); // marker | 1608 print(1 + 2); // marker |
| 1609 } | 1609 } |
| 1610 } | 1610 } |
| 1611 '''); | 1611 '''); |
| 1612 _createRefactoringWithSuffix('1 + 2', '); // marker'); | 1612 _createRefactoringWithSuffix('1 + 2', '); // marker'); |
| 1613 // apply refactoring | 1613 // apply refactoring |
| 1614 return _assertSuccessfulRefactoring(''' | 1614 return _assertSuccessfulRefactoring(''' |
| 1615 class A { | 1615 class A { |
| 1616 A(int v) {} | 1616 A(int v) {} |
| 1617 } | 1617 } |
| 1618 class B extends A { | 1618 class B extends A { |
| 1619 B() : super(res()) {} | 1619 B() : super(res()) {} |
| 1620 foo() { | 1620 foo() { |
| 1621 print(res()); // marker | 1621 print(res()); // marker |
| 1622 } | 1622 } |
| 1623 | 1623 |
| 1624 static int res() => 1 + 2; | 1624 static int res() => 1 + 2; |
| 1625 } | 1625 } |
| 1626 '''); | 1626 '''); |
| 1627 } | 1627 } |
| 1628 | 1628 |
| 1629 test_singleExpression_usesParameter() { | 1629 test_singleExpression_usesParameter() async { |
| 1630 indexTestUnit(''' | 1630 await indexTestUnit(''' |
| 1631 fooA(int a1) { | 1631 fooA(int a1) { |
| 1632 int a2 = 2; | 1632 int a2 = 2; |
| 1633 int a = a1 + a2; | 1633 int a = a1 + a2; |
| 1634 } | 1634 } |
| 1635 fooB(int b1) { | 1635 fooB(int b1) { |
| 1636 int b2 = 2; | 1636 int b2 = 2; |
| 1637 int b = b1 + b2; | 1637 int b = b1 + b2; |
| 1638 } | 1638 } |
| 1639 '''); | 1639 '''); |
| 1640 _createRefactoringForString('a1 + a2'); | 1640 _createRefactoringForString('a1 + a2'); |
| 1641 // apply refactoring | 1641 // apply refactoring |
| 1642 return _assertSuccessfulRefactoring(''' | 1642 return _assertSuccessfulRefactoring(''' |
| 1643 fooA(int a1) { | 1643 fooA(int a1) { |
| 1644 int a2 = 2; | 1644 int a2 = 2; |
| 1645 int a = res(a1, a2); | 1645 int a = res(a1, a2); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 int res(int a1, int a2) => a1 + a2; | 1648 int res(int a1, int a2) => a1 + a2; |
| 1649 fooB(int b1) { | 1649 fooB(int b1) { |
| 1650 int b2 = 2; | 1650 int b2 = 2; |
| 1651 int b = res(b1, b2); | 1651 int b = res(b1, b2); |
| 1652 } | 1652 } |
| 1653 '''); | 1653 '''); |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 test_singleExpression_withVariables() { | 1656 test_singleExpression_withVariables() async { |
| 1657 indexTestUnit(''' | 1657 await indexTestUnit(''' |
| 1658 main() { | 1658 main() { |
| 1659 int v1 = 1; | 1659 int v1 = 1; |
| 1660 int v2 = 2; | 1660 int v2 = 2; |
| 1661 int a = v1 + v2 + v1; | 1661 int a = v1 + v2 + v1; |
| 1662 } | 1662 } |
| 1663 '''); | 1663 '''); |
| 1664 _createRefactoringForString('v1 + v2 + v1'); | 1664 _createRefactoringForString('v1 + v2 + v1'); |
| 1665 // apply refactoring | 1665 // apply refactoring |
| 1666 return _assertSuccessfulRefactoring(''' | 1666 return _assertSuccessfulRefactoring(''' |
| 1667 main() { | 1667 main() { |
| 1668 int v1 = 1; | 1668 int v1 = 1; |
| 1669 int v2 = 2; | 1669 int v2 = 2; |
| 1670 int a = res(v1, v2); | 1670 int a = res(v1, v2); |
| 1671 } | 1671 } |
| 1672 | 1672 |
| 1673 int res(int v1, int v2) => v1 + v2 + v1; | 1673 int res(int v1, int v2) => v1 + v2 + v1; |
| 1674 '''); | 1674 '''); |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 test_singleExpression_withVariables_doRename() async { | 1677 test_singleExpression_withVariables_doRename() async { |
| 1678 indexTestUnit(''' | 1678 await indexTestUnit(''' |
| 1679 main() { | 1679 main() { |
| 1680 int v1 = 1; | 1680 int v1 = 1; |
| 1681 int v2 = 2; | 1681 int v2 = 2; |
| 1682 int v3 = 3; | 1682 int v3 = 3; |
| 1683 int a = v1 + v2 + v1; // marker | 1683 int a = v1 + v2 + v1; // marker |
| 1684 int b = v2 + v3 + v2; | 1684 int b = v2 + v3 + v2; |
| 1685 } | 1685 } |
| 1686 '''); | 1686 '''); |
| 1687 _createRefactoringForString('v1 + v2 + v1'); | 1687 _createRefactoringForString('v1 + v2 + v1'); |
| 1688 // apply refactoring | 1688 // apply refactoring |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1705 int v3 = 3; | 1705 int v3 = 3; |
| 1706 int a = res(v1, v2); // marker | 1706 int a = res(v1, v2); // marker |
| 1707 int b = res(v2, v3); | 1707 int b = res(v2, v3); |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 int res(int par1, int param2) => par1 + param2 + par1; | 1710 int res(int par1, int param2) => par1 + param2 + par1; |
| 1711 '''); | 1711 '''); |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 test_singleExpression_withVariables_doReorder() async { | 1714 test_singleExpression_withVariables_doReorder() async { |
| 1715 indexTestUnit(''' | 1715 await indexTestUnit(''' |
| 1716 main() { | 1716 main() { |
| 1717 int v1 = 1; | 1717 int v1 = 1; |
| 1718 int v2 = 2; | 1718 int v2 = 2; |
| 1719 int v3 = 3; | 1719 int v3 = 3; |
| 1720 int a = v1 + v2; // marker | 1720 int a = v1 + v2; // marker |
| 1721 int b = v2 + v3; | 1721 int b = v2 + v3; |
| 1722 } | 1722 } |
| 1723 '''); | 1723 '''); |
| 1724 _createRefactoringForString('v1 + v2'); | 1724 _createRefactoringForString('v1 + v2'); |
| 1725 // apply refactoring | 1725 // apply refactoring |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1741 int v2 = 2; | 1741 int v2 = 2; |
| 1742 int v3 = 3; | 1742 int v3 = 3; |
| 1743 int a = res(v2, v1); // marker | 1743 int a = res(v2, v1); // marker |
| 1744 int b = res(v3, v2); | 1744 int b = res(v3, v2); |
| 1745 } | 1745 } |
| 1746 | 1746 |
| 1747 int res(int v2, int v1) => v1 + v2; | 1747 int res(int v2, int v1) => v1 + v2; |
| 1748 '''); | 1748 '''); |
| 1749 } | 1749 } |
| 1750 | 1750 |
| 1751 test_singleExpression_withVariables_namedExpression() { | 1751 test_singleExpression_withVariables_namedExpression() async { |
| 1752 indexTestUnit(''' | 1752 await indexTestUnit(''' |
| 1753 main() { | 1753 main() { |
| 1754 int v1 = 1; | 1754 int v1 = 1; |
| 1755 int v2 = 2; | 1755 int v2 = 2; |
| 1756 int a = process(arg: v1 + v2); | 1756 int a = process(arg: v1 + v2); |
| 1757 } | 1757 } |
| 1758 process({arg}) {} | 1758 process({arg}) {} |
| 1759 '''); | 1759 '''); |
| 1760 _createRefactoringForString('process(arg: v1 + v2)'); | 1760 _createRefactoringForString('process(arg: v1 + v2)'); |
| 1761 // apply refactoring | 1761 // apply refactoring |
| 1762 return _assertSuccessfulRefactoring(''' | 1762 return _assertSuccessfulRefactoring(''' |
| 1763 main() { | 1763 main() { |
| 1764 int v1 = 1; | 1764 int v1 = 1; |
| 1765 int v2 = 2; | 1765 int v2 = 2; |
| 1766 int a = res(v1, v2); | 1766 int a = res(v1, v2); |
| 1767 } | 1767 } |
| 1768 | 1768 |
| 1769 res(int v1, int v2) => process(arg: v1 + v2); | 1769 res(int v1, int v2) => process(arg: v1 + v2); |
| 1770 process({arg}) {} | 1770 process({arg}) {} |
| 1771 '''); | 1771 '''); |
| 1772 } | 1772 } |
| 1773 | 1773 |
| 1774 test_singleExpression_withVariables_newType() async { | 1774 test_singleExpression_withVariables_newType() async { |
| 1775 indexTestUnit(''' | 1775 await indexTestUnit(''' |
| 1776 main() { | 1776 main() { |
| 1777 int v1 = 1; | 1777 int v1 = 1; |
| 1778 int v2 = 2; | 1778 int v2 = 2; |
| 1779 int v3 = 3; | 1779 int v3 = 3; |
| 1780 int a = v1 + v2 + v3; | 1780 int a = v1 + v2 + v3; |
| 1781 } | 1781 } |
| 1782 '''); | 1782 '''); |
| 1783 _createRefactoringForString('v1 + v2 + v3'); | 1783 _createRefactoringForString('v1 + v2 + v3'); |
| 1784 // apply refactoring | 1784 // apply refactoring |
| 1785 await refactoring.checkInitialConditions(); | 1785 await refactoring.checkInitialConditions(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1801 int v1 = 1; | 1801 int v1 = 1; |
| 1802 int v2 = 2; | 1802 int v2 = 2; |
| 1803 int v3 = 3; | 1803 int v3 = 3; |
| 1804 int a = res(v1, v2, v3); | 1804 int a = res(v1, v2, v3); |
| 1805 } | 1805 } |
| 1806 | 1806 |
| 1807 int res(num v1, v2, v3) => v1 + v2 + v3; | 1807 int res(num v1, v2, v3) => v1 + v2 + v3; |
| 1808 '''); | 1808 '''); |
| 1809 } | 1809 } |
| 1810 | 1810 |
| 1811 test_singleExpression_withVariables_useBestType() { | 1811 test_singleExpression_withVariables_useBestType() async { |
| 1812 indexTestUnit(''' | 1812 await indexTestUnit(''' |
| 1813 main() { | 1813 main() { |
| 1814 var v1 = 1; | 1814 var v1 = 1; |
| 1815 var v2 = 2; | 1815 var v2 = 2; |
| 1816 var a = v1 + v2 + v1; // marker | 1816 var a = v1 + v2 + v1; // marker |
| 1817 } | 1817 } |
| 1818 '''); | 1818 '''); |
| 1819 _createRefactoringForString('v1 + v2 + v1'); | 1819 _createRefactoringForString('v1 + v2 + v1'); |
| 1820 // apply refactoring | 1820 // apply refactoring |
| 1821 return _assertSuccessfulRefactoring(''' | 1821 return _assertSuccessfulRefactoring(''' |
| 1822 main() { | 1822 main() { |
| 1823 var v1 = 1; | 1823 var v1 = 1; |
| 1824 var v2 = 2; | 1824 var v2 = 2; |
| 1825 var a = res(v1, v2); // marker | 1825 var a = res(v1, v2); // marker |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 int res(int v1, int v2) => v1 + v2 + v1; | 1828 int res(int v1, int v2) => v1 + v2 + v1; |
| 1829 '''); | 1829 '''); |
| 1830 } | 1830 } |
| 1831 | 1831 |
| 1832 test_statements_assignment() { | 1832 test_statements_assignment() async { |
| 1833 indexTestUnit(''' | 1833 await indexTestUnit(''' |
| 1834 main() { | 1834 main() { |
| 1835 int v; | 1835 int v; |
| 1836 // start | 1836 // start |
| 1837 v = 5; | 1837 v = 5; |
| 1838 // end | 1838 // end |
| 1839 print(v); | 1839 print(v); |
| 1840 } | 1840 } |
| 1841 '''); | 1841 '''); |
| 1842 _createRefactoringForStartEndComments(); | 1842 _createRefactoringForStartEndComments(); |
| 1843 // apply refactoring | 1843 // apply refactoring |
| 1844 return _assertSuccessfulRefactoring(''' | 1844 return _assertSuccessfulRefactoring(''' |
| 1845 main() { | 1845 main() { |
| 1846 int v; | 1846 int v; |
| 1847 // start | 1847 // start |
| 1848 v = res(v); | 1848 v = res(v); |
| 1849 // end | 1849 // end |
| 1850 print(v); | 1850 print(v); |
| 1851 } | 1851 } |
| 1852 | 1852 |
| 1853 int res(int v) { | 1853 int res(int v) { |
| 1854 v = 5; | 1854 v = 5; |
| 1855 return v; | 1855 return v; |
| 1856 } | 1856 } |
| 1857 '''); | 1857 '''); |
| 1858 } | 1858 } |
| 1859 | 1859 |
| 1860 test_statements_changeIndentation() { | 1860 test_statements_changeIndentation() async { |
| 1861 indexTestUnit(''' | 1861 await indexTestUnit(''' |
| 1862 main() { | 1862 main() { |
| 1863 { | 1863 { |
| 1864 // start | 1864 // start |
| 1865 if (true) { | 1865 if (true) { |
| 1866 print(0); | 1866 print(0); |
| 1867 } | 1867 } |
| 1868 // end | 1868 // end |
| 1869 } | 1869 } |
| 1870 } | 1870 } |
| 1871 '''); | 1871 '''); |
| 1872 _createRefactoringForStartEndComments(); | 1872 _createRefactoringForStartEndComments(); |
| 1873 // apply refactoring | 1873 // apply refactoring |
| 1874 return _assertSuccessfulRefactoring(''' | 1874 return _assertSuccessfulRefactoring(''' |
| 1875 main() { | 1875 main() { |
| 1876 { | 1876 { |
| 1877 // start | 1877 // start |
| 1878 res(); | 1878 res(); |
| 1879 // end | 1879 // end |
| 1880 } | 1880 } |
| 1881 } | 1881 } |
| 1882 | 1882 |
| 1883 void res() { | 1883 void res() { |
| 1884 if (true) { | 1884 if (true) { |
| 1885 print(0); | 1885 print(0); |
| 1886 } | 1886 } |
| 1887 } | 1887 } |
| 1888 '''); | 1888 '''); |
| 1889 } | 1889 } |
| 1890 | 1890 |
| 1891 test_statements_changeIndentation_multilineString() { | 1891 test_statements_changeIndentation_multilineString() async { |
| 1892 indexTestUnit(''' | 1892 await indexTestUnit(''' |
| 1893 main() { | 1893 main() { |
| 1894 { | 1894 { |
| 1895 // start | 1895 // start |
| 1896 print(""" | 1896 print(""" |
| 1897 first line | 1897 first line |
| 1898 second line | 1898 second line |
| 1899 """); | 1899 """); |
| 1900 // end | 1900 // end |
| 1901 } | 1901 } |
| 1902 } | 1902 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1914 | 1914 |
| 1915 void res() { | 1915 void res() { |
| 1916 print(""" | 1916 print(""" |
| 1917 first line | 1917 first line |
| 1918 second line | 1918 second line |
| 1919 """); | 1919 """); |
| 1920 } | 1920 } |
| 1921 '''); | 1921 '''); |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 test_statements_definesVariable_notUsedOutside() { | 1924 test_statements_definesVariable_notUsedOutside() async { |
| 1925 indexTestUnit(''' | 1925 await indexTestUnit(''' |
| 1926 main() { | 1926 main() { |
| 1927 int a = 1; | 1927 int a = 1; |
| 1928 int b = 1; | 1928 int b = 1; |
| 1929 // start | 1929 // start |
| 1930 int v = a + b; | 1930 int v = a + b; |
| 1931 print(v); | 1931 print(v); |
| 1932 // end | 1932 // end |
| 1933 } | 1933 } |
| 1934 '''); | 1934 '''); |
| 1935 _createRefactoringForStartEndComments(); | 1935 _createRefactoringForStartEndComments(); |
| 1936 // apply refactoring | 1936 // apply refactoring |
| 1937 return _assertSuccessfulRefactoring(''' | 1937 return _assertSuccessfulRefactoring(''' |
| 1938 main() { | 1938 main() { |
| 1939 int a = 1; | 1939 int a = 1; |
| 1940 int b = 1; | 1940 int b = 1; |
| 1941 // start | 1941 // start |
| 1942 res(a, b); | 1942 res(a, b); |
| 1943 // end | 1943 // end |
| 1944 } | 1944 } |
| 1945 | 1945 |
| 1946 void res(int a, int b) { | 1946 void res(int a, int b) { |
| 1947 int v = a + b; | 1947 int v = a + b; |
| 1948 print(v); | 1948 print(v); |
| 1949 } | 1949 } |
| 1950 '''); | 1950 '''); |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 test_statements_definesVariable_oneUsedOutside_assignment() { | 1953 test_statements_definesVariable_oneUsedOutside_assignment() async { |
| 1954 indexTestUnit(''' | 1954 await indexTestUnit(''' |
| 1955 myFunctionA() { | 1955 myFunctionA() { |
| 1956 int a = 1; | 1956 int a = 1; |
| 1957 // start | 1957 // start |
| 1958 a += 10; | 1958 a += 10; |
| 1959 // end | 1959 // end |
| 1960 print(a); | 1960 print(a); |
| 1961 } | 1961 } |
| 1962 myFunctionB() { | 1962 myFunctionB() { |
| 1963 int b = 2; | 1963 int b = 2; |
| 1964 b += 10; | 1964 b += 10; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1981 return a; | 1981 return a; |
| 1982 } | 1982 } |
| 1983 myFunctionB() { | 1983 myFunctionB() { |
| 1984 int b = 2; | 1984 int b = 2; |
| 1985 b = res(b); | 1985 b = res(b); |
| 1986 print(b); | 1986 print(b); |
| 1987 } | 1987 } |
| 1988 '''); | 1988 '''); |
| 1989 } | 1989 } |
| 1990 | 1990 |
| 1991 test_statements_definesVariable_oneUsedOutside_declaration() { | 1991 test_statements_definesVariable_oneUsedOutside_declaration() async { |
| 1992 indexTestUnit(''' | 1992 await indexTestUnit(''' |
| 1993 myFunctionA() { | 1993 myFunctionA() { |
| 1994 int a = 1; | 1994 int a = 1; |
| 1995 int b = 2; | 1995 int b = 2; |
| 1996 // start | 1996 // start |
| 1997 int v1 = a + b; | 1997 int v1 = a + b; |
| 1998 // end | 1998 // end |
| 1999 print(v1); | 1999 print(v1); |
| 2000 } | 2000 } |
| 2001 myFunctionB() { | 2001 myFunctionB() { |
| 2002 int a = 3; | 2002 int a = 3; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2024 myFunctionB() { | 2024 myFunctionB() { |
| 2025 int a = 3; | 2025 int a = 3; |
| 2026 int b = 4; | 2026 int b = 4; |
| 2027 int v2 = res(a, b); | 2027 int v2 = res(a, b); |
| 2028 print(v2); | 2028 print(v2); |
| 2029 } | 2029 } |
| 2030 '''); | 2030 '''); |
| 2031 } | 2031 } |
| 2032 | 2032 |
| 2033 test_statements_definesVariable_twoUsedOutside() async { | 2033 test_statements_definesVariable_twoUsedOutside() async { |
| 2034 indexTestUnit(''' | 2034 await indexTestUnit(''' |
| 2035 main() { | 2035 main() { |
| 2036 // start | 2036 // start |
| 2037 int varA = 1; | 2037 int varA = 1; |
| 2038 int varB = 2; | 2038 int varB = 2; |
| 2039 // end | 2039 // end |
| 2040 int v = varA + varB; | 2040 int v = varA + varB; |
| 2041 } | 2041 } |
| 2042 '''); | 2042 '''); |
| 2043 _createRefactoringForStartEndComments(); | 2043 _createRefactoringForStartEndComments(); |
| 2044 // check conditions | 2044 // check conditions |
| 2045 RefactoringStatus status = await refactoring.checkInitialConditions(); | 2045 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 2046 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); | 2046 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL); |
| 2047 } | 2047 } |
| 2048 | 2048 |
| 2049 test_statements_duplicate_absolutelySame() { | 2049 test_statements_duplicate_absolutelySame() async { |
| 2050 indexTestUnit(''' | 2050 await indexTestUnit(''' |
| 2051 myFunctionA() { | 2051 myFunctionA() { |
| 2052 print(0); | 2052 print(0); |
| 2053 print(1); | 2053 print(1); |
| 2054 } | 2054 } |
| 2055 myFunctionB() { | 2055 myFunctionB() { |
| 2056 // start | 2056 // start |
| 2057 print(0); | 2057 print(0); |
| 2058 print(1); | 2058 print(1); |
| 2059 // end | 2059 // end |
| 2060 } | 2060 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2071 // end | 2071 // end |
| 2072 } | 2072 } |
| 2073 | 2073 |
| 2074 void res() { | 2074 void res() { |
| 2075 print(0); | 2075 print(0); |
| 2076 print(1); | 2076 print(1); |
| 2077 } | 2077 } |
| 2078 '''); | 2078 '''); |
| 2079 } | 2079 } |
| 2080 | 2080 |
| 2081 test_statements_duplicate_declaresDifferentlyNamedVariable() { | 2081 test_statements_duplicate_declaresDifferentlyNamedVariable() async { |
| 2082 indexTestUnit(''' | 2082 await indexTestUnit(''' |
| 2083 myFunctionA() { | 2083 myFunctionA() { |
| 2084 int varA = 1; | 2084 int varA = 1; |
| 2085 print(varA); | 2085 print(varA); |
| 2086 } | 2086 } |
| 2087 myFunctionB() { | 2087 myFunctionB() { |
| 2088 // start | 2088 // start |
| 2089 int varB = 1; | 2089 int varB = 1; |
| 2090 print(varB); | 2090 print(varB); |
| 2091 // end | 2091 // end |
| 2092 } | 2092 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2103 // end | 2103 // end |
| 2104 } | 2104 } |
| 2105 | 2105 |
| 2106 void res() { | 2106 void res() { |
| 2107 int varB = 1; | 2107 int varB = 1; |
| 2108 print(varB); | 2108 print(varB); |
| 2109 } | 2109 } |
| 2110 '''); | 2110 '''); |
| 2111 } | 2111 } |
| 2112 | 2112 |
| 2113 test_statements_dynamic() { | 2113 test_statements_dynamic() async { |
| 2114 indexTestUnit(''' | 2114 await indexTestUnit(''' |
| 2115 dynaFunction(p) => 0; | 2115 dynaFunction(p) => 0; |
| 2116 main() { | 2116 main() { |
| 2117 // start | 2117 // start |
| 2118 var a = 1; | 2118 var a = 1; |
| 2119 var v = dynaFunction(a); | 2119 var v = dynaFunction(a); |
| 2120 // end | 2120 // end |
| 2121 print(v); | 2121 print(v); |
| 2122 } | 2122 } |
| 2123 '''); | 2123 '''); |
| 2124 _createRefactoringForStartEndComments(); | 2124 _createRefactoringForStartEndComments(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2136 var a = 1; | 2136 var a = 1; |
| 2137 var v = dynaFunction(a); | 2137 var v = dynaFunction(a); |
| 2138 return v; | 2138 return v; |
| 2139 } | 2139 } |
| 2140 '''); | 2140 '''); |
| 2141 } | 2141 } |
| 2142 | 2142 |
| 2143 /** | 2143 /** |
| 2144 * We should always add ";" when invoke method with extracted statements. | 2144 * We should always add ";" when invoke method with extracted statements. |
| 2145 */ | 2145 */ |
| 2146 test_statements_endsWithBlock() { | 2146 test_statements_endsWithBlock() async { |
| 2147 indexTestUnit(''' | 2147 await indexTestUnit(''' |
| 2148 main() { | 2148 main() { |
| 2149 // start | 2149 // start |
| 2150 if (true) { | 2150 if (true) { |
| 2151 print(0); | 2151 print(0); |
| 2152 } | 2152 } |
| 2153 // end | 2153 // end |
| 2154 } | 2154 } |
| 2155 '''); | 2155 '''); |
| 2156 _createRefactoringForStartEndComments(); | 2156 _createRefactoringForStartEndComments(); |
| 2157 // apply refactoring | 2157 // apply refactoring |
| 2158 return _assertSuccessfulRefactoring(''' | 2158 return _assertSuccessfulRefactoring(''' |
| 2159 main() { | 2159 main() { |
| 2160 // start | 2160 // start |
| 2161 res(); | 2161 res(); |
| 2162 // end | 2162 // end |
| 2163 } | 2163 } |
| 2164 | 2164 |
| 2165 void res() { | 2165 void res() { |
| 2166 if (true) { | 2166 if (true) { |
| 2167 print(0); | 2167 print(0); |
| 2168 } | 2168 } |
| 2169 } | 2169 } |
| 2170 '''); | 2170 '''); |
| 2171 } | 2171 } |
| 2172 | 2172 |
| 2173 test_statements_exit_throws() async { | 2173 test_statements_exit_throws() async { |
| 2174 indexTestUnit(''' | 2174 await indexTestUnit(''' |
| 2175 main(int p) { | 2175 main(int p) { |
| 2176 // start | 2176 // start |
| 2177 if (p == 0) { | 2177 if (p == 0) { |
| 2178 return; | 2178 return; |
| 2179 } | 2179 } |
| 2180 throw 'boo!'; | 2180 throw 'boo!'; |
| 2181 // end | 2181 // end |
| 2182 } | 2182 } |
| 2183 '''); | 2183 '''); |
| 2184 _createRefactoringForStartEndComments(); | 2184 _createRefactoringForStartEndComments(); |
| 2185 await assertRefactoringConditionsOK(); | 2185 await assertRefactoringConditionsOK(); |
| 2186 } | 2186 } |
| 2187 | 2187 |
| 2188 test_statements_hasAwait_dynamicReturnType() { | 2188 test_statements_hasAwait_dynamicReturnType() async { |
| 2189 indexTestUnit(''' | 2189 await indexTestUnit(''' |
| 2190 import 'dart:async'; | 2190 import 'dart:async'; |
| 2191 Future getValue() => 42; | 2191 Future getValue() => 42; |
| 2192 main() async { | 2192 main() async { |
| 2193 // start | 2193 // start |
| 2194 var v = await getValue(); | 2194 var v = await getValue(); |
| 2195 // end | 2195 // end |
| 2196 print(v); | 2196 print(v); |
| 2197 } | 2197 } |
| 2198 '''); | 2198 '''); |
| 2199 _createRefactoringForStartEndComments(); | 2199 _createRefactoringForStartEndComments(); |
| 2200 // apply refactoring | 2200 // apply refactoring |
| 2201 return _assertSuccessfulRefactoring(''' | 2201 return _assertSuccessfulRefactoring(''' |
| 2202 import 'dart:async'; | 2202 import 'dart:async'; |
| 2203 Future getValue() => 42; | 2203 Future getValue() => 42; |
| 2204 main() async { | 2204 main() async { |
| 2205 // start | 2205 // start |
| 2206 var v = await res(); | 2206 var v = await res(); |
| 2207 // end | 2207 // end |
| 2208 print(v); | 2208 print(v); |
| 2209 } | 2209 } |
| 2210 | 2210 |
| 2211 Future res() async { | 2211 Future res() async { |
| 2212 var v = await getValue(); | 2212 var v = await getValue(); |
| 2213 return v; | 2213 return v; |
| 2214 } | 2214 } |
| 2215 '''); | 2215 '''); |
| 2216 } | 2216 } |
| 2217 | 2217 |
| 2218 test_statements_hasAwait_expression() { | 2218 test_statements_hasAwait_expression() async { |
| 2219 indexTestUnit(''' | 2219 await indexTestUnit(''' |
| 2220 import 'dart:async'; | 2220 import 'dart:async'; |
| 2221 Future<int> getValue() => 42; | 2221 Future<int> getValue() => 42; |
| 2222 main() async { | 2222 main() async { |
| 2223 // start | 2223 // start |
| 2224 int v = await getValue(); | 2224 int v = await getValue(); |
| 2225 v += 2; | 2225 v += 2; |
| 2226 // end | 2226 // end |
| 2227 print(v); | 2227 print(v); |
| 2228 } | 2228 } |
| 2229 '''); | 2229 '''); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2240 } | 2240 } |
| 2241 | 2241 |
| 2242 Future<int> res() async { | 2242 Future<int> res() async { |
| 2243 int v = await getValue(); | 2243 int v = await getValue(); |
| 2244 v += 2; | 2244 v += 2; |
| 2245 return v; | 2245 return v; |
| 2246 } | 2246 } |
| 2247 '''); | 2247 '''); |
| 2248 } | 2248 } |
| 2249 | 2249 |
| 2250 test_statements_hasAwait_forEach() { | 2250 test_statements_hasAwait_forEach() async { |
| 2251 indexTestUnit(''' | 2251 await indexTestUnit(''' |
| 2252 import 'dart:async'; | 2252 import 'dart:async'; |
| 2253 Stream<int> getValueStream() => null; | 2253 Stream<int> getValueStream() => null; |
| 2254 main() async { | 2254 main() async { |
| 2255 // start | 2255 // start |
| 2256 int sum = 0; | 2256 int sum = 0; |
| 2257 await for (int v in getValueStream()) { | 2257 await for (int v in getValueStream()) { |
| 2258 sum += v; | 2258 sum += v; |
| 2259 } | 2259 } |
| 2260 // end | 2260 // end |
| 2261 print(sum); | 2261 print(sum); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2276 Future<int> res() async { | 2276 Future<int> res() async { |
| 2277 int sum = 0; | 2277 int sum = 0; |
| 2278 await for (int v in getValueStream()) { | 2278 await for (int v in getValueStream()) { |
| 2279 sum += v; | 2279 sum += v; |
| 2280 } | 2280 } |
| 2281 return sum; | 2281 return sum; |
| 2282 } | 2282 } |
| 2283 '''); | 2283 '''); |
| 2284 } | 2284 } |
| 2285 | 2285 |
| 2286 test_statements_hasAwait_voidReturnType() { | 2286 test_statements_hasAwait_voidReturnType() async { |
| 2287 indexTestUnit(''' | 2287 await indexTestUnit(''' |
| 2288 import 'dart:async'; | 2288 import 'dart:async'; |
| 2289 Future<int> getValue() => 42; | 2289 Future<int> getValue() => 42; |
| 2290 main() async { | 2290 main() async { |
| 2291 // start | 2291 // start |
| 2292 int v = await getValue(); | 2292 int v = await getValue(); |
| 2293 print(v); | 2293 print(v); |
| 2294 // end | 2294 // end |
| 2295 } | 2295 } |
| 2296 '''); | 2296 '''); |
| 2297 _createRefactoringForStartEndComments(); | 2297 _createRefactoringForStartEndComments(); |
| 2298 // apply refactoring | 2298 // apply refactoring |
| 2299 return _assertSuccessfulRefactoring(''' | 2299 return _assertSuccessfulRefactoring(''' |
| 2300 import 'dart:async'; | 2300 import 'dart:async'; |
| 2301 Future<int> getValue() => 42; | 2301 Future<int> getValue() => 42; |
| 2302 main() async { | 2302 main() async { |
| 2303 // start | 2303 // start |
| 2304 await res(); | 2304 await res(); |
| 2305 // end | 2305 // end |
| 2306 } | 2306 } |
| 2307 | 2307 |
| 2308 Future res() async { | 2308 Future res() async { |
| 2309 int v = await getValue(); | 2309 int v = await getValue(); |
| 2310 print(v); | 2310 print(v); |
| 2311 } | 2311 } |
| 2312 '''); | 2312 '''); |
| 2313 } | 2313 } |
| 2314 | 2314 |
| 2315 test_statements_inSwitchMember() { | 2315 test_statements_inSwitchMember() async { |
| 2316 indexTestUnit(''' | 2316 await indexTestUnit(''' |
| 2317 class A { | 2317 class A { |
| 2318 foo(int p) { | 2318 foo(int p) { |
| 2319 switch (p) { | 2319 switch (p) { |
| 2320 case 0: | 2320 case 0: |
| 2321 // start | 2321 // start |
| 2322 print(0); | 2322 print(0); |
| 2323 // end | 2323 // end |
| 2324 break; | 2324 break; |
| 2325 default: | 2325 default: |
| 2326 break; | 2326 break; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2344 } | 2344 } |
| 2345 } | 2345 } |
| 2346 | 2346 |
| 2347 void res() { | 2347 void res() { |
| 2348 print(0); | 2348 print(0); |
| 2349 } | 2349 } |
| 2350 } | 2350 } |
| 2351 '''); | 2351 '''); |
| 2352 } | 2352 } |
| 2353 | 2353 |
| 2354 test_statements_method() { | 2354 test_statements_method() async { |
| 2355 indexTestUnit(''' | 2355 await indexTestUnit(''' |
| 2356 class A { | 2356 class A { |
| 2357 foo() { | 2357 foo() { |
| 2358 // start | 2358 // start |
| 2359 print(0); | 2359 print(0); |
| 2360 // end | 2360 // end |
| 2361 } | 2361 } |
| 2362 } | 2362 } |
| 2363 '''); | 2363 '''); |
| 2364 _createRefactoringForStartEndComments(); | 2364 _createRefactoringForStartEndComments(); |
| 2365 // apply refactoring | 2365 // apply refactoring |
| 2366 return _assertSuccessfulRefactoring(''' | 2366 return _assertSuccessfulRefactoring(''' |
| 2367 class A { | 2367 class A { |
| 2368 foo() { | 2368 foo() { |
| 2369 // start | 2369 // start |
| 2370 res(); | 2370 res(); |
| 2371 // end | 2371 // end |
| 2372 } | 2372 } |
| 2373 | 2373 |
| 2374 void res() { | 2374 void res() { |
| 2375 print(0); | 2375 print(0); |
| 2376 } | 2376 } |
| 2377 } | 2377 } |
| 2378 '''); | 2378 '''); |
| 2379 } | 2379 } |
| 2380 | 2380 |
| 2381 test_statements_noDuplicates() { | 2381 test_statements_noDuplicates() async { |
| 2382 indexTestUnit(''' | 2382 await indexTestUnit(''' |
| 2383 main() { | 2383 main() { |
| 2384 int a = 1; | 2384 int a = 1; |
| 2385 int b = 1; | 2385 int b = 1; |
| 2386 // start | 2386 // start |
| 2387 print(a); | 2387 print(a); |
| 2388 // end | 2388 // end |
| 2389 } | 2389 } |
| 2390 '''); | 2390 '''); |
| 2391 _createRefactoringForStartEndComments(); | 2391 _createRefactoringForStartEndComments(); |
| 2392 // apply refactoring | 2392 // apply refactoring |
| 2393 return _assertSuccessfulRefactoring(''' | 2393 return _assertSuccessfulRefactoring(''' |
| 2394 main() { | 2394 main() { |
| 2395 int a = 1; | 2395 int a = 1; |
| 2396 int b = 1; | 2396 int b = 1; |
| 2397 // start | 2397 // start |
| 2398 res(a); | 2398 res(a); |
| 2399 // end | 2399 // end |
| 2400 } | 2400 } |
| 2401 | 2401 |
| 2402 void res(int a) { | 2402 void res(int a) { |
| 2403 print(a); | 2403 print(a); |
| 2404 } | 2404 } |
| 2405 '''); | 2405 '''); |
| 2406 } | 2406 } |
| 2407 | 2407 |
| 2408 test_statements_parameters_ignoreInnerPropagatedType() async { | 2408 test_statements_parameters_ignoreInnerPropagatedType() async { |
| 2409 indexTestUnit(''' | 2409 await indexTestUnit(''' |
| 2410 main(Object x) { | 2410 main(Object x) { |
| 2411 // start | 2411 // start |
| 2412 if (x is int) { | 2412 if (x is int) { |
| 2413 print('int'); | 2413 print('int'); |
| 2414 } | 2414 } |
| 2415 if (x is bool) { | 2415 if (x is bool) { |
| 2416 print('bool'); | 2416 print('bool'); |
| 2417 } | 2417 } |
| 2418 // end | 2418 // end |
| 2419 } | 2419 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2431 if (x is int) { | 2431 if (x is int) { |
| 2432 print('int'); | 2432 print('int'); |
| 2433 } | 2433 } |
| 2434 if (x is bool) { | 2434 if (x is bool) { |
| 2435 print('bool'); | 2435 print('bool'); |
| 2436 } | 2436 } |
| 2437 } | 2437 } |
| 2438 '''); | 2438 '''); |
| 2439 } | 2439 } |
| 2440 | 2440 |
| 2441 test_statements_parameters_importType() { | 2441 test_statements_parameters_importType() async { |
| 2442 _addLibraryReturningAsync(); | 2442 _addLibraryReturningAsync(); |
| 2443 indexTestUnit(''' | 2443 await indexTestUnit(''' |
| 2444 import 'asyncLib.dart'; | 2444 import 'asyncLib.dart'; |
| 2445 main() { | 2445 main() { |
| 2446 var v = newFuture(); | 2446 var v = newFuture(); |
| 2447 // start | 2447 // start |
| 2448 print(v); | 2448 print(v); |
| 2449 // end | 2449 // end |
| 2450 } | 2450 } |
| 2451 '''); | 2451 '''); |
| 2452 _createRefactoringForStartEndComments(); | 2452 _createRefactoringForStartEndComments(); |
| 2453 // apply refactoring | 2453 // apply refactoring |
| 2454 return _assertSuccessfulRefactoring(''' | 2454 return _assertSuccessfulRefactoring(''' |
| 2455 import 'asyncLib.dart'; | 2455 import 'asyncLib.dart'; |
| 2456 import 'dart:async'; | 2456 import 'dart:async'; |
| 2457 main() { | 2457 main() { |
| 2458 var v = newFuture(); | 2458 var v = newFuture(); |
| 2459 // start | 2459 // start |
| 2460 res(v); | 2460 res(v); |
| 2461 // end | 2461 // end |
| 2462 } | 2462 } |
| 2463 | 2463 |
| 2464 void res(Future<int> v) { | 2464 void res(Future<int> v) { |
| 2465 print(v); | 2465 print(v); |
| 2466 } | 2466 } |
| 2467 '''); | 2467 '''); |
| 2468 } | 2468 } |
| 2469 | 2469 |
| 2470 test_statements_parameters_localFunction() { | 2470 test_statements_parameters_localFunction() async { |
| 2471 _addLibraryReturningAsync(); | 2471 _addLibraryReturningAsync(); |
| 2472 indexTestUnit(''' | 2472 await indexTestUnit(''' |
| 2473 class C { | 2473 class C { |
| 2474 int f(int a) { | 2474 int f(int a) { |
| 2475 int callback(int x, int y) => x + a; | 2475 int callback(int x, int y) => x + a; |
| 2476 int b = a + 1; | 2476 int b = a + 1; |
| 2477 // start | 2477 // start |
| 2478 int c = callback(b, 2); | 2478 int c = callback(b, 2); |
| 2479 // end | 2479 // end |
| 2480 int d = c + 1; | 2480 int d = c + 1; |
| 2481 return d; | 2481 return d; |
| 2482 } | 2482 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2496 } | 2496 } |
| 2497 | 2497 |
| 2498 int res(int callback(int x, int y), int b) { | 2498 int res(int callback(int x, int y), int b) { |
| 2499 int c = callback(b, 2); | 2499 int c = callback(b, 2); |
| 2500 return c; | 2500 return c; |
| 2501 } | 2501 } |
| 2502 }'''); | 2502 }'''); |
| 2503 } | 2503 } |
| 2504 | 2504 |
| 2505 test_statements_parameters_noLocalVariableConflict() async { | 2505 test_statements_parameters_noLocalVariableConflict() async { |
| 2506 indexTestUnit(''' | 2506 await indexTestUnit(''' |
| 2507 int f(int x) { | 2507 int f(int x) { |
| 2508 int y = x + 1; | 2508 int y = x + 1; |
| 2509 // start | 2509 // start |
| 2510 if (y % 2 == 0) { | 2510 if (y % 2 == 0) { |
| 2511 int y = x + 2; | 2511 int y = x + 2; |
| 2512 return y; | 2512 return y; |
| 2513 } else { | 2513 } else { |
| 2514 return y; | 2514 return y; |
| 2515 } | 2515 } |
| 2516 // end | 2516 // end |
| 2517 } | 2517 } |
| 2518 '''); | 2518 '''); |
| 2519 _createRefactoringForStartEndComments(); | 2519 _createRefactoringForStartEndComments(); |
| 2520 await assertRefactoringConditionsOK(); | 2520 await assertRefactoringConditionsOK(); |
| 2521 } | 2521 } |
| 2522 | 2522 |
| 2523 test_statements_return_last() { | 2523 test_statements_return_last() async { |
| 2524 indexTestUnit(''' | 2524 await indexTestUnit(''' |
| 2525 main() { | 2525 main() { |
| 2526 // start | 2526 // start |
| 2527 int v = 5; | 2527 int v = 5; |
| 2528 return v + 1; | 2528 return v + 1; |
| 2529 // end | 2529 // end |
| 2530 } | 2530 } |
| 2531 '''); | 2531 '''); |
| 2532 _createRefactoringForStartEndComments(); | 2532 _createRefactoringForStartEndComments(); |
| 2533 // apply refactoring | 2533 // apply refactoring |
| 2534 return _assertSuccessfulRefactoring(''' | 2534 return _assertSuccessfulRefactoring(''' |
| 2535 main() { | 2535 main() { |
| 2536 // start | 2536 // start |
| 2537 return res(); | 2537 return res(); |
| 2538 // end | 2538 // end |
| 2539 } | 2539 } |
| 2540 | 2540 |
| 2541 int res() { | 2541 int res() { |
| 2542 int v = 5; | 2542 int v = 5; |
| 2543 return v + 1; | 2543 return v + 1; |
| 2544 } | 2544 } |
| 2545 '''); | 2545 '''); |
| 2546 } | 2546 } |
| 2547 | 2547 |
| 2548 test_statements_return_multiple_ifElse() { | 2548 test_statements_return_multiple_ifElse() async { |
| 2549 indexTestUnit(''' | 2549 await indexTestUnit(''' |
| 2550 num main(bool b) { | 2550 num main(bool b) { |
| 2551 // start | 2551 // start |
| 2552 if (b) { | 2552 if (b) { |
| 2553 return 1; | 2553 return 1; |
| 2554 } else { | 2554 } else { |
| 2555 return 2.0; | 2555 return 2.0; |
| 2556 } | 2556 } |
| 2557 // end | 2557 // end |
| 2558 } | 2558 } |
| 2559 '''); | 2559 '''); |
| 2560 _createRefactoringForStartEndComments(); | 2560 _createRefactoringForStartEndComments(); |
| 2561 // apply refactoring | 2561 // apply refactoring |
| 2562 return _assertSuccessfulRefactoring(''' | 2562 return _assertSuccessfulRefactoring(''' |
| 2563 num main(bool b) { | 2563 num main(bool b) { |
| 2564 // start | 2564 // start |
| 2565 return res(b); | 2565 return res(b); |
| 2566 // end | 2566 // end |
| 2567 } | 2567 } |
| 2568 | 2568 |
| 2569 num res(bool b) { | 2569 num res(bool b) { |
| 2570 if (b) { | 2570 if (b) { |
| 2571 return 1; | 2571 return 1; |
| 2572 } else { | 2572 } else { |
| 2573 return 2.0; | 2573 return 2.0; |
| 2574 } | 2574 } |
| 2575 } | 2575 } |
| 2576 '''); | 2576 '''); |
| 2577 } | 2577 } |
| 2578 | 2578 |
| 2579 test_statements_return_multiple_ifThen() { | 2579 test_statements_return_multiple_ifThen() async { |
| 2580 indexTestUnit(''' | 2580 await indexTestUnit(''' |
| 2581 num main(bool b) { | 2581 num main(bool b) { |
| 2582 // start | 2582 // start |
| 2583 if (b) { | 2583 if (b) { |
| 2584 return 1; | 2584 return 1; |
| 2585 } | 2585 } |
| 2586 return 2.0; | 2586 return 2.0; |
| 2587 // end | 2587 // end |
| 2588 } | 2588 } |
| 2589 '''); | 2589 '''); |
| 2590 _createRefactoringForStartEndComments(); | 2590 _createRefactoringForStartEndComments(); |
| 2591 // apply refactoring | 2591 // apply refactoring |
| 2592 return _assertSuccessfulRefactoring(''' | 2592 return _assertSuccessfulRefactoring(''' |
| 2593 num main(bool b) { | 2593 num main(bool b) { |
| 2594 // start | 2594 // start |
| 2595 return res(b); | 2595 return res(b); |
| 2596 // end | 2596 // end |
| 2597 } | 2597 } |
| 2598 | 2598 |
| 2599 num res(bool b) { | 2599 num res(bool b) { |
| 2600 if (b) { | 2600 if (b) { |
| 2601 return 1; | 2601 return 1; |
| 2602 } | 2602 } |
| 2603 return 2.0; | 2603 return 2.0; |
| 2604 } | 2604 } |
| 2605 '''); | 2605 '''); |
| 2606 } | 2606 } |
| 2607 | 2607 |
| 2608 test_statements_return_multiple_ignoreInFunction() { | 2608 test_statements_return_multiple_ignoreInFunction() async { |
| 2609 indexTestUnit(''' | 2609 await indexTestUnit(''' |
| 2610 int main() { | 2610 int main() { |
| 2611 // start | 2611 // start |
| 2612 localFunction() { | 2612 localFunction() { |
| 2613 return 'abc'; | 2613 return 'abc'; |
| 2614 } | 2614 } |
| 2615 return 42; | 2615 return 42; |
| 2616 // end | 2616 // end |
| 2617 } | 2617 } |
| 2618 '''); | 2618 '''); |
| 2619 _createRefactoringForStartEndComments(); | 2619 _createRefactoringForStartEndComments(); |
| 2620 // apply refactoring | 2620 // apply refactoring |
| 2621 return _assertSuccessfulRefactoring(''' | 2621 return _assertSuccessfulRefactoring(''' |
| 2622 int main() { | 2622 int main() { |
| 2623 // start | 2623 // start |
| 2624 return res(); | 2624 return res(); |
| 2625 // end | 2625 // end |
| 2626 } | 2626 } |
| 2627 | 2627 |
| 2628 int res() { | 2628 int res() { |
| 2629 localFunction() { | 2629 localFunction() { |
| 2630 return 'abc'; | 2630 return 'abc'; |
| 2631 } | 2631 } |
| 2632 return 42; | 2632 return 42; |
| 2633 } | 2633 } |
| 2634 '''); | 2634 '''); |
| 2635 } | 2635 } |
| 2636 | 2636 |
| 2637 test_statements_return_multiple_interfaceFunction() { | 2637 test_statements_return_multiple_interfaceFunction() async { |
| 2638 indexTestUnit(''' | 2638 await indexTestUnit(''' |
| 2639 main(bool b) { | 2639 main(bool b) { |
| 2640 // start | 2640 // start |
| 2641 if (b) { | 2641 if (b) { |
| 2642 return 1; | 2642 return 1; |
| 2643 } | 2643 } |
| 2644 return () {}; | 2644 return () {}; |
| 2645 // end | 2645 // end |
| 2646 } | 2646 } |
| 2647 '''); | 2647 '''); |
| 2648 _createRefactoringForStartEndComments(); | 2648 _createRefactoringForStartEndComments(); |
| 2649 // apply refactoring | 2649 // apply refactoring |
| 2650 return _assertSuccessfulRefactoring(''' | 2650 return _assertSuccessfulRefactoring(''' |
| 2651 main(bool b) { | 2651 main(bool b) { |
| 2652 // start | 2652 // start |
| 2653 return res(b); | 2653 return res(b); |
| 2654 // end | 2654 // end |
| 2655 } | 2655 } |
| 2656 | 2656 |
| 2657 Object res(bool b) { | 2657 Object res(bool b) { |
| 2658 if (b) { | 2658 if (b) { |
| 2659 return 1; | 2659 return 1; |
| 2660 } | 2660 } |
| 2661 return () {}; | 2661 return () {}; |
| 2662 } | 2662 } |
| 2663 '''); | 2663 '''); |
| 2664 } | 2664 } |
| 2665 | 2665 |
| 2666 test_statements_return_multiple_sameElementDifferentTypeArgs() { | 2666 test_statements_return_multiple_sameElementDifferentTypeArgs() async { |
| 2667 indexTestUnit(''' | 2667 await indexTestUnit(''' |
| 2668 main(bool b) { | 2668 main(bool b) { |
| 2669 // start | 2669 // start |
| 2670 if (b) { | 2670 if (b) { |
| 2671 print(true); | 2671 print(true); |
| 2672 return <int>[]; | 2672 return <int>[]; |
| 2673 } else { | 2673 } else { |
| 2674 print(false); | 2674 print(false); |
| 2675 return <String>[]; | 2675 return <String>[]; |
| 2676 } | 2676 } |
| 2677 // end | 2677 // end |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2691 print(true); | 2691 print(true); |
| 2692 return <int>[]; | 2692 return <int>[]; |
| 2693 } else { | 2693 } else { |
| 2694 print(false); | 2694 print(false); |
| 2695 return <String>[]; | 2695 return <String>[]; |
| 2696 } | 2696 } |
| 2697 } | 2697 } |
| 2698 '''); | 2698 '''); |
| 2699 } | 2699 } |
| 2700 | 2700 |
| 2701 test_statements_return_single() { | 2701 test_statements_return_single() async { |
| 2702 indexTestUnit(''' | 2702 await indexTestUnit(''' |
| 2703 main() { | 2703 main() { |
| 2704 // start | 2704 // start |
| 2705 return 42; | 2705 return 42; |
| 2706 // end | 2706 // end |
| 2707 } | 2707 } |
| 2708 '''); | 2708 '''); |
| 2709 _createRefactoringForStartEndComments(); | 2709 _createRefactoringForStartEndComments(); |
| 2710 // apply refactoring | 2710 // apply refactoring |
| 2711 return _assertSuccessfulRefactoring(''' | 2711 return _assertSuccessfulRefactoring(''' |
| 2712 main() { | 2712 main() { |
| 2713 // start | 2713 // start |
| 2714 return res(); | 2714 return res(); |
| 2715 // end | 2715 // end |
| 2716 } | 2716 } |
| 2717 | 2717 |
| 2718 int res() { | 2718 int res() { |
| 2719 return 42; | 2719 return 42; |
| 2720 } | 2720 } |
| 2721 '''); | 2721 '''); |
| 2722 } | 2722 } |
| 2723 | 2723 |
| 2724 /** | 2724 /** |
| 2725 * We have 3 identical statements, but select only 2. | 2725 * We have 3 identical statements, but select only 2. |
| 2726 * This should not cause problems. | 2726 * This should not cause problems. |
| 2727 */ | 2727 */ |
| 2728 test_statements_twoOfThree() { | 2728 test_statements_twoOfThree() async { |
| 2729 indexTestUnit(''' | 2729 await indexTestUnit(''' |
| 2730 main() { | 2730 main() { |
| 2731 // start | 2731 // start |
| 2732 print(0); | 2732 print(0); |
| 2733 print(0); | 2733 print(0); |
| 2734 // end | 2734 // end |
| 2735 print(0); | 2735 print(0); |
| 2736 } | 2736 } |
| 2737 '''); | 2737 '''); |
| 2738 _createRefactoringForStartEndComments(); | 2738 _createRefactoringForStartEndComments(); |
| 2739 // apply refactoring | 2739 // apply refactoring |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2835 * Returns a deep copy of [refactoring] parameters. | 2835 * Returns a deep copy of [refactoring] parameters. |
| 2836 * There was a bug masked by updating parameter instances shared between the | 2836 * There was a bug masked by updating parameter instances shared between the |
| 2837 * refactoring and the test. | 2837 * refactoring and the test. |
| 2838 */ | 2838 */ |
| 2839 List<RefactoringMethodParameter> _getParametersCopy() { | 2839 List<RefactoringMethodParameter> _getParametersCopy() { |
| 2840 return refactoring.parameters.map((p) { | 2840 return refactoring.parameters.map((p) { |
| 2841 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); | 2841 return new RefactoringMethodParameter(p.kind, p.type, p.name, id: p.id); |
| 2842 }).toList(); | 2842 }).toList(); |
| 2843 } | 2843 } |
| 2844 } | 2844 } |
| OLD | NEW |