| 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.correction.fix; | 5 library test.services.correction.fix; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart' | 10 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; | 45 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 String myPkgLibPath = '/packages/my_pkg/lib'; | 48 String myPkgLibPath = '/packages/my_pkg/lib'; |
| 49 | 49 |
| 50 Fix fix; | 50 Fix fix; |
| 51 SourceChange change; | 51 SourceChange change; |
| 52 String resultCode; | 52 String resultCode; |
| 53 | 53 |
| 54 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { | 54 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { |
| 55 resolveTestUnit(''' | 55 await resolveTestUnit(''' |
| 56 main() { | 56 main() { |
| 57 bool b = true; | 57 bool b = true; |
| 58 $lineWithTest | 58 $lineWithTest |
| 59 } | 59 } |
| 60 '''); | 60 '''); |
| 61 await assertHasFix( | 61 await assertHasFix( |
| 62 DartFixKind.CREATE_FUNCTION, | 62 DartFixKind.CREATE_FUNCTION, |
| 63 ''' | 63 ''' |
| 64 main() { | 64 main() { |
| 65 bool b = true; | 65 bool b = true; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 191 } |
| 192 | 192 |
| 193 void _performAnalysis() { | 193 void _performAnalysis() { |
| 194 while (context.performAnalysisTask().hasMoreWork); | 194 while (context.performAnalysisTask().hasMoreWork); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 @reflectiveTest | 198 @reflectiveTest |
| 199 class FixProcessorTest extends BaseFixProcessorTest { | 199 class FixProcessorTest extends BaseFixProcessorTest { |
| 200 test_addFieldFormalParameters_hasRequiredParameter() async { | 200 test_addFieldFormalParameters_hasRequiredParameter() async { |
| 201 resolveTestUnit(''' | 201 await resolveTestUnit(''' |
| 202 class Test { | 202 class Test { |
| 203 final int a; | 203 final int a; |
| 204 final int b; | 204 final int b; |
| 205 final int c; | 205 final int c; |
| 206 Test(this.a); | 206 Test(this.a); |
| 207 } | 207 } |
| 208 '''); | 208 '''); |
| 209 await assertHasFix( | 209 await assertHasFix( |
| 210 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 210 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 211 ''' | 211 ''' |
| 212 class Test { | 212 class Test { |
| 213 final int a; | 213 final int a; |
| 214 final int b; | 214 final int b; |
| 215 final int c; | 215 final int c; |
| 216 Test(this.a, this.b, this.c); | 216 Test(this.a, this.b, this.c); |
| 217 } | 217 } |
| 218 '''); | 218 '''); |
| 219 } | 219 } |
| 220 | 220 |
| 221 test_addFieldFormalParameters_noParameters() async { | 221 test_addFieldFormalParameters_noParameters() async { |
| 222 resolveTestUnit(''' | 222 await resolveTestUnit(''' |
| 223 class Test { | 223 class Test { |
| 224 final int a; | 224 final int a; |
| 225 final int b; | 225 final int b; |
| 226 final int c; | 226 final int c; |
| 227 Test(); | 227 Test(); |
| 228 } | 228 } |
| 229 '''); | 229 '''); |
| 230 await assertHasFix( | 230 await assertHasFix( |
| 231 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 231 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 232 ''' | 232 ''' |
| 233 class Test { | 233 class Test { |
| 234 final int a; | 234 final int a; |
| 235 final int b; | 235 final int b; |
| 236 final int c; | 236 final int c; |
| 237 Test(this.a, this.b, this.c); | 237 Test(this.a, this.b, this.c); |
| 238 } | 238 } |
| 239 '''); | 239 '''); |
| 240 } | 240 } |
| 241 | 241 |
| 242 test_addFieldFormalParameters_noRequiredParameter() async { | 242 test_addFieldFormalParameters_noRequiredParameter() async { |
| 243 resolveTestUnit(''' | 243 await resolveTestUnit(''' |
| 244 class Test { | 244 class Test { |
| 245 final int a; | 245 final int a; |
| 246 final int b; | 246 final int b; |
| 247 final int c; | 247 final int c; |
| 248 Test([this.c]); | 248 Test([this.c]); |
| 249 } | 249 } |
| 250 '''); | 250 '''); |
| 251 await assertHasFix( | 251 await assertHasFix( |
| 252 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 252 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 253 ''' | 253 ''' |
| 254 class Test { | 254 class Test { |
| 255 final int a; | 255 final int a; |
| 256 final int b; | 256 final int b; |
| 257 final int c; | 257 final int c; |
| 258 Test(this.a, this.b, [this.c]); | 258 Test(this.a, this.b, [this.c]); |
| 259 } | 259 } |
| 260 '''); | 260 '''); |
| 261 } | 261 } |
| 262 | 262 |
| 263 test_addMissingParameter_function_positional_hasNamed() async { | 263 test_addMissingParameter_function_positional_hasNamed() async { |
| 264 resolveTestUnit(''' | 264 await resolveTestUnit(''' |
| 265 test({int a}) {} | 265 test({int a}) {} |
| 266 main() { | 266 main() { |
| 267 test(1); | 267 test(1); |
| 268 } | 268 } |
| 269 '''); | 269 '''); |
| 270 await assertNoFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL); | 270 await assertNoFix(DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL); |
| 271 } | 271 } |
| 272 | 272 |
| 273 test_addMissingParameter_function_positional_hasZero() async { | 273 test_addMissingParameter_function_positional_hasZero() async { |
| 274 resolveTestUnit(''' | 274 await resolveTestUnit(''' |
| 275 test() {} | 275 test() {} |
| 276 main() { | 276 main() { |
| 277 test(1); | 277 test(1); |
| 278 } | 278 } |
| 279 '''); | 279 '''); |
| 280 await assertHasFix( | 280 await assertHasFix( |
| 281 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | 281 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, |
| 282 ''' | 282 ''' |
| 283 test([int i]) {} | 283 test([int i]) {} |
| 284 main() { | 284 main() { |
| 285 test(1); | 285 test(1); |
| 286 } | 286 } |
| 287 '''); | 287 '''); |
| 288 } | 288 } |
| 289 | 289 |
| 290 test_addMissingParameter_function_required_hasNamed() async { | 290 test_addMissingParameter_function_required_hasNamed() async { |
| 291 resolveTestUnit(''' | 291 await resolveTestUnit(''' |
| 292 test({int a}) {} | 292 test({int a}) {} |
| 293 main() { | 293 main() { |
| 294 test(1); | 294 test(1); |
| 295 } | 295 } |
| 296 '''); | 296 '''); |
| 297 await assertHasFix( | 297 await assertHasFix( |
| 298 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 298 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 299 ''' | 299 ''' |
| 300 test(int i, {int a}) {} | 300 test(int i, {int a}) {} |
| 301 main() { | 301 main() { |
| 302 test(1); | 302 test(1); |
| 303 } | 303 } |
| 304 '''); | 304 '''); |
| 305 } | 305 } |
| 306 | 306 |
| 307 test_addMissingParameter_function_required_hasOne() async { | 307 test_addMissingParameter_function_required_hasOne() async { |
| 308 resolveTestUnit(''' | 308 await resolveTestUnit(''' |
| 309 test(int a) {} | 309 test(int a) {} |
| 310 main() { | 310 main() { |
| 311 test(1, 2.0); | 311 test(1, 2.0); |
| 312 } | 312 } |
| 313 '''); | 313 '''); |
| 314 await assertHasFix( | 314 await assertHasFix( |
| 315 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 315 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 316 ''' | 316 ''' |
| 317 test(int a, double d) {} | 317 test(int a, double d) {} |
| 318 main() { | 318 main() { |
| 319 test(1, 2.0); | 319 test(1, 2.0); |
| 320 } | 320 } |
| 321 '''); | 321 '''); |
| 322 } | 322 } |
| 323 | 323 |
| 324 test_addMissingParameter_function_required_hasZero() async { | 324 test_addMissingParameter_function_required_hasZero() async { |
| 325 resolveTestUnit(''' | 325 await resolveTestUnit(''' |
| 326 test() {} | 326 test() {} |
| 327 main() { | 327 main() { |
| 328 test(1); | 328 test(1); |
| 329 } | 329 } |
| 330 '''); | 330 '''); |
| 331 await assertHasFix( | 331 await assertHasFix( |
| 332 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 332 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 333 ''' | 333 ''' |
| 334 test(int i) {} | 334 test(int i) {} |
| 335 main() { | 335 main() { |
| 336 test(1); | 336 test(1); |
| 337 } | 337 } |
| 338 '''); | 338 '''); |
| 339 } | 339 } |
| 340 | 340 |
| 341 test_addMissingParameter_method_positional_hasOne() async { | 341 test_addMissingParameter_method_positional_hasOne() async { |
| 342 resolveTestUnit(''' | 342 await resolveTestUnit(''' |
| 343 class A { | 343 class A { |
| 344 test(int a) {} | 344 test(int a) {} |
| 345 main() { | 345 main() { |
| 346 test(1, 2.0); | 346 test(1, 2.0); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 '''); | 349 '''); |
| 350 await assertHasFix( | 350 await assertHasFix( |
| 351 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | 351 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, |
| 352 ''' | 352 ''' |
| 353 class A { | 353 class A { |
| 354 test(int a, [double d]) {} | 354 test(int a, [double d]) {} |
| 355 main() { | 355 main() { |
| 356 test(1, 2.0); | 356 test(1, 2.0); |
| 357 } | 357 } |
| 358 } | 358 } |
| 359 '''); | 359 '''); |
| 360 } | 360 } |
| 361 | 361 |
| 362 test_addMissingParameter_method_required_hasOne() async { | 362 test_addMissingParameter_method_required_hasOne() async { |
| 363 resolveTestUnit(''' | 363 await resolveTestUnit(''' |
| 364 class A { | 364 class A { |
| 365 test(int a) {} | 365 test(int a) {} |
| 366 main() { | 366 main() { |
| 367 test(1, 2.0); | 367 test(1, 2.0); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 '''); | 370 '''); |
| 371 await assertHasFix( | 371 await assertHasFix( |
| 372 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 372 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 373 ''' | 373 ''' |
| 374 class A { | 374 class A { |
| 375 test(int a, double d) {} | 375 test(int a, double d) {} |
| 376 main() { | 376 main() { |
| 377 test(1, 2.0); | 377 test(1, 2.0); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 '''); | 380 '''); |
| 381 } | 381 } |
| 382 | 382 |
| 383 test_addMissingParameter_method_required_hasZero() async { | 383 test_addMissingParameter_method_required_hasZero() async { |
| 384 resolveTestUnit(''' | 384 await resolveTestUnit(''' |
| 385 class A { | 385 class A { |
| 386 test() {} | 386 test() {} |
| 387 main() { | 387 main() { |
| 388 test(1); | 388 test(1); |
| 389 } | 389 } |
| 390 } | 390 } |
| 391 '''); | 391 '''); |
| 392 await assertHasFix( | 392 await assertHasFix( |
| 393 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 393 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 394 ''' | 394 ''' |
| 395 class A { | 395 class A { |
| 396 test(int i) {} | 396 test(int i) {} |
| 397 main() { | 397 main() { |
| 398 test(1); | 398 test(1); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 '''); | 401 '''); |
| 402 } | 402 } |
| 403 | 403 |
| 404 test_addPartOfDirective() async { | 404 test_addPartOfDirective() async { |
| 405 String partCode = r''' | 405 String partCode = r''' |
| 406 // Comment first. | 406 // Comment first. |
| 407 // Comment second. | 407 // Comment second. |
| 408 | 408 |
| 409 class A {} | 409 class A {} |
| 410 '''; | 410 '''; |
| 411 addSource('/part.dart', partCode); | 411 addSource('/part.dart', partCode); |
| 412 resolveTestUnit(''' | 412 await resolveTestUnit(''' |
| 413 library my.lib; | 413 library my.lib; |
| 414 part 'part.dart'; | 414 part 'part.dart'; |
| 415 '''); | 415 '''); |
| 416 _performAnalysis(); | 416 _performAnalysis(); |
| 417 AnalysisError error = _findErrorToFix(); | 417 AnalysisError error = _findErrorToFix(); |
| 418 fix = await _assertHasFix(DartFixKind.ADD_PART_OF, error); | 418 fix = await _assertHasFix(DartFixKind.ADD_PART_OF, error); |
| 419 change = fix.change; | 419 change = fix.change; |
| 420 // apply to "file" | 420 // apply to "file" |
| 421 List<SourceFileEdit> fileEdits = change.edits; | 421 List<SourceFileEdit> fileEdits = change.edits; |
| 422 expect(fileEdits, hasLength(1)); | 422 expect(fileEdits, hasLength(1)); |
| 423 SourceFileEdit fileEdit = change.edits[0]; | 423 SourceFileEdit fileEdit = change.edits[0]; |
| 424 expect(fileEdit.file, '/part.dart'); | 424 expect(fileEdit.file, '/part.dart'); |
| 425 expect( | 425 expect( |
| 426 SourceEdit.applySequence(partCode, fileEdit.edits), | 426 SourceEdit.applySequence(partCode, fileEdit.edits), |
| 427 r''' | 427 r''' |
| 428 // Comment first. | 428 // Comment first. |
| 429 // Comment second. | 429 // Comment second. |
| 430 | 430 |
| 431 part of my.lib; | 431 part of my.lib; |
| 432 | 432 |
| 433 class A {} | 433 class A {} |
| 434 '''); | 434 '''); |
| 435 } | 435 } |
| 436 | 436 |
| 437 test_addSync_asyncFor() async { | 437 test_addSync_asyncFor() async { |
| 438 resolveTestUnit(''' | 438 await resolveTestUnit(''' |
| 439 import 'dart:async'; | 439 import 'dart:async'; |
| 440 void main(Stream<String> names) { | 440 void main(Stream<String> names) { |
| 441 await for (String name in names) { | 441 await for (String name in names) { |
| 442 print(name); | 442 print(name); |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 '''); | 445 '''); |
| 446 await assertHasFix( | 446 await assertHasFix( |
| 447 DartFixKind.ADD_ASYNC, | 447 DartFixKind.ADD_ASYNC, |
| 448 ''' | 448 ''' |
| 449 import 'dart:async'; | 449 import 'dart:async'; |
| 450 Future main(Stream<String> names) async { | 450 Future main(Stream<String> names) async { |
| 451 await for (String name in names) { | 451 await for (String name in names) { |
| 452 print(name); | 452 print(name); |
| 453 } | 453 } |
| 454 } | 454 } |
| 455 '''); | 455 '''); |
| 456 } | 456 } |
| 457 | 457 |
| 458 test_addSync_BAD_nullFunctionBody() async { | 458 test_addSync_BAD_nullFunctionBody() async { |
| 459 resolveTestUnit(''' | 459 await resolveTestUnit(''' |
| 460 var F = await; | 460 var F = await; |
| 461 '''); | 461 '''); |
| 462 await assertNoFix(DartFixKind.ADD_ASYNC); | 462 await assertNoFix(DartFixKind.ADD_ASYNC); |
| 463 } | 463 } |
| 464 | 464 |
| 465 test_addSync_blockFunctionBody() async { | 465 test_addSync_blockFunctionBody() async { |
| 466 resolveTestUnit(''' | 466 await resolveTestUnit(''' |
| 467 foo() {} | 467 foo() {} |
| 468 main() { | 468 main() { |
| 469 await foo(); | 469 await foo(); |
| 470 } | 470 } |
| 471 '''); | 471 '''); |
| 472 List<AnalysisError> errors = context.computeErrors(testSource); | 472 List<AnalysisError> errors = context.computeErrors(testSource); |
| 473 expect(errors, hasLength(2)); | 473 expect(errors, hasLength(2)); |
| 474 errors.sort((a, b) => a.message.compareTo(b.message)); | 474 errors.sort((a, b) => a.message.compareTo(b.message)); |
| 475 // No fix for ";". | 475 // No fix for ";". |
| 476 { | 476 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 501 await foo(); | 501 await foo(); |
| 502 } | 502 } |
| 503 '''); | 503 '''); |
| 504 } | 504 } |
| 505 } | 505 } |
| 506 | 506 |
| 507 test_addSync_expressionFunctionBody() async { | 507 test_addSync_expressionFunctionBody() async { |
| 508 errorFilter = (AnalysisError error) { | 508 errorFilter = (AnalysisError error) { |
| 509 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 509 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
| 510 }; | 510 }; |
| 511 resolveTestUnit(''' | 511 await resolveTestUnit(''' |
| 512 foo() {} | 512 foo() {} |
| 513 main() => await foo(); | 513 main() => await foo(); |
| 514 '''); | 514 '''); |
| 515 await assertHasFix( | 515 await assertHasFix( |
| 516 DartFixKind.ADD_ASYNC, | 516 DartFixKind.ADD_ASYNC, |
| 517 ''' | 517 ''' |
| 518 foo() {} | 518 foo() {} |
| 519 main() async => await foo(); | 519 main() async => await foo(); |
| 520 '''); | 520 '''); |
| 521 } | 521 } |
| 522 | 522 |
| 523 test_addSync_returnFuture() async { | 523 test_addSync_returnFuture() async { |
| 524 errorFilter = (AnalysisError error) { | 524 errorFilter = (AnalysisError error) { |
| 525 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 525 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
| 526 }; | 526 }; |
| 527 resolveTestUnit(''' | 527 await resolveTestUnit(''' |
| 528 foo() {} | 528 foo() {} |
| 529 int main() { | 529 int main() { |
| 530 await foo(); | 530 await foo(); |
| 531 return 42; | 531 return 42; |
| 532 } | 532 } |
| 533 '''); | 533 '''); |
| 534 await assertHasFix( | 534 await assertHasFix( |
| 535 DartFixKind.ADD_ASYNC, | 535 DartFixKind.ADD_ASYNC, |
| 536 ''' | 536 ''' |
| 537 import 'dart:async'; | 537 import 'dart:async'; |
| 538 | 538 |
| 539 foo() {} | 539 foo() {} |
| 540 Future<int> main() async { | 540 Future<int> main() async { |
| 541 await foo(); | 541 await foo(); |
| 542 return 42; | 542 return 42; |
| 543 } | 543 } |
| 544 '''); | 544 '''); |
| 545 } | 545 } |
| 546 | 546 |
| 547 test_addSync_returnFuture_alreadyFuture() async { | 547 test_addSync_returnFuture_alreadyFuture() async { |
| 548 errorFilter = (AnalysisError error) { | 548 errorFilter = (AnalysisError error) { |
| 549 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 549 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
| 550 }; | 550 }; |
| 551 resolveTestUnit(''' | 551 await resolveTestUnit(''' |
| 552 import 'dart:async'; | 552 import 'dart:async'; |
| 553 foo() {} | 553 foo() {} |
| 554 Future<int> main() { | 554 Future<int> main() { |
| 555 await foo(); | 555 await foo(); |
| 556 return 42; | 556 return 42; |
| 557 } | 557 } |
| 558 '''); | 558 '''); |
| 559 await assertHasFix( | 559 await assertHasFix( |
| 560 DartFixKind.ADD_ASYNC, | 560 DartFixKind.ADD_ASYNC, |
| 561 ''' | 561 ''' |
| 562 import 'dart:async'; | 562 import 'dart:async'; |
| 563 foo() {} | 563 foo() {} |
| 564 Future<int> main() async { | 564 Future<int> main() async { |
| 565 await foo(); | 565 await foo(); |
| 566 return 42; | 566 return 42; |
| 567 } | 567 } |
| 568 '''); | 568 '''); |
| 569 } | 569 } |
| 570 | 570 |
| 571 test_addSync_returnFuture_dynamic() async { | 571 test_addSync_returnFuture_dynamic() async { |
| 572 errorFilter = (AnalysisError error) { | 572 errorFilter = (AnalysisError error) { |
| 573 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 573 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
| 574 }; | 574 }; |
| 575 resolveTestUnit(''' | 575 await resolveTestUnit(''' |
| 576 foo() {} | 576 foo() {} |
| 577 dynamic main() { | 577 dynamic main() { |
| 578 await foo(); | 578 await foo(); |
| 579 return 42; | 579 return 42; |
| 580 } | 580 } |
| 581 '''); | 581 '''); |
| 582 await assertHasFix( | 582 await assertHasFix( |
| 583 DartFixKind.ADD_ASYNC, | 583 DartFixKind.ADD_ASYNC, |
| 584 ''' | 584 ''' |
| 585 foo() {} | 585 foo() {} |
| 586 dynamic main() async { | 586 dynamic main() async { |
| 587 await foo(); | 587 await foo(); |
| 588 return 42; | 588 return 42; |
| 589 } | 589 } |
| 590 '''); | 590 '''); |
| 591 } | 591 } |
| 592 | 592 |
| 593 test_addSync_returnFuture_noType() async { | 593 test_addSync_returnFuture_noType() async { |
| 594 errorFilter = (AnalysisError error) { | 594 errorFilter = (AnalysisError error) { |
| 595 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; | 595 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER_AWAIT; |
| 596 }; | 596 }; |
| 597 resolveTestUnit(''' | 597 await resolveTestUnit(''' |
| 598 foo() {} | 598 foo() {} |
| 599 main() { | 599 main() { |
| 600 await foo(); | 600 await foo(); |
| 601 return 42; | 601 return 42; |
| 602 } | 602 } |
| 603 '''); | 603 '''); |
| 604 await assertHasFix( | 604 await assertHasFix( |
| 605 DartFixKind.ADD_ASYNC, | 605 DartFixKind.ADD_ASYNC, |
| 606 ''' | 606 ''' |
| 607 foo() {} | 607 foo() {} |
| 608 main() async { | 608 main() async { |
| 609 await foo(); | 609 await foo(); |
| 610 return 42; | 610 return 42; |
| 611 } | 611 } |
| 612 '''); | 612 '''); |
| 613 } | 613 } |
| 614 | 614 |
| 615 test_boolean() async { | 615 test_boolean() async { |
| 616 resolveTestUnit(''' | 616 await resolveTestUnit(''' |
| 617 main() { | 617 main() { |
| 618 boolean v; | 618 boolean v; |
| 619 } | 619 } |
| 620 '''); | 620 '''); |
| 621 await assertHasFix( | 621 await assertHasFix( |
| 622 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, | 622 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, |
| 623 ''' | 623 ''' |
| 624 main() { | 624 main() { |
| 625 bool v; | 625 bool v; |
| 626 } | 626 } |
| 627 '''); | 627 '''); |
| 628 } | 628 } |
| 629 | 629 |
| 630 test_canBeNullAfterNullAware_chain() async { | 630 test_canBeNullAfterNullAware_chain() async { |
| 631 resolveTestUnit(''' | 631 await resolveTestUnit(''' |
| 632 main(x) { | 632 main(x) { |
| 633 x?.a.b.c; | 633 x?.a.b.c; |
| 634 } | 634 } |
| 635 '''); | 635 '''); |
| 636 await assertHasFix( | 636 await assertHasFix( |
| 637 DartFixKind.REPLACE_WITH_NULL_AWARE, | 637 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 638 ''' | 638 ''' |
| 639 main(x) { | 639 main(x) { |
| 640 x?.a?.b?.c; | 640 x?.a?.b?.c; |
| 641 } | 641 } |
| 642 '''); | 642 '''); |
| 643 } | 643 } |
| 644 | 644 |
| 645 test_canBeNullAfterNullAware_methodInvocation() async { | 645 test_canBeNullAfterNullAware_methodInvocation() async { |
| 646 resolveTestUnit(''' | 646 await resolveTestUnit(''' |
| 647 main(x) { | 647 main(x) { |
| 648 x?.a.b(); | 648 x?.a.b(); |
| 649 } | 649 } |
| 650 '''); | 650 '''); |
| 651 await assertHasFix( | 651 await assertHasFix( |
| 652 DartFixKind.REPLACE_WITH_NULL_AWARE, | 652 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 653 ''' | 653 ''' |
| 654 main(x) { | 654 main(x) { |
| 655 x?.a?.b(); | 655 x?.a?.b(); |
| 656 } | 656 } |
| 657 '''); | 657 '''); |
| 658 } | 658 } |
| 659 | 659 |
| 660 test_canBeNullAfterNullAware_propertyAccess() async { | 660 test_canBeNullAfterNullAware_propertyAccess() async { |
| 661 resolveTestUnit(''' | 661 await resolveTestUnit(''' |
| 662 main(x) { | 662 main(x) { |
| 663 x?.a().b; | 663 x?.a().b; |
| 664 } | 664 } |
| 665 '''); | 665 '''); |
| 666 await assertHasFix( | 666 await assertHasFix( |
| 667 DartFixKind.REPLACE_WITH_NULL_AWARE, | 667 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 668 ''' | 668 ''' |
| 669 main(x) { | 669 main(x) { |
| 670 x?.a()?.b; | 670 x?.a()?.b; |
| 671 } | 671 } |
| 672 '''); | 672 '''); |
| 673 } | 673 } |
| 674 | 674 |
| 675 test_changeToStaticAccess_method() async { | 675 test_changeToStaticAccess_method() async { |
| 676 resolveTestUnit(''' | 676 await resolveTestUnit(''' |
| 677 class A { | 677 class A { |
| 678 static foo() {} | 678 static foo() {} |
| 679 } | 679 } |
| 680 main(A a) { | 680 main(A a) { |
| 681 a.foo(); | 681 a.foo(); |
| 682 } | 682 } |
| 683 '''); | 683 '''); |
| 684 await assertHasFix( | 684 await assertHasFix( |
| 685 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 685 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 686 ''' | 686 ''' |
| (...skipping 15 matching lines...) Expand all Loading... |
| 702 static foo() {} | 702 static foo() {} |
| 703 } | 703 } |
| 704 '''); | 704 '''); |
| 705 addSource( | 705 addSource( |
| 706 '/libB.dart', | 706 '/libB.dart', |
| 707 r''' | 707 r''' |
| 708 library libB; | 708 library libB; |
| 709 import 'libA.dart'; | 709 import 'libA.dart'; |
| 710 class B extends A {} | 710 class B extends A {} |
| 711 '''); | 711 '''); |
| 712 resolveTestUnit(''' | 712 await resolveTestUnit(''' |
| 713 import 'libB.dart'; | 713 import 'libB.dart'; |
| 714 main(B b) { | 714 main(B b) { |
| 715 b.foo(); | 715 b.foo(); |
| 716 } | 716 } |
| 717 '''); | 717 '''); |
| 718 await assertHasFix( | 718 await assertHasFix( |
| 719 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 719 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 720 ''' | 720 ''' |
| 721 import 'libA.dart'; | 721 import 'libA.dart'; |
| 722 import 'libB.dart'; | 722 import 'libB.dart'; |
| 723 main(B b) { | 723 main(B b) { |
| 724 A.foo(); | 724 A.foo(); |
| 725 } | 725 } |
| 726 '''); | 726 '''); |
| 727 } | 727 } |
| 728 | 728 |
| 729 test_changeToStaticAccess_method_prefixLibrary() async { | 729 test_changeToStaticAccess_method_prefixLibrary() async { |
| 730 resolveTestUnit(''' | 730 await resolveTestUnit(''' |
| 731 import 'dart:async' as pref; | 731 import 'dart:async' as pref; |
| 732 main(pref.Future f) { | 732 main(pref.Future f) { |
| 733 f.wait([]); | 733 f.wait([]); |
| 734 } | 734 } |
| 735 '''); | 735 '''); |
| 736 await assertHasFix( | 736 await assertHasFix( |
| 737 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 737 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 738 ''' | 738 ''' |
| 739 import 'dart:async' as pref; | 739 import 'dart:async' as pref; |
| 740 main(pref.Future f) { | 740 main(pref.Future f) { |
| 741 pref.Future.wait([]); | 741 pref.Future.wait([]); |
| 742 } | 742 } |
| 743 '''); | 743 '''); |
| 744 } | 744 } |
| 745 | 745 |
| 746 test_changeToStaticAccess_property() async { | 746 test_changeToStaticAccess_property() async { |
| 747 resolveTestUnit(''' | 747 await resolveTestUnit(''' |
| 748 class A { | 748 class A { |
| 749 static get foo => 42; | 749 static get foo => 42; |
| 750 } | 750 } |
| 751 main(A a) { | 751 main(A a) { |
| 752 a.foo; | 752 a.foo; |
| 753 } | 753 } |
| 754 '''); | 754 '''); |
| 755 await assertHasFix( | 755 await assertHasFix( |
| 756 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 756 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 757 ''' | 757 ''' |
| (...skipping 15 matching lines...) Expand all Loading... |
| 773 static get foo => null; | 773 static get foo => null; |
| 774 } | 774 } |
| 775 '''); | 775 '''); |
| 776 addSource( | 776 addSource( |
| 777 '/libB.dart', | 777 '/libB.dart', |
| 778 r''' | 778 r''' |
| 779 library libB; | 779 library libB; |
| 780 import 'libA.dart'; | 780 import 'libA.dart'; |
| 781 class B extends A {} | 781 class B extends A {} |
| 782 '''); | 782 '''); |
| 783 resolveTestUnit(''' | 783 await resolveTestUnit(''' |
| 784 import 'libB.dart'; | 784 import 'libB.dart'; |
| 785 main(B b) { | 785 main(B b) { |
| 786 b.foo; | 786 b.foo; |
| 787 } | 787 } |
| 788 '''); | 788 '''); |
| 789 await assertHasFix( | 789 await assertHasFix( |
| 790 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 790 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 791 ''' | 791 ''' |
| 792 import 'libA.dart'; | 792 import 'libA.dart'; |
| 793 import 'libB.dart'; | 793 import 'libB.dart'; |
| 794 main(B b) { | 794 main(B b) { |
| 795 A.foo; | 795 A.foo; |
| 796 } | 796 } |
| 797 '''); | 797 '''); |
| 798 } | 798 } |
| 799 | 799 |
| 800 test_changeTypeAnnotation_BAD_multipleVariables() async { | 800 test_changeTypeAnnotation_BAD_multipleVariables() async { |
| 801 resolveTestUnit(''' | 801 await resolveTestUnit(''' |
| 802 main() { | 802 main() { |
| 803 String a, b = 42; | 803 String a, b = 42; |
| 804 } | 804 } |
| 805 '''); | 805 '''); |
| 806 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); | 806 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); |
| 807 } | 807 } |
| 808 | 808 |
| 809 test_changeTypeAnnotation_BAD_notVariableDeclaration() async { | 809 test_changeTypeAnnotation_BAD_notVariableDeclaration() async { |
| 810 resolveTestUnit(''' | 810 await resolveTestUnit(''' |
| 811 main() { | 811 main() { |
| 812 String v; | 812 String v; |
| 813 v = 42; | 813 v = 42; |
| 814 } | 814 } |
| 815 '''); | 815 '''); |
| 816 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); | 816 await assertNoFix(DartFixKind.CHANGE_TYPE_ANNOTATION); |
| 817 } | 817 } |
| 818 | 818 |
| 819 test_changeTypeAnnotation_OK_generic() async { | 819 test_changeTypeAnnotation_OK_generic() async { |
| 820 resolveTestUnit(''' | 820 await resolveTestUnit(''' |
| 821 main() { | 821 main() { |
| 822 String v = <int>[]; | 822 String v = <int>[]; |
| 823 } | 823 } |
| 824 '''); | 824 '''); |
| 825 await assertHasFix( | 825 await assertHasFix( |
| 826 DartFixKind.CHANGE_TYPE_ANNOTATION, | 826 DartFixKind.CHANGE_TYPE_ANNOTATION, |
| 827 ''' | 827 ''' |
| 828 main() { | 828 main() { |
| 829 List<int> v = <int>[]; | 829 List<int> v = <int>[]; |
| 830 } | 830 } |
| 831 '''); | 831 '''); |
| 832 } | 832 } |
| 833 | 833 |
| 834 test_changeTypeAnnotation_OK_simple() async { | 834 test_changeTypeAnnotation_OK_simple() async { |
| 835 resolveTestUnit(''' | 835 await resolveTestUnit(''' |
| 836 main() { | 836 main() { |
| 837 String v = 'abc'.length; | 837 String v = 'abc'.length; |
| 838 } | 838 } |
| 839 '''); | 839 '''); |
| 840 await assertHasFix( | 840 await assertHasFix( |
| 841 DartFixKind.CHANGE_TYPE_ANNOTATION, | 841 DartFixKind.CHANGE_TYPE_ANNOTATION, |
| 842 ''' | 842 ''' |
| 843 main() { | 843 main() { |
| 844 int v = 'abc'.length; | 844 int v = 'abc'.length; |
| 845 } | 845 } |
| 846 '''); | 846 '''); |
| 847 } | 847 } |
| 848 | 848 |
| 849 test_createClass() async { | 849 test_createClass() async { |
| 850 resolveTestUnit(''' | 850 await resolveTestUnit(''' |
| 851 main() { | 851 main() { |
| 852 Test v = null; | 852 Test v = null; |
| 853 } | 853 } |
| 854 '''); | 854 '''); |
| 855 await assertHasFix( | 855 await assertHasFix( |
| 856 DartFixKind.CREATE_CLASS, | 856 DartFixKind.CREATE_CLASS, |
| 857 ''' | 857 ''' |
| 858 main() { | 858 main() { |
| 859 Test v = null; | 859 Test v = null; |
| 860 } | 860 } |
| 861 | 861 |
| 862 class Test { | 862 class Test { |
| 863 } | 863 } |
| 864 '''); | 864 '''); |
| 865 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 865 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 866 } | 866 } |
| 867 | 867 |
| 868 test_createClass_BAD_hasUnresolvedPrefix() async { | 868 test_createClass_BAD_hasUnresolvedPrefix() async { |
| 869 resolveTestUnit(''' | 869 await resolveTestUnit(''' |
| 870 main() { | 870 main() { |
| 871 prefix.Test v = null; | 871 prefix.Test v = null; |
| 872 } | 872 } |
| 873 '''); | 873 '''); |
| 874 await assertNoFix(DartFixKind.CREATE_CLASS); | 874 await assertNoFix(DartFixKind.CREATE_CLASS); |
| 875 } | 875 } |
| 876 | 876 |
| 877 test_createClass_inLibraryOfPrefix() async { | 877 test_createClass_inLibraryOfPrefix() async { |
| 878 String libCode = r''' | 878 String libCode = r''' |
| 879 library my.lib; | 879 library my.lib; |
| 880 | 880 |
| 881 class A {} | 881 class A {} |
| 882 '''; | 882 '''; |
| 883 addSource('/lib.dart', libCode); | 883 addSource('/lib.dart', libCode); |
| 884 resolveTestUnit(''' | 884 await resolveTestUnit(''' |
| 885 import 'lib.dart' as lib; | 885 import 'lib.dart' as lib; |
| 886 | 886 |
| 887 main() { | 887 main() { |
| 888 lib.A a = null; | 888 lib.A a = null; |
| 889 lib.Test t = null; | 889 lib.Test t = null; |
| 890 } | 890 } |
| 891 '''); | 891 '''); |
| 892 AnalysisError error = _findErrorToFix(); | 892 AnalysisError error = _findErrorToFix(); |
| 893 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); | 893 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); |
| 894 change = fix.change; | 894 change = fix.change; |
| 895 // apply to "lib.dart" | 895 // apply to "lib.dart" |
| 896 List<SourceFileEdit> fileEdits = change.edits; | 896 List<SourceFileEdit> fileEdits = change.edits; |
| 897 expect(fileEdits, hasLength(1)); | 897 expect(fileEdits, hasLength(1)); |
| 898 SourceFileEdit fileEdit = change.edits[0]; | 898 SourceFileEdit fileEdit = change.edits[0]; |
| 899 expect(fileEdit.file, '/lib.dart'); | 899 expect(fileEdit.file, '/lib.dart'); |
| 900 expect( | 900 expect( |
| 901 SourceEdit.applySequence(libCode, fileEdit.edits), | 901 SourceEdit.applySequence(libCode, fileEdit.edits), |
| 902 r''' | 902 r''' |
| 903 library my.lib; | 903 library my.lib; |
| 904 | 904 |
| 905 class A {} | 905 class A {} |
| 906 | 906 |
| 907 class Test { | 907 class Test { |
| 908 } | 908 } |
| 909 '''); | 909 '''); |
| 910 expect(change.linkedEditGroups, isEmpty); | 910 expect(change.linkedEditGroups, isEmpty); |
| 911 } | 911 } |
| 912 | 912 |
| 913 test_createClass_innerLocalFunction() async { | 913 test_createClass_innerLocalFunction() async { |
| 914 resolveTestUnit(''' | 914 await resolveTestUnit(''' |
| 915 f() { | 915 f() { |
| 916 g() { | 916 g() { |
| 917 Test v = null; | 917 Test v = null; |
| 918 } | 918 } |
| 919 } | 919 } |
| 920 '''); | 920 '''); |
| 921 await assertHasFix( | 921 await assertHasFix( |
| 922 DartFixKind.CREATE_CLASS, | 922 DartFixKind.CREATE_CLASS, |
| 923 ''' | 923 ''' |
| 924 f() { | 924 f() { |
| 925 g() { | 925 g() { |
| 926 Test v = null; | 926 Test v = null; |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 | 929 |
| 930 class Test { | 930 class Test { |
| 931 } | 931 } |
| 932 '''); | 932 '''); |
| 933 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 933 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 934 } | 934 } |
| 935 | 935 |
| 936 test_createClass_itemOfList() async { | 936 test_createClass_itemOfList() async { |
| 937 resolveTestUnit(''' | 937 await resolveTestUnit(''' |
| 938 main() { | 938 main() { |
| 939 var a = [Test]; | 939 var a = [Test]; |
| 940 } | 940 } |
| 941 '''); | 941 '''); |
| 942 await assertHasFix( | 942 await assertHasFix( |
| 943 DartFixKind.CREATE_CLASS, | 943 DartFixKind.CREATE_CLASS, |
| 944 ''' | 944 ''' |
| 945 main() { | 945 main() { |
| 946 var a = [Test]; | 946 var a = [Test]; |
| 947 } | 947 } |
| 948 | 948 |
| 949 class Test { | 949 class Test { |
| 950 } | 950 } |
| 951 '''); | 951 '''); |
| 952 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); | 952 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); |
| 953 } | 953 } |
| 954 | 954 |
| 955 test_createClass_itemOfList_inAnnotation() async { | 955 test_createClass_itemOfList_inAnnotation() async { |
| 956 errorFilter = (AnalysisError error) { | 956 errorFilter = (AnalysisError error) { |
| 957 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 957 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 958 }; | 958 }; |
| 959 resolveTestUnit(''' | 959 await resolveTestUnit(''' |
| 960 class MyAnnotation { | 960 class MyAnnotation { |
| 961 const MyAnnotation(a, b); | 961 const MyAnnotation(a, b); |
| 962 } | 962 } |
| 963 @MyAnnotation(int, const [Test]) | 963 @MyAnnotation(int, const [Test]) |
| 964 main() {} | 964 main() {} |
| 965 '''); | 965 '''); |
| 966 await assertHasFix( | 966 await assertHasFix( |
| 967 DartFixKind.CREATE_CLASS, | 967 DartFixKind.CREATE_CLASS, |
| 968 ''' | 968 ''' |
| 969 class MyAnnotation { | 969 class MyAnnotation { |
| 970 const MyAnnotation(a, b); | 970 const MyAnnotation(a, b); |
| 971 } | 971 } |
| 972 @MyAnnotation(int, const [Test]) | 972 @MyAnnotation(int, const [Test]) |
| 973 main() {} | 973 main() {} |
| 974 | 974 |
| 975 class Test { | 975 class Test { |
| 976 } | 976 } |
| 977 '''); | 977 '''); |
| 978 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); | 978 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); |
| 979 } | 979 } |
| 980 | 980 |
| 981 test_createConstructor_forFinalFields() async { | 981 test_createConstructor_forFinalFields() async { |
| 982 errorFilter = (AnalysisError error) { | 982 errorFilter = (AnalysisError error) { |
| 983 return error.message.contains("'a'"); | 983 return error.message.contains("'a'"); |
| 984 }; | 984 }; |
| 985 resolveTestUnit(''' | 985 await resolveTestUnit(''' |
| 986 class Test { | 986 class Test { |
| 987 final int a; | 987 final int a; |
| 988 final int b = 2; | 988 final int b = 2; |
| 989 final int c; | 989 final int c; |
| 990 } | 990 } |
| 991 '''); | 991 '''); |
| 992 await assertHasFix( | 992 await assertHasFix( |
| 993 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, | 993 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, |
| 994 ''' | 994 ''' |
| 995 class Test { | 995 class Test { |
| 996 final int a; | 996 final int a; |
| 997 final int b = 2; | 997 final int b = 2; |
| 998 final int c; | 998 final int c; |
| 999 | 999 |
| 1000 Test(this.a, this.c); | 1000 Test(this.a, this.c); |
| 1001 } | 1001 } |
| 1002 '''); | 1002 '''); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 test_createConstructor_insteadOfSyntheticDefault() async { | 1005 test_createConstructor_insteadOfSyntheticDefault() async { |
| 1006 resolveTestUnit(''' | 1006 await resolveTestUnit(''' |
| 1007 class A { | 1007 class A { |
| 1008 int field; | 1008 int field; |
| 1009 | 1009 |
| 1010 method() {} | 1010 method() {} |
| 1011 } | 1011 } |
| 1012 main() { | 1012 main() { |
| 1013 new A(1, 2.0); | 1013 new A(1, 2.0); |
| 1014 } | 1014 } |
| 1015 '''); | 1015 '''); |
| 1016 await assertHasFix( | 1016 await assertHasFix( |
| 1017 DartFixKind.CREATE_CONSTRUCTOR, | 1017 DartFixKind.CREATE_CONSTRUCTOR, |
| 1018 ''' | 1018 ''' |
| 1019 class A { | 1019 class A { |
| 1020 int field; | 1020 int field; |
| 1021 | 1021 |
| 1022 A(int i, double d); | 1022 A(int i, double d); |
| 1023 | 1023 |
| 1024 method() {} | 1024 method() {} |
| 1025 } | 1025 } |
| 1026 main() { | 1026 main() { |
| 1027 new A(1, 2.0); | 1027 new A(1, 2.0); |
| 1028 } | 1028 } |
| 1029 '''); | 1029 '''); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 test_createConstructor_named() async { | 1032 test_createConstructor_named() async { |
| 1033 resolveTestUnit(''' | 1033 await resolveTestUnit(''' |
| 1034 class A { | 1034 class A { |
| 1035 method() {} | 1035 method() {} |
| 1036 } | 1036 } |
| 1037 main() { | 1037 main() { |
| 1038 new A.named(1, 2.0); | 1038 new A.named(1, 2.0); |
| 1039 } | 1039 } |
| 1040 '''); | 1040 '''); |
| 1041 await assertHasFix( | 1041 await assertHasFix( |
| 1042 DartFixKind.CREATE_CONSTRUCTOR, | 1042 DartFixKind.CREATE_CONSTRUCTOR, |
| 1043 ''' | 1043 ''' |
| 1044 class A { | 1044 class A { |
| 1045 A.named(int i, double d); | 1045 A.named(int i, double d); |
| 1046 | 1046 |
| 1047 method() {} | 1047 method() {} |
| 1048 } | 1048 } |
| 1049 main() { | 1049 main() { |
| 1050 new A.named(1, 2.0); | 1050 new A.named(1, 2.0); |
| 1051 } | 1051 } |
| 1052 '''); | 1052 '''); |
| 1053 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); | 1053 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); |
| 1054 } | 1054 } |
| 1055 | 1055 |
| 1056 test_createConstructor_named_emptyClassBody() async { | 1056 test_createConstructor_named_emptyClassBody() async { |
| 1057 resolveTestUnit(''' | 1057 await resolveTestUnit(''' |
| 1058 class A {} | 1058 class A {} |
| 1059 main() { | 1059 main() { |
| 1060 new A.named(1); | 1060 new A.named(1); |
| 1061 } | 1061 } |
| 1062 '''); | 1062 '''); |
| 1063 await assertHasFix( | 1063 await assertHasFix( |
| 1064 DartFixKind.CREATE_CONSTRUCTOR, | 1064 DartFixKind.CREATE_CONSTRUCTOR, |
| 1065 ''' | 1065 ''' |
| 1066 class A { | 1066 class A { |
| 1067 A.named(int i); | 1067 A.named(int i); |
| 1068 } | 1068 } |
| 1069 main() { | 1069 main() { |
| 1070 new A.named(1); | 1070 new A.named(1); |
| 1071 } | 1071 } |
| 1072 '''); | 1072 '''); |
| 1073 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); | 1073 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 test_createConstructorForFinalFields_inTopLevelMethod() async { | 1076 test_createConstructorForFinalFields_inTopLevelMethod() async { |
| 1077 resolveTestUnit(''' | 1077 await resolveTestUnit(''' |
| 1078 main() { | 1078 main() { |
| 1079 final int v; | 1079 final int v; |
| 1080 } | 1080 } |
| 1081 '''); | 1081 '''); |
| 1082 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); | 1082 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 test_createConstructorForFinalFields_topLevelField() async { | 1085 test_createConstructorForFinalFields_topLevelField() async { |
| 1086 resolveTestUnit(''' | 1086 await resolveTestUnit(''' |
| 1087 final int v; | 1087 final int v; |
| 1088 '''); | 1088 '''); |
| 1089 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); | 1089 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 test_createConstructorSuperExplicit() async { | 1092 test_createConstructorSuperExplicit() async { |
| 1093 resolveTestUnit(''' | 1093 await resolveTestUnit(''' |
| 1094 class A { | 1094 class A { |
| 1095 A(bool p1, int p2, double p3, String p4, {p5}); | 1095 A(bool p1, int p2, double p3, String p4, {p5}); |
| 1096 } | 1096 } |
| 1097 class B extends A { | 1097 class B extends A { |
| 1098 B() {} | 1098 B() {} |
| 1099 } | 1099 } |
| 1100 '''); | 1100 '''); |
| 1101 await assertHasFix( | 1101 await assertHasFix( |
| 1102 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 1102 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 1103 ''' | 1103 ''' |
| 1104 class A { | 1104 class A { |
| 1105 A(bool p1, int p2, double p3, String p4, {p5}); | 1105 A(bool p1, int p2, double p3, String p4, {p5}); |
| 1106 } | 1106 } |
| 1107 class B extends A { | 1107 class B extends A { |
| 1108 B() : super(false, 0, 0.0, '') {} | 1108 B() : super(false, 0, 0.0, '') {} |
| 1109 } | 1109 } |
| 1110 '''); | 1110 '''); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 test_createConstructorSuperExplicit_hasInitializers() async { | 1113 test_createConstructorSuperExplicit_hasInitializers() async { |
| 1114 resolveTestUnit(''' | 1114 await resolveTestUnit(''' |
| 1115 class A { | 1115 class A { |
| 1116 A(int p); | 1116 A(int p); |
| 1117 } | 1117 } |
| 1118 class B extends A { | 1118 class B extends A { |
| 1119 int field; | 1119 int field; |
| 1120 B() : field = 42 {} | 1120 B() : field = 42 {} |
| 1121 } | 1121 } |
| 1122 '''); | 1122 '''); |
| 1123 await assertHasFix( | 1123 await assertHasFix( |
| 1124 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 1124 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 1125 ''' | 1125 ''' |
| 1126 class A { | 1126 class A { |
| 1127 A(int p); | 1127 A(int p); |
| 1128 } | 1128 } |
| 1129 class B extends A { | 1129 class B extends A { |
| 1130 int field; | 1130 int field; |
| 1131 B() : field = 42, super(0) {} | 1131 B() : field = 42, super(0) {} |
| 1132 } | 1132 } |
| 1133 '''); | 1133 '''); |
| 1134 } | 1134 } |
| 1135 | 1135 |
| 1136 test_createConstructorSuperExplicit_named() async { | 1136 test_createConstructorSuperExplicit_named() async { |
| 1137 resolveTestUnit(''' | 1137 await resolveTestUnit(''' |
| 1138 class A { | 1138 class A { |
| 1139 A.named(int p); | 1139 A.named(int p); |
| 1140 } | 1140 } |
| 1141 class B extends A { | 1141 class B extends A { |
| 1142 B() {} | 1142 B() {} |
| 1143 } | 1143 } |
| 1144 '''); | 1144 '''); |
| 1145 await assertHasFix( | 1145 await assertHasFix( |
| 1146 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 1146 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 1147 ''' | 1147 ''' |
| 1148 class A { | 1148 class A { |
| 1149 A.named(int p); | 1149 A.named(int p); |
| 1150 } | 1150 } |
| 1151 class B extends A { | 1151 class B extends A { |
| 1152 B() : super.named(0) {} | 1152 B() : super.named(0) {} |
| 1153 } | 1153 } |
| 1154 '''); | 1154 '''); |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 test_createConstructorSuperExplicit_named_private() async { | 1157 test_createConstructorSuperExplicit_named_private() async { |
| 1158 resolveTestUnit(''' | 1158 await resolveTestUnit(''' |
| 1159 class A { | 1159 class A { |
| 1160 A._named(int p); | 1160 A._named(int p); |
| 1161 } | 1161 } |
| 1162 class B extends A { | 1162 class B extends A { |
| 1163 B() {} | 1163 B() {} |
| 1164 } | 1164 } |
| 1165 '''); | 1165 '''); |
| 1166 await assertNoFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); | 1166 await assertNoFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 test_createConstructorSuperExplicit_typeArgument() async { | 1169 test_createConstructorSuperExplicit_typeArgument() async { |
| 1170 resolveTestUnit(''' | 1170 await resolveTestUnit(''' |
| 1171 class A<T> { | 1171 class A<T> { |
| 1172 A(T p); | 1172 A(T p); |
| 1173 } | 1173 } |
| 1174 class B extends A<int> { | 1174 class B extends A<int> { |
| 1175 B(); | 1175 B(); |
| 1176 } | 1176 } |
| 1177 '''); | 1177 '''); |
| 1178 await assertHasFix( | 1178 await assertHasFix( |
| 1179 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 1179 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 1180 ''' | 1180 ''' |
| 1181 class A<T> { | 1181 class A<T> { |
| 1182 A(T p); | 1182 A(T p); |
| 1183 } | 1183 } |
| 1184 class B extends A<int> { | 1184 class B extends A<int> { |
| 1185 B() : super(0); | 1185 B() : super(0); |
| 1186 } | 1186 } |
| 1187 '''); | 1187 '''); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 test_createConstructorSuperImplicit() async { | 1190 test_createConstructorSuperImplicit() async { |
| 1191 resolveTestUnit(''' | 1191 await resolveTestUnit(''' |
| 1192 class A { | 1192 class A { |
| 1193 A(p1, int p2, List<String> p3, [int p4]); | 1193 A(p1, int p2, List<String> p3, [int p4]); |
| 1194 } | 1194 } |
| 1195 class B extends A { | 1195 class B extends A { |
| 1196 int existingField; | 1196 int existingField; |
| 1197 | 1197 |
| 1198 void existingMethod() {} | 1198 void existingMethod() {} |
| 1199 } | 1199 } |
| 1200 '''); | 1200 '''); |
| 1201 await assertHasFix( | 1201 await assertHasFix( |
| 1202 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 1202 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 1203 ''' | 1203 ''' |
| 1204 class A { | 1204 class A { |
| 1205 A(p1, int p2, List<String> p3, [int p4]); | 1205 A(p1, int p2, List<String> p3, [int p4]); |
| 1206 } | 1206 } |
| 1207 class B extends A { | 1207 class B extends A { |
| 1208 int existingField; | 1208 int existingField; |
| 1209 | 1209 |
| 1210 B(p1, int p2, List<String> p3) : super(p1, p2, p3); | 1210 B(p1, int p2, List<String> p3) : super(p1, p2, p3); |
| 1211 | 1211 |
| 1212 void existingMethod() {} | 1212 void existingMethod() {} |
| 1213 } | 1213 } |
| 1214 '''); | 1214 '''); |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 test_createConstructorSuperImplicit_fieldInitializer() async { | 1217 test_createConstructorSuperImplicit_fieldInitializer() async { |
| 1218 resolveTestUnit(''' | 1218 await resolveTestUnit(''' |
| 1219 class A { | 1219 class A { |
| 1220 int _field; | 1220 int _field; |
| 1221 A(this._field); | 1221 A(this._field); |
| 1222 } | 1222 } |
| 1223 class B extends A { | 1223 class B extends A { |
| 1224 int existingField; | 1224 int existingField; |
| 1225 | 1225 |
| 1226 void existingMethod() {} | 1226 void existingMethod() {} |
| 1227 } | 1227 } |
| 1228 '''); | 1228 '''); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1252 '''); | 1252 '''); |
| 1253 addSource( | 1253 addSource( |
| 1254 '/libB.dart', | 1254 '/libB.dart', |
| 1255 r''' | 1255 r''' |
| 1256 library libB; | 1256 library libB; |
| 1257 import 'libA.dart'; | 1257 import 'libA.dart'; |
| 1258 class B { | 1258 class B { |
| 1259 B(A a); | 1259 B(A a); |
| 1260 } | 1260 } |
| 1261 '''); | 1261 '''); |
| 1262 resolveTestUnit(''' | 1262 await resolveTestUnit(''' |
| 1263 import 'libB.dart'; | 1263 import 'libB.dart'; |
| 1264 class C extends B { | 1264 class C extends B { |
| 1265 } | 1265 } |
| 1266 '''); | 1266 '''); |
| 1267 await assertHasFix( | 1267 await assertHasFix( |
| 1268 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 1268 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 1269 ''' | 1269 ''' |
| 1270 import 'libA.dart'; | 1270 import 'libA.dart'; |
| 1271 import 'libB.dart'; | 1271 import 'libB.dart'; |
| 1272 class C extends B { | 1272 class C extends B { |
| 1273 C(A a) : super(a); | 1273 C(A a) : super(a); |
| 1274 } | 1274 } |
| 1275 '''); | 1275 '''); |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 test_createConstructorSuperImplicit_named() async { | 1278 test_createConstructorSuperImplicit_named() async { |
| 1279 resolveTestUnit(''' | 1279 await resolveTestUnit(''' |
| 1280 class A { | 1280 class A { |
| 1281 A.named(p1, int p2); | 1281 A.named(p1, int p2); |
| 1282 } | 1282 } |
| 1283 class B extends A { | 1283 class B extends A { |
| 1284 int existingField; | 1284 int existingField; |
| 1285 | 1285 |
| 1286 void existingMethod() {} | 1286 void existingMethod() {} |
| 1287 } | 1287 } |
| 1288 '''); | 1288 '''); |
| 1289 await assertHasFix( | 1289 await assertHasFix( |
| 1290 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 1290 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 1291 ''' | 1291 ''' |
| 1292 class A { | 1292 class A { |
| 1293 A.named(p1, int p2); | 1293 A.named(p1, int p2); |
| 1294 } | 1294 } |
| 1295 class B extends A { | 1295 class B extends A { |
| 1296 int existingField; | 1296 int existingField; |
| 1297 | 1297 |
| 1298 B.named(p1, int p2) : super.named(p1, p2); | 1298 B.named(p1, int p2) : super.named(p1, p2); |
| 1299 | 1299 |
| 1300 void existingMethod() {} | 1300 void existingMethod() {} |
| 1301 } | 1301 } |
| 1302 '''); | 1302 '''); |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 test_createConstructorSuperImplicit_private() async { | 1305 test_createConstructorSuperImplicit_private() async { |
| 1306 resolveTestUnit(''' | 1306 await resolveTestUnit(''' |
| 1307 class A { | 1307 class A { |
| 1308 A._named(p); | 1308 A._named(p); |
| 1309 } | 1309 } |
| 1310 class B extends A { | 1310 class B extends A { |
| 1311 } | 1311 } |
| 1312 '''); | 1312 '''); |
| 1313 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER); | 1313 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER); |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 test_createConstructorSuperImplicit_typeArgument() async { | 1316 test_createConstructorSuperImplicit_typeArgument() async { |
| 1317 resolveTestUnit(''' | 1317 await resolveTestUnit(''' |
| 1318 class C<T> { | 1318 class C<T> { |
| 1319 final T x; | 1319 final T x; |
| 1320 C(this.x); | 1320 C(this.x); |
| 1321 } | 1321 } |
| 1322 class D extends C<int> { | 1322 class D extends C<int> { |
| 1323 }'''); | 1323 }'''); |
| 1324 await assertHasFix( | 1324 await assertHasFix( |
| 1325 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 1325 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 1326 ''' | 1326 ''' |
| 1327 class C<T> { | 1327 class C<T> { |
| 1328 final T x; | 1328 final T x; |
| 1329 C(this.x); | 1329 C(this.x); |
| 1330 } | 1330 } |
| 1331 class D extends C<int> { | 1331 class D extends C<int> { |
| 1332 D(int x) : super(x); | 1332 D(int x) : super(x); |
| 1333 }'''); | 1333 }'''); |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 test_createField_BAD_inEnum() async { | 1336 test_createField_BAD_inEnum() async { |
| 1337 resolveTestUnit(''' | 1337 await resolveTestUnit(''' |
| 1338 enum MyEnum { | 1338 enum MyEnum { |
| 1339 AAA, BBB | 1339 AAA, BBB |
| 1340 } | 1340 } |
| 1341 main() { | 1341 main() { |
| 1342 MyEnum.foo; | 1342 MyEnum.foo; |
| 1343 } | 1343 } |
| 1344 '''); | 1344 '''); |
| 1345 await assertNoFix(DartFixKind.CREATE_FIELD); | 1345 await assertNoFix(DartFixKind.CREATE_FIELD); |
| 1346 } | 1346 } |
| 1347 | 1347 |
| 1348 test_createField_BAD_inSDK() async { | 1348 test_createField_BAD_inSDK() async { |
| 1349 resolveTestUnit(''' | 1349 await resolveTestUnit(''' |
| 1350 main(List p) { | 1350 main(List p) { |
| 1351 p.foo = 1; | 1351 p.foo = 1; |
| 1352 } | 1352 } |
| 1353 '''); | 1353 '''); |
| 1354 await assertNoFix(DartFixKind.CREATE_FIELD); | 1354 await assertNoFix(DartFixKind.CREATE_FIELD); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 test_createField_getter_multiLevel() async { | 1357 test_createField_getter_multiLevel() async { |
| 1358 resolveTestUnit(''' | 1358 await resolveTestUnit(''' |
| 1359 class A { | 1359 class A { |
| 1360 } | 1360 } |
| 1361 class B { | 1361 class B { |
| 1362 A a; | 1362 A a; |
| 1363 } | 1363 } |
| 1364 class C { | 1364 class C { |
| 1365 B b; | 1365 B b; |
| 1366 } | 1366 } |
| 1367 main(C c) { | 1367 main(C c) { |
| 1368 int v = c.b.a.test; | 1368 int v = c.b.a.test; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1380 class C { | 1380 class C { |
| 1381 B b; | 1381 B b; |
| 1382 } | 1382 } |
| 1383 main(C c) { | 1383 main(C c) { |
| 1384 int v = c.b.a.test; | 1384 int v = c.b.a.test; |
| 1385 } | 1385 } |
| 1386 '''); | 1386 '''); |
| 1387 } | 1387 } |
| 1388 | 1388 |
| 1389 test_createField_getter_qualified_instance() async { | 1389 test_createField_getter_qualified_instance() async { |
| 1390 resolveTestUnit(''' | 1390 await resolveTestUnit(''' |
| 1391 class A { | 1391 class A { |
| 1392 } | 1392 } |
| 1393 main(A a) { | 1393 main(A a) { |
| 1394 int v = a.test; | 1394 int v = a.test; |
| 1395 } | 1395 } |
| 1396 '''); | 1396 '''); |
| 1397 await assertHasFix( | 1397 await assertHasFix( |
| 1398 DartFixKind.CREATE_FIELD, | 1398 DartFixKind.CREATE_FIELD, |
| 1399 ''' | 1399 ''' |
| 1400 class A { | 1400 class A { |
| 1401 int test; | 1401 int test; |
| 1402 } | 1402 } |
| 1403 main(A a) { | 1403 main(A a) { |
| 1404 int v = a.test; | 1404 int v = a.test; |
| 1405 } | 1405 } |
| 1406 '''); | 1406 '''); |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 test_createField_getter_qualified_instance_dynamicType() async { | 1409 test_createField_getter_qualified_instance_dynamicType() async { |
| 1410 resolveTestUnit(''' | 1410 await resolveTestUnit(''' |
| 1411 class A { | 1411 class A { |
| 1412 B b; | 1412 B b; |
| 1413 void f(Object p) { | 1413 void f(Object p) { |
| 1414 p == b.test; | 1414 p == b.test; |
| 1415 } | 1415 } |
| 1416 } | 1416 } |
| 1417 class B { | 1417 class B { |
| 1418 } | 1418 } |
| 1419 '''); | 1419 '''); |
| 1420 await assertHasFix( | 1420 await assertHasFix( |
| 1421 DartFixKind.CREATE_FIELD, | 1421 DartFixKind.CREATE_FIELD, |
| 1422 ''' | 1422 ''' |
| 1423 class A { | 1423 class A { |
| 1424 B b; | 1424 B b; |
| 1425 void f(Object p) { | 1425 void f(Object p) { |
| 1426 p == b.test; | 1426 p == b.test; |
| 1427 } | 1427 } |
| 1428 } | 1428 } |
| 1429 class B { | 1429 class B { |
| 1430 var test; | 1430 var test; |
| 1431 } | 1431 } |
| 1432 '''); | 1432 '''); |
| 1433 } | 1433 } |
| 1434 | 1434 |
| 1435 test_createField_getter_qualified_propagatedType() async { | 1435 test_createField_getter_qualified_propagatedType() async { |
| 1436 resolveTestUnit(''' | 1436 await resolveTestUnit(''' |
| 1437 class A { | 1437 class A { |
| 1438 A get self => this; | 1438 A get self => this; |
| 1439 } | 1439 } |
| 1440 main() { | 1440 main() { |
| 1441 var a = new A(); | 1441 var a = new A(); |
| 1442 int v = a.self.test; | 1442 int v = a.self.test; |
| 1443 } | 1443 } |
| 1444 '''); | 1444 '''); |
| 1445 await assertHasFix( | 1445 await assertHasFix( |
| 1446 DartFixKind.CREATE_FIELD, | 1446 DartFixKind.CREATE_FIELD, |
| 1447 ''' | 1447 ''' |
| 1448 class A { | 1448 class A { |
| 1449 int test; | 1449 int test; |
| 1450 | 1450 |
| 1451 A get self => this; | 1451 A get self => this; |
| 1452 } | 1452 } |
| 1453 main() { | 1453 main() { |
| 1454 var a = new A(); | 1454 var a = new A(); |
| 1455 int v = a.self.test; | 1455 int v = a.self.test; |
| 1456 } | 1456 } |
| 1457 '''); | 1457 '''); |
| 1458 } | 1458 } |
| 1459 | 1459 |
| 1460 test_createField_getter_unqualified_instance_asInvocationArgument() async { | 1460 test_createField_getter_unqualified_instance_asInvocationArgument() async { |
| 1461 resolveTestUnit(''' | 1461 await resolveTestUnit(''' |
| 1462 class A { | 1462 class A { |
| 1463 main() { | 1463 main() { |
| 1464 f(test); | 1464 f(test); |
| 1465 } | 1465 } |
| 1466 } | 1466 } |
| 1467 f(String s) {} | 1467 f(String s) {} |
| 1468 '''); | 1468 '''); |
| 1469 await assertHasFix( | 1469 await assertHasFix( |
| 1470 DartFixKind.CREATE_FIELD, | 1470 DartFixKind.CREATE_FIELD, |
| 1471 ''' | 1471 ''' |
| 1472 class A { | 1472 class A { |
| 1473 String test; | 1473 String test; |
| 1474 | 1474 |
| 1475 main() { | 1475 main() { |
| 1476 f(test); | 1476 f(test); |
| 1477 } | 1477 } |
| 1478 } | 1478 } |
| 1479 f(String s) {} | 1479 f(String s) {} |
| 1480 '''); | 1480 '''); |
| 1481 } | 1481 } |
| 1482 | 1482 |
| 1483 test_createField_getter_unqualified_instance_assignmentRhs() async { | 1483 test_createField_getter_unqualified_instance_assignmentRhs() async { |
| 1484 resolveTestUnit(''' | 1484 await resolveTestUnit(''' |
| 1485 class A { | 1485 class A { |
| 1486 main() { | 1486 main() { |
| 1487 int v = test; | 1487 int v = test; |
| 1488 } | 1488 } |
| 1489 } | 1489 } |
| 1490 '''); | 1490 '''); |
| 1491 await assertHasFix( | 1491 await assertHasFix( |
| 1492 DartFixKind.CREATE_FIELD, | 1492 DartFixKind.CREATE_FIELD, |
| 1493 ''' | 1493 ''' |
| 1494 class A { | 1494 class A { |
| 1495 int test; | 1495 int test; |
| 1496 | 1496 |
| 1497 main() { | 1497 main() { |
| 1498 int v = test; | 1498 int v = test; |
| 1499 } | 1499 } |
| 1500 } | 1500 } |
| 1501 '''); | 1501 '''); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 test_createField_getter_unqualified_instance_asStatement() async { | 1504 test_createField_getter_unqualified_instance_asStatement() async { |
| 1505 resolveTestUnit(''' | 1505 await resolveTestUnit(''' |
| 1506 class A { | 1506 class A { |
| 1507 main() { | 1507 main() { |
| 1508 test; | 1508 test; |
| 1509 } | 1509 } |
| 1510 } | 1510 } |
| 1511 '''); | 1511 '''); |
| 1512 await assertHasFix( | 1512 await assertHasFix( |
| 1513 DartFixKind.CREATE_FIELD, | 1513 DartFixKind.CREATE_FIELD, |
| 1514 ''' | 1514 ''' |
| 1515 class A { | 1515 class A { |
| 1516 var test; | 1516 var test; |
| 1517 | 1517 |
| 1518 main() { | 1518 main() { |
| 1519 test; | 1519 test; |
| 1520 } | 1520 } |
| 1521 } | 1521 } |
| 1522 '''); | 1522 '''); |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 test_createField_hint() async { | 1525 test_createField_hint() async { |
| 1526 resolveTestUnit(''' | 1526 await resolveTestUnit(''' |
| 1527 class A { | 1527 class A { |
| 1528 } | 1528 } |
| 1529 main(A a) { | 1529 main(A a) { |
| 1530 var x = a; | 1530 var x = a; |
| 1531 int v = x.test; | 1531 int v = x.test; |
| 1532 } | 1532 } |
| 1533 '''); | 1533 '''); |
| 1534 await assertHasFix( | 1534 await assertHasFix( |
| 1535 DartFixKind.CREATE_FIELD, | 1535 DartFixKind.CREATE_FIELD, |
| 1536 ''' | 1536 ''' |
| 1537 class A { | 1537 class A { |
| 1538 int test; | 1538 int test; |
| 1539 } | 1539 } |
| 1540 main(A a) { | 1540 main(A a) { |
| 1541 var x = a; | 1541 var x = a; |
| 1542 int v = x.test; | 1542 int v = x.test; |
| 1543 } | 1543 } |
| 1544 '''); | 1544 '''); |
| 1545 } | 1545 } |
| 1546 | 1546 |
| 1547 test_createField_hint_setter() async { | 1547 test_createField_hint_setter() async { |
| 1548 resolveTestUnit(''' | 1548 await resolveTestUnit(''' |
| 1549 class A { | 1549 class A { |
| 1550 } | 1550 } |
| 1551 main(A a) { | 1551 main(A a) { |
| 1552 var x = a; | 1552 var x = a; |
| 1553 x.test = 0; | 1553 x.test = 0; |
| 1554 } | 1554 } |
| 1555 '''); | 1555 '''); |
| 1556 await assertHasFix( | 1556 await assertHasFix( |
| 1557 DartFixKind.CREATE_FIELD, | 1557 DartFixKind.CREATE_FIELD, |
| 1558 ''' | 1558 ''' |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1573 library libA; | 1573 library libA; |
| 1574 class A {} | 1574 class A {} |
| 1575 '''); | 1575 '''); |
| 1576 addSource( | 1576 addSource( |
| 1577 '/libB.dart', | 1577 '/libB.dart', |
| 1578 r''' | 1578 r''' |
| 1579 library libB; | 1579 library libB; |
| 1580 import 'libA.dart'; | 1580 import 'libA.dart'; |
| 1581 A getA() => null; | 1581 A getA() => null; |
| 1582 '''); | 1582 '''); |
| 1583 resolveTestUnit(''' | 1583 await resolveTestUnit(''' |
| 1584 import 'libB.dart'; | 1584 import 'libB.dart'; |
| 1585 class C { | 1585 class C { |
| 1586 } | 1586 } |
| 1587 main(C c) { | 1587 main(C c) { |
| 1588 c.test = getA(); | 1588 c.test = getA(); |
| 1589 } | 1589 } |
| 1590 '''); | 1590 '''); |
| 1591 await assertHasFix( | 1591 await assertHasFix( |
| 1592 DartFixKind.CREATE_FIELD, | 1592 DartFixKind.CREATE_FIELD, |
| 1593 ''' | 1593 ''' |
| 1594 import 'libA.dart'; | 1594 import 'libA.dart'; |
| 1595 import 'libB.dart'; | 1595 import 'libB.dart'; |
| 1596 class C { | 1596 class C { |
| 1597 A test; | 1597 A test; |
| 1598 } | 1598 } |
| 1599 main(C c) { | 1599 main(C c) { |
| 1600 c.test = getA(); | 1600 c.test = getA(); |
| 1601 } | 1601 } |
| 1602 '''); | 1602 '''); |
| 1603 } | 1603 } |
| 1604 | 1604 |
| 1605 test_createField_setter_generic_BAD() async { | 1605 test_createField_setter_generic_BAD() async { |
| 1606 resolveTestUnit(''' | 1606 await resolveTestUnit(''' |
| 1607 class A { | 1607 class A { |
| 1608 } | 1608 } |
| 1609 class B<T> { | 1609 class B<T> { |
| 1610 List<T> items; | 1610 List<T> items; |
| 1611 main(A a) { | 1611 main(A a) { |
| 1612 a.test = items; | 1612 a.test = items; |
| 1613 } | 1613 } |
| 1614 } | 1614 } |
| 1615 '''); | 1615 '''); |
| 1616 await assertHasFix( | 1616 await assertHasFix( |
| 1617 DartFixKind.CREATE_FIELD, | 1617 DartFixKind.CREATE_FIELD, |
| 1618 ''' | 1618 ''' |
| 1619 class A { | 1619 class A { |
| 1620 List test; | 1620 List test; |
| 1621 } | 1621 } |
| 1622 class B<T> { | 1622 class B<T> { |
| 1623 List<T> items; | 1623 List<T> items; |
| 1624 main(A a) { | 1624 main(A a) { |
| 1625 a.test = items; | 1625 a.test = items; |
| 1626 } | 1626 } |
| 1627 } | 1627 } |
| 1628 '''); | 1628 '''); |
| 1629 } | 1629 } |
| 1630 | 1630 |
| 1631 test_createField_setter_generic_OK_local() async { | 1631 test_createField_setter_generic_OK_local() async { |
| 1632 resolveTestUnit(''' | 1632 await resolveTestUnit(''' |
| 1633 class A<T> { | 1633 class A<T> { |
| 1634 List<T> items; | 1634 List<T> items; |
| 1635 | 1635 |
| 1636 main(A a) { | 1636 main(A a) { |
| 1637 test = items; | 1637 test = items; |
| 1638 } | 1638 } |
| 1639 } | 1639 } |
| 1640 '''); | 1640 '''); |
| 1641 await assertHasFix( | 1641 await assertHasFix( |
| 1642 DartFixKind.CREATE_FIELD, | 1642 DartFixKind.CREATE_FIELD, |
| 1643 ''' | 1643 ''' |
| 1644 class A<T> { | 1644 class A<T> { |
| 1645 List<T> items; | 1645 List<T> items; |
| 1646 | 1646 |
| 1647 List<T> test; | 1647 List<T> test; |
| 1648 | 1648 |
| 1649 main(A a) { | 1649 main(A a) { |
| 1650 test = items; | 1650 test = items; |
| 1651 } | 1651 } |
| 1652 } | 1652 } |
| 1653 '''); | 1653 '''); |
| 1654 } | 1654 } |
| 1655 | 1655 |
| 1656 test_createField_setter_qualified_instance_hasField() async { | 1656 test_createField_setter_qualified_instance_hasField() async { |
| 1657 resolveTestUnit(''' | 1657 await resolveTestUnit(''' |
| 1658 class A { | 1658 class A { |
| 1659 int aaa; | 1659 int aaa; |
| 1660 int zzz; | 1660 int zzz; |
| 1661 | 1661 |
| 1662 existingMethod() {} | 1662 existingMethod() {} |
| 1663 } | 1663 } |
| 1664 main(A a) { | 1664 main(A a) { |
| 1665 a.test = 5; | 1665 a.test = 5; |
| 1666 } | 1666 } |
| 1667 '''); | 1667 '''); |
| 1668 await assertHasFix( | 1668 await assertHasFix( |
| 1669 DartFixKind.CREATE_FIELD, | 1669 DartFixKind.CREATE_FIELD, |
| 1670 ''' | 1670 ''' |
| 1671 class A { | 1671 class A { |
| 1672 int aaa; | 1672 int aaa; |
| 1673 int zzz; | 1673 int zzz; |
| 1674 | 1674 |
| 1675 int test; | 1675 int test; |
| 1676 | 1676 |
| 1677 existingMethod() {} | 1677 existingMethod() {} |
| 1678 } | 1678 } |
| 1679 main(A a) { | 1679 main(A a) { |
| 1680 a.test = 5; | 1680 a.test = 5; |
| 1681 } | 1681 } |
| 1682 '''); | 1682 '''); |
| 1683 } | 1683 } |
| 1684 | 1684 |
| 1685 test_createField_setter_qualified_instance_hasMethod() async { | 1685 test_createField_setter_qualified_instance_hasMethod() async { |
| 1686 resolveTestUnit(''' | 1686 await resolveTestUnit(''' |
| 1687 class A { | 1687 class A { |
| 1688 existingMethod() {} | 1688 existingMethod() {} |
| 1689 } | 1689 } |
| 1690 main(A a) { | 1690 main(A a) { |
| 1691 a.test = 5; | 1691 a.test = 5; |
| 1692 } | 1692 } |
| 1693 '''); | 1693 '''); |
| 1694 await assertHasFix( | 1694 await assertHasFix( |
| 1695 DartFixKind.CREATE_FIELD, | 1695 DartFixKind.CREATE_FIELD, |
| 1696 ''' | 1696 ''' |
| 1697 class A { | 1697 class A { |
| 1698 int test; | 1698 int test; |
| 1699 | 1699 |
| 1700 existingMethod() {} | 1700 existingMethod() {} |
| 1701 } | 1701 } |
| 1702 main(A a) { | 1702 main(A a) { |
| 1703 a.test = 5; | 1703 a.test = 5; |
| 1704 } | 1704 } |
| 1705 '''); | 1705 '''); |
| 1706 } | 1706 } |
| 1707 | 1707 |
| 1708 test_createField_setter_qualified_static() async { | 1708 test_createField_setter_qualified_static() async { |
| 1709 resolveTestUnit(''' | 1709 await resolveTestUnit(''' |
| 1710 class A { | 1710 class A { |
| 1711 } | 1711 } |
| 1712 main() { | 1712 main() { |
| 1713 A.test = 5; | 1713 A.test = 5; |
| 1714 } | 1714 } |
| 1715 '''); | 1715 '''); |
| 1716 await assertHasFix( | 1716 await assertHasFix( |
| 1717 DartFixKind.CREATE_FIELD, | 1717 DartFixKind.CREATE_FIELD, |
| 1718 ''' | 1718 ''' |
| 1719 class A { | 1719 class A { |
| 1720 static int test; | 1720 static int test; |
| 1721 } | 1721 } |
| 1722 main() { | 1722 main() { |
| 1723 A.test = 5; | 1723 A.test = 5; |
| 1724 } | 1724 } |
| 1725 '''); | 1725 '''); |
| 1726 } | 1726 } |
| 1727 | 1727 |
| 1728 test_createField_setter_unqualified_instance() async { | 1728 test_createField_setter_unqualified_instance() async { |
| 1729 resolveTestUnit(''' | 1729 await resolveTestUnit(''' |
| 1730 class A { | 1730 class A { |
| 1731 main() { | 1731 main() { |
| 1732 test = 5; | 1732 test = 5; |
| 1733 } | 1733 } |
| 1734 } | 1734 } |
| 1735 '''); | 1735 '''); |
| 1736 await assertHasFix( | 1736 await assertHasFix( |
| 1737 DartFixKind.CREATE_FIELD, | 1737 DartFixKind.CREATE_FIELD, |
| 1738 ''' | 1738 ''' |
| 1739 class A { | 1739 class A { |
| 1740 int test; | 1740 int test; |
| 1741 | 1741 |
| 1742 main() { | 1742 main() { |
| 1743 test = 5; | 1743 test = 5; |
| 1744 } | 1744 } |
| 1745 } | 1745 } |
| 1746 '''); | 1746 '''); |
| 1747 } | 1747 } |
| 1748 | 1748 |
| 1749 test_createField_setter_unqualified_static() async { | 1749 test_createField_setter_unqualified_static() async { |
| 1750 resolveTestUnit(''' | 1750 await resolveTestUnit(''' |
| 1751 class A { | 1751 class A { |
| 1752 static main() { | 1752 static main() { |
| 1753 test = 5; | 1753 test = 5; |
| 1754 } | 1754 } |
| 1755 } | 1755 } |
| 1756 '''); | 1756 '''); |
| 1757 await assertHasFix( | 1757 await assertHasFix( |
| 1758 DartFixKind.CREATE_FIELD, | 1758 DartFixKind.CREATE_FIELD, |
| 1759 ''' | 1759 ''' |
| 1760 class A { | 1760 class A { |
| 1761 static int test; | 1761 static int test; |
| 1762 | 1762 |
| 1763 static main() { | 1763 static main() { |
| 1764 test = 5; | 1764 test = 5; |
| 1765 } | 1765 } |
| 1766 } | 1766 } |
| 1767 '''); | 1767 '''); |
| 1768 } | 1768 } |
| 1769 | 1769 |
| 1770 test_createFile_forImport() async { | 1770 test_createFile_forImport() async { |
| 1771 testFile = '/my/project/bin/test.dart'; | 1771 testFile = '/my/project/bin/test.dart'; |
| 1772 resolveTestUnit(''' | 1772 await resolveTestUnit(''' |
| 1773 import 'my_file.dart'; | 1773 import 'my_file.dart'; |
| 1774 '''); | 1774 '''); |
| 1775 AnalysisError error = _findErrorToFix(); | 1775 AnalysisError error = _findErrorToFix(); |
| 1776 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1776 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1777 change = fix.change; | 1777 change = fix.change; |
| 1778 // validate change | 1778 // validate change |
| 1779 List<SourceFileEdit> fileEdits = change.edits; | 1779 List<SourceFileEdit> fileEdits = change.edits; |
| 1780 expect(fileEdits, hasLength(1)); | 1780 expect(fileEdits, hasLength(1)); |
| 1781 SourceFileEdit fileEdit = change.edits[0]; | 1781 SourceFileEdit fileEdit = change.edits[0]; |
| 1782 expect(fileEdit.file, '/my/project/bin/my_file.dart'); | 1782 expect(fileEdit.file, '/my/project/bin/my_file.dart'); |
| 1783 expect(fileEdit.fileStamp, -1); | 1783 expect(fileEdit.fileStamp, -1); |
| 1784 expect(fileEdit.edits, hasLength(1)); | 1784 expect(fileEdit.edits, hasLength(1)); |
| 1785 expect(fileEdit.edits[0].replacement, contains('library my_file;')); | 1785 expect(fileEdit.edits[0].replacement, contains('library my_file;')); |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 test_createFile_forImport_BAD_inPackage_lib_justLib() async { | 1788 test_createFile_forImport_BAD_inPackage_lib_justLib() async { |
| 1789 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1789 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1790 testFile = '/projects/my_package/test.dart'; | 1790 testFile = '/projects/my_package/test.dart'; |
| 1791 resolveTestUnit(''' | 1791 await resolveTestUnit(''' |
| 1792 import 'lib'; | 1792 import 'lib'; |
| 1793 '''); | 1793 '''); |
| 1794 await assertNoFix(DartFixKind.CREATE_FILE); | 1794 await assertNoFix(DartFixKind.CREATE_FILE); |
| 1795 } | 1795 } |
| 1796 | 1796 |
| 1797 test_createFile_forImport_BAD_notDart() async { | 1797 test_createFile_forImport_BAD_notDart() async { |
| 1798 testFile = '/my/project/bin/test.dart'; | 1798 testFile = '/my/project/bin/test.dart'; |
| 1799 resolveTestUnit(''' | 1799 await resolveTestUnit(''' |
| 1800 import 'my_file.txt'; | 1800 import 'my_file.txt'; |
| 1801 '''); | 1801 '''); |
| 1802 await assertNoFix(DartFixKind.CREATE_FILE); | 1802 await assertNoFix(DartFixKind.CREATE_FILE); |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 test_createFile_forImport_inPackage_lib() async { | 1805 test_createFile_forImport_inPackage_lib() async { |
| 1806 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1806 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1807 testFile = '/projects/my_package/lib/test.dart'; | 1807 testFile = '/projects/my_package/lib/test.dart'; |
| 1808 provider.newFolder('/projects/my_package/lib'); | 1808 provider.newFolder('/projects/my_package/lib'); |
| 1809 resolveTestUnit(''' | 1809 await resolveTestUnit(''' |
| 1810 import 'a/bb/c_cc/my_lib.dart'; | 1810 import 'a/bb/c_cc/my_lib.dart'; |
| 1811 '''); | 1811 '''); |
| 1812 AnalysisError error = _findErrorToFix(); | 1812 AnalysisError error = _findErrorToFix(); |
| 1813 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1813 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1814 change = fix.change; | 1814 change = fix.change; |
| 1815 // validate change | 1815 // validate change |
| 1816 List<SourceFileEdit> fileEdits = change.edits; | 1816 List<SourceFileEdit> fileEdits = change.edits; |
| 1817 expect(fileEdits, hasLength(1)); | 1817 expect(fileEdits, hasLength(1)); |
| 1818 SourceFileEdit fileEdit = change.edits[0]; | 1818 SourceFileEdit fileEdit = change.edits[0]; |
| 1819 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); | 1819 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); |
| 1820 expect(fileEdit.fileStamp, -1); | 1820 expect(fileEdit.fileStamp, -1); |
| 1821 expect(fileEdit.edits, hasLength(1)); | 1821 expect(fileEdit.edits, hasLength(1)); |
| 1822 expect(fileEdit.edits[0].replacement, | 1822 expect(fileEdit.edits[0].replacement, |
| 1823 contains('library my_package.a.bb.c_cc.my_lib;')); | 1823 contains('library my_package.a.bb.c_cc.my_lib;')); |
| 1824 } | 1824 } |
| 1825 | 1825 |
| 1826 test_createFile_forImport_inPackage_test() async { | 1826 test_createFile_forImport_inPackage_test() async { |
| 1827 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1827 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1828 testFile = '/projects/my_package/test/misc/test_all.dart'; | 1828 testFile = '/projects/my_package/test/misc/test_all.dart'; |
| 1829 resolveTestUnit(''' | 1829 await resolveTestUnit(''' |
| 1830 import 'a/bb/my_lib.dart'; | 1830 import 'a/bb/my_lib.dart'; |
| 1831 '''); | 1831 '''); |
| 1832 AnalysisError error = _findErrorToFix(); | 1832 AnalysisError error = _findErrorToFix(); |
| 1833 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1833 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1834 change = fix.change; | 1834 change = fix.change; |
| 1835 // validate change | 1835 // validate change |
| 1836 List<SourceFileEdit> fileEdits = change.edits; | 1836 List<SourceFileEdit> fileEdits = change.edits; |
| 1837 expect(fileEdits, hasLength(1)); | 1837 expect(fileEdits, hasLength(1)); |
| 1838 SourceFileEdit fileEdit = change.edits[0]; | 1838 SourceFileEdit fileEdit = change.edits[0]; |
| 1839 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); | 1839 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); |
| 1840 expect(fileEdit.fileStamp, -1); | 1840 expect(fileEdit.fileStamp, -1); |
| 1841 expect(fileEdit.edits, hasLength(1)); | 1841 expect(fileEdit.edits, hasLength(1)); |
| 1842 expect(fileEdit.edits[0].replacement, | 1842 expect(fileEdit.edits[0].replacement, |
| 1843 contains('library my_package.test.misc.a.bb.my_lib;')); | 1843 contains('library my_package.test.misc.a.bb.my_lib;')); |
| 1844 } | 1844 } |
| 1845 | 1845 |
| 1846 test_createFile_forPart() async { | 1846 test_createFile_forPart() async { |
| 1847 testFile = '/my/project/bin/test.dart'; | 1847 testFile = '/my/project/bin/test.dart'; |
| 1848 resolveTestUnit(''' | 1848 await resolveTestUnit(''' |
| 1849 library my.lib; | 1849 library my.lib; |
| 1850 part 'my_part.dart'; | 1850 part 'my_part.dart'; |
| 1851 '''); | 1851 '''); |
| 1852 AnalysisError error = _findErrorToFix(); | 1852 AnalysisError error = _findErrorToFix(); |
| 1853 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1853 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1854 change = fix.change; | 1854 change = fix.change; |
| 1855 // validate change | 1855 // validate change |
| 1856 List<SourceFileEdit> fileEdits = change.edits; | 1856 List<SourceFileEdit> fileEdits = change.edits; |
| 1857 expect(fileEdits, hasLength(1)); | 1857 expect(fileEdits, hasLength(1)); |
| 1858 SourceFileEdit fileEdit = change.edits[0]; | 1858 SourceFileEdit fileEdit = change.edits[0]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1875 part 'my_part.dart'; | 1875 part 'my_part.dart'; |
| 1876 ''', | 1876 ''', |
| 1877 Uri.parse('package:my/test.dart')); | 1877 Uri.parse('package:my/test.dart')); |
| 1878 // configure SourceFactory | 1878 // configure SourceFactory |
| 1879 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 1879 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 1880 'my': <Folder>[provider.getResource('/my/lib')], | 1880 'my': <Folder>[provider.getResource('/my/lib')], |
| 1881 }); | 1881 }); |
| 1882 context.sourceFactory = new SourceFactory( | 1882 context.sourceFactory = new SourceFactory( |
| 1883 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); | 1883 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
| 1884 // prepare fix | 1884 // prepare fix |
| 1885 testUnit = resolveLibraryUnit(testSource); | 1885 testUnit = await resolveLibraryUnit(testSource); |
| 1886 AnalysisError error = _findErrorToFix(); | 1886 AnalysisError error = _findErrorToFix(); |
| 1887 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1887 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1888 change = fix.change; | 1888 change = fix.change; |
| 1889 // validate change | 1889 // validate change |
| 1890 List<SourceFileEdit> fileEdits = change.edits; | 1890 List<SourceFileEdit> fileEdits = change.edits; |
| 1891 expect(fileEdits, hasLength(1)); | 1891 expect(fileEdits, hasLength(1)); |
| 1892 SourceFileEdit fileEdit = change.edits[0]; | 1892 SourceFileEdit fileEdit = change.edits[0]; |
| 1893 expect(fileEdit.file, '/my/lib/my_part.dart'); | 1893 expect(fileEdit.file, '/my/lib/my_part.dart'); |
| 1894 expect(fileEdit.fileStamp, -1); | 1894 expect(fileEdit.fileStamp, -1); |
| 1895 expect(fileEdit.edits, hasLength(1)); | 1895 expect(fileEdit.edits, hasLength(1)); |
| 1896 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 1896 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
| 1897 } | 1897 } |
| 1898 | 1898 |
| 1899 test_createGetter_BAD_inSDK() async { | 1899 test_createGetter_BAD_inSDK() async { |
| 1900 resolveTestUnit(''' | 1900 await resolveTestUnit(''' |
| 1901 main(List p) { | 1901 main(List p) { |
| 1902 int v = p.foo; | 1902 int v = p.foo; |
| 1903 } | 1903 } |
| 1904 '''); | 1904 '''); |
| 1905 await assertNoFix(DartFixKind.CREATE_GETTER); | 1905 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 1906 } | 1906 } |
| 1907 | 1907 |
| 1908 test_createGetter_hint_getter() async { | 1908 test_createGetter_hint_getter() async { |
| 1909 resolveTestUnit(''' | 1909 await resolveTestUnit(''' |
| 1910 class A { | 1910 class A { |
| 1911 } | 1911 } |
| 1912 main(A a) { | 1912 main(A a) { |
| 1913 var x = a; | 1913 var x = a; |
| 1914 int v = x.test; | 1914 int v = x.test; |
| 1915 } | 1915 } |
| 1916 '''); | 1916 '''); |
| 1917 await assertHasFix( | 1917 await assertHasFix( |
| 1918 DartFixKind.CREATE_GETTER, | 1918 DartFixKind.CREATE_GETTER, |
| 1919 ''' | 1919 ''' |
| 1920 class A { | 1920 class A { |
| 1921 int get test => null; | 1921 int get test => null; |
| 1922 } | 1922 } |
| 1923 main(A a) { | 1923 main(A a) { |
| 1924 var x = a; | 1924 var x = a; |
| 1925 int v = x.test; | 1925 int v = x.test; |
| 1926 } | 1926 } |
| 1927 '''); | 1927 '''); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 test_createGetter_location_afterLastGetter() async { | 1930 test_createGetter_location_afterLastGetter() async { |
| 1931 resolveTestUnit(''' | 1931 await resolveTestUnit(''' |
| 1932 class A { | 1932 class A { |
| 1933 int existingField; | 1933 int existingField; |
| 1934 | 1934 |
| 1935 int get existingGetter => null; | 1935 int get existingGetter => null; |
| 1936 | 1936 |
| 1937 existingMethod() {} | 1937 existingMethod() {} |
| 1938 } | 1938 } |
| 1939 main(A a) { | 1939 main(A a) { |
| 1940 int v = a.test; | 1940 int v = a.test; |
| 1941 } | 1941 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1952 | 1952 |
| 1953 existingMethod() {} | 1953 existingMethod() {} |
| 1954 } | 1954 } |
| 1955 main(A a) { | 1955 main(A a) { |
| 1956 int v = a.test; | 1956 int v = a.test; |
| 1957 } | 1957 } |
| 1958 '''); | 1958 '''); |
| 1959 } | 1959 } |
| 1960 | 1960 |
| 1961 test_createGetter_multiLevel() async { | 1961 test_createGetter_multiLevel() async { |
| 1962 resolveTestUnit(''' | 1962 await resolveTestUnit(''' |
| 1963 class A { | 1963 class A { |
| 1964 } | 1964 } |
| 1965 class B { | 1965 class B { |
| 1966 A a; | 1966 A a; |
| 1967 } | 1967 } |
| 1968 class C { | 1968 class C { |
| 1969 B b; | 1969 B b; |
| 1970 } | 1970 } |
| 1971 main(C c) { | 1971 main(C c) { |
| 1972 int v = c.b.a.test; | 1972 int v = c.b.a.test; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1984 class C { | 1984 class C { |
| 1985 B b; | 1985 B b; |
| 1986 } | 1986 } |
| 1987 main(C c) { | 1987 main(C c) { |
| 1988 int v = c.b.a.test; | 1988 int v = c.b.a.test; |
| 1989 } | 1989 } |
| 1990 '''); | 1990 '''); |
| 1991 } | 1991 } |
| 1992 | 1992 |
| 1993 test_createGetter_qualified_instance() async { | 1993 test_createGetter_qualified_instance() async { |
| 1994 resolveTestUnit(''' | 1994 await resolveTestUnit(''' |
| 1995 class A { | 1995 class A { |
| 1996 } | 1996 } |
| 1997 main(A a) { | 1997 main(A a) { |
| 1998 int v = a.test; | 1998 int v = a.test; |
| 1999 } | 1999 } |
| 2000 '''); | 2000 '''); |
| 2001 await assertHasFix( | 2001 await assertHasFix( |
| 2002 DartFixKind.CREATE_GETTER, | 2002 DartFixKind.CREATE_GETTER, |
| 2003 ''' | 2003 ''' |
| 2004 class A { | 2004 class A { |
| 2005 int get test => null; | 2005 int get test => null; |
| 2006 } | 2006 } |
| 2007 main(A a) { | 2007 main(A a) { |
| 2008 int v = a.test; | 2008 int v = a.test; |
| 2009 } | 2009 } |
| 2010 '''); | 2010 '''); |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 test_createGetter_qualified_instance_dynamicType() async { | 2013 test_createGetter_qualified_instance_dynamicType() async { |
| 2014 resolveTestUnit(''' | 2014 await resolveTestUnit(''' |
| 2015 class A { | 2015 class A { |
| 2016 B b; | 2016 B b; |
| 2017 void f(Object p) { | 2017 void f(Object p) { |
| 2018 p == b.test; | 2018 p == b.test; |
| 2019 } | 2019 } |
| 2020 } | 2020 } |
| 2021 class B { | 2021 class B { |
| 2022 } | 2022 } |
| 2023 '''); | 2023 '''); |
| 2024 await assertHasFix( | 2024 await assertHasFix( |
| 2025 DartFixKind.CREATE_GETTER, | 2025 DartFixKind.CREATE_GETTER, |
| 2026 ''' | 2026 ''' |
| 2027 class A { | 2027 class A { |
| 2028 B b; | 2028 B b; |
| 2029 void f(Object p) { | 2029 void f(Object p) { |
| 2030 p == b.test; | 2030 p == b.test; |
| 2031 } | 2031 } |
| 2032 } | 2032 } |
| 2033 class B { | 2033 class B { |
| 2034 get test => null; | 2034 get test => null; |
| 2035 } | 2035 } |
| 2036 '''); | 2036 '''); |
| 2037 } | 2037 } |
| 2038 | 2038 |
| 2039 test_createGetter_qualified_propagatedType() async { | 2039 test_createGetter_qualified_propagatedType() async { |
| 2040 resolveTestUnit(''' | 2040 await resolveTestUnit(''' |
| 2041 class A { | 2041 class A { |
| 2042 A get self => this; | 2042 A get self => this; |
| 2043 } | 2043 } |
| 2044 main() { | 2044 main() { |
| 2045 var a = new A(); | 2045 var a = new A(); |
| 2046 int v = a.self.test; | 2046 int v = a.self.test; |
| 2047 } | 2047 } |
| 2048 '''); | 2048 '''); |
| 2049 await assertHasFix( | 2049 await assertHasFix( |
| 2050 DartFixKind.CREATE_GETTER, | 2050 DartFixKind.CREATE_GETTER, |
| 2051 ''' | 2051 ''' |
| 2052 class A { | 2052 class A { |
| 2053 A get self => this; | 2053 A get self => this; |
| 2054 | 2054 |
| 2055 int get test => null; | 2055 int get test => null; |
| 2056 } | 2056 } |
| 2057 main() { | 2057 main() { |
| 2058 var a = new A(); | 2058 var a = new A(); |
| 2059 int v = a.self.test; | 2059 int v = a.self.test; |
| 2060 } | 2060 } |
| 2061 '''); | 2061 '''); |
| 2062 } | 2062 } |
| 2063 | 2063 |
| 2064 test_createGetter_setterContext() async { | 2064 test_createGetter_setterContext() async { |
| 2065 resolveTestUnit(''' | 2065 await resolveTestUnit(''' |
| 2066 class A { | 2066 class A { |
| 2067 } | 2067 } |
| 2068 main(A a) { | 2068 main(A a) { |
| 2069 a.test = 42; | 2069 a.test = 42; |
| 2070 } | 2070 } |
| 2071 '''); | 2071 '''); |
| 2072 await assertNoFix(DartFixKind.CREATE_GETTER); | 2072 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 2073 } | 2073 } |
| 2074 | 2074 |
| 2075 test_createGetter_unqualified_instance_asInvocationArgument() async { | 2075 test_createGetter_unqualified_instance_asInvocationArgument() async { |
| 2076 resolveTestUnit(''' | 2076 await resolveTestUnit(''' |
| 2077 class A { | 2077 class A { |
| 2078 main() { | 2078 main() { |
| 2079 f(test); | 2079 f(test); |
| 2080 } | 2080 } |
| 2081 } | 2081 } |
| 2082 f(String s) {} | 2082 f(String s) {} |
| 2083 '''); | 2083 '''); |
| 2084 await assertHasFix( | 2084 await assertHasFix( |
| 2085 DartFixKind.CREATE_GETTER, | 2085 DartFixKind.CREATE_GETTER, |
| 2086 ''' | 2086 ''' |
| 2087 class A { | 2087 class A { |
| 2088 String get test => null; | 2088 String get test => null; |
| 2089 | 2089 |
| 2090 main() { | 2090 main() { |
| 2091 f(test); | 2091 f(test); |
| 2092 } | 2092 } |
| 2093 } | 2093 } |
| 2094 f(String s) {} | 2094 f(String s) {} |
| 2095 '''); | 2095 '''); |
| 2096 } | 2096 } |
| 2097 | 2097 |
| 2098 test_createGetter_unqualified_instance_assignmentLhs() async { | 2098 test_createGetter_unqualified_instance_assignmentLhs() async { |
| 2099 resolveTestUnit(''' | 2099 await resolveTestUnit(''' |
| 2100 class A { | 2100 class A { |
| 2101 main() { | 2101 main() { |
| 2102 test = 42; | 2102 test = 42; |
| 2103 } | 2103 } |
| 2104 } | 2104 } |
| 2105 '''); | 2105 '''); |
| 2106 await assertNoFix(DartFixKind.CREATE_GETTER); | 2106 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 2107 } | 2107 } |
| 2108 | 2108 |
| 2109 test_createGetter_unqualified_instance_assignmentRhs() async { | 2109 test_createGetter_unqualified_instance_assignmentRhs() async { |
| 2110 resolveTestUnit(''' | 2110 await resolveTestUnit(''' |
| 2111 class A { | 2111 class A { |
| 2112 main() { | 2112 main() { |
| 2113 int v = test; | 2113 int v = test; |
| 2114 } | 2114 } |
| 2115 } | 2115 } |
| 2116 '''); | 2116 '''); |
| 2117 await assertHasFix( | 2117 await assertHasFix( |
| 2118 DartFixKind.CREATE_GETTER, | 2118 DartFixKind.CREATE_GETTER, |
| 2119 ''' | 2119 ''' |
| 2120 class A { | 2120 class A { |
| 2121 int get test => null; | 2121 int get test => null; |
| 2122 | 2122 |
| 2123 main() { | 2123 main() { |
| 2124 int v = test; | 2124 int v = test; |
| 2125 } | 2125 } |
| 2126 } | 2126 } |
| 2127 '''); | 2127 '''); |
| 2128 } | 2128 } |
| 2129 | 2129 |
| 2130 test_createGetter_unqualified_instance_asStatement() async { | 2130 test_createGetter_unqualified_instance_asStatement() async { |
| 2131 resolveTestUnit(''' | 2131 await resolveTestUnit(''' |
| 2132 class A { | 2132 class A { |
| 2133 main() { | 2133 main() { |
| 2134 test; | 2134 test; |
| 2135 } | 2135 } |
| 2136 } | 2136 } |
| 2137 '''); | 2137 '''); |
| 2138 await assertHasFix( | 2138 await assertHasFix( |
| 2139 DartFixKind.CREATE_GETTER, | 2139 DartFixKind.CREATE_GETTER, |
| 2140 ''' | 2140 ''' |
| 2141 class A { | 2141 class A { |
| 2142 get test => null; | 2142 get test => null; |
| 2143 | 2143 |
| 2144 main() { | 2144 main() { |
| 2145 test; | 2145 test; |
| 2146 } | 2146 } |
| 2147 } | 2147 } |
| 2148 '''); | 2148 '''); |
| 2149 } | 2149 } |
| 2150 | 2150 |
| 2151 test_createLocalVariable_functionType_named() async { | 2151 test_createLocalVariable_functionType_named() async { |
| 2152 resolveTestUnit(''' | 2152 await resolveTestUnit(''' |
| 2153 typedef MY_FUNCTION(int p); | 2153 typedef MY_FUNCTION(int p); |
| 2154 foo(MY_FUNCTION f) {} | 2154 foo(MY_FUNCTION f) {} |
| 2155 main() { | 2155 main() { |
| 2156 foo(bar); | 2156 foo(bar); |
| 2157 } | 2157 } |
| 2158 '''); | 2158 '''); |
| 2159 await assertHasFix( | 2159 await assertHasFix( |
| 2160 DartFixKind.CREATE_LOCAL_VARIABLE, | 2160 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2161 ''' | 2161 ''' |
| 2162 typedef MY_FUNCTION(int p); | 2162 typedef MY_FUNCTION(int p); |
| 2163 foo(MY_FUNCTION f) {} | 2163 foo(MY_FUNCTION f) {} |
| 2164 main() { | 2164 main() { |
| 2165 MY_FUNCTION bar; | 2165 MY_FUNCTION bar; |
| 2166 foo(bar); | 2166 foo(bar); |
| 2167 } | 2167 } |
| 2168 '''); | 2168 '''); |
| 2169 } | 2169 } |
| 2170 | 2170 |
| 2171 test_createLocalVariable_functionType_synthetic() async { | 2171 test_createLocalVariable_functionType_synthetic() async { |
| 2172 resolveTestUnit(''' | 2172 await resolveTestUnit(''' |
| 2173 foo(f(int p)) {} | 2173 foo(f(int p)) {} |
| 2174 main() { | 2174 main() { |
| 2175 foo(bar); | 2175 foo(bar); |
| 2176 } | 2176 } |
| 2177 '''); | 2177 '''); |
| 2178 await assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); | 2178 await assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); |
| 2179 } | 2179 } |
| 2180 | 2180 |
| 2181 test_createLocalVariable_read_typeAssignment() async { | 2181 test_createLocalVariable_read_typeAssignment() async { |
| 2182 resolveTestUnit(''' | 2182 await resolveTestUnit(''' |
| 2183 main() { | 2183 main() { |
| 2184 int a = test; | 2184 int a = test; |
| 2185 } | 2185 } |
| 2186 '''); | 2186 '''); |
| 2187 await assertHasFix( | 2187 await assertHasFix( |
| 2188 DartFixKind.CREATE_LOCAL_VARIABLE, | 2188 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2189 ''' | 2189 ''' |
| 2190 main() { | 2190 main() { |
| 2191 int test; | 2191 int test; |
| 2192 int a = test; | 2192 int a = test; |
| 2193 } | 2193 } |
| 2194 '''); | 2194 '''); |
| 2195 } | 2195 } |
| 2196 | 2196 |
| 2197 test_createLocalVariable_read_typeCondition() async { | 2197 test_createLocalVariable_read_typeCondition() async { |
| 2198 resolveTestUnit(''' | 2198 await resolveTestUnit(''' |
| 2199 main() { | 2199 main() { |
| 2200 if (!test) { | 2200 if (!test) { |
| 2201 print(42); | 2201 print(42); |
| 2202 } | 2202 } |
| 2203 } | 2203 } |
| 2204 '''); | 2204 '''); |
| 2205 await assertHasFix( | 2205 await assertHasFix( |
| 2206 DartFixKind.CREATE_LOCAL_VARIABLE, | 2206 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2207 ''' | 2207 ''' |
| 2208 main() { | 2208 main() { |
| 2209 bool test; | 2209 bool test; |
| 2210 if (!test) { | 2210 if (!test) { |
| 2211 print(42); | 2211 print(42); |
| 2212 } | 2212 } |
| 2213 } | 2213 } |
| 2214 '''); | 2214 '''); |
| 2215 } | 2215 } |
| 2216 | 2216 |
| 2217 test_createLocalVariable_read_typeInvocationArgument() async { | 2217 test_createLocalVariable_read_typeInvocationArgument() async { |
| 2218 resolveTestUnit(''' | 2218 await resolveTestUnit(''' |
| 2219 main() { | 2219 main() { |
| 2220 f(test); | 2220 f(test); |
| 2221 } | 2221 } |
| 2222 f(String p) {} | 2222 f(String p) {} |
| 2223 '''); | 2223 '''); |
| 2224 await assertHasFix( | 2224 await assertHasFix( |
| 2225 DartFixKind.CREATE_LOCAL_VARIABLE, | 2225 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2226 ''' | 2226 ''' |
| 2227 main() { | 2227 main() { |
| 2228 String test; | 2228 String test; |
| 2229 f(test); | 2229 f(test); |
| 2230 } | 2230 } |
| 2231 f(String p) {} | 2231 f(String p) {} |
| 2232 '''); | 2232 '''); |
| 2233 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); | 2233 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); |
| 2234 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); | 2234 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); |
| 2235 } | 2235 } |
| 2236 | 2236 |
| 2237 test_createLocalVariable_read_typeInvocationTarget() async { | 2237 test_createLocalVariable_read_typeInvocationTarget() async { |
| 2238 resolveTestUnit(''' | 2238 await resolveTestUnit(''' |
| 2239 main() { | 2239 main() { |
| 2240 test.add('hello'); | 2240 test.add('hello'); |
| 2241 } | 2241 } |
| 2242 '''); | 2242 '''); |
| 2243 await assertHasFix( | 2243 await assertHasFix( |
| 2244 DartFixKind.CREATE_LOCAL_VARIABLE, | 2244 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2245 ''' | 2245 ''' |
| 2246 main() { | 2246 main() { |
| 2247 var test; | 2247 var test; |
| 2248 test.add('hello'); | 2248 test.add('hello'); |
| 2249 } | 2249 } |
| 2250 '''); | 2250 '''); |
| 2251 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); | 2251 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); |
| 2252 } | 2252 } |
| 2253 | 2253 |
| 2254 test_createLocalVariable_write_assignment() async { | 2254 test_createLocalVariable_write_assignment() async { |
| 2255 resolveTestUnit(''' | 2255 await resolveTestUnit(''' |
| 2256 main() { | 2256 main() { |
| 2257 test = 42; | 2257 test = 42; |
| 2258 } | 2258 } |
| 2259 '''); | 2259 '''); |
| 2260 await assertHasFix( | 2260 await assertHasFix( |
| 2261 DartFixKind.CREATE_LOCAL_VARIABLE, | 2261 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2262 ''' | 2262 ''' |
| 2263 main() { | 2263 main() { |
| 2264 var test = 42; | 2264 var test = 42; |
| 2265 } | 2265 } |
| 2266 '''); | 2266 '''); |
| 2267 } | 2267 } |
| 2268 | 2268 |
| 2269 test_createLocalVariable_write_assignment_compound() async { | 2269 test_createLocalVariable_write_assignment_compound() async { |
| 2270 resolveTestUnit(''' | 2270 await resolveTestUnit(''' |
| 2271 main() { | 2271 main() { |
| 2272 test += 42; | 2272 test += 42; |
| 2273 } | 2273 } |
| 2274 '''); | 2274 '''); |
| 2275 await assertHasFix( | 2275 await assertHasFix( |
| 2276 DartFixKind.CREATE_LOCAL_VARIABLE, | 2276 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 2277 ''' | 2277 ''' |
| 2278 main() { | 2278 main() { |
| 2279 int test; | 2279 int test; |
| 2280 test += 42; | 2280 test += 42; |
| 2281 } | 2281 } |
| 2282 '''); | 2282 '''); |
| 2283 } | 2283 } |
| 2284 | 2284 |
| 2285 test_createMissingMethodCall() async { | 2285 test_createMissingMethodCall() async { |
| 2286 resolveTestUnit(''' | 2286 await resolveTestUnit(''' |
| 2287 class C implements Function { | 2287 class C implements Function { |
| 2288 } | 2288 } |
| 2289 '''); | 2289 '''); |
| 2290 await assertHasFix( | 2290 await assertHasFix( |
| 2291 DartFixKind.CREATE_MISSING_METHOD_CALL, | 2291 DartFixKind.CREATE_MISSING_METHOD_CALL, |
| 2292 ''' | 2292 ''' |
| 2293 class C implements Function { | 2293 class C implements Function { |
| 2294 call() { | 2294 call() { |
| 2295 // TODO: implement call | 2295 // TODO: implement call |
| 2296 } | 2296 } |
| 2297 } | 2297 } |
| 2298 '''); | 2298 '''); |
| 2299 } | 2299 } |
| 2300 | 2300 |
| 2301 test_createMissingOverrides_field_untyped() async { | 2301 test_createMissingOverrides_field_untyped() async { |
| 2302 resolveTestUnit(''' | 2302 await resolveTestUnit(''' |
| 2303 class A { | 2303 class A { |
| 2304 var f; | 2304 var f; |
| 2305 } | 2305 } |
| 2306 | 2306 |
| 2307 class B implements A { | 2307 class B implements A { |
| 2308 } | 2308 } |
| 2309 '''); | 2309 '''); |
| 2310 await assertHasFix( | 2310 await assertHasFix( |
| 2311 DartFixKind.CREATE_MISSING_OVERRIDES, | 2311 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2312 ''' | 2312 ''' |
| 2313 class A { | 2313 class A { |
| 2314 var f; | 2314 var f; |
| 2315 } | 2315 } |
| 2316 | 2316 |
| 2317 class B implements A { | 2317 class B implements A { |
| 2318 @override | 2318 @override |
| 2319 var f; | 2319 var f; |
| 2320 } | 2320 } |
| 2321 '''); | 2321 '''); |
| 2322 } | 2322 } |
| 2323 | 2323 |
| 2324 test_createMissingOverrides_functionTypeAlias() async { | 2324 test_createMissingOverrides_functionTypeAlias() async { |
| 2325 resolveTestUnit(''' | 2325 await resolveTestUnit(''' |
| 2326 typedef int Binary(int left, int right); | 2326 typedef int Binary(int left, int right); |
| 2327 | 2327 |
| 2328 abstract class Emulator { | 2328 abstract class Emulator { |
| 2329 void performBinary(Binary binary); | 2329 void performBinary(Binary binary); |
| 2330 } | 2330 } |
| 2331 | 2331 |
| 2332 class MyEmulator extends Emulator { | 2332 class MyEmulator extends Emulator { |
| 2333 } | 2333 } |
| 2334 '''); | 2334 '''); |
| 2335 await assertHasFix( | 2335 await assertHasFix( |
| 2336 DartFixKind.CREATE_MISSING_OVERRIDES, | 2336 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2337 ''' | 2337 ''' |
| 2338 typedef int Binary(int left, int right); | 2338 typedef int Binary(int left, int right); |
| 2339 | 2339 |
| 2340 abstract class Emulator { | 2340 abstract class Emulator { |
| 2341 void performBinary(Binary binary); | 2341 void performBinary(Binary binary); |
| 2342 } | 2342 } |
| 2343 | 2343 |
| 2344 class MyEmulator extends Emulator { | 2344 class MyEmulator extends Emulator { |
| 2345 @override | 2345 @override |
| 2346 void performBinary(Binary binary) { | 2346 void performBinary(Binary binary) { |
| 2347 // TODO: implement performBinary | 2347 // TODO: implement performBinary |
| 2348 } | 2348 } |
| 2349 } | 2349 } |
| 2350 '''); | 2350 '''); |
| 2351 } | 2351 } |
| 2352 | 2352 |
| 2353 test_createMissingOverrides_functionTypedParameter() async { | 2353 test_createMissingOverrides_functionTypedParameter() async { |
| 2354 resolveTestUnit(''' | 2354 await resolveTestUnit(''' |
| 2355 abstract class A { | 2355 abstract class A { |
| 2356 forEach(int f(double p1, String p2)); | 2356 forEach(int f(double p1, String p2)); |
| 2357 } | 2357 } |
| 2358 | 2358 |
| 2359 class B extends A { | 2359 class B extends A { |
| 2360 } | 2360 } |
| 2361 '''); | 2361 '''); |
| 2362 await assertHasFix( | 2362 await assertHasFix( |
| 2363 DartFixKind.CREATE_MISSING_OVERRIDES, | 2363 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2364 ''' | 2364 ''' |
| 2365 abstract class A { | 2365 abstract class A { |
| 2366 forEach(int f(double p1, String p2)); | 2366 forEach(int f(double p1, String p2)); |
| 2367 } | 2367 } |
| 2368 | 2368 |
| 2369 class B extends A { | 2369 class B extends A { |
| 2370 @override | 2370 @override |
| 2371 forEach(int f(double p1, String p2)) { | 2371 forEach(int f(double p1, String p2)) { |
| 2372 // TODO: implement forEach | 2372 // TODO: implement forEach |
| 2373 } | 2373 } |
| 2374 } | 2374 } |
| 2375 '''); | 2375 '''); |
| 2376 } | 2376 } |
| 2377 | 2377 |
| 2378 test_createMissingOverrides_generics_typeArguments() async { | 2378 test_createMissingOverrides_generics_typeArguments() async { |
| 2379 resolveTestUnit(''' | 2379 await resolveTestUnit(''' |
| 2380 class Iterator<T> { | 2380 class Iterator<T> { |
| 2381 } | 2381 } |
| 2382 | 2382 |
| 2383 abstract class IterableMixin<T> { | 2383 abstract class IterableMixin<T> { |
| 2384 Iterator<T> get iterator; | 2384 Iterator<T> get iterator; |
| 2385 } | 2385 } |
| 2386 | 2386 |
| 2387 class Test extends IterableMixin<int> { | 2387 class Test extends IterableMixin<int> { |
| 2388 } | 2388 } |
| 2389 '''); | 2389 '''); |
| 2390 await assertHasFix( | 2390 await assertHasFix( |
| 2391 DartFixKind.CREATE_MISSING_OVERRIDES, | 2391 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2392 ''' | 2392 ''' |
| 2393 class Iterator<T> { | 2393 class Iterator<T> { |
| 2394 } | 2394 } |
| 2395 | 2395 |
| 2396 abstract class IterableMixin<T> { | 2396 abstract class IterableMixin<T> { |
| 2397 Iterator<T> get iterator; | 2397 Iterator<T> get iterator; |
| 2398 } | 2398 } |
| 2399 | 2399 |
| 2400 class Test extends IterableMixin<int> { | 2400 class Test extends IterableMixin<int> { |
| 2401 // TODO: implement iterator | 2401 // TODO: implement iterator |
| 2402 @override | 2402 @override |
| 2403 Iterator<int> get iterator => null; | 2403 Iterator<int> get iterator => null; |
| 2404 } | 2404 } |
| 2405 '''); | 2405 '''); |
| 2406 } | 2406 } |
| 2407 | 2407 |
| 2408 test_createMissingOverrides_generics_typeParameters() async { | 2408 test_createMissingOverrides_generics_typeParameters() async { |
| 2409 resolveTestUnit(''' | 2409 await resolveTestUnit(''' |
| 2410 abstract class ItemProvider<T> { | 2410 abstract class ItemProvider<T> { |
| 2411 List<T> getItems(); | 2411 List<T> getItems(); |
| 2412 } | 2412 } |
| 2413 | 2413 |
| 2414 class Test<V> extends ItemProvider<V> { | 2414 class Test<V> extends ItemProvider<V> { |
| 2415 } | 2415 } |
| 2416 '''); | 2416 '''); |
| 2417 await assertHasFix( | 2417 await assertHasFix( |
| 2418 DartFixKind.CREATE_MISSING_OVERRIDES, | 2418 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2419 ''' | 2419 ''' |
| 2420 abstract class ItemProvider<T> { | 2420 abstract class ItemProvider<T> { |
| 2421 List<T> getItems(); | 2421 List<T> getItems(); |
| 2422 } | 2422 } |
| 2423 | 2423 |
| 2424 class Test<V> extends ItemProvider<V> { | 2424 class Test<V> extends ItemProvider<V> { |
| 2425 @override | 2425 @override |
| 2426 List<V> getItems() { | 2426 List<V> getItems() { |
| 2427 // TODO: implement getItems | 2427 // TODO: implement getItems |
| 2428 } | 2428 } |
| 2429 } | 2429 } |
| 2430 '''); | 2430 '''); |
| 2431 } | 2431 } |
| 2432 | 2432 |
| 2433 test_createMissingOverrides_getter() async { | 2433 test_createMissingOverrides_getter() async { |
| 2434 resolveTestUnit(''' | 2434 await resolveTestUnit(''' |
| 2435 abstract class A { | 2435 abstract class A { |
| 2436 get g1; | 2436 get g1; |
| 2437 int get g2; | 2437 int get g2; |
| 2438 } | 2438 } |
| 2439 | 2439 |
| 2440 class B extends A { | 2440 class B extends A { |
| 2441 } | 2441 } |
| 2442 '''); | 2442 '''); |
| 2443 await assertHasFix( | 2443 await assertHasFix( |
| 2444 DartFixKind.CREATE_MISSING_OVERRIDES, | 2444 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2445 ''' | 2445 ''' |
| 2446 abstract class A { | 2446 abstract class A { |
| 2447 get g1; | 2447 get g1; |
| 2448 int get g2; | 2448 int get g2; |
| 2449 } | 2449 } |
| 2450 | 2450 |
| 2451 class B extends A { | 2451 class B extends A { |
| 2452 // TODO: implement g1 | 2452 // TODO: implement g1 |
| 2453 @override | 2453 @override |
| 2454 get g1 => null; | 2454 get g1 => null; |
| 2455 | 2455 |
| 2456 // TODO: implement g2 | 2456 // TODO: implement g2 |
| 2457 @override | 2457 @override |
| 2458 int get g2 => null; | 2458 int get g2 => null; |
| 2459 } | 2459 } |
| 2460 '''); | 2460 '''); |
| 2461 } | 2461 } |
| 2462 | 2462 |
| 2463 test_createMissingOverrides_importPrefix() async { | 2463 test_createMissingOverrides_importPrefix() async { |
| 2464 resolveTestUnit(''' | 2464 await resolveTestUnit(''' |
| 2465 import 'dart:async' as aaa; | 2465 import 'dart:async' as aaa; |
| 2466 abstract class A { | 2466 abstract class A { |
| 2467 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2467 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
| 2468 } | 2468 } |
| 2469 | 2469 |
| 2470 class B extends A { | 2470 class B extends A { |
| 2471 } | 2471 } |
| 2472 '''); | 2472 '''); |
| 2473 await assertHasFix( | 2473 await assertHasFix( |
| 2474 DartFixKind.CREATE_MISSING_OVERRIDES, | 2474 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2475 ''' | 2475 ''' |
| 2476 import 'dart:async' as aaa; | 2476 import 'dart:async' as aaa; |
| 2477 abstract class A { | 2477 abstract class A { |
| 2478 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2478 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
| 2479 } | 2479 } |
| 2480 | 2480 |
| 2481 class B extends A { | 2481 class B extends A { |
| 2482 @override | 2482 @override |
| 2483 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { | 2483 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { |
| 2484 // TODO: implement g | 2484 // TODO: implement g |
| 2485 } | 2485 } |
| 2486 } | 2486 } |
| 2487 '''); | 2487 '''); |
| 2488 } | 2488 } |
| 2489 | 2489 |
| 2490 test_createMissingOverrides_mergeToField_getterSetter() async { | 2490 test_createMissingOverrides_mergeToField_getterSetter() async { |
| 2491 resolveTestUnit(''' | 2491 await resolveTestUnit(''' |
| 2492 class A { | 2492 class A { |
| 2493 int ma; | 2493 int ma; |
| 2494 void mb() {} | 2494 void mb() {} |
| 2495 double mc; | 2495 double mc; |
| 2496 } | 2496 } |
| 2497 | 2497 |
| 2498 class B implements A { | 2498 class B implements A { |
| 2499 } | 2499 } |
| 2500 '''); | 2500 '''); |
| 2501 await assertHasFix( | 2501 await assertHasFix( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2516 | 2516 |
| 2517 @override | 2517 @override |
| 2518 void mb() { | 2518 void mb() { |
| 2519 // TODO: implement mb | 2519 // TODO: implement mb |
| 2520 } | 2520 } |
| 2521 } | 2521 } |
| 2522 '''); | 2522 '''); |
| 2523 } | 2523 } |
| 2524 | 2524 |
| 2525 test_createMissingOverrides_method() async { | 2525 test_createMissingOverrides_method() async { |
| 2526 resolveTestUnit(''' | 2526 await resolveTestUnit(''' |
| 2527 abstract class A { | 2527 abstract class A { |
| 2528 m1(); | 2528 m1(); |
| 2529 int m2(); | 2529 int m2(); |
| 2530 String m3(int p1, double p2, Map<int, List<String>> p3); | 2530 String m3(int p1, double p2, Map<int, List<String>> p3); |
| 2531 String m4(p1, p2); | 2531 String m4(p1, p2); |
| 2532 String m5(p1, [int p2 = 2, int p3, p4 = 4]); | 2532 String m5(p1, [int p2 = 2, int p3, p4 = 4]); |
| 2533 String m6(p1, {int p2: 2, int p3, p4: 4}); | 2533 String m6(p1, {int p2: 2, int p3, p4: 4}); |
| 2534 } | 2534 } |
| 2535 | 2535 |
| 2536 class B extends A { | 2536 class B extends A { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2589 expect(endString, contains('m1')); | 2589 expect(endString, contains('m1')); |
| 2590 expect(endString, isNot(contains('m2'))); | 2590 expect(endString, isNot(contains('m2'))); |
| 2591 expect(endString, isNot(contains('m3'))); | 2591 expect(endString, isNot(contains('m3'))); |
| 2592 expect(endString, isNot(contains('m4'))); | 2592 expect(endString, isNot(contains('m4'))); |
| 2593 expect(endString, isNot(contains('m5'))); | 2593 expect(endString, isNot(contains('m5'))); |
| 2594 expect(endString, isNot(contains('m6'))); | 2594 expect(endString, isNot(contains('m6'))); |
| 2595 } | 2595 } |
| 2596 } | 2596 } |
| 2597 | 2597 |
| 2598 test_createMissingOverrides_method_emptyClassBody() async { | 2598 test_createMissingOverrides_method_emptyClassBody() async { |
| 2599 resolveTestUnit(''' | 2599 await resolveTestUnit(''' |
| 2600 abstract class A { | 2600 abstract class A { |
| 2601 void foo(); | 2601 void foo(); |
| 2602 } | 2602 } |
| 2603 | 2603 |
| 2604 class B extends A {} | 2604 class B extends A {} |
| 2605 '''); | 2605 '''); |
| 2606 await assertHasFix( | 2606 await assertHasFix( |
| 2607 DartFixKind.CREATE_MISSING_OVERRIDES, | 2607 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2608 ''' | 2608 ''' |
| 2609 abstract class A { | 2609 abstract class A { |
| 2610 void foo(); | 2610 void foo(); |
| 2611 } | 2611 } |
| 2612 | 2612 |
| 2613 class B extends A { | 2613 class B extends A { |
| 2614 @override | 2614 @override |
| 2615 void foo() { | 2615 void foo() { |
| 2616 // TODO: implement foo | 2616 // TODO: implement foo |
| 2617 } | 2617 } |
| 2618 } | 2618 } |
| 2619 '''); | 2619 '''); |
| 2620 } | 2620 } |
| 2621 | 2621 |
| 2622 test_createMissingOverrides_method_generic() async { | 2622 test_createMissingOverrides_method_generic() async { |
| 2623 resolveTestUnit(''' | 2623 await resolveTestUnit(''' |
| 2624 class C<T> {} | 2624 class C<T> {} |
| 2625 class V<E> {} | 2625 class V<E> {} |
| 2626 | 2626 |
| 2627 abstract class A { | 2627 abstract class A { |
| 2628 E1 foo<E1, E2 extends C<int>>(V<E2> v); | 2628 E1 foo<E1, E2 extends C<int>>(V<E2> v); |
| 2629 } | 2629 } |
| 2630 | 2630 |
| 2631 class B implements A { | 2631 class B implements A { |
| 2632 } | 2632 } |
| 2633 '''); | 2633 '''); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2644 class B implements A { | 2644 class B implements A { |
| 2645 @override | 2645 @override |
| 2646 E1 foo<E1, E2 extends C<int>>(V<E2> v) { | 2646 E1 foo<E1, E2 extends C<int>>(V<E2> v) { |
| 2647 // TODO: implement foo | 2647 // TODO: implement foo |
| 2648 } | 2648 } |
| 2649 } | 2649 } |
| 2650 '''); | 2650 '''); |
| 2651 } | 2651 } |
| 2652 | 2652 |
| 2653 test_createMissingOverrides_operator() async { | 2653 test_createMissingOverrides_operator() async { |
| 2654 resolveTestUnit(''' | 2654 await resolveTestUnit(''' |
| 2655 abstract class A { | 2655 abstract class A { |
| 2656 int operator [](int index); | 2656 int operator [](int index); |
| 2657 void operator []=(int index, String value); | 2657 void operator []=(int index, String value); |
| 2658 } | 2658 } |
| 2659 | 2659 |
| 2660 class B extends A { | 2660 class B extends A { |
| 2661 } | 2661 } |
| 2662 '''); | 2662 '''); |
| 2663 await assertHasFix( | 2663 await assertHasFix( |
| 2664 DartFixKind.CREATE_MISSING_OVERRIDES, | 2664 DartFixKind.CREATE_MISSING_OVERRIDES, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2676 | 2676 |
| 2677 @override | 2677 @override |
| 2678 void operator []=(int index, String value) { | 2678 void operator []=(int index, String value) { |
| 2679 // TODO: implement []= | 2679 // TODO: implement []= |
| 2680 } | 2680 } |
| 2681 } | 2681 } |
| 2682 '''); | 2682 '''); |
| 2683 } | 2683 } |
| 2684 | 2684 |
| 2685 test_createMissingOverrides_setter() async { | 2685 test_createMissingOverrides_setter() async { |
| 2686 resolveTestUnit(''' | 2686 await resolveTestUnit(''' |
| 2687 abstract class A { | 2687 abstract class A { |
| 2688 set s1(x); | 2688 set s1(x); |
| 2689 set s2(int x); | 2689 set s2(int x); |
| 2690 void set s3(String x); | 2690 void set s3(String x); |
| 2691 } | 2691 } |
| 2692 | 2692 |
| 2693 class B extends A { | 2693 class B extends A { |
| 2694 } | 2694 } |
| 2695 '''); | 2695 '''); |
| 2696 await assertHasFix( | 2696 await assertHasFix( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2715 | 2715 |
| 2716 @override | 2716 @override |
| 2717 set s3(String x) { | 2717 set s3(String x) { |
| 2718 // TODO: implement s3 | 2718 // TODO: implement s3 |
| 2719 } | 2719 } |
| 2720 } | 2720 } |
| 2721 '''); | 2721 '''); |
| 2722 } | 2722 } |
| 2723 | 2723 |
| 2724 test_createNoSuchMethod() async { | 2724 test_createNoSuchMethod() async { |
| 2725 resolveTestUnit(''' | 2725 await resolveTestUnit(''' |
| 2726 abstract class A { | 2726 abstract class A { |
| 2727 m1(); | 2727 m1(); |
| 2728 int m2(); | 2728 int m2(); |
| 2729 } | 2729 } |
| 2730 | 2730 |
| 2731 class B extends A { | 2731 class B extends A { |
| 2732 existing() {} | 2732 existing() {} |
| 2733 } | 2733 } |
| 2734 '''); | 2734 '''); |
| 2735 await assertHasFix( | 2735 await assertHasFix( |
| 2736 DartFixKind.CREATE_NO_SUCH_METHOD, | 2736 DartFixKind.CREATE_NO_SUCH_METHOD, |
| 2737 ''' | 2737 ''' |
| 2738 abstract class A { | 2738 abstract class A { |
| 2739 m1(); | 2739 m1(); |
| 2740 int m2(); | 2740 int m2(); |
| 2741 } | 2741 } |
| 2742 | 2742 |
| 2743 class B extends A { | 2743 class B extends A { |
| 2744 existing() {} | 2744 existing() {} |
| 2745 | 2745 |
| 2746 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2746 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2747 } | 2747 } |
| 2748 '''); | 2748 '''); |
| 2749 } | 2749 } |
| 2750 | 2750 |
| 2751 test_creationFunction_forFunctionType_cascadeSecond() async { | 2751 test_creationFunction_forFunctionType_cascadeSecond() async { |
| 2752 resolveTestUnit(''' | 2752 await resolveTestUnit(''' |
| 2753 class A { | 2753 class A { |
| 2754 B ma() => null; | 2754 B ma() => null; |
| 2755 } | 2755 } |
| 2756 class B { | 2756 class B { |
| 2757 useFunction(int g(double a, String b)) {} | 2757 useFunction(int g(double a, String b)) {} |
| 2758 } | 2758 } |
| 2759 | 2759 |
| 2760 main() { | 2760 main() { |
| 2761 A a = new A(); | 2761 A a = new A(); |
| 2762 a..ma().useFunction(test); | 2762 a..ma().useFunction(test); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2776 A a = new A(); | 2776 A a = new A(); |
| 2777 a..ma().useFunction(test); | 2777 a..ma().useFunction(test); |
| 2778 } | 2778 } |
| 2779 | 2779 |
| 2780 int test(double a, String b) { | 2780 int test(double a, String b) { |
| 2781 } | 2781 } |
| 2782 '''); | 2782 '''); |
| 2783 } | 2783 } |
| 2784 | 2784 |
| 2785 test_creationFunction_forFunctionType_coreFunction() async { | 2785 test_creationFunction_forFunctionType_coreFunction() async { |
| 2786 resolveTestUnit(''' | 2786 await resolveTestUnit(''' |
| 2787 main() { | 2787 main() { |
| 2788 useFunction(g: test); | 2788 useFunction(g: test); |
| 2789 } | 2789 } |
| 2790 useFunction({Function g}) {} | 2790 useFunction({Function g}) {} |
| 2791 '''); | 2791 '''); |
| 2792 await assertHasFix( | 2792 await assertHasFix( |
| 2793 DartFixKind.CREATE_FUNCTION, | 2793 DartFixKind.CREATE_FUNCTION, |
| 2794 ''' | 2794 ''' |
| 2795 main() { | 2795 main() { |
| 2796 useFunction(g: test); | 2796 useFunction(g: test); |
| 2797 } | 2797 } |
| 2798 useFunction({Function g}) {} | 2798 useFunction({Function g}) {} |
| 2799 | 2799 |
| 2800 test() { | 2800 test() { |
| 2801 } | 2801 } |
| 2802 '''); | 2802 '''); |
| 2803 } | 2803 } |
| 2804 | 2804 |
| 2805 test_creationFunction_forFunctionType_dynamicArgument() async { | 2805 test_creationFunction_forFunctionType_dynamicArgument() async { |
| 2806 resolveTestUnit(''' | 2806 await resolveTestUnit(''' |
| 2807 main() { | 2807 main() { |
| 2808 useFunction(test); | 2808 useFunction(test); |
| 2809 } | 2809 } |
| 2810 useFunction(int g(a, b)) {} | 2810 useFunction(int g(a, b)) {} |
| 2811 '''); | 2811 '''); |
| 2812 await assertHasFix( | 2812 await assertHasFix( |
| 2813 DartFixKind.CREATE_FUNCTION, | 2813 DartFixKind.CREATE_FUNCTION, |
| 2814 ''' | 2814 ''' |
| 2815 main() { | 2815 main() { |
| 2816 useFunction(test); | 2816 useFunction(test); |
| 2817 } | 2817 } |
| 2818 useFunction(int g(a, b)) {} | 2818 useFunction(int g(a, b)) {} |
| 2819 | 2819 |
| 2820 int test(a, b) { | 2820 int test(a, b) { |
| 2821 } | 2821 } |
| 2822 '''); | 2822 '''); |
| 2823 } | 2823 } |
| 2824 | 2824 |
| 2825 test_creationFunction_forFunctionType_function() async { | 2825 test_creationFunction_forFunctionType_function() async { |
| 2826 resolveTestUnit(''' | 2826 await resolveTestUnit(''' |
| 2827 main() { | 2827 main() { |
| 2828 useFunction(test); | 2828 useFunction(test); |
| 2829 } | 2829 } |
| 2830 useFunction(int g(double a, String b)) {} | 2830 useFunction(int g(double a, String b)) {} |
| 2831 '''); | 2831 '''); |
| 2832 await assertHasFix( | 2832 await assertHasFix( |
| 2833 DartFixKind.CREATE_FUNCTION, | 2833 DartFixKind.CREATE_FUNCTION, |
| 2834 ''' | 2834 ''' |
| 2835 main() { | 2835 main() { |
| 2836 useFunction(test); | 2836 useFunction(test); |
| 2837 } | 2837 } |
| 2838 useFunction(int g(double a, String b)) {} | 2838 useFunction(int g(double a, String b)) {} |
| 2839 | 2839 |
| 2840 int test(double a, String b) { | 2840 int test(double a, String b) { |
| 2841 } | 2841 } |
| 2842 '''); | 2842 '''); |
| 2843 } | 2843 } |
| 2844 | 2844 |
| 2845 test_creationFunction_forFunctionType_function_namedArgument() async { | 2845 test_creationFunction_forFunctionType_function_namedArgument() async { |
| 2846 resolveTestUnit(''' | 2846 await resolveTestUnit(''' |
| 2847 main() { | 2847 main() { |
| 2848 useFunction(g: test); | 2848 useFunction(g: test); |
| 2849 } | 2849 } |
| 2850 useFunction({int g(double a, String b)}) {} | 2850 useFunction({int g(double a, String b)}) {} |
| 2851 '''); | 2851 '''); |
| 2852 await assertHasFix( | 2852 await assertHasFix( |
| 2853 DartFixKind.CREATE_FUNCTION, | 2853 DartFixKind.CREATE_FUNCTION, |
| 2854 ''' | 2854 ''' |
| 2855 main() { | 2855 main() { |
| 2856 useFunction(g: test); | 2856 useFunction(g: test); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2869 library libA; | 2869 library libA; |
| 2870 class A {} | 2870 class A {} |
| 2871 '''); | 2871 '''); |
| 2872 addSource( | 2872 addSource( |
| 2873 '/libB.dart', | 2873 '/libB.dart', |
| 2874 r''' | 2874 r''' |
| 2875 library libB; | 2875 library libB; |
| 2876 import 'libA.dart'; | 2876 import 'libA.dart'; |
| 2877 useFunction(int g(A a)) {} | 2877 useFunction(int g(A a)) {} |
| 2878 '''); | 2878 '''); |
| 2879 resolveTestUnit(''' | 2879 await resolveTestUnit(''' |
| 2880 import 'libB.dart'; | 2880 import 'libB.dart'; |
| 2881 main() { | 2881 main() { |
| 2882 useFunction(test); | 2882 useFunction(test); |
| 2883 } | 2883 } |
| 2884 '''); | 2884 '''); |
| 2885 await assertHasFix( | 2885 await assertHasFix( |
| 2886 DartFixKind.CREATE_FUNCTION, | 2886 DartFixKind.CREATE_FUNCTION, |
| 2887 ''' | 2887 ''' |
| 2888 import 'libA.dart'; | 2888 import 'libA.dart'; |
| 2889 import 'libB.dart'; | 2889 import 'libB.dart'; |
| 2890 main() { | 2890 main() { |
| 2891 useFunction(test); | 2891 useFunction(test); |
| 2892 } | 2892 } |
| 2893 | 2893 |
| 2894 int test(A a) { | 2894 int test(A a) { |
| 2895 } | 2895 } |
| 2896 '''); | 2896 '''); |
| 2897 } | 2897 } |
| 2898 | 2898 |
| 2899 test_creationFunction_forFunctionType_method_enclosingClass_static() async { | 2899 test_creationFunction_forFunctionType_method_enclosingClass_static() async { |
| 2900 resolveTestUnit(''' | 2900 await resolveTestUnit(''' |
| 2901 class A { | 2901 class A { |
| 2902 static foo() { | 2902 static foo() { |
| 2903 useFunction(test); | 2903 useFunction(test); |
| 2904 } | 2904 } |
| 2905 } | 2905 } |
| 2906 useFunction(int g(double a, String b)) {} | 2906 useFunction(int g(double a, String b)) {} |
| 2907 '''); | 2907 '''); |
| 2908 await assertHasFix( | 2908 await assertHasFix( |
| 2909 DartFixKind.CREATE_METHOD, | 2909 DartFixKind.CREATE_METHOD, |
| 2910 ''' | 2910 ''' |
| 2911 class A { | 2911 class A { |
| 2912 static foo() { | 2912 static foo() { |
| 2913 useFunction(test); | 2913 useFunction(test); |
| 2914 } | 2914 } |
| 2915 | 2915 |
| 2916 static int test(double a, String b) { | 2916 static int test(double a, String b) { |
| 2917 } | 2917 } |
| 2918 } | 2918 } |
| 2919 useFunction(int g(double a, String b)) {} | 2919 useFunction(int g(double a, String b)) {} |
| 2920 '''); | 2920 '''); |
| 2921 } | 2921 } |
| 2922 | 2922 |
| 2923 test_creationFunction_forFunctionType_method_enclosingClass_static2() async { | 2923 test_creationFunction_forFunctionType_method_enclosingClass_static2() async { |
| 2924 resolveTestUnit(''' | 2924 await resolveTestUnit(''' |
| 2925 class A { | 2925 class A { |
| 2926 var f; | 2926 var f; |
| 2927 A() : f = useFunction(test); | 2927 A() : f = useFunction(test); |
| 2928 } | 2928 } |
| 2929 useFunction(int g(double a, String b)) {} | 2929 useFunction(int g(double a, String b)) {} |
| 2930 '''); | 2930 '''); |
| 2931 await assertHasFix( | 2931 await assertHasFix( |
| 2932 DartFixKind.CREATE_METHOD, | 2932 DartFixKind.CREATE_METHOD, |
| 2933 ''' | 2933 ''' |
| 2934 class A { | 2934 class A { |
| 2935 var f; | 2935 var f; |
| 2936 A() : f = useFunction(test); | 2936 A() : f = useFunction(test); |
| 2937 | 2937 |
| 2938 static int test(double a, String b) { | 2938 static int test(double a, String b) { |
| 2939 } | 2939 } |
| 2940 } | 2940 } |
| 2941 useFunction(int g(double a, String b)) {} | 2941 useFunction(int g(double a, String b)) {} |
| 2942 '''); | 2942 '''); |
| 2943 } | 2943 } |
| 2944 | 2944 |
| 2945 test_creationFunction_forFunctionType_method_targetClass() async { | 2945 test_creationFunction_forFunctionType_method_targetClass() async { |
| 2946 resolveTestUnit(''' | 2946 await resolveTestUnit(''' |
| 2947 main(A a) { | 2947 main(A a) { |
| 2948 useFunction(a.test); | 2948 useFunction(a.test); |
| 2949 } | 2949 } |
| 2950 class A { | 2950 class A { |
| 2951 } | 2951 } |
| 2952 useFunction(int g(double a, String b)) {} | 2952 useFunction(int g(double a, String b)) {} |
| 2953 '''); | 2953 '''); |
| 2954 await assertHasFix( | 2954 await assertHasFix( |
| 2955 DartFixKind.CREATE_METHOD, | 2955 DartFixKind.CREATE_METHOD, |
| 2956 ''' | 2956 ''' |
| 2957 main(A a) { | 2957 main(A a) { |
| 2958 useFunction(a.test); | 2958 useFunction(a.test); |
| 2959 } | 2959 } |
| 2960 class A { | 2960 class A { |
| 2961 int test(double a, String b) { | 2961 int test(double a, String b) { |
| 2962 } | 2962 } |
| 2963 } | 2963 } |
| 2964 useFunction(int g(double a, String b)) {} | 2964 useFunction(int g(double a, String b)) {} |
| 2965 '''); | 2965 '''); |
| 2966 } | 2966 } |
| 2967 | 2967 |
| 2968 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() asyn
c { | 2968 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() asyn
c { |
| 2969 resolveTestUnit(''' | 2969 await resolveTestUnit(''' |
| 2970 main(A a) { | 2970 main(A a) { |
| 2971 useFunction(a.test); | 2971 useFunction(a.test); |
| 2972 } | 2972 } |
| 2973 class A { | 2973 class A { |
| 2974 m() {} | 2974 m() {} |
| 2975 } | 2975 } |
| 2976 useFunction(int g(double a, String b)) {} | 2976 useFunction(int g(double a, String b)) {} |
| 2977 '''); | 2977 '''); |
| 2978 await assertHasFix( | 2978 await assertHasFix( |
| 2979 DartFixKind.CREATE_METHOD, | 2979 DartFixKind.CREATE_METHOD, |
| 2980 ''' | 2980 ''' |
| 2981 main(A a) { | 2981 main(A a) { |
| 2982 useFunction(a.test); | 2982 useFunction(a.test); |
| 2983 } | 2983 } |
| 2984 class A { | 2984 class A { |
| 2985 m() {} | 2985 m() {} |
| 2986 | 2986 |
| 2987 int test(double a, String b) { | 2987 int test(double a, String b) { |
| 2988 } | 2988 } |
| 2989 } | 2989 } |
| 2990 useFunction(int g(double a, String b)) {} | 2990 useFunction(int g(double a, String b)) {} |
| 2991 '''); | 2991 '''); |
| 2992 } | 2992 } |
| 2993 | 2993 |
| 2994 test_creationFunction_forFunctionType_notFunctionType() async { | 2994 test_creationFunction_forFunctionType_notFunctionType() async { |
| 2995 resolveTestUnit(''' | 2995 await resolveTestUnit(''' |
| 2996 main(A a) { | 2996 main(A a) { |
| 2997 useFunction(a.test); | 2997 useFunction(a.test); |
| 2998 } | 2998 } |
| 2999 typedef A(); | 2999 typedef A(); |
| 3000 useFunction(g) {} | 3000 useFunction(g) {} |
| 3001 '''); | 3001 '''); |
| 3002 await assertNoFix(DartFixKind.CREATE_METHOD); | 3002 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 3003 await assertNoFix(DartFixKind.CREATE_FUNCTION); | 3003 await assertNoFix(DartFixKind.CREATE_FUNCTION); |
| 3004 } | 3004 } |
| 3005 | 3005 |
| 3006 test_creationFunction_forFunctionType_unknownTarget() async { | 3006 test_creationFunction_forFunctionType_unknownTarget() async { |
| 3007 resolveTestUnit(''' | 3007 await resolveTestUnit(''' |
| 3008 main(A a) { | 3008 main(A a) { |
| 3009 useFunction(a.test); | 3009 useFunction(a.test); |
| 3010 } | 3010 } |
| 3011 class A { | 3011 class A { |
| 3012 } | 3012 } |
| 3013 useFunction(g) {} | 3013 useFunction(g) {} |
| 3014 '''); | 3014 '''); |
| 3015 await assertNoFix(DartFixKind.CREATE_METHOD); | 3015 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 3016 } | 3016 } |
| 3017 | 3017 |
| 3018 test_expectedToken_semicolon() async { | 3018 test_expectedToken_semicolon() async { |
| 3019 resolveTestUnit(''' | 3019 await resolveTestUnit(''' |
| 3020 main() { | 3020 main() { |
| 3021 print(0) | 3021 print(0) |
| 3022 } | 3022 } |
| 3023 '''); | 3023 '''); |
| 3024 await assertHasFix( | 3024 await assertHasFix( |
| 3025 DartFixKind.INSERT_SEMICOLON, | 3025 DartFixKind.INSERT_SEMICOLON, |
| 3026 ''' | 3026 ''' |
| 3027 main() { | 3027 main() { |
| 3028 print(0); | 3028 print(0); |
| 3029 } | 3029 } |
| 3030 '''); | 3030 '''); |
| 3031 } | 3031 } |
| 3032 | 3032 |
| 3033 test_illegalAsyncReturnType_adjacentNodes() async { | 3033 test_illegalAsyncReturnType_adjacentNodes() async { |
| 3034 errorFilter = (AnalysisError error) { | 3034 errorFilter = (AnalysisError error) { |
| 3035 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3035 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 3036 }; | 3036 }; |
| 3037 resolveTestUnit(''' | 3037 await resolveTestUnit(''' |
| 3038 import 'dart:async'; | 3038 import 'dart:async'; |
| 3039 var v;int main() async => 0; | 3039 var v;int main() async => 0; |
| 3040 '''); | 3040 '''); |
| 3041 await assertHasFix( | 3041 await assertHasFix( |
| 3042 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 3042 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 3043 ''' | 3043 ''' |
| 3044 import 'dart:async'; | 3044 import 'dart:async'; |
| 3045 var v;Future<int> main() async => 0; | 3045 var v;Future<int> main() async => 0; |
| 3046 '''); | 3046 '''); |
| 3047 } | 3047 } |
| 3048 | 3048 |
| 3049 test_illegalAsyncReturnType_asyncLibrary_import() async { | 3049 test_illegalAsyncReturnType_asyncLibrary_import() async { |
| 3050 errorFilter = (AnalysisError error) { | 3050 errorFilter = (AnalysisError error) { |
| 3051 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3051 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 3052 }; | 3052 }; |
| 3053 resolveTestUnit(''' | 3053 await resolveTestUnit(''' |
| 3054 library main; | 3054 library main; |
| 3055 int main() async { | 3055 int main() async { |
| 3056 } | 3056 } |
| 3057 '''); | 3057 '''); |
| 3058 await assertHasFix( | 3058 await assertHasFix( |
| 3059 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 3059 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 3060 ''' | 3060 ''' |
| 3061 library main; | 3061 library main; |
| 3062 | 3062 |
| 3063 import 'dart:async'; | 3063 import 'dart:async'; |
| 3064 Future<int> main() async { | 3064 Future<int> main() async { |
| 3065 } | 3065 } |
| 3066 '''); | 3066 '''); |
| 3067 } | 3067 } |
| 3068 | 3068 |
| 3069 test_illegalAsyncReturnType_asyncLibrary_usePrefix() async { | 3069 test_illegalAsyncReturnType_asyncLibrary_usePrefix() async { |
| 3070 errorFilter = (AnalysisError error) { | 3070 errorFilter = (AnalysisError error) { |
| 3071 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3071 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 3072 }; | 3072 }; |
| 3073 resolveTestUnit(''' | 3073 await resolveTestUnit(''' |
| 3074 import 'dart:async' as al; | 3074 import 'dart:async' as al; |
| 3075 int main() async { | 3075 int main() async { |
| 3076 } | 3076 } |
| 3077 '''); | 3077 '''); |
| 3078 await assertHasFix( | 3078 await assertHasFix( |
| 3079 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 3079 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 3080 ''' | 3080 ''' |
| 3081 import 'dart:async' as al; | 3081 import 'dart:async' as al; |
| 3082 al.Future<int> main() async { | 3082 al.Future<int> main() async { |
| 3083 } | 3083 } |
| 3084 '''); | 3084 '''); |
| 3085 } | 3085 } |
| 3086 | 3086 |
| 3087 test_illegalAsyncReturnType_complexTypeName() async { | 3087 test_illegalAsyncReturnType_complexTypeName() async { |
| 3088 errorFilter = (AnalysisError error) { | 3088 errorFilter = (AnalysisError error) { |
| 3089 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3089 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 3090 }; | 3090 }; |
| 3091 resolveTestUnit(''' | 3091 await resolveTestUnit(''' |
| 3092 import 'dart:async'; | 3092 import 'dart:async'; |
| 3093 List<int> main() async { | 3093 List<int> main() async { |
| 3094 } | 3094 } |
| 3095 '''); | 3095 '''); |
| 3096 await assertHasFix( | 3096 await assertHasFix( |
| 3097 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 3097 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 3098 ''' | 3098 ''' |
| 3099 import 'dart:async'; | 3099 import 'dart:async'; |
| 3100 Future<List<int>> main() async { | 3100 Future<List<int>> main() async { |
| 3101 } | 3101 } |
| 3102 '''); | 3102 '''); |
| 3103 } | 3103 } |
| 3104 | 3104 |
| 3105 test_illegalAsyncReturnType_void() async { | 3105 test_illegalAsyncReturnType_void() async { |
| 3106 errorFilter = (AnalysisError error) { | 3106 errorFilter = (AnalysisError error) { |
| 3107 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 3107 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 3108 }; | 3108 }; |
| 3109 resolveTestUnit(''' | 3109 await resolveTestUnit(''' |
| 3110 import 'dart:async'; | 3110 import 'dart:async'; |
| 3111 void main() async { | 3111 void main() async { |
| 3112 } | 3112 } |
| 3113 '''); | 3113 '''); |
| 3114 await assertHasFix( | 3114 await assertHasFix( |
| 3115 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 3115 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 3116 ''' | 3116 ''' |
| 3117 import 'dart:async'; | 3117 import 'dart:async'; |
| 3118 Future main() async { | 3118 Future main() async { |
| 3119 } | 3119 } |
| 3120 '''); | 3120 '''); |
| 3121 } | 3121 } |
| 3122 | 3122 |
| 3123 test_importLibraryPackage_preferDirectOverExport() async { | 3123 test_importLibraryPackage_preferDirectOverExport() async { |
| 3124 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); | 3124 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
| 3125 resolveTestUnit(''' | 3125 await resolveTestUnit(''' |
| 3126 main() { | 3126 main() { |
| 3127 Test test = null; | 3127 Test test = null; |
| 3128 } | 3128 } |
| 3129 '''); | 3129 '''); |
| 3130 performAllAnalysisTasks(); | 3130 performAllAnalysisTasks(); |
| 3131 await assertHasFix( | 3131 await assertHasFix( |
| 3132 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3132 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3133 ''' | 3133 ''' |
| 3134 import 'package:my_pkg/b.dart'; | 3134 import 'package:my_pkg/b.dart'; |
| 3135 | 3135 |
| 3136 main() { | 3136 main() { |
| 3137 Test test = null; | 3137 Test test = null; |
| 3138 } | 3138 } |
| 3139 '''); | 3139 '''); |
| 3140 await assertHasFix( | 3140 await assertHasFix( |
| 3141 DartFixKind.IMPORT_LIBRARY_PROJECT2, | 3141 DartFixKind.IMPORT_LIBRARY_PROJECT2, |
| 3142 ''' | 3142 ''' |
| 3143 import 'package:my_pkg/a.dart'; | 3143 import 'package:my_pkg/a.dart'; |
| 3144 | 3144 |
| 3145 main() { | 3145 main() { |
| 3146 Test test = null; | 3146 Test test = null; |
| 3147 } | 3147 } |
| 3148 '''); | 3148 '''); |
| 3149 } | 3149 } |
| 3150 | 3150 |
| 3151 test_importLibraryPackage_preferDirectOverExport_src() async { | 3151 test_importLibraryPackage_preferDirectOverExport_src() async { |
| 3152 myPkgLibPath = '/my/src/packages/my_pkg/lib'; | 3152 myPkgLibPath = '/my/src/packages/my_pkg/lib'; |
| 3153 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); | 3153 _configureMyPkg({'b.dart': 'class Test {}', 'a.dart': "export 'b.dart';"}); |
| 3154 resolveTestUnit(''' | 3154 await resolveTestUnit(''' |
| 3155 main() { | 3155 main() { |
| 3156 Test test = null; | 3156 Test test = null; |
| 3157 } | 3157 } |
| 3158 '''); | 3158 '''); |
| 3159 performAllAnalysisTasks(); | 3159 performAllAnalysisTasks(); |
| 3160 await assertHasFix( | 3160 await assertHasFix( |
| 3161 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3161 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3162 ''' | 3162 ''' |
| 3163 import 'package:my_pkg/b.dart'; | 3163 import 'package:my_pkg/b.dart'; |
| 3164 | 3164 |
| 3165 main() { | 3165 main() { |
| 3166 Test test = null; | 3166 Test test = null; |
| 3167 } | 3167 } |
| 3168 '''); | 3168 '''); |
| 3169 await assertHasFix( | 3169 await assertHasFix( |
| 3170 DartFixKind.IMPORT_LIBRARY_PROJECT2, | 3170 DartFixKind.IMPORT_LIBRARY_PROJECT2, |
| 3171 ''' | 3171 ''' |
| 3172 import 'package:my_pkg/a.dart'; | 3172 import 'package:my_pkg/a.dart'; |
| 3173 | 3173 |
| 3174 main() { | 3174 main() { |
| 3175 Test test = null; | 3175 Test test = null; |
| 3176 } | 3176 } |
| 3177 '''); | 3177 '''); |
| 3178 } | 3178 } |
| 3179 | 3179 |
| 3180 test_importLibraryPackage_preferPublicOverPrivate() async { | 3180 test_importLibraryPackage_preferPublicOverPrivate() async { |
| 3181 _configureMyPkg( | 3181 _configureMyPkg( |
| 3182 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); | 3182 {'src/a.dart': 'class Test {}', 'b.dart': "export 'src/a.dart';"}); |
| 3183 resolveTestUnit(''' | 3183 await resolveTestUnit(''' |
| 3184 main() { | 3184 main() { |
| 3185 Test test = null; | 3185 Test test = null; |
| 3186 } | 3186 } |
| 3187 '''); | 3187 '''); |
| 3188 performAllAnalysisTasks(); | 3188 performAllAnalysisTasks(); |
| 3189 await assertHasFix( | 3189 await assertHasFix( |
| 3190 DartFixKind.IMPORT_LIBRARY_PROJECT2, | 3190 DartFixKind.IMPORT_LIBRARY_PROJECT2, |
| 3191 ''' | 3191 ''' |
| 3192 import 'package:my_pkg/b.dart'; | 3192 import 'package:my_pkg/b.dart'; |
| 3193 | 3193 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3208 | 3208 |
| 3209 test_importLibraryProject_withClass_annotation() async { | 3209 test_importLibraryProject_withClass_annotation() async { |
| 3210 addSource( | 3210 addSource( |
| 3211 '/lib.dart', | 3211 '/lib.dart', |
| 3212 ''' | 3212 ''' |
| 3213 library lib; | 3213 library lib; |
| 3214 class Test { | 3214 class Test { |
| 3215 const Test(int p); | 3215 const Test(int p); |
| 3216 } | 3216 } |
| 3217 '''); | 3217 '''); |
| 3218 resolveTestUnit(''' | 3218 await resolveTestUnit(''' |
| 3219 @Test(0) | 3219 @Test(0) |
| 3220 main() { | 3220 main() { |
| 3221 } | 3221 } |
| 3222 '''); | 3222 '''); |
| 3223 performAllAnalysisTasks(); | 3223 performAllAnalysisTasks(); |
| 3224 await assertHasFix( | 3224 await assertHasFix( |
| 3225 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3225 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3226 ''' | 3226 ''' |
| 3227 import 'lib.dart'; | 3227 import 'lib.dart'; |
| 3228 | 3228 |
| 3229 @Test(0) | 3229 @Test(0) |
| 3230 main() { | 3230 main() { |
| 3231 } | 3231 } |
| 3232 '''); | 3232 '''); |
| 3233 } | 3233 } |
| 3234 | 3234 |
| 3235 test_importLibraryProject_withClass_constInstanceCreation() async { | 3235 test_importLibraryProject_withClass_constInstanceCreation() async { |
| 3236 addSource( | 3236 addSource( |
| 3237 '/lib.dart', | 3237 '/lib.dart', |
| 3238 ''' | 3238 ''' |
| 3239 class Test { | 3239 class Test { |
| 3240 const Test(); | 3240 const Test(); |
| 3241 } | 3241 } |
| 3242 '''); | 3242 '''); |
| 3243 resolveTestUnit(''' | 3243 await resolveTestUnit(''' |
| 3244 main() { | 3244 main() { |
| 3245 const Test(); | 3245 const Test(); |
| 3246 } | 3246 } |
| 3247 '''); | 3247 '''); |
| 3248 performAllAnalysisTasks(); | 3248 performAllAnalysisTasks(); |
| 3249 await assertHasFix( | 3249 await assertHasFix( |
| 3250 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3250 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3251 ''' | 3251 ''' |
| 3252 import 'lib.dart'; | 3252 import 'lib.dart'; |
| 3253 | 3253 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3265 library a; | 3265 library a; |
| 3266 class One {} | 3266 class One {} |
| 3267 '''); | 3267 '''); |
| 3268 addSource( | 3268 addSource( |
| 3269 '/project/bin/b.dart', | 3269 '/project/bin/b.dart', |
| 3270 ''' | 3270 ''' |
| 3271 library b; | 3271 library b; |
| 3272 class One {} | 3272 class One {} |
| 3273 class Two {} | 3273 class Two {} |
| 3274 '''); | 3274 '''); |
| 3275 resolveTestUnit(''' | 3275 await resolveTestUnit(''' |
| 3276 import 'b.dart' show Two; | 3276 import 'b.dart' show Two; |
| 3277 main () { | 3277 main () { |
| 3278 new Two(); | 3278 new Two(); |
| 3279 new One(); | 3279 new One(); |
| 3280 } | 3280 } |
| 3281 '''); | 3281 '''); |
| 3282 performAllAnalysisTasks(); | 3282 performAllAnalysisTasks(); |
| 3283 await assertHasFix( | 3283 await assertHasFix( |
| 3284 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3284 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3285 ''' | 3285 ''' |
| 3286 import 'a.dart'; | 3286 import 'a.dart'; |
| 3287 import 'b.dart' show Two; | 3287 import 'b.dart' show Two; |
| 3288 main () { | 3288 main () { |
| 3289 new Two(); | 3289 new Two(); |
| 3290 new One(); | 3290 new One(); |
| 3291 } | 3291 } |
| 3292 '''); | 3292 '''); |
| 3293 } | 3293 } |
| 3294 | 3294 |
| 3295 test_importLibraryProject_withClass_inParentFolder() async { | 3295 test_importLibraryProject_withClass_inParentFolder() async { |
| 3296 testFile = '/project/bin/test.dart'; | 3296 testFile = '/project/bin/test.dart'; |
| 3297 addSource( | 3297 addSource( |
| 3298 '/project/lib.dart', | 3298 '/project/lib.dart', |
| 3299 ''' | 3299 ''' |
| 3300 library lib; | 3300 library lib; |
| 3301 class Test {} | 3301 class Test {} |
| 3302 '''); | 3302 '''); |
| 3303 resolveTestUnit(''' | 3303 await resolveTestUnit(''' |
| 3304 main() { | 3304 main() { |
| 3305 Test t = null; | 3305 Test t = null; |
| 3306 } | 3306 } |
| 3307 '''); | 3307 '''); |
| 3308 performAllAnalysisTasks(); | 3308 performAllAnalysisTasks(); |
| 3309 await assertHasFix( | 3309 await assertHasFix( |
| 3310 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3310 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3311 ''' | 3311 ''' |
| 3312 import '../lib.dart'; | 3312 import '../lib.dart'; |
| 3313 | 3313 |
| 3314 main() { | 3314 main() { |
| 3315 Test t = null; | 3315 Test t = null; |
| 3316 } | 3316 } |
| 3317 '''); | 3317 '''); |
| 3318 } | 3318 } |
| 3319 | 3319 |
| 3320 test_importLibraryProject_withClass_inRelativeFolder() async { | 3320 test_importLibraryProject_withClass_inRelativeFolder() async { |
| 3321 testFile = '/project/bin/test.dart'; | 3321 testFile = '/project/bin/test.dart'; |
| 3322 addSource( | 3322 addSource( |
| 3323 '/project/lib/sub/folder/lib.dart', | 3323 '/project/lib/sub/folder/lib.dart', |
| 3324 ''' | 3324 ''' |
| 3325 library lib; | 3325 library lib; |
| 3326 class Test {} | 3326 class Test {} |
| 3327 '''); | 3327 '''); |
| 3328 resolveTestUnit(''' | 3328 await resolveTestUnit(''' |
| 3329 main() { | 3329 main() { |
| 3330 Test t = null; | 3330 Test t = null; |
| 3331 } | 3331 } |
| 3332 '''); | 3332 '''); |
| 3333 performAllAnalysisTasks(); | 3333 performAllAnalysisTasks(); |
| 3334 await assertHasFix( | 3334 await assertHasFix( |
| 3335 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3335 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3336 ''' | 3336 ''' |
| 3337 import '../lib/sub/folder/lib.dart'; | 3337 import '../lib/sub/folder/lib.dart'; |
| 3338 | 3338 |
| 3339 main() { | 3339 main() { |
| 3340 Test t = null; | 3340 Test t = null; |
| 3341 } | 3341 } |
| 3342 '''); | 3342 '''); |
| 3343 } | 3343 } |
| 3344 | 3344 |
| 3345 test_importLibraryProject_withClass_inSameFolder() async { | 3345 test_importLibraryProject_withClass_inSameFolder() async { |
| 3346 testFile = '/project/bin/test.dart'; | 3346 testFile = '/project/bin/test.dart'; |
| 3347 addSource( | 3347 addSource( |
| 3348 '/project/bin/lib.dart', | 3348 '/project/bin/lib.dart', |
| 3349 ''' | 3349 ''' |
| 3350 library lib; | 3350 library lib; |
| 3351 class Test {} | 3351 class Test {} |
| 3352 '''); | 3352 '''); |
| 3353 resolveTestUnit(''' | 3353 await resolveTestUnit(''' |
| 3354 main() { | 3354 main() { |
| 3355 Test t = null; | 3355 Test t = null; |
| 3356 } | 3356 } |
| 3357 '''); | 3357 '''); |
| 3358 performAllAnalysisTasks(); | 3358 performAllAnalysisTasks(); |
| 3359 await assertHasFix( | 3359 await assertHasFix( |
| 3360 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3360 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3361 ''' | 3361 ''' |
| 3362 import 'lib.dart'; | 3362 import 'lib.dart'; |
| 3363 | 3363 |
| 3364 main() { | 3364 main() { |
| 3365 Test t = null; | 3365 Test t = null; |
| 3366 } | 3366 } |
| 3367 '''); | 3367 '''); |
| 3368 } | 3368 } |
| 3369 | 3369 |
| 3370 test_importLibraryProject_withFunction() async { | 3370 test_importLibraryProject_withFunction() async { |
| 3371 addSource( | 3371 addSource( |
| 3372 '/lib.dart', | 3372 '/lib.dart', |
| 3373 ''' | 3373 ''' |
| 3374 library lib; | 3374 library lib; |
| 3375 myFunction() {} | 3375 myFunction() {} |
| 3376 '''); | 3376 '''); |
| 3377 resolveTestUnit(''' | 3377 await resolveTestUnit(''' |
| 3378 main() { | 3378 main() { |
| 3379 myFunction(); | 3379 myFunction(); |
| 3380 } | 3380 } |
| 3381 '''); | 3381 '''); |
| 3382 performAllAnalysisTasks(); | 3382 performAllAnalysisTasks(); |
| 3383 await assertHasFix( | 3383 await assertHasFix( |
| 3384 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3384 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3385 ''' | 3385 ''' |
| 3386 import 'lib.dart'; | 3386 import 'lib.dart'; |
| 3387 | 3387 |
| 3388 main() { | 3388 main() { |
| 3389 myFunction(); | 3389 myFunction(); |
| 3390 } | 3390 } |
| 3391 '''); | 3391 '''); |
| 3392 } | 3392 } |
| 3393 | 3393 |
| 3394 test_importLibraryProject_withFunction_unresolvedMethod() async { | 3394 test_importLibraryProject_withFunction_unresolvedMethod() async { |
| 3395 addSource( | 3395 addSource( |
| 3396 '/lib.dart', | 3396 '/lib.dart', |
| 3397 ''' | 3397 ''' |
| 3398 library lib; | 3398 library lib; |
| 3399 myFunction() {} | 3399 myFunction() {} |
| 3400 '''); | 3400 '''); |
| 3401 resolveTestUnit(''' | 3401 await resolveTestUnit(''' |
| 3402 class A { | 3402 class A { |
| 3403 main() { | 3403 main() { |
| 3404 myFunction(); | 3404 myFunction(); |
| 3405 } | 3405 } |
| 3406 } | 3406 } |
| 3407 '''); | 3407 '''); |
| 3408 performAllAnalysisTasks(); | 3408 performAllAnalysisTasks(); |
| 3409 await assertHasFix( | 3409 await assertHasFix( |
| 3410 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3410 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3411 ''' | 3411 ''' |
| 3412 import 'lib.dart'; | 3412 import 'lib.dart'; |
| 3413 | 3413 |
| 3414 class A { | 3414 class A { |
| 3415 main() { | 3415 main() { |
| 3416 myFunction(); | 3416 myFunction(); |
| 3417 } | 3417 } |
| 3418 } | 3418 } |
| 3419 '''); | 3419 '''); |
| 3420 } | 3420 } |
| 3421 | 3421 |
| 3422 test_importLibraryProject_withFunctionTypeAlias() async { | 3422 test_importLibraryProject_withFunctionTypeAlias() async { |
| 3423 testFile = '/project/bin/test.dart'; | 3423 testFile = '/project/bin/test.dart'; |
| 3424 addSource( | 3424 addSource( |
| 3425 '/project/bin/lib.dart', | 3425 '/project/bin/lib.dart', |
| 3426 ''' | 3426 ''' |
| 3427 library lib; | 3427 library lib; |
| 3428 typedef MyFunction(); | 3428 typedef MyFunction(); |
| 3429 '''); | 3429 '''); |
| 3430 resolveTestUnit(''' | 3430 await resolveTestUnit(''' |
| 3431 main() { | 3431 main() { |
| 3432 MyFunction t = null; | 3432 MyFunction t = null; |
| 3433 } | 3433 } |
| 3434 '''); | 3434 '''); |
| 3435 performAllAnalysisTasks(); | 3435 performAllAnalysisTasks(); |
| 3436 await assertHasFix( | 3436 await assertHasFix( |
| 3437 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3437 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3438 ''' | 3438 ''' |
| 3439 import 'lib.dart'; | 3439 import 'lib.dart'; |
| 3440 | 3440 |
| 3441 main() { | 3441 main() { |
| 3442 MyFunction t = null; | 3442 MyFunction t = null; |
| 3443 } | 3443 } |
| 3444 '''); | 3444 '''); |
| 3445 } | 3445 } |
| 3446 | 3446 |
| 3447 test_importLibraryProject_withTopLevelVariable() async { | 3447 test_importLibraryProject_withTopLevelVariable() async { |
| 3448 addSource( | 3448 addSource( |
| 3449 '/lib.dart', | 3449 '/lib.dart', |
| 3450 ''' | 3450 ''' |
| 3451 library lib; | 3451 library lib; |
| 3452 int MY_VAR = 42; | 3452 int MY_VAR = 42; |
| 3453 '''); | 3453 '''); |
| 3454 resolveTestUnit(''' | 3454 await resolveTestUnit(''' |
| 3455 main() { | 3455 main() { |
| 3456 print(MY_VAR); | 3456 print(MY_VAR); |
| 3457 } | 3457 } |
| 3458 '''); | 3458 '''); |
| 3459 performAllAnalysisTasks(); | 3459 performAllAnalysisTasks(); |
| 3460 await assertHasFix( | 3460 await assertHasFix( |
| 3461 DartFixKind.IMPORT_LIBRARY_PROJECT1, | 3461 DartFixKind.IMPORT_LIBRARY_PROJECT1, |
| 3462 ''' | 3462 ''' |
| 3463 import 'lib.dart'; | 3463 import 'lib.dart'; |
| 3464 | 3464 |
| 3465 main() { | 3465 main() { |
| 3466 print(MY_VAR); | 3466 print(MY_VAR); |
| 3467 } | 3467 } |
| 3468 '''); | 3468 '''); |
| 3469 } | 3469 } |
| 3470 | 3470 |
| 3471 test_importLibrarySdk_withClass_AsExpression() async { | 3471 test_importLibrarySdk_withClass_AsExpression() async { |
| 3472 resolveTestUnit(''' | 3472 await resolveTestUnit(''' |
| 3473 main(p) { | 3473 main(p) { |
| 3474 p as Future; | 3474 p as Future; |
| 3475 } | 3475 } |
| 3476 '''); | 3476 '''); |
| 3477 await assertHasFix( | 3477 await assertHasFix( |
| 3478 DartFixKind.IMPORT_LIBRARY_SDK, | 3478 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3479 ''' | 3479 ''' |
| 3480 import 'dart:async'; | 3480 import 'dart:async'; |
| 3481 | 3481 |
| 3482 main(p) { | 3482 main(p) { |
| 3483 p as Future; | 3483 p as Future; |
| 3484 } | 3484 } |
| 3485 '''); | 3485 '''); |
| 3486 } | 3486 } |
| 3487 | 3487 |
| 3488 test_importLibrarySdk_withClass_invocationTarget() async { | 3488 test_importLibrarySdk_withClass_invocationTarget() async { |
| 3489 resolveTestUnit(''' | 3489 await resolveTestUnit(''' |
| 3490 main() { | 3490 main() { |
| 3491 Future.wait(null); | 3491 Future.wait(null); |
| 3492 } | 3492 } |
| 3493 '''); | 3493 '''); |
| 3494 await assertHasFix( | 3494 await assertHasFix( |
| 3495 DartFixKind.IMPORT_LIBRARY_SDK, | 3495 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3496 ''' | 3496 ''' |
| 3497 import 'dart:async'; | 3497 import 'dart:async'; |
| 3498 | 3498 |
| 3499 main() { | 3499 main() { |
| 3500 Future.wait(null); | 3500 Future.wait(null); |
| 3501 } | 3501 } |
| 3502 '''); | 3502 '''); |
| 3503 } | 3503 } |
| 3504 | 3504 |
| 3505 test_importLibrarySdk_withClass_IsExpression() async { | 3505 test_importLibrarySdk_withClass_IsExpression() async { |
| 3506 resolveTestUnit(''' | 3506 await resolveTestUnit(''' |
| 3507 main(p) { | 3507 main(p) { |
| 3508 p is Future; | 3508 p is Future; |
| 3509 } | 3509 } |
| 3510 '''); | 3510 '''); |
| 3511 await assertHasFix( | 3511 await assertHasFix( |
| 3512 DartFixKind.IMPORT_LIBRARY_SDK, | 3512 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3513 ''' | 3513 ''' |
| 3514 import 'dart:async'; | 3514 import 'dart:async'; |
| 3515 | 3515 |
| 3516 main(p) { | 3516 main(p) { |
| 3517 p is Future; | 3517 p is Future; |
| 3518 } | 3518 } |
| 3519 '''); | 3519 '''); |
| 3520 } | 3520 } |
| 3521 | 3521 |
| 3522 test_importLibrarySdk_withClass_itemOfList() async { | 3522 test_importLibrarySdk_withClass_itemOfList() async { |
| 3523 resolveTestUnit(''' | 3523 await resolveTestUnit(''' |
| 3524 main() { | 3524 main() { |
| 3525 var a = [Future]; | 3525 var a = [Future]; |
| 3526 } | 3526 } |
| 3527 '''); | 3527 '''); |
| 3528 performAllAnalysisTasks(); | 3528 performAllAnalysisTasks(); |
| 3529 await assertHasFix( | 3529 await assertHasFix( |
| 3530 DartFixKind.IMPORT_LIBRARY_SDK, | 3530 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3531 ''' | 3531 ''' |
| 3532 import 'dart:async'; | 3532 import 'dart:async'; |
| 3533 | 3533 |
| 3534 main() { | 3534 main() { |
| 3535 var a = [Future]; | 3535 var a = [Future]; |
| 3536 } | 3536 } |
| 3537 '''); | 3537 '''); |
| 3538 } | 3538 } |
| 3539 | 3539 |
| 3540 test_importLibrarySdk_withClass_itemOfList_inAnnotation() async { | 3540 test_importLibrarySdk_withClass_itemOfList_inAnnotation() async { |
| 3541 errorFilter = (AnalysisError error) { | 3541 errorFilter = (AnalysisError error) { |
| 3542 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 3542 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 3543 }; | 3543 }; |
| 3544 resolveTestUnit(''' | 3544 await resolveTestUnit(''' |
| 3545 class MyAnnotation { | 3545 class MyAnnotation { |
| 3546 const MyAnnotation(a, b); | 3546 const MyAnnotation(a, b); |
| 3547 } | 3547 } |
| 3548 @MyAnnotation(int, const [Future]) | 3548 @MyAnnotation(int, const [Future]) |
| 3549 main() {} | 3549 main() {} |
| 3550 '''); | 3550 '''); |
| 3551 await assertHasFix( | 3551 await assertHasFix( |
| 3552 DartFixKind.IMPORT_LIBRARY_SDK, | 3552 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3553 ''' | 3553 ''' |
| 3554 import 'dart:async'; | 3554 import 'dart:async'; |
| 3555 | 3555 |
| 3556 class MyAnnotation { | 3556 class MyAnnotation { |
| 3557 const MyAnnotation(a, b); | 3557 const MyAnnotation(a, b); |
| 3558 } | 3558 } |
| 3559 @MyAnnotation(int, const [Future]) | 3559 @MyAnnotation(int, const [Future]) |
| 3560 main() {} | 3560 main() {} |
| 3561 '''); | 3561 '''); |
| 3562 } | 3562 } |
| 3563 | 3563 |
| 3564 test_importLibrarySdk_withClass_typeAnnotation() async { | 3564 test_importLibrarySdk_withClass_typeAnnotation() async { |
| 3565 resolveTestUnit(''' | 3565 await resolveTestUnit(''' |
| 3566 main() { | 3566 main() { |
| 3567 Future f = null; | 3567 Future f = null; |
| 3568 } | 3568 } |
| 3569 '''); | 3569 '''); |
| 3570 await assertHasFix( | 3570 await assertHasFix( |
| 3571 DartFixKind.IMPORT_LIBRARY_SDK, | 3571 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3572 ''' | 3572 ''' |
| 3573 import 'dart:async'; | 3573 import 'dart:async'; |
| 3574 | 3574 |
| 3575 main() { | 3575 main() { |
| 3576 Future f = null; | 3576 Future f = null; |
| 3577 } | 3577 } |
| 3578 '''); | 3578 '''); |
| 3579 } | 3579 } |
| 3580 | 3580 |
| 3581 test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() async { | 3581 test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() async { |
| 3582 resolveTestUnit(''' | 3582 await resolveTestUnit(''' |
| 3583 main() { | 3583 main() { |
| 3584 Future.wait; | 3584 Future.wait; |
| 3585 } | 3585 } |
| 3586 '''); | 3586 '''); |
| 3587 await assertHasFix( | 3587 await assertHasFix( |
| 3588 DartFixKind.IMPORT_LIBRARY_SDK, | 3588 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3589 ''' | 3589 ''' |
| 3590 import 'dart:async'; | 3590 import 'dart:async'; |
| 3591 | 3591 |
| 3592 main() { | 3592 main() { |
| 3593 Future.wait; | 3593 Future.wait; |
| 3594 } | 3594 } |
| 3595 '''); | 3595 '''); |
| 3596 } | 3596 } |
| 3597 | 3597 |
| 3598 test_importLibrarySdk_withClass_typeArgument() async { | 3598 test_importLibrarySdk_withClass_typeArgument() async { |
| 3599 resolveTestUnit(''' | 3599 await resolveTestUnit(''' |
| 3600 main() { | 3600 main() { |
| 3601 List<Future> futures = []; | 3601 List<Future> futures = []; |
| 3602 } | 3602 } |
| 3603 '''); | 3603 '''); |
| 3604 await assertHasFix( | 3604 await assertHasFix( |
| 3605 DartFixKind.IMPORT_LIBRARY_SDK, | 3605 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3606 ''' | 3606 ''' |
| 3607 import 'dart:async'; | 3607 import 'dart:async'; |
| 3608 | 3608 |
| 3609 main() { | 3609 main() { |
| 3610 List<Future> futures = []; | 3610 List<Future> futures = []; |
| 3611 } | 3611 } |
| 3612 '''); | 3612 '''); |
| 3613 } | 3613 } |
| 3614 | 3614 |
| 3615 test_importLibrarySdk_withTopLevelVariable() async { | 3615 test_importLibrarySdk_withTopLevelVariable() async { |
| 3616 resolveTestUnit(''' | 3616 await resolveTestUnit(''' |
| 3617 main() { | 3617 main() { |
| 3618 print(PI); | 3618 print(PI); |
| 3619 } | 3619 } |
| 3620 '''); | 3620 '''); |
| 3621 performAllAnalysisTasks(); | 3621 performAllAnalysisTasks(); |
| 3622 await assertHasFix( | 3622 await assertHasFix( |
| 3623 DartFixKind.IMPORT_LIBRARY_SDK, | 3623 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3624 ''' | 3624 ''' |
| 3625 import 'dart:math'; | 3625 import 'dart:math'; |
| 3626 | 3626 |
| 3627 main() { | 3627 main() { |
| 3628 print(PI); | 3628 print(PI); |
| 3629 } | 3629 } |
| 3630 '''); | 3630 '''); |
| 3631 } | 3631 } |
| 3632 | 3632 |
| 3633 test_importLibrarySdk_withTopLevelVariable_annotation() async { | 3633 test_importLibrarySdk_withTopLevelVariable_annotation() async { |
| 3634 resolveTestUnit(''' | 3634 await resolveTestUnit(''' |
| 3635 @PI | 3635 @PI |
| 3636 main() { | 3636 main() { |
| 3637 } | 3637 } |
| 3638 '''); | 3638 '''); |
| 3639 performAllAnalysisTasks(); | 3639 performAllAnalysisTasks(); |
| 3640 await assertHasFix( | 3640 await assertHasFix( |
| 3641 DartFixKind.IMPORT_LIBRARY_SDK, | 3641 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3642 ''' | 3642 ''' |
| 3643 import 'dart:math'; | 3643 import 'dart:math'; |
| 3644 | 3644 |
| 3645 @PI | 3645 @PI |
| 3646 main() { | 3646 main() { |
| 3647 } | 3647 } |
| 3648 '''); | 3648 '''); |
| 3649 } | 3649 } |
| 3650 | 3650 |
| 3651 test_importLibraryShow_project() async { | 3651 test_importLibraryShow_project() async { |
| 3652 testFile = '/project/bin/test.dart'; | 3652 testFile = '/project/bin/test.dart'; |
| 3653 addSource( | 3653 addSource( |
| 3654 '/project/bin/lib.dart', | 3654 '/project/bin/lib.dart', |
| 3655 ''' | 3655 ''' |
| 3656 class A {} | 3656 class A {} |
| 3657 class B {} | 3657 class B {} |
| 3658 '''); | 3658 '''); |
| 3659 resolveTestUnit(''' | 3659 await resolveTestUnit(''' |
| 3660 import 'lib.dart' show A; | 3660 import 'lib.dart' show A; |
| 3661 main() { | 3661 main() { |
| 3662 A a; | 3662 A a; |
| 3663 B b; | 3663 B b; |
| 3664 } | 3664 } |
| 3665 '''); | 3665 '''); |
| 3666 performAllAnalysisTasks(); | 3666 performAllAnalysisTasks(); |
| 3667 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); | 3667 await assertNoFix(DartFixKind.IMPORT_LIBRARY_PROJECT1); |
| 3668 await assertHasFix( | 3668 await assertHasFix( |
| 3669 DartFixKind.IMPORT_LIBRARY_SHOW, | 3669 DartFixKind.IMPORT_LIBRARY_SHOW, |
| 3670 ''' | 3670 ''' |
| 3671 import 'lib.dart' show A, B; | 3671 import 'lib.dart' show A, B; |
| 3672 main() { | 3672 main() { |
| 3673 A a; | 3673 A a; |
| 3674 B b; | 3674 B b; |
| 3675 } | 3675 } |
| 3676 '''); | 3676 '''); |
| 3677 } | 3677 } |
| 3678 | 3678 |
| 3679 test_importLibraryShow_sdk() async { | 3679 test_importLibraryShow_sdk() async { |
| 3680 resolveTestUnit(''' | 3680 await resolveTestUnit(''' |
| 3681 import 'dart:async' show Stream; | 3681 import 'dart:async' show Stream; |
| 3682 main() { | 3682 main() { |
| 3683 Stream s = null; | 3683 Stream s = null; |
| 3684 Future f = null; | 3684 Future f = null; |
| 3685 } | 3685 } |
| 3686 '''); | 3686 '''); |
| 3687 await assertNoFix(DartFixKind.IMPORT_LIBRARY_SDK); | 3687 await assertNoFix(DartFixKind.IMPORT_LIBRARY_SDK); |
| 3688 await assertHasFix( | 3688 await assertHasFix( |
| 3689 DartFixKind.IMPORT_LIBRARY_SHOW, | 3689 DartFixKind.IMPORT_LIBRARY_SHOW, |
| 3690 ''' | 3690 ''' |
| 3691 import 'dart:async' show Future, Stream; | 3691 import 'dart:async' show Future, Stream; |
| 3692 main() { | 3692 main() { |
| 3693 Stream s = null; | 3693 Stream s = null; |
| 3694 Future f = null; | 3694 Future f = null; |
| 3695 } | 3695 } |
| 3696 '''); | 3696 '''); |
| 3697 } | 3697 } |
| 3698 | 3698 |
| 3699 test_isNotNull() async { | 3699 test_isNotNull() async { |
| 3700 resolveTestUnit(''' | 3700 await resolveTestUnit(''' |
| 3701 main(p) { | 3701 main(p) { |
| 3702 p is! Null; | 3702 p is! Null; |
| 3703 } | 3703 } |
| 3704 '''); | 3704 '''); |
| 3705 await assertHasFix( | 3705 await assertHasFix( |
| 3706 DartFixKind.USE_NOT_EQ_NULL, | 3706 DartFixKind.USE_NOT_EQ_NULL, |
| 3707 ''' | 3707 ''' |
| 3708 main(p) { | 3708 main(p) { |
| 3709 p != null; | 3709 p != null; |
| 3710 } | 3710 } |
| 3711 '''); | 3711 '''); |
| 3712 } | 3712 } |
| 3713 | 3713 |
| 3714 test_isNull() async { | 3714 test_isNull() async { |
| 3715 resolveTestUnit(''' | 3715 await resolveTestUnit(''' |
| 3716 main(p) { | 3716 main(p) { |
| 3717 p is Null; | 3717 p is Null; |
| 3718 } | 3718 } |
| 3719 '''); | 3719 '''); |
| 3720 await assertHasFix( | 3720 await assertHasFix( |
| 3721 DartFixKind.USE_EQ_EQ_NULL, | 3721 DartFixKind.USE_EQ_EQ_NULL, |
| 3722 ''' | 3722 ''' |
| 3723 main(p) { | 3723 main(p) { |
| 3724 p == null; | 3724 p == null; |
| 3725 } | 3725 } |
| 3726 '''); | 3726 '''); |
| 3727 } | 3727 } |
| 3728 | 3728 |
| 3729 test_makeEnclosingClassAbstract_declaresAbstractMethod() async { | 3729 test_makeEnclosingClassAbstract_declaresAbstractMethod() async { |
| 3730 resolveTestUnit(''' | 3730 await resolveTestUnit(''' |
| 3731 class A { | 3731 class A { |
| 3732 m(); | 3732 m(); |
| 3733 } | 3733 } |
| 3734 '''); | 3734 '''); |
| 3735 await assertHasFix( | 3735 await assertHasFix( |
| 3736 DartFixKind.MAKE_CLASS_ABSTRACT, | 3736 DartFixKind.MAKE_CLASS_ABSTRACT, |
| 3737 ''' | 3737 ''' |
| 3738 abstract class A { | 3738 abstract class A { |
| 3739 m(); | 3739 m(); |
| 3740 } | 3740 } |
| 3741 '''); | 3741 '''); |
| 3742 } | 3742 } |
| 3743 | 3743 |
| 3744 test_makeEnclosingClassAbstract_inheritsAbstractMethod() async { | 3744 test_makeEnclosingClassAbstract_inheritsAbstractMethod() async { |
| 3745 resolveTestUnit(''' | 3745 await resolveTestUnit(''' |
| 3746 abstract class A { | 3746 abstract class A { |
| 3747 m(); | 3747 m(); |
| 3748 } | 3748 } |
| 3749 class B extends A { | 3749 class B extends A { |
| 3750 } | 3750 } |
| 3751 '''); | 3751 '''); |
| 3752 await assertHasFix( | 3752 await assertHasFix( |
| 3753 DartFixKind.MAKE_CLASS_ABSTRACT, | 3753 DartFixKind.MAKE_CLASS_ABSTRACT, |
| 3754 ''' | 3754 ''' |
| 3755 abstract class A { | 3755 abstract class A { |
| 3756 m(); | 3756 m(); |
| 3757 } | 3757 } |
| 3758 abstract class B extends A { | 3758 abstract class B extends A { |
| 3759 } | 3759 } |
| 3760 '''); | 3760 '''); |
| 3761 } | 3761 } |
| 3762 | 3762 |
| 3763 test_makeFieldNotFinal_hasType() async { | 3763 test_makeFieldNotFinal_hasType() async { |
| 3764 resolveTestUnit(''' | 3764 await resolveTestUnit(''' |
| 3765 class A { | 3765 class A { |
| 3766 final int fff = 1; | 3766 final int fff = 1; |
| 3767 main() { | 3767 main() { |
| 3768 fff = 2; | 3768 fff = 2; |
| 3769 } | 3769 } |
| 3770 } | 3770 } |
| 3771 '''); | 3771 '''); |
| 3772 await assertHasFix( | 3772 await assertHasFix( |
| 3773 DartFixKind.MAKE_FIELD_NOT_FINAL, | 3773 DartFixKind.MAKE_FIELD_NOT_FINAL, |
| 3774 ''' | 3774 ''' |
| 3775 class A { | 3775 class A { |
| 3776 int fff = 1; | 3776 int fff = 1; |
| 3777 main() { | 3777 main() { |
| 3778 fff = 2; | 3778 fff = 2; |
| 3779 } | 3779 } |
| 3780 } | 3780 } |
| 3781 '''); | 3781 '''); |
| 3782 } | 3782 } |
| 3783 | 3783 |
| 3784 test_makeFieldNotFinal_noType() async { | 3784 test_makeFieldNotFinal_noType() async { |
| 3785 resolveTestUnit(''' | 3785 await resolveTestUnit(''' |
| 3786 class A { | 3786 class A { |
| 3787 final fff = 1; | 3787 final fff = 1; |
| 3788 main() { | 3788 main() { |
| 3789 fff = 2; | 3789 fff = 2; |
| 3790 } | 3790 } |
| 3791 } | 3791 } |
| 3792 '''); | 3792 '''); |
| 3793 await assertHasFix( | 3793 await assertHasFix( |
| 3794 DartFixKind.MAKE_FIELD_NOT_FINAL, | 3794 DartFixKind.MAKE_FIELD_NOT_FINAL, |
| 3795 ''' | 3795 ''' |
| 3796 class A { | 3796 class A { |
| 3797 var fff = 1; | 3797 var fff = 1; |
| 3798 main() { | 3798 main() { |
| 3799 fff = 2; | 3799 fff = 2; |
| 3800 } | 3800 } |
| 3801 } | 3801 } |
| 3802 '''); | 3802 '''); |
| 3803 } | 3803 } |
| 3804 | 3804 |
| 3805 test_noException_1() async { | 3805 test_noException_1() async { |
| 3806 resolveTestUnit(''' | 3806 await resolveTestUnit(''' |
| 3807 main(p) { | 3807 main(p) { |
| 3808 p i s Null; | 3808 p i s Null; |
| 3809 }'''); | 3809 }'''); |
| 3810 List<AnalysisError> errors = context.computeErrors(testSource); | 3810 List<AnalysisError> errors = context.computeErrors(testSource); |
| 3811 for (var error in errors) { | 3811 for (var error in errors) { |
| 3812 await _computeFixes(error); | 3812 await _computeFixes(error); |
| 3813 } | 3813 } |
| 3814 } | 3814 } |
| 3815 | 3815 |
| 3816 test_nonBoolCondition_addNotNull() async { | 3816 test_nonBoolCondition_addNotNull() async { |
| 3817 resolveTestUnit(''' | 3817 await resolveTestUnit(''' |
| 3818 main(String p) { | 3818 main(String p) { |
| 3819 if (p) { | 3819 if (p) { |
| 3820 print(p); | 3820 print(p); |
| 3821 } | 3821 } |
| 3822 } | 3822 } |
| 3823 '''); | 3823 '''); |
| 3824 await assertHasFix( | 3824 await assertHasFix( |
| 3825 DartFixKind.ADD_NE_NULL, | 3825 DartFixKind.ADD_NE_NULL, |
| 3826 ''' | 3826 ''' |
| 3827 main(String p) { | 3827 main(String p) { |
| 3828 if (p != null) { | 3828 if (p != null) { |
| 3829 print(p); | 3829 print(p); |
| 3830 } | 3830 } |
| 3831 } | 3831 } |
| 3832 '''); | 3832 '''); |
| 3833 } | 3833 } |
| 3834 | 3834 |
| 3835 test_removeDeadCode_condition() async { | 3835 test_removeDeadCode_condition() async { |
| 3836 resolveTestUnit(''' | 3836 await resolveTestUnit(''' |
| 3837 main(int p) { | 3837 main(int p) { |
| 3838 if (true || p > 5) { | 3838 if (true || p > 5) { |
| 3839 print(1); | 3839 print(1); |
| 3840 } | 3840 } |
| 3841 } | 3841 } |
| 3842 '''); | 3842 '''); |
| 3843 await assertHasFix( | 3843 await assertHasFix( |
| 3844 DartFixKind.REMOVE_DEAD_CODE, | 3844 DartFixKind.REMOVE_DEAD_CODE, |
| 3845 ''' | 3845 ''' |
| 3846 main(int p) { | 3846 main(int p) { |
| 3847 if (true) { | 3847 if (true) { |
| 3848 print(1); | 3848 print(1); |
| 3849 } | 3849 } |
| 3850 } | 3850 } |
| 3851 '''); | 3851 '''); |
| 3852 } | 3852 } |
| 3853 | 3853 |
| 3854 test_removeDeadCode_statements_one() async { | 3854 test_removeDeadCode_statements_one() async { |
| 3855 resolveTestUnit(''' | 3855 await resolveTestUnit(''' |
| 3856 int main() { | 3856 int main() { |
| 3857 print(0); | 3857 print(0); |
| 3858 return 42; | 3858 return 42; |
| 3859 print(1); | 3859 print(1); |
| 3860 } | 3860 } |
| 3861 '''); | 3861 '''); |
| 3862 await assertHasFix( | 3862 await assertHasFix( |
| 3863 DartFixKind.REMOVE_DEAD_CODE, | 3863 DartFixKind.REMOVE_DEAD_CODE, |
| 3864 ''' | 3864 ''' |
| 3865 int main() { | 3865 int main() { |
| 3866 print(0); | 3866 print(0); |
| 3867 return 42; | 3867 return 42; |
| 3868 } | 3868 } |
| 3869 '''); | 3869 '''); |
| 3870 } | 3870 } |
| 3871 | 3871 |
| 3872 test_removeDeadCode_statements_two() async { | 3872 test_removeDeadCode_statements_two() async { |
| 3873 resolveTestUnit(''' | 3873 await resolveTestUnit(''' |
| 3874 int main() { | 3874 int main() { |
| 3875 print(0); | 3875 print(0); |
| 3876 return 42; | 3876 return 42; |
| 3877 print(1); | 3877 print(1); |
| 3878 print(2); | 3878 print(2); |
| 3879 } | 3879 } |
| 3880 '''); | 3880 '''); |
| 3881 await assertHasFix( | 3881 await assertHasFix( |
| 3882 DartFixKind.REMOVE_DEAD_CODE, | 3882 DartFixKind.REMOVE_DEAD_CODE, |
| 3883 ''' | 3883 ''' |
| 3884 int main() { | 3884 int main() { |
| 3885 print(0); | 3885 print(0); |
| 3886 return 42; | 3886 return 42; |
| 3887 } | 3887 } |
| 3888 '''); | 3888 '''); |
| 3889 } | 3889 } |
| 3890 | 3890 |
| 3891 test_removeParentheses_inGetterDeclaration() async { | 3891 test_removeParentheses_inGetterDeclaration() async { |
| 3892 resolveTestUnit(''' | 3892 await resolveTestUnit(''' |
| 3893 class A { | 3893 class A { |
| 3894 int get foo() => 0; | 3894 int get foo() => 0; |
| 3895 } | 3895 } |
| 3896 '''); | 3896 '''); |
| 3897 await assertHasFix( | 3897 await assertHasFix( |
| 3898 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, | 3898 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, |
| 3899 ''' | 3899 ''' |
| 3900 class A { | 3900 class A { |
| 3901 int get foo => 0; | 3901 int get foo => 0; |
| 3902 } | 3902 } |
| 3903 '''); | 3903 '''); |
| 3904 } | 3904 } |
| 3905 | 3905 |
| 3906 test_removeParentheses_inGetterInvocation() async { | 3906 test_removeParentheses_inGetterInvocation() async { |
| 3907 resolveTestUnit(''' | 3907 await resolveTestUnit(''' |
| 3908 class A { | 3908 class A { |
| 3909 int get foo => 0; | 3909 int get foo => 0; |
| 3910 } | 3910 } |
| 3911 main(A a) { | 3911 main(A a) { |
| 3912 a.foo(); | 3912 a.foo(); |
| 3913 } | 3913 } |
| 3914 '''); | 3914 '''); |
| 3915 await assertHasFix( | 3915 await assertHasFix( |
| 3916 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, | 3916 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, |
| 3917 ''' | 3917 ''' |
| 3918 class A { | 3918 class A { |
| 3919 int get foo => 0; | 3919 int get foo => 0; |
| 3920 } | 3920 } |
| 3921 main(A a) { | 3921 main(A a) { |
| 3922 a.foo; | 3922 a.foo; |
| 3923 } | 3923 } |
| 3924 '''); | 3924 '''); |
| 3925 } | 3925 } |
| 3926 | 3926 |
| 3927 test_removeUnnecessaryCast_assignment() async { | 3927 test_removeUnnecessaryCast_assignment() async { |
| 3928 resolveTestUnit(''' | 3928 await resolveTestUnit(''' |
| 3929 main(Object p) { | 3929 main(Object p) { |
| 3930 if (p is String) { | 3930 if (p is String) { |
| 3931 String v = ((p as String)); | 3931 String v = ((p as String)); |
| 3932 } | 3932 } |
| 3933 } | 3933 } |
| 3934 '''); | 3934 '''); |
| 3935 await assertHasFix( | 3935 await assertHasFix( |
| 3936 DartFixKind.REMOVE_UNNECESSARY_CAST, | 3936 DartFixKind.REMOVE_UNNECESSARY_CAST, |
| 3937 ''' | 3937 ''' |
| 3938 main(Object p) { | 3938 main(Object p) { |
| 3939 if (p is String) { | 3939 if (p is String) { |
| 3940 String v = p; | 3940 String v = p; |
| 3941 } | 3941 } |
| 3942 } | 3942 } |
| 3943 '''); | 3943 '''); |
| 3944 } | 3944 } |
| 3945 | 3945 |
| 3946 test_removeUnusedCatchClause() async { | 3946 test_removeUnusedCatchClause() async { |
| 3947 errorFilter = (AnalysisError error) => true; | 3947 errorFilter = (AnalysisError error) => true; |
| 3948 resolveTestUnit(''' | 3948 await resolveTestUnit(''' |
| 3949 main() { | 3949 main() { |
| 3950 try { | 3950 try { |
| 3951 throw 42; | 3951 throw 42; |
| 3952 } on int catch (e) { | 3952 } on int catch (e) { |
| 3953 } | 3953 } |
| 3954 } | 3954 } |
| 3955 '''); | 3955 '''); |
| 3956 await assertHasFix( | 3956 await assertHasFix( |
| 3957 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, | 3957 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, |
| 3958 ''' | 3958 ''' |
| 3959 main() { | 3959 main() { |
| 3960 try { | 3960 try { |
| 3961 throw 42; | 3961 throw 42; |
| 3962 } on int { | 3962 } on int { |
| 3963 } | 3963 } |
| 3964 } | 3964 } |
| 3965 '''); | 3965 '''); |
| 3966 } | 3966 } |
| 3967 | 3967 |
| 3968 test_removeUnusedCatchStack() async { | 3968 test_removeUnusedCatchStack() async { |
| 3969 errorFilter = (AnalysisError error) => true; | 3969 errorFilter = (AnalysisError error) => true; |
| 3970 resolveTestUnit(''' | 3970 await resolveTestUnit(''' |
| 3971 main() { | 3971 main() { |
| 3972 try { | 3972 try { |
| 3973 throw 42; | 3973 throw 42; |
| 3974 } catch (e, stack) { | 3974 } catch (e, stack) { |
| 3975 } | 3975 } |
| 3976 } | 3976 } |
| 3977 '''); | 3977 '''); |
| 3978 await assertHasFix( | 3978 await assertHasFix( |
| 3979 DartFixKind.REMOVE_UNUSED_CATCH_STACK, | 3979 DartFixKind.REMOVE_UNUSED_CATCH_STACK, |
| 3980 ''' | 3980 ''' |
| 3981 main() { | 3981 main() { |
| 3982 try { | 3982 try { |
| 3983 throw 42; | 3983 throw 42; |
| 3984 } catch (e) { | 3984 } catch (e) { |
| 3985 } | 3985 } |
| 3986 } | 3986 } |
| 3987 '''); | 3987 '''); |
| 3988 } | 3988 } |
| 3989 | 3989 |
| 3990 test_removeUnusedImport() async { | 3990 test_removeUnusedImport() async { |
| 3991 resolveTestUnit(''' | 3991 await resolveTestUnit(''' |
| 3992 import 'dart:math'; | 3992 import 'dart:math'; |
| 3993 main() { | 3993 main() { |
| 3994 } | 3994 } |
| 3995 '''); | 3995 '''); |
| 3996 await assertHasFix( | 3996 await assertHasFix( |
| 3997 DartFixKind.REMOVE_UNUSED_IMPORT, | 3997 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 3998 ''' | 3998 ''' |
| 3999 main() { | 3999 main() { |
| 4000 } | 4000 } |
| 4001 '''); | 4001 '''); |
| 4002 } | 4002 } |
| 4003 | 4003 |
| 4004 test_removeUnusedImport_anotherImportOnLine() async { | 4004 test_removeUnusedImport_anotherImportOnLine() async { |
| 4005 resolveTestUnit(''' | 4005 await resolveTestUnit(''' |
| 4006 import 'dart:math'; import 'dart:async'; | 4006 import 'dart:math'; import 'dart:async'; |
| 4007 | 4007 |
| 4008 main() { | 4008 main() { |
| 4009 Future f; | 4009 Future f; |
| 4010 } | 4010 } |
| 4011 '''); | 4011 '''); |
| 4012 await assertHasFix( | 4012 await assertHasFix( |
| 4013 DartFixKind.REMOVE_UNUSED_IMPORT, | 4013 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 4014 ''' | 4014 ''' |
| 4015 import 'dart:async'; | 4015 import 'dart:async'; |
| 4016 | 4016 |
| 4017 main() { | 4017 main() { |
| 4018 Future f; | 4018 Future f; |
| 4019 } | 4019 } |
| 4020 '''); | 4020 '''); |
| 4021 } | 4021 } |
| 4022 | 4022 |
| 4023 test_removeUnusedImport_severalLines() async { | 4023 test_removeUnusedImport_severalLines() async { |
| 4024 resolveTestUnit(''' | 4024 await resolveTestUnit(''' |
| 4025 import | 4025 import |
| 4026 'dart:math'; | 4026 'dart:math'; |
| 4027 main() { | 4027 main() { |
| 4028 } | 4028 } |
| 4029 '''); | 4029 '''); |
| 4030 await assertHasFix( | 4030 await assertHasFix( |
| 4031 DartFixKind.REMOVE_UNUSED_IMPORT, | 4031 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 4032 ''' | 4032 ''' |
| 4033 main() { | 4033 main() { |
| 4034 } | 4034 } |
| 4035 '''); | 4035 '''); |
| 4036 } | 4036 } |
| 4037 | 4037 |
| 4038 test_replaceImportUri_inProject() async { | 4038 test_replaceImportUri_inProject() async { |
| 4039 testFile = '/project/bin/test.dart'; | 4039 testFile = '/project/bin/test.dart'; |
| 4040 addSource('/project/foo/bar/lib.dart', ''); | 4040 addSource('/project/foo/bar/lib.dart', ''); |
| 4041 resolveTestUnit(''' | 4041 await resolveTestUnit(''' |
| 4042 import 'no/matter/lib.dart'; | 4042 import 'no/matter/lib.dart'; |
| 4043 '''); | 4043 '''); |
| 4044 performAllAnalysisTasks(); | 4044 performAllAnalysisTasks(); |
| 4045 await assertHasFix( | 4045 await assertHasFix( |
| 4046 DartFixKind.REPLACE_IMPORT_URI, | 4046 DartFixKind.REPLACE_IMPORT_URI, |
| 4047 ''' | 4047 ''' |
| 4048 import '../foo/bar/lib.dart'; | 4048 import '../foo/bar/lib.dart'; |
| 4049 '''); | 4049 '''); |
| 4050 } | 4050 } |
| 4051 | 4051 |
| 4052 test_replaceImportUri_package() async { | 4052 test_replaceImportUri_package() async { |
| 4053 _configureMyPkg({'my_lib.dart': ''}); | 4053 _configureMyPkg({'my_lib.dart': ''}); |
| 4054 resolveTestUnit(''' | 4054 await resolveTestUnit(''' |
| 4055 import 'no/matter/my_lib.dart'; | 4055 import 'no/matter/my_lib.dart'; |
| 4056 '''); | 4056 '''); |
| 4057 performAllAnalysisTasks(); | 4057 performAllAnalysisTasks(); |
| 4058 await assertHasFix( | 4058 await assertHasFix( |
| 4059 DartFixKind.REPLACE_IMPORT_URI, | 4059 DartFixKind.REPLACE_IMPORT_URI, |
| 4060 ''' | 4060 ''' |
| 4061 import 'package:my_pkg/my_lib.dart'; | 4061 import 'package:my_pkg/my_lib.dart'; |
| 4062 '''); | 4062 '''); |
| 4063 } | 4063 } |
| 4064 | 4064 |
| 4065 test_replaceVarWithDynamic() async { | 4065 test_replaceVarWithDynamic() async { |
| 4066 errorFilter = (AnalysisError error) { | 4066 errorFilter = (AnalysisError error) { |
| 4067 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; | 4067 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; |
| 4068 }; | 4068 }; |
| 4069 resolveTestUnit(''' | 4069 await resolveTestUnit(''' |
| 4070 class A { | 4070 class A { |
| 4071 Map<String, var> m; | 4071 Map<String, var> m; |
| 4072 } | 4072 } |
| 4073 '''); | 4073 '''); |
| 4074 await assertHasFix( | 4074 await assertHasFix( |
| 4075 DartFixKind.REPLACE_VAR_WITH_DYNAMIC, | 4075 DartFixKind.REPLACE_VAR_WITH_DYNAMIC, |
| 4076 ''' | 4076 ''' |
| 4077 class A { | 4077 class A { |
| 4078 Map<String, dynamic> m; | 4078 Map<String, dynamic> m; |
| 4079 } | 4079 } |
| 4080 '''); | 4080 '''); |
| 4081 } | 4081 } |
| 4082 | 4082 |
| 4083 test_replaceWithConstInstanceCreation() async { | 4083 test_replaceWithConstInstanceCreation() async { |
| 4084 resolveTestUnit(''' | 4084 await resolveTestUnit(''' |
| 4085 class A { | 4085 class A { |
| 4086 const A(); | 4086 const A(); |
| 4087 } | 4087 } |
| 4088 const a = new A(); | 4088 const a = new A(); |
| 4089 '''); | 4089 '''); |
| 4090 await assertHasFix( | 4090 await assertHasFix( |
| 4091 DartFixKind.USE_CONST, | 4091 DartFixKind.USE_CONST, |
| 4092 ''' | 4092 ''' |
| 4093 class A { | 4093 class A { |
| 4094 const A(); | 4094 const A(); |
| 4095 } | 4095 } |
| 4096 const a = const A(); | 4096 const a = const A(); |
| 4097 '''); | 4097 '''); |
| 4098 } | 4098 } |
| 4099 | 4099 |
| 4100 test_undefinedClass_useSimilar_BAD_prefixed() async { | 4100 test_undefinedClass_useSimilar_BAD_prefixed() async { |
| 4101 resolveTestUnit(''' | 4101 await resolveTestUnit(''' |
| 4102 import 'dart:async' as c; | 4102 import 'dart:async' as c; |
| 4103 main() { | 4103 main() { |
| 4104 c.Fture v = null; | 4104 c.Fture v = null; |
| 4105 } | 4105 } |
| 4106 '''); | 4106 '''); |
| 4107 await assertHasFix( | 4107 await assertHasFix( |
| 4108 DartFixKind.CHANGE_TO, | 4108 DartFixKind.CHANGE_TO, |
| 4109 ''' | 4109 ''' |
| 4110 import 'dart:async' as c; | 4110 import 'dart:async' as c; |
| 4111 main() { | 4111 main() { |
| 4112 c.Future v = null; | 4112 c.Future v = null; |
| 4113 } | 4113 } |
| 4114 '''); | 4114 '''); |
| 4115 } | 4115 } |
| 4116 | 4116 |
| 4117 test_undefinedClass_useSimilar_fromImport() async { | 4117 test_undefinedClass_useSimilar_fromImport() async { |
| 4118 resolveTestUnit(''' | 4118 await resolveTestUnit(''' |
| 4119 main() { | 4119 main() { |
| 4120 Stirng s = 'abc'; | 4120 Stirng s = 'abc'; |
| 4121 } | 4121 } |
| 4122 '''); | 4122 '''); |
| 4123 await assertHasFix( | 4123 await assertHasFix( |
| 4124 DartFixKind.CHANGE_TO, | 4124 DartFixKind.CHANGE_TO, |
| 4125 ''' | 4125 ''' |
| 4126 main() { | 4126 main() { |
| 4127 String s = 'abc'; | 4127 String s = 'abc'; |
| 4128 } | 4128 } |
| 4129 '''); | 4129 '''); |
| 4130 } | 4130 } |
| 4131 | 4131 |
| 4132 test_undefinedClass_useSimilar_fromThisLibrary() async { | 4132 test_undefinedClass_useSimilar_fromThisLibrary() async { |
| 4133 resolveTestUnit(''' | 4133 await resolveTestUnit(''' |
| 4134 class MyClass {} | 4134 class MyClass {} |
| 4135 main() { | 4135 main() { |
| 4136 MyCalss v = null; | 4136 MyCalss v = null; |
| 4137 } | 4137 } |
| 4138 '''); | 4138 '''); |
| 4139 await assertHasFix( | 4139 await assertHasFix( |
| 4140 DartFixKind.CHANGE_TO, | 4140 DartFixKind.CHANGE_TO, |
| 4141 ''' | 4141 ''' |
| 4142 class MyClass {} | 4142 class MyClass {} |
| 4143 main() { | 4143 main() { |
| 4144 MyClass v = null; | 4144 MyClass v = null; |
| 4145 } | 4145 } |
| 4146 '''); | 4146 '''); |
| 4147 } | 4147 } |
| 4148 | 4148 |
| 4149 test_undefinedFunction_create_duplicateArgumentNames() async { | 4149 test_undefinedFunction_create_duplicateArgumentNames() async { |
| 4150 resolveTestUnit(''' | 4150 await resolveTestUnit(''' |
| 4151 class C { | 4151 class C { |
| 4152 int x; | 4152 int x; |
| 4153 } | 4153 } |
| 4154 | 4154 |
| 4155 foo(C c1, C c2) { | 4155 foo(C c1, C c2) { |
| 4156 bar(c1.x, c2.x); | 4156 bar(c1.x, c2.x); |
| 4157 } | 4157 } |
| 4158 '''); | 4158 '''); |
| 4159 await assertHasFix( | 4159 await assertHasFix( |
| 4160 DartFixKind.CREATE_FUNCTION, | 4160 DartFixKind.CREATE_FUNCTION, |
| 4161 ''' | 4161 ''' |
| 4162 class C { | 4162 class C { |
| 4163 int x; | 4163 int x; |
| 4164 } | 4164 } |
| 4165 | 4165 |
| 4166 foo(C c1, C c2) { | 4166 foo(C c1, C c2) { |
| 4167 bar(c1.x, c2.x); | 4167 bar(c1.x, c2.x); |
| 4168 } | 4168 } |
| 4169 | 4169 |
| 4170 void bar(int x, int x2) { | 4170 void bar(int x, int x2) { |
| 4171 } | 4171 } |
| 4172 '''); | 4172 '''); |
| 4173 } | 4173 } |
| 4174 | 4174 |
| 4175 test_undefinedFunction_create_dynamicArgument() async { | 4175 test_undefinedFunction_create_dynamicArgument() async { |
| 4176 resolveTestUnit(''' | 4176 await resolveTestUnit(''' |
| 4177 main() { | 4177 main() { |
| 4178 dynamic v; | 4178 dynamic v; |
| 4179 test(v); | 4179 test(v); |
| 4180 } | 4180 } |
| 4181 '''); | 4181 '''); |
| 4182 await assertHasFix( | 4182 await assertHasFix( |
| 4183 DartFixKind.CREATE_FUNCTION, | 4183 DartFixKind.CREATE_FUNCTION, |
| 4184 ''' | 4184 ''' |
| 4185 main() { | 4185 main() { |
| 4186 dynamic v; | 4186 dynamic v; |
| 4187 test(v); | 4187 test(v); |
| 4188 } | 4188 } |
| 4189 | 4189 |
| 4190 void test(v) { | 4190 void test(v) { |
| 4191 } | 4191 } |
| 4192 '''); | 4192 '''); |
| 4193 } | 4193 } |
| 4194 | 4194 |
| 4195 test_undefinedFunction_create_dynamicReturnType() async { | 4195 test_undefinedFunction_create_dynamicReturnType() async { |
| 4196 resolveTestUnit(''' | 4196 await resolveTestUnit(''' |
| 4197 main() { | 4197 main() { |
| 4198 dynamic v = test(); | 4198 dynamic v = test(); |
| 4199 } | 4199 } |
| 4200 '''); | 4200 '''); |
| 4201 await assertHasFix( | 4201 await assertHasFix( |
| 4202 DartFixKind.CREATE_FUNCTION, | 4202 DartFixKind.CREATE_FUNCTION, |
| 4203 ''' | 4203 ''' |
| 4204 main() { | 4204 main() { |
| 4205 dynamic v = test(); | 4205 dynamic v = test(); |
| 4206 } | 4206 } |
| 4207 | 4207 |
| 4208 test() { | 4208 test() { |
| 4209 } | 4209 } |
| 4210 '''); | 4210 '''); |
| 4211 } | 4211 } |
| 4212 | 4212 |
| 4213 test_undefinedFunction_create_fromFunction() async { | 4213 test_undefinedFunction_create_fromFunction() async { |
| 4214 resolveTestUnit(''' | 4214 await resolveTestUnit(''' |
| 4215 main() { | 4215 main() { |
| 4216 int v = myUndefinedFunction(1, 2.0, '3'); | 4216 int v = myUndefinedFunction(1, 2.0, '3'); |
| 4217 } | 4217 } |
| 4218 '''); | 4218 '''); |
| 4219 await assertHasFix( | 4219 await assertHasFix( |
| 4220 DartFixKind.CREATE_FUNCTION, | 4220 DartFixKind.CREATE_FUNCTION, |
| 4221 ''' | 4221 ''' |
| 4222 main() { | 4222 main() { |
| 4223 int v = myUndefinedFunction(1, 2.0, '3'); | 4223 int v = myUndefinedFunction(1, 2.0, '3'); |
| 4224 } | 4224 } |
| 4225 | 4225 |
| 4226 int myUndefinedFunction(int i, double d, String s) { | 4226 int myUndefinedFunction(int i, double d, String s) { |
| 4227 } | 4227 } |
| 4228 '''); | 4228 '''); |
| 4229 } | 4229 } |
| 4230 | 4230 |
| 4231 test_undefinedFunction_create_fromMethod() async { | 4231 test_undefinedFunction_create_fromMethod() async { |
| 4232 resolveTestUnit(''' | 4232 await resolveTestUnit(''' |
| 4233 class A { | 4233 class A { |
| 4234 main() { | 4234 main() { |
| 4235 int v = myUndefinedFunction(1, 2.0, '3'); | 4235 int v = myUndefinedFunction(1, 2.0, '3'); |
| 4236 } | 4236 } |
| 4237 } | 4237 } |
| 4238 '''); | 4238 '''); |
| 4239 await assertHasFix( | 4239 await assertHasFix( |
| 4240 DartFixKind.CREATE_FUNCTION, | 4240 DartFixKind.CREATE_FUNCTION, |
| 4241 ''' | 4241 ''' |
| 4242 class A { | 4242 class A { |
| 4243 main() { | 4243 main() { |
| 4244 int v = myUndefinedFunction(1, 2.0, '3'); | 4244 int v = myUndefinedFunction(1, 2.0, '3'); |
| 4245 } | 4245 } |
| 4246 } | 4246 } |
| 4247 | 4247 |
| 4248 int myUndefinedFunction(int i, double d, String s) { | 4248 int myUndefinedFunction(int i, double d, String s) { |
| 4249 } | 4249 } |
| 4250 '''); | 4250 '''); |
| 4251 } | 4251 } |
| 4252 | 4252 |
| 4253 test_undefinedFunction_create_generic_BAD() async { | 4253 test_undefinedFunction_create_generic_BAD() async { |
| 4254 resolveTestUnit(''' | 4254 await resolveTestUnit(''' |
| 4255 class A<T> { | 4255 class A<T> { |
| 4256 Map<int, T> items; | 4256 Map<int, T> items; |
| 4257 main() { | 4257 main() { |
| 4258 process(items); | 4258 process(items); |
| 4259 } | 4259 } |
| 4260 } | 4260 } |
| 4261 '''); | 4261 '''); |
| 4262 await assertHasFix( | 4262 await assertHasFix( |
| 4263 DartFixKind.CREATE_FUNCTION, | 4263 DartFixKind.CREATE_FUNCTION, |
| 4264 ''' | 4264 ''' |
| 4265 class A<T> { | 4265 class A<T> { |
| 4266 Map<int, T> items; | 4266 Map<int, T> items; |
| 4267 main() { | 4267 main() { |
| 4268 process(items); | 4268 process(items); |
| 4269 } | 4269 } |
| 4270 } | 4270 } |
| 4271 | 4271 |
| 4272 void process(Map items) { | 4272 void process(Map items) { |
| 4273 } | 4273 } |
| 4274 '''); | 4274 '''); |
| 4275 } | 4275 } |
| 4276 | 4276 |
| 4277 test_undefinedFunction_create_generic_OK() async { | 4277 test_undefinedFunction_create_generic_OK() async { |
| 4278 resolveTestUnit(''' | 4278 await resolveTestUnit(''' |
| 4279 class A { | 4279 class A { |
| 4280 List<int> items; | 4280 List<int> items; |
| 4281 main() { | 4281 main() { |
| 4282 process(items); | 4282 process(items); |
| 4283 } | 4283 } |
| 4284 } | 4284 } |
| 4285 '''); | 4285 '''); |
| 4286 await assertHasFix( | 4286 await assertHasFix( |
| 4287 DartFixKind.CREATE_FUNCTION, | 4287 DartFixKind.CREATE_FUNCTION, |
| 4288 ''' | 4288 ''' |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4308 } | 4308 } |
| 4309 | 4309 |
| 4310 test_undefinedFunction_create_importType() async { | 4310 test_undefinedFunction_create_importType() async { |
| 4311 addSource( | 4311 addSource( |
| 4312 '/lib.dart', | 4312 '/lib.dart', |
| 4313 r''' | 4313 r''' |
| 4314 library lib; | 4314 library lib; |
| 4315 import 'dart:async'; | 4315 import 'dart:async'; |
| 4316 Future getFuture() => null; | 4316 Future getFuture() => null; |
| 4317 '''); | 4317 '''); |
| 4318 resolveTestUnit(''' | 4318 await resolveTestUnit(''' |
| 4319 import 'lib.dart'; | 4319 import 'lib.dart'; |
| 4320 main() { | 4320 main() { |
| 4321 test(getFuture()); | 4321 test(getFuture()); |
| 4322 } | 4322 } |
| 4323 '''); | 4323 '''); |
| 4324 await assertHasFix( | 4324 await assertHasFix( |
| 4325 DartFixKind.CREATE_FUNCTION, | 4325 DartFixKind.CREATE_FUNCTION, |
| 4326 ''' | 4326 ''' |
| 4327 import 'dart:async'; | 4327 import 'dart:async'; |
| 4328 import 'lib.dart'; | 4328 import 'lib.dart'; |
| 4329 main() { | 4329 main() { |
| 4330 test(getFuture()); | 4330 test(getFuture()); |
| 4331 } | 4331 } |
| 4332 | 4332 |
| 4333 void test(Future future) { | 4333 void test(Future future) { |
| 4334 } | 4334 } |
| 4335 '''); | 4335 '''); |
| 4336 } | 4336 } |
| 4337 | 4337 |
| 4338 test_undefinedFunction_create_nullArgument() async { | 4338 test_undefinedFunction_create_nullArgument() async { |
| 4339 resolveTestUnit(''' | 4339 await resolveTestUnit(''' |
| 4340 main() { | 4340 main() { |
| 4341 test(null); | 4341 test(null); |
| 4342 } | 4342 } |
| 4343 '''); | 4343 '''); |
| 4344 await assertHasFix( | 4344 await assertHasFix( |
| 4345 DartFixKind.CREATE_FUNCTION, | 4345 DartFixKind.CREATE_FUNCTION, |
| 4346 ''' | 4346 ''' |
| 4347 main() { | 4347 main() { |
| 4348 test(null); | 4348 test(null); |
| 4349 } | 4349 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4364 test_undefinedFunction_create_returnType_bool_statements() async { | 4364 test_undefinedFunction_create_returnType_bool_statements() async { |
| 4365 await assert_undefinedFunction_create_returnType_bool("assert ( test() );"); | 4365 await assert_undefinedFunction_create_returnType_bool("assert ( test() );"); |
| 4366 await assert_undefinedFunction_create_returnType_bool("if ( test() ) {}"); | 4366 await assert_undefinedFunction_create_returnType_bool("if ( test() ) {}"); |
| 4367 await assert_undefinedFunction_create_returnType_bool( | 4367 await assert_undefinedFunction_create_returnType_bool( |
| 4368 "while ( test() ) {}"); | 4368 "while ( test() ) {}"); |
| 4369 await assert_undefinedFunction_create_returnType_bool( | 4369 await assert_undefinedFunction_create_returnType_bool( |
| 4370 "do {} while ( test() );"); | 4370 "do {} while ( test() );"); |
| 4371 } | 4371 } |
| 4372 | 4372 |
| 4373 test_undefinedFunction_create_returnType_fromAssignment_eq() async { | 4373 test_undefinedFunction_create_returnType_fromAssignment_eq() async { |
| 4374 resolveTestUnit(''' | 4374 await resolveTestUnit(''' |
| 4375 main() { | 4375 main() { |
| 4376 int v; | 4376 int v; |
| 4377 v = myUndefinedFunction(); | 4377 v = myUndefinedFunction(); |
| 4378 } | 4378 } |
| 4379 '''); | 4379 '''); |
| 4380 await assertHasFix( | 4380 await assertHasFix( |
| 4381 DartFixKind.CREATE_FUNCTION, | 4381 DartFixKind.CREATE_FUNCTION, |
| 4382 ''' | 4382 ''' |
| 4383 main() { | 4383 main() { |
| 4384 int v; | 4384 int v; |
| 4385 v = myUndefinedFunction(); | 4385 v = myUndefinedFunction(); |
| 4386 } | 4386 } |
| 4387 | 4387 |
| 4388 int myUndefinedFunction() { | 4388 int myUndefinedFunction() { |
| 4389 } | 4389 } |
| 4390 '''); | 4390 '''); |
| 4391 } | 4391 } |
| 4392 | 4392 |
| 4393 test_undefinedFunction_create_returnType_fromAssignment_plusEq() async { | 4393 test_undefinedFunction_create_returnType_fromAssignment_plusEq() async { |
| 4394 resolveTestUnit(''' | 4394 await resolveTestUnit(''' |
| 4395 main() { | 4395 main() { |
| 4396 int v; | 4396 int v; |
| 4397 v += myUndefinedFunction(); | 4397 v += myUndefinedFunction(); |
| 4398 } | 4398 } |
| 4399 '''); | 4399 '''); |
| 4400 await assertHasFix( | 4400 await assertHasFix( |
| 4401 DartFixKind.CREATE_FUNCTION, | 4401 DartFixKind.CREATE_FUNCTION, |
| 4402 ''' | 4402 ''' |
| 4403 main() { | 4403 main() { |
| 4404 int v; | 4404 int v; |
| 4405 v += myUndefinedFunction(); | 4405 v += myUndefinedFunction(); |
| 4406 } | 4406 } |
| 4407 | 4407 |
| 4408 num myUndefinedFunction() { | 4408 num myUndefinedFunction() { |
| 4409 } | 4409 } |
| 4410 '''); | 4410 '''); |
| 4411 } | 4411 } |
| 4412 | 4412 |
| 4413 test_undefinedFunction_create_returnType_fromBinary_right() async { | 4413 test_undefinedFunction_create_returnType_fromBinary_right() async { |
| 4414 resolveTestUnit(''' | 4414 await resolveTestUnit(''' |
| 4415 main() { | 4415 main() { |
| 4416 0 + myUndefinedFunction(); | 4416 0 + myUndefinedFunction(); |
| 4417 } | 4417 } |
| 4418 '''); | 4418 '''); |
| 4419 await assertHasFix( | 4419 await assertHasFix( |
| 4420 DartFixKind.CREATE_FUNCTION, | 4420 DartFixKind.CREATE_FUNCTION, |
| 4421 ''' | 4421 ''' |
| 4422 main() { | 4422 main() { |
| 4423 0 + myUndefinedFunction(); | 4423 0 + myUndefinedFunction(); |
| 4424 } | 4424 } |
| 4425 | 4425 |
| 4426 num myUndefinedFunction() { | 4426 num myUndefinedFunction() { |
| 4427 } | 4427 } |
| 4428 '''); | 4428 '''); |
| 4429 } | 4429 } |
| 4430 | 4430 |
| 4431 test_undefinedFunction_create_returnType_fromInitializer() async { | 4431 test_undefinedFunction_create_returnType_fromInitializer() async { |
| 4432 resolveTestUnit(''' | 4432 await resolveTestUnit(''' |
| 4433 main() { | 4433 main() { |
| 4434 int v = myUndefinedFunction(); | 4434 int v = myUndefinedFunction(); |
| 4435 } | 4435 } |
| 4436 '''); | 4436 '''); |
| 4437 await assertHasFix( | 4437 await assertHasFix( |
| 4438 DartFixKind.CREATE_FUNCTION, | 4438 DartFixKind.CREATE_FUNCTION, |
| 4439 ''' | 4439 ''' |
| 4440 main() { | 4440 main() { |
| 4441 int v = myUndefinedFunction(); | 4441 int v = myUndefinedFunction(); |
| 4442 } | 4442 } |
| 4443 | 4443 |
| 4444 int myUndefinedFunction() { | 4444 int myUndefinedFunction() { |
| 4445 } | 4445 } |
| 4446 '''); | 4446 '''); |
| 4447 } | 4447 } |
| 4448 | 4448 |
| 4449 test_undefinedFunction_create_returnType_fromInvocationArgument() async { | 4449 test_undefinedFunction_create_returnType_fromInvocationArgument() async { |
| 4450 resolveTestUnit(''' | 4450 await resolveTestUnit(''' |
| 4451 foo(int p) {} | 4451 foo(int p) {} |
| 4452 main() { | 4452 main() { |
| 4453 foo( myUndefinedFunction() ); | 4453 foo( myUndefinedFunction() ); |
| 4454 } | 4454 } |
| 4455 '''); | 4455 '''); |
| 4456 await assertHasFix( | 4456 await assertHasFix( |
| 4457 DartFixKind.CREATE_FUNCTION, | 4457 DartFixKind.CREATE_FUNCTION, |
| 4458 ''' | 4458 ''' |
| 4459 foo(int p) {} | 4459 foo(int p) {} |
| 4460 main() { | 4460 main() { |
| 4461 foo( myUndefinedFunction() ); | 4461 foo( myUndefinedFunction() ); |
| 4462 } | 4462 } |
| 4463 | 4463 |
| 4464 int myUndefinedFunction() { | 4464 int myUndefinedFunction() { |
| 4465 } | 4465 } |
| 4466 '''); | 4466 '''); |
| 4467 } | 4467 } |
| 4468 | 4468 |
| 4469 test_undefinedFunction_create_returnType_fromReturn() async { | 4469 test_undefinedFunction_create_returnType_fromReturn() async { |
| 4470 resolveTestUnit(''' | 4470 await resolveTestUnit(''' |
| 4471 int main() { | 4471 int main() { |
| 4472 return myUndefinedFunction(); | 4472 return myUndefinedFunction(); |
| 4473 } | 4473 } |
| 4474 '''); | 4474 '''); |
| 4475 await assertHasFix( | 4475 await assertHasFix( |
| 4476 DartFixKind.CREATE_FUNCTION, | 4476 DartFixKind.CREATE_FUNCTION, |
| 4477 ''' | 4477 ''' |
| 4478 int main() { | 4478 int main() { |
| 4479 return myUndefinedFunction(); | 4479 return myUndefinedFunction(); |
| 4480 } | 4480 } |
| 4481 | 4481 |
| 4482 int myUndefinedFunction() { | 4482 int myUndefinedFunction() { |
| 4483 } | 4483 } |
| 4484 '''); | 4484 '''); |
| 4485 } | 4485 } |
| 4486 | 4486 |
| 4487 test_undefinedFunction_create_returnType_void() async { | 4487 test_undefinedFunction_create_returnType_void() async { |
| 4488 resolveTestUnit(''' | 4488 await resolveTestUnit(''' |
| 4489 main() { | 4489 main() { |
| 4490 myUndefinedFunction(); | 4490 myUndefinedFunction(); |
| 4491 } | 4491 } |
| 4492 '''); | 4492 '''); |
| 4493 await assertHasFix( | 4493 await assertHasFix( |
| 4494 DartFixKind.CREATE_FUNCTION, | 4494 DartFixKind.CREATE_FUNCTION, |
| 4495 ''' | 4495 ''' |
| 4496 main() { | 4496 main() { |
| 4497 myUndefinedFunction(); | 4497 myUndefinedFunction(); |
| 4498 } | 4498 } |
| 4499 | 4499 |
| 4500 void myUndefinedFunction() { | 4500 void myUndefinedFunction() { |
| 4501 } | 4501 } |
| 4502 '''); | 4502 '''); |
| 4503 } | 4503 } |
| 4504 | 4504 |
| 4505 test_undefinedFunction_useSimilar_fromImport() async { | 4505 test_undefinedFunction_useSimilar_fromImport() async { |
| 4506 resolveTestUnit(''' | 4506 await resolveTestUnit(''' |
| 4507 main() { | 4507 main() { |
| 4508 pritn(0); | 4508 pritn(0); |
| 4509 } | 4509 } |
| 4510 '''); | 4510 '''); |
| 4511 await assertHasFix( | 4511 await assertHasFix( |
| 4512 DartFixKind.CHANGE_TO, | 4512 DartFixKind.CHANGE_TO, |
| 4513 ''' | 4513 ''' |
| 4514 main() { | 4514 main() { |
| 4515 print(0); | 4515 print(0); |
| 4516 } | 4516 } |
| 4517 '''); | 4517 '''); |
| 4518 } | 4518 } |
| 4519 | 4519 |
| 4520 test_undefinedFunction_useSimilar_prefixed_fromImport() async { | 4520 test_undefinedFunction_useSimilar_prefixed_fromImport() async { |
| 4521 resolveTestUnit(''' | 4521 await resolveTestUnit(''' |
| 4522 import 'dart:core' as c; | 4522 import 'dart:core' as c; |
| 4523 main() { | 4523 main() { |
| 4524 c.prnt(42); | 4524 c.prnt(42); |
| 4525 } | 4525 } |
| 4526 '''); | 4526 '''); |
| 4527 await assertHasFix( | 4527 await assertHasFix( |
| 4528 DartFixKind.CHANGE_TO, | 4528 DartFixKind.CHANGE_TO, |
| 4529 ''' | 4529 ''' |
| 4530 import 'dart:core' as c; | 4530 import 'dart:core' as c; |
| 4531 main() { | 4531 main() { |
| 4532 c.print(42); | 4532 c.print(42); |
| 4533 } | 4533 } |
| 4534 '''); | 4534 '''); |
| 4535 } | 4535 } |
| 4536 | 4536 |
| 4537 test_undefinedFunction_useSimilar_prefixed_ignoreLocal() async { | 4537 test_undefinedFunction_useSimilar_prefixed_ignoreLocal() async { |
| 4538 resolveTestUnit(''' | 4538 await resolveTestUnit(''' |
| 4539 import 'dart:async' as c; | 4539 import 'dart:async' as c; |
| 4540 main() { | 4540 main() { |
| 4541 c.main(); | 4541 c.main(); |
| 4542 } | 4542 } |
| 4543 '''); | 4543 '''); |
| 4544 await assertNoFix(DartFixKind.CHANGE_TO); | 4544 await assertNoFix(DartFixKind.CHANGE_TO); |
| 4545 } | 4545 } |
| 4546 | 4546 |
| 4547 test_undefinedFunction_useSimilar_thisLibrary() async { | 4547 test_undefinedFunction_useSimilar_thisLibrary() async { |
| 4548 resolveTestUnit(''' | 4548 await resolveTestUnit(''' |
| 4549 myFunction() {} | 4549 myFunction() {} |
| 4550 main() { | 4550 main() { |
| 4551 myFuntcion(); | 4551 myFuntcion(); |
| 4552 } | 4552 } |
| 4553 '''); | 4553 '''); |
| 4554 await assertHasFix( | 4554 await assertHasFix( |
| 4555 DartFixKind.CHANGE_TO, | 4555 DartFixKind.CHANGE_TO, |
| 4556 ''' | 4556 ''' |
| 4557 myFunction() {} | 4557 myFunction() {} |
| 4558 main() { | 4558 main() { |
| 4559 myFunction(); | 4559 myFunction(); |
| 4560 } | 4560 } |
| 4561 '''); | 4561 '''); |
| 4562 } | 4562 } |
| 4563 | 4563 |
| 4564 test_undefinedGetter_useSimilar_hint() async { | 4564 test_undefinedGetter_useSimilar_hint() async { |
| 4565 resolveTestUnit(''' | 4565 await resolveTestUnit(''' |
| 4566 class A { | 4566 class A { |
| 4567 int myField; | 4567 int myField; |
| 4568 } | 4568 } |
| 4569 main(A a) { | 4569 main(A a) { |
| 4570 var x = a; | 4570 var x = a; |
| 4571 print(x.myFild); | 4571 print(x.myFild); |
| 4572 } | 4572 } |
| 4573 '''); | 4573 '''); |
| 4574 await assertHasFix( | 4574 await assertHasFix( |
| 4575 DartFixKind.CHANGE_TO, | 4575 DartFixKind.CHANGE_TO, |
| 4576 ''' | 4576 ''' |
| 4577 class A { | 4577 class A { |
| 4578 int myField; | 4578 int myField; |
| 4579 } | 4579 } |
| 4580 main(A a) { | 4580 main(A a) { |
| 4581 var x = a; | 4581 var x = a; |
| 4582 print(x.myField); | 4582 print(x.myField); |
| 4583 } | 4583 } |
| 4584 '''); | 4584 '''); |
| 4585 } | 4585 } |
| 4586 | 4586 |
| 4587 test_undefinedGetter_useSimilar_qualified() async { | 4587 test_undefinedGetter_useSimilar_qualified() async { |
| 4588 resolveTestUnit(''' | 4588 await resolveTestUnit(''' |
| 4589 class A { | 4589 class A { |
| 4590 int myField; | 4590 int myField; |
| 4591 } | 4591 } |
| 4592 main(A a) { | 4592 main(A a) { |
| 4593 print(a.myFild); | 4593 print(a.myFild); |
| 4594 } | 4594 } |
| 4595 '''); | 4595 '''); |
| 4596 await assertHasFix( | 4596 await assertHasFix( |
| 4597 DartFixKind.CHANGE_TO, | 4597 DartFixKind.CHANGE_TO, |
| 4598 ''' | 4598 ''' |
| 4599 class A { | 4599 class A { |
| 4600 int myField; | 4600 int myField; |
| 4601 } | 4601 } |
| 4602 main(A a) { | 4602 main(A a) { |
| 4603 print(a.myField); | 4603 print(a.myField); |
| 4604 } | 4604 } |
| 4605 '''); | 4605 '''); |
| 4606 } | 4606 } |
| 4607 | 4607 |
| 4608 test_undefinedGetter_useSimilar_qualified_static() async { | 4608 test_undefinedGetter_useSimilar_qualified_static() async { |
| 4609 resolveTestUnit(''' | 4609 await resolveTestUnit(''' |
| 4610 class A { | 4610 class A { |
| 4611 static int MY_NAME = 1; | 4611 static int MY_NAME = 1; |
| 4612 } | 4612 } |
| 4613 main() { | 4613 main() { |
| 4614 A.MY_NAM; | 4614 A.MY_NAM; |
| 4615 } | 4615 } |
| 4616 '''); | 4616 '''); |
| 4617 await assertHasFix( | 4617 await assertHasFix( |
| 4618 DartFixKind.CHANGE_TO, | 4618 DartFixKind.CHANGE_TO, |
| 4619 ''' | 4619 ''' |
| 4620 class A { | 4620 class A { |
| 4621 static int MY_NAME = 1; | 4621 static int MY_NAME = 1; |
| 4622 } | 4622 } |
| 4623 main() { | 4623 main() { |
| 4624 A.MY_NAME; | 4624 A.MY_NAME; |
| 4625 } | 4625 } |
| 4626 '''); | 4626 '''); |
| 4627 } | 4627 } |
| 4628 | 4628 |
| 4629 test_undefinedGetter_useSimilar_unqualified() async { | 4629 test_undefinedGetter_useSimilar_unqualified() async { |
| 4630 resolveTestUnit(''' | 4630 await resolveTestUnit(''' |
| 4631 class A { | 4631 class A { |
| 4632 int myField; | 4632 int myField; |
| 4633 main() { | 4633 main() { |
| 4634 print(myFild); | 4634 print(myFild); |
| 4635 } | 4635 } |
| 4636 } | 4636 } |
| 4637 '''); | 4637 '''); |
| 4638 await assertHasFix( | 4638 await assertHasFix( |
| 4639 DartFixKind.CHANGE_TO, | 4639 DartFixKind.CHANGE_TO, |
| 4640 ''' | 4640 ''' |
| 4641 class A { | 4641 class A { |
| 4642 int myField; | 4642 int myField; |
| 4643 main() { | 4643 main() { |
| 4644 print(myField); | 4644 print(myField); |
| 4645 } | 4645 } |
| 4646 } | 4646 } |
| 4647 '''); | 4647 '''); |
| 4648 } | 4648 } |
| 4649 | 4649 |
| 4650 test_undefinedMethod_create_BAD_inSDK() async { | 4650 test_undefinedMethod_create_BAD_inSDK() async { |
| 4651 resolveTestUnit(''' | 4651 await resolveTestUnit(''' |
| 4652 main() { | 4652 main() { |
| 4653 List.foo(); | 4653 List.foo(); |
| 4654 } | 4654 } |
| 4655 '''); | 4655 '''); |
| 4656 await assertNoFix(DartFixKind.CREATE_METHOD); | 4656 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4657 } | 4657 } |
| 4658 | 4658 |
| 4659 test_undefinedMethod_create_BAD_targetIsEnum() async { | 4659 test_undefinedMethod_create_BAD_targetIsEnum() async { |
| 4660 resolveTestUnit(''' | 4660 await resolveTestUnit(''' |
| 4661 enum MyEnum {A, B} | 4661 enum MyEnum {A, B} |
| 4662 main() { | 4662 main() { |
| 4663 MyEnum.foo(); | 4663 MyEnum.foo(); |
| 4664 } | 4664 } |
| 4665 '''); | 4665 '''); |
| 4666 await assertNoFix(DartFixKind.CREATE_METHOD); | 4666 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4667 } | 4667 } |
| 4668 | 4668 |
| 4669 test_undefinedMethod_create_generic_BAD_argumentType() async { | 4669 test_undefinedMethod_create_generic_BAD_argumentType() async { |
| 4670 resolveTestUnit(''' | 4670 await resolveTestUnit(''' |
| 4671 class A<T> { | 4671 class A<T> { |
| 4672 B b; | 4672 B b; |
| 4673 Map<int, T> items; | 4673 Map<int, T> items; |
| 4674 main() { | 4674 main() { |
| 4675 b.process(items); | 4675 b.process(items); |
| 4676 } | 4676 } |
| 4677 } | 4677 } |
| 4678 | 4678 |
| 4679 class B { | 4679 class B { |
| 4680 } | 4680 } |
| 4681 '''); | 4681 '''); |
| 4682 await assertHasFix( | 4682 await assertHasFix( |
| 4683 DartFixKind.CREATE_METHOD, | 4683 DartFixKind.CREATE_METHOD, |
| 4684 ''' | 4684 ''' |
| 4685 class A<T> { | 4685 class A<T> { |
| 4686 B b; | 4686 B b; |
| 4687 Map<int, T> items; | 4687 Map<int, T> items; |
| 4688 main() { | 4688 main() { |
| 4689 b.process(items); | 4689 b.process(items); |
| 4690 } | 4690 } |
| 4691 } | 4691 } |
| 4692 | 4692 |
| 4693 class B { | 4693 class B { |
| 4694 void process(Map items) {} | 4694 void process(Map items) {} |
| 4695 } | 4695 } |
| 4696 '''); | 4696 '''); |
| 4697 } | 4697 } |
| 4698 | 4698 |
| 4699 test_undefinedMethod_create_generic_BAD_returnType() async { | 4699 test_undefinedMethod_create_generic_BAD_returnType() async { |
| 4700 resolveTestUnit(''' | 4700 await resolveTestUnit(''' |
| 4701 class A<T> { | 4701 class A<T> { |
| 4702 main() { | 4702 main() { |
| 4703 T t = new B().compute(); | 4703 T t = new B().compute(); |
| 4704 } | 4704 } |
| 4705 } | 4705 } |
| 4706 | 4706 |
| 4707 class B { | 4707 class B { |
| 4708 } | 4708 } |
| 4709 '''); | 4709 '''); |
| 4710 await assertHasFix( | 4710 await assertHasFix( |
| 4711 DartFixKind.CREATE_METHOD, | 4711 DartFixKind.CREATE_METHOD, |
| 4712 ''' | 4712 ''' |
| 4713 class A<T> { | 4713 class A<T> { |
| 4714 main() { | 4714 main() { |
| 4715 T t = new B().compute(); | 4715 T t = new B().compute(); |
| 4716 } | 4716 } |
| 4717 } | 4717 } |
| 4718 | 4718 |
| 4719 class B { | 4719 class B { |
| 4720 dynamic compute() {} | 4720 dynamic compute() {} |
| 4721 } | 4721 } |
| 4722 '''); | 4722 '''); |
| 4723 } | 4723 } |
| 4724 | 4724 |
| 4725 test_undefinedMethod_create_generic_OK_literal() async { | 4725 test_undefinedMethod_create_generic_OK_literal() async { |
| 4726 resolveTestUnit(''' | 4726 await resolveTestUnit(''' |
| 4727 class A { | 4727 class A { |
| 4728 B b; | 4728 B b; |
| 4729 List<int> items; | 4729 List<int> items; |
| 4730 main() { | 4730 main() { |
| 4731 b.process(items); | 4731 b.process(items); |
| 4732 } | 4732 } |
| 4733 } | 4733 } |
| 4734 | 4734 |
| 4735 class B {} | 4735 class B {} |
| 4736 '''); | 4736 '''); |
| 4737 await assertHasFix( | 4737 await assertHasFix( |
| 4738 DartFixKind.CREATE_METHOD, | 4738 DartFixKind.CREATE_METHOD, |
| 4739 ''' | 4739 ''' |
| 4740 class A { | 4740 class A { |
| 4741 B b; | 4741 B b; |
| 4742 List<int> items; | 4742 List<int> items; |
| 4743 main() { | 4743 main() { |
| 4744 b.process(items); | 4744 b.process(items); |
| 4745 } | 4745 } |
| 4746 } | 4746 } |
| 4747 | 4747 |
| 4748 class B { | 4748 class B { |
| 4749 void process(List<int> items) {} | 4749 void process(List<int> items) {} |
| 4750 } | 4750 } |
| 4751 '''); | 4751 '''); |
| 4752 } | 4752 } |
| 4753 | 4753 |
| 4754 test_undefinedMethod_create_generic_OK_local() async { | 4754 test_undefinedMethod_create_generic_OK_local() async { |
| 4755 resolveTestUnit(''' | 4755 await resolveTestUnit(''' |
| 4756 class A<T> { | 4756 class A<T> { |
| 4757 List<T> items; | 4757 List<T> items; |
| 4758 main() { | 4758 main() { |
| 4759 process(items); | 4759 process(items); |
| 4760 } | 4760 } |
| 4761 } | 4761 } |
| 4762 '''); | 4762 '''); |
| 4763 await assertHasFix( | 4763 await assertHasFix( |
| 4764 DartFixKind.CREATE_METHOD, | 4764 DartFixKind.CREATE_METHOD, |
| 4765 ''' | 4765 ''' |
| 4766 class A<T> { | 4766 class A<T> { |
| 4767 List<T> items; | 4767 List<T> items; |
| 4768 main() { | 4768 main() { |
| 4769 process(items); | 4769 process(items); |
| 4770 } | 4770 } |
| 4771 | 4771 |
| 4772 void process(List<T> items) {} | 4772 void process(List<T> items) {} |
| 4773 } | 4773 } |
| 4774 '''); | 4774 '''); |
| 4775 } | 4775 } |
| 4776 | 4776 |
| 4777 test_undefinedMethod_createQualified_emptyClassBody() async { | 4777 test_undefinedMethod_createQualified_emptyClassBody() async { |
| 4778 resolveTestUnit(''' | 4778 await resolveTestUnit(''' |
| 4779 class A {} | 4779 class A {} |
| 4780 main() { | 4780 main() { |
| 4781 A.myUndefinedMethod(); | 4781 A.myUndefinedMethod(); |
| 4782 } | 4782 } |
| 4783 '''); | 4783 '''); |
| 4784 await assertHasFix( | 4784 await assertHasFix( |
| 4785 DartFixKind.CREATE_METHOD, | 4785 DartFixKind.CREATE_METHOD, |
| 4786 ''' | 4786 ''' |
| 4787 class A { | 4787 class A { |
| 4788 static void myUndefinedMethod() {} | 4788 static void myUndefinedMethod() {} |
| 4789 } | 4789 } |
| 4790 main() { | 4790 main() { |
| 4791 A.myUndefinedMethod(); | 4791 A.myUndefinedMethod(); |
| 4792 } | 4792 } |
| 4793 '''); | 4793 '''); |
| 4794 } | 4794 } |
| 4795 | 4795 |
| 4796 test_undefinedMethod_createQualified_fromClass() async { | 4796 test_undefinedMethod_createQualified_fromClass() async { |
| 4797 resolveTestUnit(''' | 4797 await resolveTestUnit(''' |
| 4798 class A { | 4798 class A { |
| 4799 } | 4799 } |
| 4800 main() { | 4800 main() { |
| 4801 A.myUndefinedMethod(); | 4801 A.myUndefinedMethod(); |
| 4802 } | 4802 } |
| 4803 '''); | 4803 '''); |
| 4804 await assertHasFix( | 4804 await assertHasFix( |
| 4805 DartFixKind.CREATE_METHOD, | 4805 DartFixKind.CREATE_METHOD, |
| 4806 ''' | 4806 ''' |
| 4807 class A { | 4807 class A { |
| 4808 static void myUndefinedMethod() {} | 4808 static void myUndefinedMethod() {} |
| 4809 } | 4809 } |
| 4810 main() { | 4810 main() { |
| 4811 A.myUndefinedMethod(); | 4811 A.myUndefinedMethod(); |
| 4812 } | 4812 } |
| 4813 '''); | 4813 '''); |
| 4814 } | 4814 } |
| 4815 | 4815 |
| 4816 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { | 4816 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { |
| 4817 resolveTestUnit(''' | 4817 await resolveTestUnit(''' |
| 4818 class A { | 4818 class A { |
| 4819 foo() {} | 4819 foo() {} |
| 4820 } | 4820 } |
| 4821 main() { | 4821 main() { |
| 4822 A.myUndefinedMethod(); | 4822 A.myUndefinedMethod(); |
| 4823 } | 4823 } |
| 4824 '''); | 4824 '''); |
| 4825 await assertHasFix( | 4825 await assertHasFix( |
| 4826 DartFixKind.CREATE_METHOD, | 4826 DartFixKind.CREATE_METHOD, |
| 4827 ''' | 4827 ''' |
| 4828 class A { | 4828 class A { |
| 4829 foo() {} | 4829 foo() {} |
| 4830 | 4830 |
| 4831 static void myUndefinedMethod() {} | 4831 static void myUndefinedMethod() {} |
| 4832 } | 4832 } |
| 4833 main() { | 4833 main() { |
| 4834 A.myUndefinedMethod(); | 4834 A.myUndefinedMethod(); |
| 4835 } | 4835 } |
| 4836 '''); | 4836 '''); |
| 4837 } | 4837 } |
| 4838 | 4838 |
| 4839 test_undefinedMethod_createQualified_fromInstance() async { | 4839 test_undefinedMethod_createQualified_fromInstance() async { |
| 4840 resolveTestUnit(''' | 4840 await resolveTestUnit(''' |
| 4841 class A { | 4841 class A { |
| 4842 } | 4842 } |
| 4843 main(A a) { | 4843 main(A a) { |
| 4844 a.myUndefinedMethod(); | 4844 a.myUndefinedMethod(); |
| 4845 } | 4845 } |
| 4846 '''); | 4846 '''); |
| 4847 await assertHasFix( | 4847 await assertHasFix( |
| 4848 DartFixKind.CREATE_METHOD, | 4848 DartFixKind.CREATE_METHOD, |
| 4849 ''' | 4849 ''' |
| 4850 class A { | 4850 class A { |
| 4851 void myUndefinedMethod() {} | 4851 void myUndefinedMethod() {} |
| 4852 } | 4852 } |
| 4853 main(A a) { | 4853 main(A a) { |
| 4854 a.myUndefinedMethod(); | 4854 a.myUndefinedMethod(); |
| 4855 } | 4855 } |
| 4856 '''); | 4856 '''); |
| 4857 } | 4857 } |
| 4858 | 4858 |
| 4859 test_undefinedMethod_createQualified_targetIsFunctionType() async { | 4859 test_undefinedMethod_createQualified_targetIsFunctionType() async { |
| 4860 resolveTestUnit(''' | 4860 await resolveTestUnit(''' |
| 4861 typedef A(); | 4861 typedef A(); |
| 4862 main() { | 4862 main() { |
| 4863 A.myUndefinedMethod(); | 4863 A.myUndefinedMethod(); |
| 4864 } | 4864 } |
| 4865 '''); | 4865 '''); |
| 4866 await assertNoFix(DartFixKind.CREATE_METHOD); | 4866 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4867 } | 4867 } |
| 4868 | 4868 |
| 4869 test_undefinedMethod_createQualified_targetIsUnresolved() async { | 4869 test_undefinedMethod_createQualified_targetIsUnresolved() async { |
| 4870 resolveTestUnit(''' | 4870 await resolveTestUnit(''' |
| 4871 main() { | 4871 main() { |
| 4872 NoSuchClass.myUndefinedMethod(); | 4872 NoSuchClass.myUndefinedMethod(); |
| 4873 } | 4873 } |
| 4874 '''); | 4874 '''); |
| 4875 await assertNoFix(DartFixKind.CREATE_METHOD); | 4875 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4876 } | 4876 } |
| 4877 | 4877 |
| 4878 test_undefinedMethod_createUnqualified_duplicateArgumentNames() async { | 4878 test_undefinedMethod_createUnqualified_duplicateArgumentNames() async { |
| 4879 resolveTestUnit(''' | 4879 await resolveTestUnit(''' |
| 4880 class C { | 4880 class C { |
| 4881 int x; | 4881 int x; |
| 4882 } | 4882 } |
| 4883 | 4883 |
| 4884 class D { | 4884 class D { |
| 4885 foo(C c1, C c2) { | 4885 foo(C c1, C c2) { |
| 4886 bar(c1.x, c2.x); | 4886 bar(c1.x, c2.x); |
| 4887 } | 4887 } |
| 4888 }'''); | 4888 }'''); |
| 4889 await assertHasFix( | 4889 await assertHasFix( |
| 4890 DartFixKind.CREATE_METHOD, | 4890 DartFixKind.CREATE_METHOD, |
| 4891 ''' | 4891 ''' |
| 4892 class C { | 4892 class C { |
| 4893 int x; | 4893 int x; |
| 4894 } | 4894 } |
| 4895 | 4895 |
| 4896 class D { | 4896 class D { |
| 4897 foo(C c1, C c2) { | 4897 foo(C c1, C c2) { |
| 4898 bar(c1.x, c2.x); | 4898 bar(c1.x, c2.x); |
| 4899 } | 4899 } |
| 4900 | 4900 |
| 4901 void bar(int x, int x2) {} | 4901 void bar(int x, int x2) {} |
| 4902 }'''); | 4902 }'''); |
| 4903 } | 4903 } |
| 4904 | 4904 |
| 4905 test_undefinedMethod_createUnqualified_parameters() async { | 4905 test_undefinedMethod_createUnqualified_parameters() async { |
| 4906 resolveTestUnit(''' | 4906 await resolveTestUnit(''' |
| 4907 class A { | 4907 class A { |
| 4908 main() { | 4908 main() { |
| 4909 myUndefinedMethod(0, 1.0, '3'); | 4909 myUndefinedMethod(0, 1.0, '3'); |
| 4910 } | 4910 } |
| 4911 } | 4911 } |
| 4912 '''); | 4912 '''); |
| 4913 await assertHasFix( | 4913 await assertHasFix( |
| 4914 DartFixKind.CREATE_METHOD, | 4914 DartFixKind.CREATE_METHOD, |
| 4915 ''' | 4915 ''' |
| 4916 class A { | 4916 class A { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4941 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); | 4941 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); |
| 4942 _assertLinkedGroup( | 4942 _assertLinkedGroup( |
| 4943 change.linkedEditGroups[index++], | 4943 change.linkedEditGroups[index++], |
| 4944 ['String s'], | 4944 ['String s'], |
| 4945 expectedSuggestions(LinkedEditSuggestionKind.TYPE, | 4945 expectedSuggestions(LinkedEditSuggestionKind.TYPE, |
| 4946 ['String', 'Object', 'Comparable<String>', 'Pattern'])); | 4946 ['String', 'Object', 'Comparable<String>', 'Pattern'])); |
| 4947 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); | 4947 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); |
| 4948 } | 4948 } |
| 4949 | 4949 |
| 4950 test_undefinedMethod_createUnqualified_parameters_named() async { | 4950 test_undefinedMethod_createUnqualified_parameters_named() async { |
| 4951 resolveTestUnit(''' | 4951 await resolveTestUnit(''' |
| 4952 class A { | 4952 class A { |
| 4953 main() { | 4953 main() { |
| 4954 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); | 4954 myUndefinedMethod(0, bbb: 1.0, ccc: '2'); |
| 4955 } | 4955 } |
| 4956 } | 4956 } |
| 4957 '''); | 4957 '''); |
| 4958 await assertHasFix( | 4958 await assertHasFix( |
| 4959 DartFixKind.CREATE_METHOD, | 4959 DartFixKind.CREATE_METHOD, |
| 4960 ''' | 4960 ''' |
| 4961 class A { | 4961 class A { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4984 expectedSuggestions(LinkedEditSuggestionKind.TYPE, | 4984 expectedSuggestions(LinkedEditSuggestionKind.TYPE, |
| 4985 ['double', 'num', 'Object', 'Comparable<num>'])); | 4985 ['double', 'num', 'Object', 'Comparable<num>'])); |
| 4986 _assertLinkedGroup( | 4986 _assertLinkedGroup( |
| 4987 change.linkedEditGroups[index++], | 4987 change.linkedEditGroups[index++], |
| 4988 ['String ccc'], | 4988 ['String ccc'], |
| 4989 expectedSuggestions(LinkedEditSuggestionKind.TYPE, | 4989 expectedSuggestions(LinkedEditSuggestionKind.TYPE, |
| 4990 ['String', 'Object', 'Comparable<String>', 'Pattern'])); | 4990 ['String', 'Object', 'Comparable<String>', 'Pattern'])); |
| 4991 } | 4991 } |
| 4992 | 4992 |
| 4993 test_undefinedMethod_createUnqualified_returnType() async { | 4993 test_undefinedMethod_createUnqualified_returnType() async { |
| 4994 resolveTestUnit(''' | 4994 await resolveTestUnit(''' |
| 4995 class A { | 4995 class A { |
| 4996 main() { | 4996 main() { |
| 4997 int v = myUndefinedMethod(); | 4997 int v = myUndefinedMethod(); |
| 4998 } | 4998 } |
| 4999 } | 4999 } |
| 5000 '''); | 5000 '''); |
| 5001 await assertHasFix( | 5001 await assertHasFix( |
| 5002 DartFixKind.CREATE_METHOD, | 5002 DartFixKind.CREATE_METHOD, |
| 5003 ''' | 5003 ''' |
| 5004 class A { | 5004 class A { |
| 5005 main() { | 5005 main() { |
| 5006 int v = myUndefinedMethod(); | 5006 int v = myUndefinedMethod(); |
| 5007 } | 5007 } |
| 5008 | 5008 |
| 5009 int myUndefinedMethod() {} | 5009 int myUndefinedMethod() {} |
| 5010 } | 5010 } |
| 5011 '''); | 5011 '''); |
| 5012 // linked positions | 5012 // linked positions |
| 5013 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); | 5013 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); |
| 5014 _assertLinkedGroup(change.linkedEditGroups[1], | 5014 _assertLinkedGroup(change.linkedEditGroups[1], |
| 5015 ['myUndefinedMethod();', 'myUndefinedMethod() {']); | 5015 ['myUndefinedMethod();', 'myUndefinedMethod() {']); |
| 5016 } | 5016 } |
| 5017 | 5017 |
| 5018 test_undefinedMethod_createUnqualified_staticFromField() async { | 5018 test_undefinedMethod_createUnqualified_staticFromField() async { |
| 5019 resolveTestUnit(''' | 5019 await resolveTestUnit(''' |
| 5020 class A { | 5020 class A { |
| 5021 static var f = myUndefinedMethod(); | 5021 static var f = myUndefinedMethod(); |
| 5022 } | 5022 } |
| 5023 '''); | 5023 '''); |
| 5024 await assertHasFix( | 5024 await assertHasFix( |
| 5025 DartFixKind.CREATE_METHOD, | 5025 DartFixKind.CREATE_METHOD, |
| 5026 ''' | 5026 ''' |
| 5027 class A { | 5027 class A { |
| 5028 static var f = myUndefinedMethod(); | 5028 static var f = myUndefinedMethod(); |
| 5029 | 5029 |
| 5030 static myUndefinedMethod() {} | 5030 static myUndefinedMethod() {} |
| 5031 } | 5031 } |
| 5032 '''); | 5032 '''); |
| 5033 } | 5033 } |
| 5034 | 5034 |
| 5035 test_undefinedMethod_createUnqualified_staticFromMethod() async { | 5035 test_undefinedMethod_createUnqualified_staticFromMethod() async { |
| 5036 resolveTestUnit(''' | 5036 await resolveTestUnit(''' |
| 5037 class A { | 5037 class A { |
| 5038 static main() { | 5038 static main() { |
| 5039 myUndefinedMethod(); | 5039 myUndefinedMethod(); |
| 5040 } | 5040 } |
| 5041 } | 5041 } |
| 5042 '''); | 5042 '''); |
| 5043 await assertHasFix( | 5043 await assertHasFix( |
| 5044 DartFixKind.CREATE_METHOD, | 5044 DartFixKind.CREATE_METHOD, |
| 5045 ''' | 5045 ''' |
| 5046 class A { | 5046 class A { |
| 5047 static main() { | 5047 static main() { |
| 5048 myUndefinedMethod(); | 5048 myUndefinedMethod(); |
| 5049 } | 5049 } |
| 5050 | 5050 |
| 5051 static void myUndefinedMethod() {} | 5051 static void myUndefinedMethod() {} |
| 5052 } | 5052 } |
| 5053 '''); | 5053 '''); |
| 5054 } | 5054 } |
| 5055 | 5055 |
| 5056 test_undefinedMethod_hint_createQualified_fromInstance() async { | 5056 test_undefinedMethod_hint_createQualified_fromInstance() async { |
| 5057 resolveTestUnit(''' | 5057 await resolveTestUnit(''' |
| 5058 class A { | 5058 class A { |
| 5059 } | 5059 } |
| 5060 main() { | 5060 main() { |
| 5061 var a = new A(); | 5061 var a = new A(); |
| 5062 a.myUndefinedMethod(); | 5062 a.myUndefinedMethod(); |
| 5063 } | 5063 } |
| 5064 '''); | 5064 '''); |
| 5065 await assertHasFix( | 5065 await assertHasFix( |
| 5066 DartFixKind.CREATE_METHOD, | 5066 DartFixKind.CREATE_METHOD, |
| 5067 ''' | 5067 ''' |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5083 class D { | 5083 class D { |
| 5084 } | 5084 } |
| 5085 '''; | 5085 '''; |
| 5086 addSource('/test2.dart', code2); | 5086 addSource('/test2.dart', code2); |
| 5087 addSource( | 5087 addSource( |
| 5088 '/test3.dart', | 5088 '/test3.dart', |
| 5089 r''' | 5089 r''' |
| 5090 library test3; | 5090 library test3; |
| 5091 class E {} | 5091 class E {} |
| 5092 '''); | 5092 '''); |
| 5093 resolveTestUnit(''' | 5093 await resolveTestUnit(''' |
| 5094 library test; | 5094 library test; |
| 5095 import 'test2.dart' as aaa; | 5095 import 'test2.dart' as aaa; |
| 5096 main(aaa.D d, aaa.E e) { | 5096 main(aaa.D d, aaa.E e) { |
| 5097 d.foo(e); | 5097 d.foo(e); |
| 5098 } | 5098 } |
| 5099 '''); | 5099 '''); |
| 5100 AnalysisError error = _findErrorToFix(); | 5100 AnalysisError error = _findErrorToFix(); |
| 5101 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5101 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 5102 change = fix.change; | 5102 change = fix.change; |
| 5103 // apply to "test2.dart" | 5103 // apply to "test2.dart" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5118 } | 5118 } |
| 5119 | 5119 |
| 5120 test_undefinedMethod_parameterType_inTargetUnit() async { | 5120 test_undefinedMethod_parameterType_inTargetUnit() async { |
| 5121 String code2 = r''' | 5121 String code2 = r''' |
| 5122 library test2; | 5122 library test2; |
| 5123 class D { | 5123 class D { |
| 5124 } | 5124 } |
| 5125 class E {} | 5125 class E {} |
| 5126 '''; | 5126 '''; |
| 5127 addSource('/test2.dart', code2); | 5127 addSource('/test2.dart', code2); |
| 5128 resolveTestUnit(''' | 5128 await resolveTestUnit(''' |
| 5129 library test; | 5129 library test; |
| 5130 import 'test2.dart' as test2; | 5130 import 'test2.dart' as test2; |
| 5131 main(test2.D d, test2.E e) { | 5131 main(test2.D d, test2.E e) { |
| 5132 d.foo(e); | 5132 d.foo(e); |
| 5133 } | 5133 } |
| 5134 '''); | 5134 '''); |
| 5135 AnalysisError error = _findErrorToFix(); | 5135 AnalysisError error = _findErrorToFix(); |
| 5136 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5136 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 5137 change = fix.change; | 5137 change = fix.change; |
| 5138 // apply to "test2.dart" | 5138 // apply to "test2.dart" |
| 5139 List<SourceFileEdit> fileEdits = change.edits; | 5139 List<SourceFileEdit> fileEdits = change.edits; |
| 5140 expect(fileEdits, hasLength(1)); | 5140 expect(fileEdits, hasLength(1)); |
| 5141 SourceFileEdit fileEdit = change.edits[0]; | 5141 SourceFileEdit fileEdit = change.edits[0]; |
| 5142 expect(fileEdit.file, '/test2.dart'); | 5142 expect(fileEdit.file, '/test2.dart'); |
| 5143 expect( | 5143 expect( |
| 5144 SourceEdit.applySequence(code2, fileEdit.edits), | 5144 SourceEdit.applySequence(code2, fileEdit.edits), |
| 5145 r''' | 5145 r''' |
| 5146 library test2; | 5146 library test2; |
| 5147 class D { | 5147 class D { |
| 5148 void foo(E e) {} | 5148 void foo(E e) {} |
| 5149 } | 5149 } |
| 5150 class E {} | 5150 class E {} |
| 5151 '''); | 5151 '''); |
| 5152 } | 5152 } |
| 5153 | 5153 |
| 5154 test_undefinedMethod_useSimilar_ignoreOperators() async { | 5154 test_undefinedMethod_useSimilar_ignoreOperators() async { |
| 5155 resolveTestUnit(''' | 5155 await resolveTestUnit(''' |
| 5156 main(Object object) { | 5156 main(Object object) { |
| 5157 object.then(); | 5157 object.then(); |
| 5158 } | 5158 } |
| 5159 '''); | 5159 '''); |
| 5160 await assertNoFix(DartFixKind.CHANGE_TO); | 5160 await assertNoFix(DartFixKind.CHANGE_TO); |
| 5161 } | 5161 } |
| 5162 | 5162 |
| 5163 test_undefinedMethod_useSimilar_qualified() async { | 5163 test_undefinedMethod_useSimilar_qualified() async { |
| 5164 resolveTestUnit(''' | 5164 await resolveTestUnit(''' |
| 5165 class A { | 5165 class A { |
| 5166 myMethod() {} | 5166 myMethod() {} |
| 5167 } | 5167 } |
| 5168 main() { | 5168 main() { |
| 5169 A a = new A(); | 5169 A a = new A(); |
| 5170 a.myMehtod(); | 5170 a.myMehtod(); |
| 5171 } | 5171 } |
| 5172 '''); | 5172 '''); |
| 5173 await assertHasFix( | 5173 await assertHasFix( |
| 5174 DartFixKind.CHANGE_TO, | 5174 DartFixKind.CHANGE_TO, |
| 5175 ''' | 5175 ''' |
| 5176 class A { | 5176 class A { |
| 5177 myMethod() {} | 5177 myMethod() {} |
| 5178 } | 5178 } |
| 5179 main() { | 5179 main() { |
| 5180 A a = new A(); | 5180 A a = new A(); |
| 5181 a.myMethod(); | 5181 a.myMethod(); |
| 5182 } | 5182 } |
| 5183 '''); | 5183 '''); |
| 5184 } | 5184 } |
| 5185 | 5185 |
| 5186 test_undefinedMethod_useSimilar_unqualified_superClass() async { | 5186 test_undefinedMethod_useSimilar_unqualified_superClass() async { |
| 5187 resolveTestUnit(''' | 5187 await resolveTestUnit(''' |
| 5188 class A { | 5188 class A { |
| 5189 myMethod() {} | 5189 myMethod() {} |
| 5190 } | 5190 } |
| 5191 class B extends A { | 5191 class B extends A { |
| 5192 main() { | 5192 main() { |
| 5193 myMehtod(); | 5193 myMehtod(); |
| 5194 } | 5194 } |
| 5195 } | 5195 } |
| 5196 '''); | 5196 '''); |
| 5197 await assertHasFix( | 5197 await assertHasFix( |
| 5198 DartFixKind.CHANGE_TO, | 5198 DartFixKind.CHANGE_TO, |
| 5199 ''' | 5199 ''' |
| 5200 class A { | 5200 class A { |
| 5201 myMethod() {} | 5201 myMethod() {} |
| 5202 } | 5202 } |
| 5203 class B extends A { | 5203 class B extends A { |
| 5204 main() { | 5204 main() { |
| 5205 myMethod(); | 5205 myMethod(); |
| 5206 } | 5206 } |
| 5207 } | 5207 } |
| 5208 '''); | 5208 '''); |
| 5209 } | 5209 } |
| 5210 | 5210 |
| 5211 test_undefinedMethod_useSimilar_unqualified_thisClass() async { | 5211 test_undefinedMethod_useSimilar_unqualified_thisClass() async { |
| 5212 resolveTestUnit(''' | 5212 await resolveTestUnit(''' |
| 5213 class A { | 5213 class A { |
| 5214 myMethod() {} | 5214 myMethod() {} |
| 5215 main() { | 5215 main() { |
| 5216 myMehtod(); | 5216 myMehtod(); |
| 5217 } | 5217 } |
| 5218 } | 5218 } |
| 5219 '''); | 5219 '''); |
| 5220 await assertHasFix( | 5220 await assertHasFix( |
| 5221 DartFixKind.CHANGE_TO, | 5221 DartFixKind.CHANGE_TO, |
| 5222 ''' | 5222 ''' |
| 5223 class A { | 5223 class A { |
| 5224 myMethod() {} | 5224 myMethod() {} |
| 5225 main() { | 5225 main() { |
| 5226 myMethod(); | 5226 myMethod(); |
| 5227 } | 5227 } |
| 5228 } | 5228 } |
| 5229 '''); | 5229 '''); |
| 5230 } | 5230 } |
| 5231 | 5231 |
| 5232 test_undefinedSetter_useSimilar_hint() async { | 5232 test_undefinedSetter_useSimilar_hint() async { |
| 5233 resolveTestUnit(''' | 5233 await resolveTestUnit(''' |
| 5234 class A { | 5234 class A { |
| 5235 int myField; | 5235 int myField; |
| 5236 } | 5236 } |
| 5237 main(A a) { | 5237 main(A a) { |
| 5238 var x = a; | 5238 var x = a; |
| 5239 x.myFild = 42; | 5239 x.myFild = 42; |
| 5240 } | 5240 } |
| 5241 '''); | 5241 '''); |
| 5242 await assertHasFix( | 5242 await assertHasFix( |
| 5243 DartFixKind.CHANGE_TO, | 5243 DartFixKind.CHANGE_TO, |
| 5244 ''' | 5244 ''' |
| 5245 class A { | 5245 class A { |
| 5246 int myField; | 5246 int myField; |
| 5247 } | 5247 } |
| 5248 main(A a) { | 5248 main(A a) { |
| 5249 var x = a; | 5249 var x = a; |
| 5250 x.myField = 42; | 5250 x.myField = 42; |
| 5251 } | 5251 } |
| 5252 '''); | 5252 '''); |
| 5253 } | 5253 } |
| 5254 | 5254 |
| 5255 test_undefinedSetter_useSimilar_qualified() async { | 5255 test_undefinedSetter_useSimilar_qualified() async { |
| 5256 resolveTestUnit(''' | 5256 await resolveTestUnit(''' |
| 5257 class A { | 5257 class A { |
| 5258 int myField; | 5258 int myField; |
| 5259 } | 5259 } |
| 5260 main(A a) { | 5260 main(A a) { |
| 5261 a.myFild = 42; | 5261 a.myFild = 42; |
| 5262 } | 5262 } |
| 5263 '''); | 5263 '''); |
| 5264 await assertHasFix( | 5264 await assertHasFix( |
| 5265 DartFixKind.CHANGE_TO, | 5265 DartFixKind.CHANGE_TO, |
| 5266 ''' | 5266 ''' |
| 5267 class A { | 5267 class A { |
| 5268 int myField; | 5268 int myField; |
| 5269 } | 5269 } |
| 5270 main(A a) { | 5270 main(A a) { |
| 5271 a.myField = 42; | 5271 a.myField = 42; |
| 5272 } | 5272 } |
| 5273 '''); | 5273 '''); |
| 5274 } | 5274 } |
| 5275 | 5275 |
| 5276 test_undefinedSetter_useSimilar_unqualified() async { | 5276 test_undefinedSetter_useSimilar_unqualified() async { |
| 5277 resolveTestUnit(''' | 5277 await resolveTestUnit(''' |
| 5278 class A { | 5278 class A { |
| 5279 int myField; | 5279 int myField; |
| 5280 main() { | 5280 main() { |
| 5281 myFild = 42; | 5281 myFild = 42; |
| 5282 } | 5282 } |
| 5283 } | 5283 } |
| 5284 '''); | 5284 '''); |
| 5285 await assertHasFix( | 5285 await assertHasFix( |
| 5286 DartFixKind.CHANGE_TO, | 5286 DartFixKind.CHANGE_TO, |
| 5287 ''' | 5287 ''' |
| 5288 class A { | 5288 class A { |
| 5289 int myField; | 5289 int myField; |
| 5290 main() { | 5290 main() { |
| 5291 myField = 42; | 5291 myField = 42; |
| 5292 } | 5292 } |
| 5293 } | 5293 } |
| 5294 '''); | 5294 '''); |
| 5295 } | 5295 } |
| 5296 | 5296 |
| 5297 test_useEffectiveIntegerDivision() async { | 5297 test_useEffectiveIntegerDivision() async { |
| 5298 resolveTestUnit(''' | 5298 await resolveTestUnit(''' |
| 5299 main() { | 5299 main() { |
| 5300 var a = 5; | 5300 var a = 5; |
| 5301 var b = 2; | 5301 var b = 2; |
| 5302 print((a / b).toInt()); | 5302 print((a / b).toInt()); |
| 5303 } | 5303 } |
| 5304 '''); | 5304 '''); |
| 5305 await assertHasFix( | 5305 await assertHasFix( |
| 5306 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, | 5306 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, |
| 5307 ''' | 5307 ''' |
| 5308 main() { | 5308 main() { |
| 5309 var a = 5; | 5309 var a = 5; |
| 5310 var b = 2; | 5310 var b = 2; |
| 5311 print(a ~/ b); | 5311 print(a ~/ b); |
| 5312 } | 5312 } |
| 5313 '''); | 5313 '''); |
| 5314 } | 5314 } |
| 5315 | 5315 |
| 5316 test_useImportPrefix_withClass() async { | 5316 test_useImportPrefix_withClass() async { |
| 5317 resolveTestUnit(''' | 5317 await resolveTestUnit(''' |
| 5318 import 'dart:async' as pref; | 5318 import 'dart:async' as pref; |
| 5319 main() { | 5319 main() { |
| 5320 pref.Stream s = null; | 5320 pref.Stream s = null; |
| 5321 Future f = null; | 5321 Future f = null; |
| 5322 } | 5322 } |
| 5323 '''); | 5323 '''); |
| 5324 await assertHasFix( | 5324 await assertHasFix( |
| 5325 DartFixKind.IMPORT_LIBRARY_PREFIX, | 5325 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 5326 ''' | 5326 ''' |
| 5327 import 'dart:async' as pref; | 5327 import 'dart:async' as pref; |
| 5328 main() { | 5328 main() { |
| 5329 pref.Stream s = null; | 5329 pref.Stream s = null; |
| 5330 pref.Future f = null; | 5330 pref.Future f = null; |
| 5331 } | 5331 } |
| 5332 '''); | 5332 '''); |
| 5333 } | 5333 } |
| 5334 | 5334 |
| 5335 test_useImportPrefix_withTopLevelVariable() async { | 5335 test_useImportPrefix_withTopLevelVariable() async { |
| 5336 resolveTestUnit(''' | 5336 await resolveTestUnit(''' |
| 5337 import 'dart:math' as pref; | 5337 import 'dart:math' as pref; |
| 5338 main() { | 5338 main() { |
| 5339 print(pref.E); | 5339 print(pref.E); |
| 5340 print(PI); | 5340 print(PI); |
| 5341 } | 5341 } |
| 5342 '''); | 5342 '''); |
| 5343 await assertHasFix( | 5343 await assertHasFix( |
| 5344 DartFixKind.IMPORT_LIBRARY_PREFIX, | 5344 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 5345 ''' | 5345 ''' |
| 5346 import 'dart:math' as pref; | 5346 import 'dart:math' as pref; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5358 | 5358 |
| 5359 Future applyFix(FixKind kind) async { | 5359 Future applyFix(FixKind kind) async { |
| 5360 fix = await _assertHasFix(kind, error); | 5360 fix = await _assertHasFix(kind, error); |
| 5361 change = fix.change; | 5361 change = fix.change; |
| 5362 // apply to "file" | 5362 // apply to "file" |
| 5363 List<SourceFileEdit> fileEdits = change.edits; | 5363 List<SourceFileEdit> fileEdits = change.edits; |
| 5364 expect(fileEdits, hasLength(1)); | 5364 expect(fileEdits, hasLength(1)); |
| 5365 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 5365 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 5366 } | 5366 } |
| 5367 | 5367 |
| 5368 void findLint(String src, String lintCode, {int length: 1}) { | 5368 Future<Null> findLint(String src, String lintCode, {int length: 1}) async { |
| 5369 int errorOffset = src.indexOf('/*LINT*/'); | 5369 int errorOffset = src.indexOf('/*LINT*/'); |
| 5370 resolveTestUnit(src.replaceAll('/*LINT*/', '')); | 5370 await resolveTestUnit(src.replaceAll('/*LINT*/', '')); |
| 5371 error = new AnalysisError( | 5371 error = new AnalysisError( |
| 5372 resolutionMap.elementDeclaredByCompilationUnit(testUnit).source, | 5372 resolutionMap.elementDeclaredByCompilationUnit(testUnit).source, |
| 5373 errorOffset, | 5373 errorOffset, |
| 5374 length, | 5374 length, |
| 5375 new LintCode(lintCode, '<ignored>')); | 5375 new LintCode(lintCode, '<ignored>')); |
| 5376 } | 5376 } |
| 5377 | 5377 |
| 5378 test_lint_addMissingOverride_field() async { | 5378 test_lint_addMissingOverride_field() async { |
| 5379 String src = ''' | 5379 String src = ''' |
| 5380 class abstract Test { | 5380 class abstract Test { |
| 5381 int get t; | 5381 int get t; |
| 5382 } | 5382 } |
| 5383 class Sub extends Test { | 5383 class Sub extends Test { |
| 5384 int /*LINT*/t = 42; | 5384 int /*LINT*/t = 42; |
| 5385 } | 5385 } |
| 5386 '''; | 5386 '''; |
| 5387 findLint(src, LintNames.annotate_overrides); | 5387 await findLint(src, LintNames.annotate_overrides); |
| 5388 | 5388 |
| 5389 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5389 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5390 | 5390 |
| 5391 verifyResult(''' | 5391 verifyResult(''' |
| 5392 class abstract Test { | 5392 class abstract Test { |
| 5393 int get t; | 5393 int get t; |
| 5394 } | 5394 } |
| 5395 class Sub extends Test { | 5395 class Sub extends Test { |
| 5396 @override | 5396 @override |
| 5397 int t = 42; | 5397 int t = 42; |
| 5398 } | 5398 } |
| 5399 '''); | 5399 '''); |
| 5400 } | 5400 } |
| 5401 | 5401 |
| 5402 test_lint_addMissingOverride_getter() async { | 5402 test_lint_addMissingOverride_getter() async { |
| 5403 String src = ''' | 5403 String src = ''' |
| 5404 class Test { | 5404 class Test { |
| 5405 int get t => null; | 5405 int get t => null; |
| 5406 } | 5406 } |
| 5407 class Sub extends Test { | 5407 class Sub extends Test { |
| 5408 int get /*LINT*/t => null; | 5408 int get /*LINT*/t => null; |
| 5409 } | 5409 } |
| 5410 '''; | 5410 '''; |
| 5411 findLint(src, LintNames.annotate_overrides); | 5411 await findLint(src, LintNames.annotate_overrides); |
| 5412 | 5412 |
| 5413 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5413 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5414 | 5414 |
| 5415 verifyResult(''' | 5415 verifyResult(''' |
| 5416 class Test { | 5416 class Test { |
| 5417 int get t => null; | 5417 int get t => null; |
| 5418 } | 5418 } |
| 5419 class Sub extends Test { | 5419 class Sub extends Test { |
| 5420 @override | 5420 @override |
| 5421 int get t => null; | 5421 int get t => null; |
| 5422 } | 5422 } |
| 5423 '''); | 5423 '''); |
| 5424 } | 5424 } |
| 5425 | 5425 |
| 5426 test_lint_addMissingOverride_method() async { | 5426 test_lint_addMissingOverride_method() async { |
| 5427 String src = ''' | 5427 String src = ''' |
| 5428 class Test { | 5428 class Test { |
| 5429 void t() { } | 5429 void t() { } |
| 5430 } | 5430 } |
| 5431 class Sub extends Test { | 5431 class Sub extends Test { |
| 5432 void /*LINT*/t() { } | 5432 void /*LINT*/t() { } |
| 5433 } | 5433 } |
| 5434 '''; | 5434 '''; |
| 5435 findLint(src, LintNames.annotate_overrides); | 5435 await findLint(src, LintNames.annotate_overrides); |
| 5436 | 5436 |
| 5437 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5437 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5438 | 5438 |
| 5439 verifyResult(''' | 5439 verifyResult(''' |
| 5440 class Test { | 5440 class Test { |
| 5441 void t() { } | 5441 void t() { } |
| 5442 } | 5442 } |
| 5443 class Sub extends Test { | 5443 class Sub extends Test { |
| 5444 @override | 5444 @override |
| 5445 void t() { } | 5445 void t() { } |
| 5446 } | 5446 } |
| 5447 '''); | 5447 '''); |
| 5448 } | 5448 } |
| 5449 | 5449 |
| 5450 test_lint_addMissingOverride_method_with_doc_comment() async { | 5450 test_lint_addMissingOverride_method_with_doc_comment() async { |
| 5451 String src = ''' | 5451 String src = ''' |
| 5452 class Test { | 5452 class Test { |
| 5453 void t() { } | 5453 void t() { } |
| 5454 } | 5454 } |
| 5455 class Sub extends Test { | 5455 class Sub extends Test { |
| 5456 /// Doc comment. | 5456 /// Doc comment. |
| 5457 void /*LINT*/t() { } | 5457 void /*LINT*/t() { } |
| 5458 } | 5458 } |
| 5459 '''; | 5459 '''; |
| 5460 findLint(src, LintNames.annotate_overrides); | 5460 await findLint(src, LintNames.annotate_overrides); |
| 5461 | 5461 |
| 5462 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5462 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5463 | 5463 |
| 5464 verifyResult(''' | 5464 verifyResult(''' |
| 5465 class Test { | 5465 class Test { |
| 5466 void t() { } | 5466 void t() { } |
| 5467 } | 5467 } |
| 5468 class Sub extends Test { | 5468 class Sub extends Test { |
| 5469 /// Doc comment. | 5469 /// Doc comment. |
| 5470 @override | 5470 @override |
| 5471 void t() { } | 5471 void t() { } |
| 5472 } | 5472 } |
| 5473 '''); | 5473 '''); |
| 5474 } | 5474 } |
| 5475 | 5475 |
| 5476 test_lint_addMissingOverride_method_with_doc_comment_2() async { | 5476 test_lint_addMissingOverride_method_with_doc_comment_2() async { |
| 5477 String src = ''' | 5477 String src = ''' |
| 5478 class Test { | 5478 class Test { |
| 5479 void t() { } | 5479 void t() { } |
| 5480 } | 5480 } |
| 5481 class Sub extends Test { | 5481 class Sub extends Test { |
| 5482 /** | 5482 /** |
| 5483 * Doc comment. | 5483 * Doc comment. |
| 5484 */ | 5484 */ |
| 5485 void /*LINT*/t() { } | 5485 void /*LINT*/t() { } |
| 5486 } | 5486 } |
| 5487 '''; | 5487 '''; |
| 5488 findLint(src, LintNames.annotate_overrides); | 5488 await findLint(src, LintNames.annotate_overrides); |
| 5489 | 5489 |
| 5490 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5490 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5491 | 5491 |
| 5492 verifyResult(''' | 5492 verifyResult(''' |
| 5493 class Test { | 5493 class Test { |
| 5494 void t() { } | 5494 void t() { } |
| 5495 } | 5495 } |
| 5496 class Sub extends Test { | 5496 class Sub extends Test { |
| 5497 /** | 5497 /** |
| 5498 * Doc comment. | 5498 * Doc comment. |
| 5499 */ | 5499 */ |
| 5500 @override | 5500 @override |
| 5501 void t() { } | 5501 void t() { } |
| 5502 } | 5502 } |
| 5503 '''); | 5503 '''); |
| 5504 } | 5504 } |
| 5505 | 5505 |
| 5506 test_lint_addMissingOverride_method_with_doc_comment_and_metadata() async { | 5506 test_lint_addMissingOverride_method_with_doc_comment_and_metadata() async { |
| 5507 String src = ''' | 5507 String src = ''' |
| 5508 class Test { | 5508 class Test { |
| 5509 void t() { } | 5509 void t() { } |
| 5510 } | 5510 } |
| 5511 class Sub extends Test { | 5511 class Sub extends Test { |
| 5512 /// Doc comment. | 5512 /// Doc comment. |
| 5513 @foo | 5513 @foo |
| 5514 void /*LINT*/t() { } | 5514 void /*LINT*/t() { } |
| 5515 } | 5515 } |
| 5516 '''; | 5516 '''; |
| 5517 findLint(src, LintNames.annotate_overrides); | 5517 await findLint(src, LintNames.annotate_overrides); |
| 5518 | 5518 |
| 5519 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5519 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5520 | 5520 |
| 5521 verifyResult(''' | 5521 verifyResult(''' |
| 5522 class Test { | 5522 class Test { |
| 5523 void t() { } | 5523 void t() { } |
| 5524 } | 5524 } |
| 5525 class Sub extends Test { | 5525 class Sub extends Test { |
| 5526 /// Doc comment. | 5526 /// Doc comment. |
| 5527 @override | 5527 @override |
| 5528 @foo | 5528 @foo |
| 5529 void t() { } | 5529 void t() { } |
| 5530 } | 5530 } |
| 5531 '''); | 5531 '''); |
| 5532 } | 5532 } |
| 5533 | 5533 |
| 5534 test_lint_addMissingOverride_method_with_non_doc_comment() async { | 5534 test_lint_addMissingOverride_method_with_non_doc_comment() async { |
| 5535 String src = ''' | 5535 String src = ''' |
| 5536 class Test { | 5536 class Test { |
| 5537 void t() { } | 5537 void t() { } |
| 5538 } | 5538 } |
| 5539 class Sub extends Test { | 5539 class Sub extends Test { |
| 5540 // Non-doc comment. | 5540 // Non-doc comment. |
| 5541 void /*LINT*/t() { } | 5541 void /*LINT*/t() { } |
| 5542 } | 5542 } |
| 5543 '''; | 5543 '''; |
| 5544 findLint(src, LintNames.annotate_overrides); | 5544 await findLint(src, LintNames.annotate_overrides); |
| 5545 | 5545 |
| 5546 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); | 5546 await applyFix(DartFixKind.LINT_ADD_OVERRIDE); |
| 5547 | 5547 |
| 5548 verifyResult(''' | 5548 verifyResult(''' |
| 5549 class Test { | 5549 class Test { |
| 5550 void t() { } | 5550 void t() { } |
| 5551 } | 5551 } |
| 5552 class Sub extends Test { | 5552 class Sub extends Test { |
| 5553 // Non-doc comment. | 5553 // Non-doc comment. |
| 5554 @override | 5554 @override |
| 5555 void t() { } | 5555 void t() { } |
| 5556 } | 5556 } |
| 5557 '''); | 5557 '''); |
| 5558 } | 5558 } |
| 5559 | 5559 |
| 5560 test_lint_removeInterpolationBraces() async { | 5560 test_lint_removeInterpolationBraces() async { |
| 5561 String src = r''' | 5561 String src = r''' |
| 5562 main() { | 5562 main() { |
| 5563 var v = 42; | 5563 var v = 42; |
| 5564 print('v: /*LINT*/${ v}'); | 5564 print('v: /*LINT*/${ v}'); |
| 5565 } | 5565 } |
| 5566 '''; | 5566 '''; |
| 5567 findLint(src, LintNames.unnecessary_brace_in_string_interp, length: 4); | 5567 await findLint(src, LintNames.unnecessary_brace_in_string_interp, |
| 5568 length: 4); |
| 5568 await applyFix(DartFixKind.LINT_REMOVE_INTERPOLATION_BRACES); | 5569 await applyFix(DartFixKind.LINT_REMOVE_INTERPOLATION_BRACES); |
| 5569 verifyResult(r''' | 5570 verifyResult(r''' |
| 5570 main() { | 5571 main() { |
| 5571 var v = 42; | 5572 var v = 42; |
| 5572 print('v: $v'); | 5573 print('v: $v'); |
| 5573 } | 5574 } |
| 5574 '''); | 5575 '''); |
| 5575 } | 5576 } |
| 5576 | 5577 |
| 5577 void verifyResult(String expectedResult) { | 5578 void verifyResult(String expectedResult) { |
| 5578 expect(resultCode, expectedResult); | 5579 expect(resultCode, expectedResult); |
| 5579 } | 5580 } |
| 5580 } | 5581 } |
| OLD | NEW |