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.assist; | 5 library test.services.correction.assist; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; | 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; |
10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; | 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1029 ''' | 1029 ''' |
1030 class A { | 1030 class A { |
1031 /// AAAAAAA [int] AAAAAAA | 1031 /// AAAAAAA [int] AAAAAAA |
1032 /// BBBBBBBB BBBB BBBB | 1032 /// BBBBBBBB BBBB BBBB |
1033 /// CCC [A] CCCCCCCCCCC | 1033 /// CCC [A] CCCCCCCCCCC |
1034 mmm() {} | 1034 mmm() {} |
1035 } | 1035 } |
1036 '''); | 1036 '''); |
1037 } | 1037 } |
1038 | 1038 |
1039 test_convertFlutterChild_OK_multiLine() async { | |
1040 _configureFlutterPkg({ | |
1041 'src/widgets/framework.dart': _flutter_framework_code, | |
1042 }); | |
1043 await resolveTestUnit(''' | |
1044 import 'package:flutter/src/widgets/framework.dart'; | |
1045 build() { | |
1046 return new Scaffold( | |
1047 // start | |
scheglov
2017/03/15 23:19:03
I think _setCaretLocation() does not use //start a
| |
1048 body: new Center( | |
1049 /*caret*/child: new Container( | |
1050 width: 200.0, | |
1051 height: 300.0, | |
1052 ), | |
1053 key: null, | |
1054 ), | |
1055 // end | |
1056 ); | |
1057 } | |
1058 '''); | |
1059 _setCaretLocation(); | |
1060 await assertHasAssist( | |
1061 DartAssistKind.CONVERT_FLUTTER_CHILD, | |
1062 ''' | |
1063 import 'package:flutter/src/widgets/framework.dart'; | |
1064 build() { | |
1065 return new Scaffold( | |
1066 // start | |
1067 body: new Center( | |
1068 /*caret*/children: <Widget>[ | |
1069 new Container( | |
1070 width: 200.0, | |
1071 height: 300.0, | |
1072 ), | |
1073 ], | |
1074 key: null, | |
1075 ), | |
1076 // end | |
1077 ); | |
1078 } | |
1079 '''); | |
1080 } | |
1081 | |
1082 test_convertFlutterChild_OK_newlineChild() async { | |
1083 // This case could occur with deeply nested constructors, common in Flutter. | |
1084 _configureFlutterPkg({ | |
1085 'src/widgets/framework.dart': _flutter_framework_code, | |
1086 }); | |
1087 await resolveTestUnit(''' | |
1088 import 'package:flutter/src/widgets/framework.dart'; | |
1089 build() { | |
1090 return new Scaffold( | |
1091 // start | |
1092 body: new Center( | |
1093 /*caret*/child: | |
1094 new Container( | |
1095 width: 200.0, | |
1096 height: 300.0, | |
1097 ), | |
1098 key: null, | |
1099 ), | |
1100 // end | |
1101 ); | |
1102 } | |
1103 '''); | |
1104 _setCaretLocation(); | |
1105 await assertHasAssist( | |
1106 DartAssistKind.CONVERT_FLUTTER_CHILD, | |
1107 ''' | |
1108 import 'package:flutter/src/widgets/framework.dart'; | |
1109 build() { | |
1110 return new Scaffold( | |
1111 // start | |
1112 body: new Center( | |
1113 /*caret*/children: <Widget>[ | |
1114 new Container( | |
1115 width: 200.0, | |
1116 height: 300.0, | |
1117 ), | |
1118 ], | |
1119 key: null, | |
1120 ), | |
1121 // end | |
1122 ); | |
1123 } | |
1124 '''); | |
1125 } | |
1126 | |
1127 test_convertFlutterChild_OK_singleLine() async { | |
1128 _configureFlutterPkg({ | |
1129 'src/widgets/framework.dart': _flutter_framework_code, | |
1130 }); | |
1131 await resolveTestUnit(''' | |
1132 import 'package:flutter/src/widgets/framework.dart'; | |
1133 build() { | |
1134 return new Scaffold( | |
1135 // start | |
1136 body: new Center( | |
1137 /*caret*/child: new GestureDetector(), | |
1138 key: null, | |
1139 ), | |
1140 // end | |
1141 ); | |
1142 } | |
1143 '''); | |
1144 _setCaretLocation(); | |
1145 await assertHasAssist( | |
1146 DartAssistKind.CONVERT_FLUTTER_CHILD, | |
1147 ''' | |
1148 import 'package:flutter/src/widgets/framework.dart'; | |
1149 build() { | |
1150 return new Scaffold( | |
1151 // start | |
1152 body: new Center( | |
1153 /*caret*/children: <Widget>[new GestureDetector()], | |
1154 key: null, | |
1155 ), | |
1156 // end | |
1157 ); | |
1158 } | |
1159 '''); | |
1160 } | |
1161 | |
1039 test_convertToBlockBody_BAD_noEnclosingFunction() async { | 1162 test_convertToBlockBody_BAD_noEnclosingFunction() async { |
1040 await resolveTestUnit(''' | 1163 await resolveTestUnit(''' |
1041 var v = 123; | 1164 var v = 123; |
1042 '''); | 1165 '''); |
1043 await assertNoAssistAt('v =', DartAssistKind.CONVERT_INTO_BLOCK_BODY); | 1166 await assertNoAssistAt('v =', DartAssistKind.CONVERT_INTO_BLOCK_BODY); |
1044 } | 1167 } |
1045 | 1168 |
1046 test_convertToBlockBody_BAD_notExpressionBlock() async { | 1169 test_convertToBlockBody_BAD_notExpressionBlock() async { |
1047 await resolveTestUnit(''' | 1170 await resolveTestUnit(''' |
1048 fff() { | 1171 fff() { |
(...skipping 2446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3495 await assertHasAssistAt( | 3618 await assertHasAssistAt( |
3496 'var v', | 3619 'var v', |
3497 DartAssistKind.JOIN_VARIABLE_DECLARATION, | 3620 DartAssistKind.JOIN_VARIABLE_DECLARATION, |
3498 ''' | 3621 ''' |
3499 main() { | 3622 main() { |
3500 var v = 1; | 3623 var v = 1; |
3501 } | 3624 } |
3502 '''); | 3625 '''); |
3503 } | 3626 } |
3504 | 3627 |
3628 test_moveFlutterWidgetDown_OK() async { | |
3629 _configureFlutterPkg({ | |
3630 'src/widgets/framework.dart': _flutter_framework_code, | |
3631 }); | |
3632 await resolveTestUnit(''' | |
3633 import 'package:flutter/src/widgets/framework.dart'; | |
3634 build() { | |
3635 return new Scaffold( | |
3636 // start | |
3637 body: new /*caret*/GestureDetector( | |
3638 onTap: () => startResize(), | |
3639 child: new Center( | |
3640 child: new Container( | |
3641 width: 200.0, | |
3642 height: 300.0, | |
3643 ), | |
3644 key: null, | |
3645 ), | |
3646 ), | |
3647 // end | |
3648 ); | |
3649 } | |
3650 startResize() {} | |
3651 '''); | |
3652 _setCaretLocation(); | |
3653 await assertHasAssist( | |
3654 DartAssistKind.MOVE_FLUTTER_WIDGET_DOWN, | |
3655 ''' | |
3656 import 'package:flutter/src/widgets/framework.dart'; | |
3657 build() { | |
3658 return new Scaffold( | |
3659 // start | |
3660 body: new Center( | |
3661 child: new /*caret*/GestureDetector( | |
3662 onTap: () => startResize(), | |
3663 child: new Container( | |
3664 width: 200.0, | |
3665 height: 300.0, | |
3666 ), | |
3667 ), | |
3668 key: null, | |
3669 ), | |
3670 // end | |
3671 ); | |
3672 } | |
3673 startResize() {} | |
3674 '''); | |
3675 } | |
3676 | |
3677 test_moveFlutterWidgetUp_OK() async { | |
3678 _configureFlutterPkg({ | |
3679 'src/widgets/framework.dart': _flutter_framework_code, | |
3680 }); | |
3681 await resolveTestUnit(''' | |
3682 import 'package:flutter/src/widgets/framework.dart'; | |
3683 build() { | |
3684 return new Scaffold( | |
3685 // start | |
3686 body: new Center( | |
3687 child: new /*caret*/GestureDetector( | |
3688 onTap: () => startResize(), | |
3689 child: new Container( | |
3690 width: 200.0, | |
3691 height: 300.0, | |
3692 ), | |
3693 ), | |
3694 key: null, | |
3695 ), | |
3696 // end | |
3697 ); | |
3698 } | |
3699 startResize() {} | |
3700 '''); | |
3701 _setCaretLocation(); | |
3702 await assertHasAssist( | |
3703 DartAssistKind.MOVE_FLUTTER_WIDGET_UP, | |
3704 ''' | |
3705 import 'package:flutter/src/widgets/framework.dart'; | |
3706 build() { | |
3707 return new Scaffold( | |
3708 // start | |
3709 body: new /*caret*/GestureDetector( | |
3710 onTap: () => startResize(), | |
3711 child: new Center( | |
3712 child: new Container( | |
3713 width: 200.0, | |
3714 height: 300.0, | |
3715 ), | |
3716 key: null, | |
3717 ), | |
3718 ), | |
3719 // end | |
3720 ); | |
3721 } | |
3722 startResize() {} | |
3723 '''); | |
3724 } | |
3725 | |
3505 test_removeTypeAnnotation_classField_OK() async { | 3726 test_removeTypeAnnotation_classField_OK() async { |
3506 await resolveTestUnit(''' | 3727 await resolveTestUnit(''' |
3507 class A { | 3728 class A { |
3508 int v = 1; | 3729 int v = 1; |
3509 } | 3730 } |
3510 '''); | 3731 '''); |
3511 await assertHasAssistAt( | 3732 await assertHasAssistAt( |
3512 'v = ', | 3733 'v = ', |
3513 DartAssistKind.REMOVE_TYPE_ANNOTATION, | 3734 DartAssistKind.REMOVE_TYPE_ANNOTATION, |
3514 ''' | 3735 ''' |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3659 // start | 3880 // start |
3660 return new Row(children: [/*caret*/ new Transform()]); | 3881 return new Row(children: [/*caret*/ new Transform()]); |
3661 // end | 3882 // end |
3662 } | 3883 } |
3663 } | 3884 } |
3664 '''); | 3885 '''); |
3665 _setCaretLocation(); | 3886 _setCaretLocation(); |
3666 await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_LIST); | 3887 await assertNoAssist(DartAssistKind.REPARENT_FLUTTER_LIST); |
3667 } | 3888 } |
3668 | 3889 |
3669 test_moveFlutterWidgetDown_OK() async { | |
3670 _configureFlutterPkg({ | |
3671 'src/widgets/framework.dart': _flutter_framework_code, | |
3672 }); | |
3673 await resolveTestUnit(''' | |
3674 import 'package:flutter/src/widgets/framework.dart'; | |
3675 build() { | |
3676 return new Scaffold( | |
3677 // start | |
3678 body: new /*caret*/GestureDetector( | |
3679 onTap: () => startResize(), | |
3680 child: new Center( | |
3681 child: new Container( | |
3682 width: 200.0, | |
3683 height: 300.0, | |
3684 ), | |
3685 key: null, | |
3686 ), | |
3687 ), | |
3688 // end | |
3689 ); | |
3690 } | |
3691 startResize() {} | |
3692 '''); | |
3693 _setCaretLocation(); | |
3694 await assertHasAssist( | |
3695 DartAssistKind.MOVE_FLUTTER_WIDGET_DOWN, | |
3696 ''' | |
3697 import 'package:flutter/src/widgets/framework.dart'; | |
3698 build() { | |
3699 return new Scaffold( | |
3700 // start | |
3701 body: new Center( | |
3702 child: new /*caret*/GestureDetector( | |
3703 onTap: () => startResize(), | |
3704 child: new Container( | |
3705 width: 200.0, | |
3706 height: 300.0, | |
3707 ), | |
3708 ), | |
3709 key: null, | |
3710 ), | |
3711 // end | |
3712 ); | |
3713 } | |
3714 startResize() {} | |
3715 '''); | |
3716 } | |
3717 | |
3718 test_moveFlutterWidgetUp_OK() async { | |
3719 _configureFlutterPkg({ | |
3720 'src/widgets/framework.dart': _flutter_framework_code, | |
3721 }); | |
3722 await resolveTestUnit(''' | |
3723 import 'package:flutter/src/widgets/framework.dart'; | |
3724 build() { | |
3725 return new Scaffold( | |
3726 // start | |
3727 body: new Center( | |
3728 child: new /*caret*/GestureDetector( | |
3729 onTap: () => startResize(), | |
3730 child: new Container( | |
3731 width: 200.0, | |
3732 height: 300.0, | |
3733 ), | |
3734 ), | |
3735 key: null, | |
3736 ), | |
3737 // end | |
3738 ); | |
3739 } | |
3740 startResize() {} | |
3741 '''); | |
3742 _setCaretLocation(); | |
3743 await assertHasAssist( | |
3744 DartAssistKind.MOVE_FLUTTER_WIDGET_UP, | |
3745 ''' | |
3746 import 'package:flutter/src/widgets/framework.dart'; | |
3747 build() { | |
3748 return new Scaffold( | |
3749 // start | |
3750 body: new /*caret*/GestureDetector( | |
3751 onTap: () => startResize(), | |
3752 child: new Center( | |
3753 child: new Container( | |
3754 width: 200.0, | |
3755 height: 300.0, | |
3756 ), | |
3757 key: null, | |
3758 ), | |
3759 ), | |
3760 // end | |
3761 ); | |
3762 } | |
3763 startResize() {} | |
3764 '''); | |
3765 } | |
3766 | |
3767 test_reparentFlutterList_OK_multiLine() async { | 3890 test_reparentFlutterList_OK_multiLine() async { |
3768 _configureFlutterPkg({ | 3891 _configureFlutterPkg({ |
3769 'src/widgets/framework.dart': _flutter_framework_code, | 3892 'src/widgets/framework.dart': _flutter_framework_code, |
3770 }); | 3893 }); |
3771 await resolveTestUnit(''' | 3894 await resolveTestUnit(''' |
3772 import 'package:flutter/src/widgets/framework.dart'; | 3895 import 'package:flutter/src/widgets/framework.dart'; |
3773 build() { | 3896 build() { |
3774 return new Container( | 3897 return new Container( |
3775 child: new Row( | 3898 child: new Row( |
3776 // start | 3899 // start |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4617 | 4740 |
4618 @override | 4741 @override |
4619 final AnalysisContext analysisContext; | 4742 final AnalysisContext analysisContext; |
4620 | 4743 |
4621 @override | 4744 @override |
4622 final CompilationUnit unit; | 4745 final CompilationUnit unit; |
4623 | 4746 |
4624 _DartAssistContextForValues(this.source, this.selectionOffset, | 4747 _DartAssistContextForValues(this.source, this.selectionOffset, |
4625 this.selectionLength, this.analysisContext, this.unit); | 4748 this.selectionLength, this.analysisContext, this.unit); |
4626 } | 4749 } |
OLD | NEW |