| 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 'package:analysis_server/src/protocol.dart' hide AnalysisError; | 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError; |
| 8 import 'package:analysis_server/src/services/correction/fix.dart'; | 8 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/source/package_map_resolver.dart'; | 10 import 'package:analyzer/source/package_map_resolver.dart'; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' | 178 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' |
| 179 class A { | 179 class A { |
| 180 static foo() {} | 180 static foo() {} |
| 181 } | 181 } |
| 182 main(A a) { | 182 main(A a) { |
| 183 A.foo(); | 183 A.foo(); |
| 184 } | 184 } |
| 185 '''); | 185 '''); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void test_changeToStaticAccess_method_importType() { |
| 189 addSource('/libA.dart', r''' |
| 190 library libA; |
| 191 class A { |
| 192 static foo() {} |
| 193 } |
| 194 '''); |
| 195 addSource('/libB.dart', r''' |
| 196 library libB; |
| 197 import 'libA.dart'; |
| 198 class B extends A {} |
| 199 '''); |
| 200 resolveTestUnit(''' |
| 201 import 'libB.dart'; |
| 202 main(B b) { |
| 203 b.foo(); |
| 204 } |
| 205 '''); |
| 206 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' |
| 207 import 'libB.dart'; |
| 208 import 'libA.dart'; |
| 209 main(B b) { |
| 210 A.foo(); |
| 211 } |
| 212 '''); |
| 213 } |
| 214 |
| 188 void test_changeToStaticAccess_method_prefixLibrary() { | 215 void test_changeToStaticAccess_method_prefixLibrary() { |
| 189 resolveTestUnit(''' | 216 resolveTestUnit(''' |
| 190 import 'dart:async' as pref; | 217 import 'dart:async' as pref; |
| 191 main(pref.Future f) { | 218 main(pref.Future f) { |
| 192 f.wait([]); | 219 f.wait([]); |
| 193 } | 220 } |
| 194 '''); | 221 '''); |
| 195 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' | 222 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' |
| 196 import 'dart:async' as pref; | 223 import 'dart:async' as pref; |
| 197 main(pref.Future f) { | 224 main(pref.Future f) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 212 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' | 239 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' |
| 213 class A { | 240 class A { |
| 214 static get foo => 42; | 241 static get foo => 42; |
| 215 } | 242 } |
| 216 main(A a) { | 243 main(A a) { |
| 217 A.foo; | 244 A.foo; |
| 218 } | 245 } |
| 219 '''); | 246 '''); |
| 220 } | 247 } |
| 221 | 248 |
| 249 void test_changeToStaticAccess_property_importType() { |
| 250 addSource('/libA.dart', r''' |
| 251 library libA; |
| 252 class A { |
| 253 static get foo => null; |
| 254 } |
| 255 '''); |
| 256 addSource('/libB.dart', r''' |
| 257 library libB; |
| 258 import 'libA.dart'; |
| 259 class B extends A {} |
| 260 '''); |
| 261 resolveTestUnit(''' |
| 262 import 'libB.dart'; |
| 263 main(B b) { |
| 264 b.foo; |
| 265 } |
| 266 '''); |
| 267 assertHasFix(FixKind.CHANGE_TO_STATIC_ACCESS, ''' |
| 268 import 'libB.dart'; |
| 269 import 'libA.dart'; |
| 270 main(B b) { |
| 271 A.foo; |
| 272 } |
| 273 '''); |
| 274 } |
| 275 |
| 222 void test_createClass() { | 276 void test_createClass() { |
| 223 resolveTestUnit(''' | 277 resolveTestUnit(''' |
| 224 main() { | 278 main() { |
| 225 Test v = null; | 279 Test v = null; |
| 226 } | 280 } |
| 227 '''); | 281 '''); |
| 228 assertHasFix(FixKind.CREATE_CLASS, ''' | 282 assertHasFix(FixKind.CREATE_CLASS, ''' |
| 229 main() { | 283 main() { |
| 230 Test v = null; | 284 Test v = null; |
| 231 } | 285 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 class B extends A { | 455 class B extends A { |
| 402 int existingField; | 456 int existingField; |
| 403 | 457 |
| 404 B(int field) : super(field); | 458 B(int field) : super(field); |
| 405 | 459 |
| 406 void existingMethod() {} | 460 void existingMethod() {} |
| 407 } | 461 } |
| 408 '''); | 462 '''); |
| 409 } | 463 } |
| 410 | 464 |
| 465 void test_createConstructorSuperImplicit_importType() { |
| 466 addSource('/libA.dart', r''' |
| 467 library libA; |
| 468 class A {} |
| 469 '''); |
| 470 addSource('/libB.dart', r''' |
| 471 library libB; |
| 472 import 'libA.dart'; |
| 473 class B { |
| 474 B(A a); |
| 475 } |
| 476 '''); |
| 477 resolveTestUnit(''' |
| 478 import 'libB.dart'; |
| 479 class C extends B { |
| 480 } |
| 481 '''); |
| 482 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' |
| 483 import 'libB.dart'; |
| 484 import 'libA.dart'; |
| 485 class C extends B { |
| 486 C(A a) : super(a); |
| 487 } |
| 488 '''); |
| 489 } |
| 490 |
| 411 void test_createConstructorSuperImplicit_named() { | 491 void test_createConstructorSuperImplicit_named() { |
| 412 resolveTestUnit(''' | 492 resolveTestUnit(''' |
| 413 class A { | 493 class A { |
| 414 A.named(p1, int p2); | 494 A.named(p1, int p2); |
| 415 } | 495 } |
| 416 class B extends A { | 496 class B extends A { |
| 417 int existingField; | 497 int existingField; |
| 418 | 498 |
| 419 void existingMethod() {} | 499 void existingMethod() {} |
| 420 } | 500 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 class A { | 657 class A { |
| 578 var test; | 658 var test; |
| 579 | 659 |
| 580 main() { | 660 main() { |
| 581 test; | 661 test; |
| 582 } | 662 } |
| 583 } | 663 } |
| 584 '''); | 664 '''); |
| 585 } | 665 } |
| 586 | 666 |
| 667 void test_createField_importType() { |
| 668 addSource('/libA.dart', r''' |
| 669 library libA; |
| 670 class A {} |
| 671 '''); |
| 672 addSource('/libB.dart', r''' |
| 673 library libB; |
| 674 import 'libA.dart'; |
| 675 A getA() => null; |
| 676 '''); |
| 677 resolveTestUnit(''' |
| 678 import 'libB.dart'; |
| 679 class C { |
| 680 } |
| 681 main(C c) { |
| 682 c.test = getA(); |
| 683 } |
| 684 '''); |
| 685 assertHasFix(FixKind.CREATE_FIELD, ''' |
| 686 import 'libB.dart'; |
| 687 import 'libA.dart'; |
| 688 class C { |
| 689 A test; |
| 690 } |
| 691 main(C c) { |
| 692 c.test = getA(); |
| 693 } |
| 694 '''); |
| 695 } |
| 696 |
| 587 void test_createField_setter_generic_BAD() { | 697 void test_createField_setter_generic_BAD() { |
| 588 resolveTestUnit(''' | 698 resolveTestUnit(''' |
| 589 class A { | 699 class A { |
| 590 } | 700 } |
| 591 class B<T> { | 701 class B<T> { |
| 592 List<T> items; | 702 List<T> items; |
| 593 main(A a) { | 703 main(A a) { |
| 594 a.test = items; | 704 a.test = items; |
| 595 } | 705 } |
| 596 } | 706 } |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 main() { | 1580 main() { |
| 1471 useFunction(g: test); | 1581 useFunction(g: test); |
| 1472 } | 1582 } |
| 1473 useFunction({int g(double a, String b)}) {} | 1583 useFunction({int g(double a, String b)}) {} |
| 1474 | 1584 |
| 1475 int test(double a, String b) { | 1585 int test(double a, String b) { |
| 1476 } | 1586 } |
| 1477 '''); | 1587 '''); |
| 1478 } | 1588 } |
| 1479 | 1589 |
| 1590 void test_creationFunction_forFunctionType_importType() { |
| 1591 addSource('/libA.dart', r''' |
| 1592 library libA; |
| 1593 class A {} |
| 1594 '''); |
| 1595 addSource('/libB.dart', r''' |
| 1596 library libB; |
| 1597 import 'libA.dart'; |
| 1598 useFunction(int g(A a)) {} |
| 1599 '''); |
| 1600 resolveTestUnit(''' |
| 1601 import 'libB.dart'; |
| 1602 main() { |
| 1603 useFunction(test); |
| 1604 } |
| 1605 '''); |
| 1606 assertHasFix(FixKind.CREATE_FUNCTION, ''' |
| 1607 import 'libB.dart'; |
| 1608 import 'libA.dart'; |
| 1609 main() { |
| 1610 useFunction(test); |
| 1611 } |
| 1612 |
| 1613 int test(A a) { |
| 1614 } |
| 1615 '''); |
| 1616 } |
| 1617 |
| 1480 void test_creationFunction_forFunctionType_method_enclosingClass_static() { | 1618 void test_creationFunction_forFunctionType_method_enclosingClass_static() { |
| 1481 resolveTestUnit(''' | 1619 resolveTestUnit(''' |
| 1482 class A { | 1620 class A { |
| 1483 static foo() { | 1621 static foo() { |
| 1484 useFunction(test); | 1622 useFunction(test); |
| 1485 } | 1623 } |
| 1486 } | 1624 } |
| 1487 useFunction(int g(double a, String b)) {} | 1625 useFunction(int g(double a, String b)) {} |
| 1488 '''); | 1626 '''); |
| 1489 assertHasFix(FixKind.CREATE_METHOD, ''' | 1627 assertHasFix(FixKind.CREATE_METHOD, ''' |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 main() { | 2419 main() { |
| 2282 process(items); | 2420 process(items); |
| 2283 } | 2421 } |
| 2284 } | 2422 } |
| 2285 | 2423 |
| 2286 void process(List<int> items) { | 2424 void process(List<int> items) { |
| 2287 } | 2425 } |
| 2288 '''); | 2426 '''); |
| 2289 } | 2427 } |
| 2290 | 2428 |
| 2429 void test_undefinedFunction_create_importType() { |
| 2430 addSource('/lib.dart', r''' |
| 2431 library lib; |
| 2432 import 'dart:async'; |
| 2433 Future getFuture() => null; |
| 2434 '''); |
| 2435 resolveTestUnit(''' |
| 2436 import 'lib.dart'; |
| 2437 main() { |
| 2438 test(getFuture()); |
| 2439 } |
| 2440 '''); |
| 2441 assertHasFix(FixKind.CREATE_FUNCTION, ''' |
| 2442 import 'lib.dart'; |
| 2443 import 'dart:async'; |
| 2444 main() { |
| 2445 test(getFuture()); |
| 2446 } |
| 2447 |
| 2448 void test(Future future) { |
| 2449 } |
| 2450 '''); |
| 2451 } |
| 2452 |
| 2291 void test_undefinedFunction_create_nullArgument() { | 2453 void test_undefinedFunction_create_nullArgument() { |
| 2292 resolveTestUnit(''' | 2454 resolveTestUnit(''' |
| 2293 main() { | 2455 main() { |
| 2294 test(null); | 2456 test(null); |
| 2295 } | 2457 } |
| 2296 '''); | 2458 '''); |
| 2297 assertHasFix(FixKind.CREATE_FUNCTION, ''' | 2459 assertHasFix(FixKind.CREATE_FUNCTION, ''' |
| 2298 main() { | 2460 main() { |
| 2299 test(null); | 2461 test(null); |
| 2300 } | 2462 } |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2908 | 3070 |
| 2909 List<Position> _findResultPositions(List<String> searchStrings) { | 3071 List<Position> _findResultPositions(List<String> searchStrings) { |
| 2910 List<Position> positions = <Position>[]; | 3072 List<Position> positions = <Position>[]; |
| 2911 for (String search in searchStrings) { | 3073 for (String search in searchStrings) { |
| 2912 int offset = resultCode.indexOf(search); | 3074 int offset = resultCode.indexOf(search); |
| 2913 positions.add(new Position(testFile, offset)); | 3075 positions.add(new Position(testFile, offset)); |
| 2914 } | 3076 } |
| 2915 return positions; | 3077 return positions; |
| 2916 } | 3078 } |
| 2917 } | 3079 } |
| OLD | NEW |