| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 7 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
| 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; | 8 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; |
| 9 import 'package:analysis_server/src/services/correction/fix.dart'; | 9 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 10 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| (...skipping 5558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5569 '''; | 5569 '''; |
| 5570 await findLint(src, LintNames.always_require_non_null_named_parameters); | 5570 await findLint(src, LintNames.always_require_non_null_named_parameters); |
| 5571 await applyFix(DartFixKind.LINT_ADD_REQUIRED); | 5571 await applyFix(DartFixKind.LINT_ADD_REQUIRED); |
| 5572 verifyResult(''' | 5572 verifyResult(''' |
| 5573 void function({@required String param}) { | 5573 void function({@required String param}) { |
| 5574 assert(param != null); | 5574 assert(param != null); |
| 5575 } | 5575 } |
| 5576 '''); | 5576 '''); |
| 5577 } | 5577 } |
| 5578 | 5578 |
| 5579 test_isNotEmpty() async { |
| 5580 String src = ''' |
| 5581 f(c) { |
| 5582 if (/*LINT*/!c.isEmpty) {} |
| 5583 } |
| 5584 '''; |
| 5585 await findLint(src, LintNames.prefer_is_not_empty); |
| 5586 |
| 5587 await applyFix(DartFixKind.USE_IS_NOT_EMPTY); |
| 5588 |
| 5589 verifyResult(''' |
| 5590 f(c) { |
| 5591 if (c.isNotEmpty) {} |
| 5592 } |
| 5593 '''); |
| 5594 } |
| 5595 |
| 5579 test_lint_addMissingOverride_field() async { | 5596 test_lint_addMissingOverride_field() async { |
| 5580 String src = ''' | 5597 String src = ''' |
| 5581 class abstract Test { | 5598 class abstract Test { |
| 5582 int get t; | 5599 int get t; |
| 5583 } | 5600 } |
| 5584 class Sub extends Test { | 5601 class Sub extends Test { |
| 5585 int /*LINT*/t = 42; | 5602 int /*LINT*/t = 42; |
| 5586 } | 5603 } |
| 5587 '''; | 5604 '''; |
| 5588 await findLint(src, LintNames.annotate_overrides); | 5605 await findLint(src, LintNames.annotate_overrides); |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6101 verifyResult(''' | 6118 verifyResult(''' |
| 6102 class A { | 6119 class A { |
| 6103 int x; | 6120 int x; |
| 6104 void foo() { | 6121 void foo() { |
| 6105 x = 2; | 6122 x = 2; |
| 6106 } | 6123 } |
| 6107 } | 6124 } |
| 6108 '''); | 6125 '''); |
| 6109 } | 6126 } |
| 6110 | 6127 |
| 6111 test_removeTypeName_avoidAnnotatingWithDynamic_InsideFunctionTypedFormalParame
ter() async { | 6128 test_removeTypeAnnotation_avoidAnnotatingWithDynamic_InsideFunctionTypedFormal
Parameter() async { |
| 6112 String src = ''' | 6129 String src = ''' |
| 6113 bad(void foo(/*LINT*/dynamic x)) { | 6130 bad(void foo(/*LINT*/dynamic x)) { |
| 6114 return null; | 6131 return null; |
| 6115 } | 6132 } |
| 6116 '''; | 6133 '''; |
| 6117 await findLint(src, LintNames.avoid_annotating_with_dynamic); | 6134 await findLint(src, LintNames.avoid_annotating_with_dynamic); |
| 6118 | 6135 |
| 6119 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6136 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6120 | 6137 |
| 6121 verifyResult(''' | 6138 verifyResult(''' |
| 6122 bad(void foo(x)) { | 6139 bad(void foo(x)) { |
| 6123 return null; | 6140 return null; |
| 6124 } | 6141 } |
| 6125 '''); | 6142 '''); |
| 6126 } | 6143 } |
| 6127 | 6144 |
| 6128 test_removeTypeName_avoidAnnotatingWithDynamic_NamedParameter() async { | 6145 test_removeTypeAnnotation_avoidAnnotatingWithDynamic_NamedParameter() async { |
| 6129 String src = ''' | 6146 String src = ''' |
| 6130 bad({/*LINT*/dynamic defaultValue}) { | 6147 bad({/*LINT*/dynamic defaultValue}) { |
| 6131 return null; | 6148 return null; |
| 6132 } | 6149 } |
| 6133 '''; | 6150 '''; |
| 6134 await findLint(src, LintNames.avoid_annotating_with_dynamic); | 6151 await findLint(src, LintNames.avoid_annotating_with_dynamic); |
| 6135 | 6152 |
| 6136 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6153 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6137 | 6154 |
| 6138 verifyResult(''' | 6155 verifyResult(''' |
| 6139 bad({defaultValue}) { | 6156 bad({defaultValue}) { |
| 6140 return null; | 6157 return null; |
| 6141 } | 6158 } |
| 6142 '''); | 6159 '''); |
| 6143 } | 6160 } |
| 6144 | 6161 |
| 6145 test_removeTypeName_avoidAnnotatingWithDynamic_NormalParameter() async { | 6162 test_removeTypeAnnotation_avoidAnnotatingWithDynamic_NormalParameter() async { |
| 6146 String src = ''' | 6163 String src = ''' |
| 6147 bad(/*LINT*/dynamic defaultValue) { | 6164 bad(/*LINT*/dynamic defaultValue) { |
| 6148 return null; | 6165 return null; |
| 6149 } | 6166 } |
| 6150 '''; | 6167 '''; |
| 6151 await findLint(src, LintNames.avoid_annotating_with_dynamic); | 6168 await findLint(src, LintNames.avoid_annotating_with_dynamic); |
| 6152 | 6169 |
| 6153 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6170 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6154 | 6171 |
| 6155 verifyResult(''' | 6172 verifyResult(''' |
| 6156 bad(defaultValue) { | 6173 bad(defaultValue) { |
| 6157 return null; | 6174 return null; |
| 6158 } | 6175 } |
| 6159 '''); | 6176 '''); |
| 6160 } | 6177 } |
| 6161 | 6178 |
| 6162 test_removeTypeName_avoidAnnotatingWithDynamic_OptionalParameter() async { | 6179 test_removeTypeAnnotation_avoidAnnotatingWithDynamic_OptionalParameter() async
{ |
| 6163 String src = ''' | 6180 String src = ''' |
| 6164 bad([/*LINT*/dynamic defaultValue]) { | 6181 bad([/*LINT*/dynamic defaultValue]) { |
| 6165 return null; | 6182 return null; |
| 6166 } | 6183 } |
| 6167 '''; | 6184 '''; |
| 6168 await findLint(src, LintNames.avoid_annotating_with_dynamic); | 6185 await findLint(src, LintNames.avoid_annotating_with_dynamic); |
| 6169 | 6186 |
| 6170 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6187 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6171 | 6188 |
| 6172 verifyResult(''' | 6189 verifyResult(''' |
| 6173 bad([defaultValue]) { | 6190 bad([defaultValue]) { |
| 6174 return null; | 6191 return null; |
| 6175 } | 6192 } |
| 6176 '''); | 6193 '''); |
| 6177 } | 6194 } |
| 6178 | 6195 |
| 6179 test_removeTypeName_avoidReturnTypesOnSetters_void() async { | 6196 test_removeTypeAnnotation_avoidReturnTypesOnSetters_void() async { |
| 6180 String src = ''' | 6197 String src = ''' |
| 6181 /*LINT*/void set speed2(int ms) {} | 6198 /*LINT*/void set speed2(int ms) {} |
| 6182 '''; | 6199 '''; |
| 6183 await findLint(src, LintNames.avoid_return_types_on_setters); | 6200 await findLint(src, LintNames.avoid_return_types_on_setters); |
| 6184 | 6201 |
| 6185 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6202 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6186 | 6203 |
| 6187 verifyResult(''' | 6204 verifyResult(''' |
| 6188 set speed2(int ms) {} | 6205 set speed2(int ms) {} |
| 6189 '''); | 6206 '''); |
| 6190 } | 6207 } |
| 6191 | 6208 |
| 6192 test_removeTypeName_avoidTypesOnClosureParameters_FunctionTypedFormalParameter
() async { | 6209 test_removeTypeAnnotation_avoidTypesOnClosureParameters_FunctionTypedFormalPar
ameter() async { |
| 6193 String src = ''' | 6210 String src = ''' |
| 6194 var functionWithFunction = (/*LINT*/int f(int x)) => f(0); | 6211 var functionWithFunction = (/*LINT*/int f(int x)) => f(0); |
| 6195 '''; | 6212 '''; |
| 6196 await findLint(src, LintNames.avoid_types_on_closure_parameters); | 6213 await findLint(src, LintNames.avoid_types_on_closure_parameters); |
| 6197 | 6214 |
| 6198 await applyFix(DartFixKind.REPLACE_WITH_IDENTIFIER); | 6215 await applyFix(DartFixKind.REPLACE_WITH_IDENTIFIER); |
| 6199 | 6216 |
| 6200 verifyResult(''' | 6217 verifyResult(''' |
| 6201 var functionWithFunction = (f) => f(0); | 6218 var functionWithFunction = (f) => f(0); |
| 6202 '''); | 6219 '''); |
| 6203 } | 6220 } |
| 6204 | 6221 |
| 6205 test_removeTypeName_avoidTypesOnClosureParameters_NamedParameter() async { | 6222 test_removeTypeAnnotation_avoidTypesOnClosureParameters_NamedParameter() async
{ |
| 6206 String src = ''' | 6223 String src = ''' |
| 6207 var x = ({/*LINT*/Future<int> defaultValue}) { | 6224 var x = ({/*LINT*/Future<int> defaultValue}) { |
| 6208 return null; | 6225 return null; |
| 6209 }; | 6226 }; |
| 6210 '''; | 6227 '''; |
| 6211 await findLint(src, LintNames.avoid_types_on_closure_parameters); | 6228 await findLint(src, LintNames.avoid_types_on_closure_parameters); |
| 6212 | 6229 |
| 6213 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6230 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6214 | 6231 |
| 6215 verifyResult(''' | 6232 verifyResult(''' |
| 6216 var x = ({defaultValue}) { | 6233 var x = ({defaultValue}) { |
| 6217 return null; | 6234 return null; |
| 6218 }; | 6235 }; |
| 6219 '''); | 6236 '''); |
| 6220 } | 6237 } |
| 6221 | 6238 |
| 6222 test_removeTypeName_avoidTypesOnClosureParameters_NormalParameter() async { | 6239 test_removeTypeAnnotation_avoidTypesOnClosureParameters_NormalParameter() asyn
c { |
| 6223 String src = ''' | 6240 String src = ''' |
| 6224 var x = (/*LINT*/Future<int> defaultValue) { | 6241 var x = (/*LINT*/Future<int> defaultValue) { |
| 6225 return null; | 6242 return null; |
| 6226 }; | 6243 }; |
| 6227 '''; | 6244 '''; |
| 6228 await findLint(src, LintNames.avoid_types_on_closure_parameters); | 6245 await findLint(src, LintNames.avoid_types_on_closure_parameters); |
| 6229 | 6246 |
| 6230 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6247 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6231 | 6248 |
| 6232 verifyResult(''' | 6249 verifyResult(''' |
| 6233 var x = (defaultValue) { | 6250 var x = (defaultValue) { |
| 6234 return null; | 6251 return null; |
| 6235 }; | 6252 }; |
| 6236 '''); | 6253 '''); |
| 6237 } | 6254 } |
| 6238 | 6255 |
| 6239 test_removeTypeName_avoidTypesOnClosureParameters_OptionalParameter() async { | 6256 test_removeTypeAnnotation_avoidTypesOnClosureParameters_OptionalParameter() as
ync { |
| 6240 String src = ''' | 6257 String src = ''' |
| 6241 var x = ([/*LINT*/Future<int> defaultValue]) { | 6258 var x = ([/*LINT*/Future<int> defaultValue]) { |
| 6242 return null; | 6259 return null; |
| 6243 }; | 6260 }; |
| 6244 '''; | 6261 '''; |
| 6245 await findLint(src, LintNames.avoid_types_on_closure_parameters); | 6262 await findLint(src, LintNames.avoid_types_on_closure_parameters); |
| 6246 | 6263 |
| 6247 await applyFix(DartFixKind.REMOVE_TYPE_NAME); | 6264 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6248 | 6265 |
| 6249 verifyResult(''' | 6266 verifyResult(''' |
| 6250 var x = ([defaultValue]) { | 6267 var x = ([defaultValue]) { |
| 6251 return null; | 6268 return null; |
| 6252 }; | 6269 }; |
| 6253 '''); | 6270 '''); |
| 6254 } | 6271 } |
| 6255 | 6272 |
| 6273 test_removeTypeAnnotation_typeInitFormals_void() async { |
| 6274 String src = ''' |
| 6275 class C { |
| 6276 int f; |
| 6277 C(/*LINT*/int this.f); |
| 6278 } |
| 6279 '''; |
| 6280 await findLint(src, LintNames.type_init_formals); |
| 6281 |
| 6282 await applyFix(DartFixKind.REMOVE_TYPE_NAME); |
| 6283 |
| 6284 verifyResult(''' |
| 6285 class C { |
| 6286 int f; |
| 6287 C(this.f); |
| 6288 } |
| 6289 '''); |
| 6290 } |
| 6291 |
| 6256 test_replaceWithConditionalAssignment_withCodeBeforeAndAfter() async { | 6292 test_replaceWithConditionalAssignment_withCodeBeforeAndAfter() async { |
| 6257 String src = ''' | 6293 String src = ''' |
| 6258 class Person { | 6294 class Person { |
| 6259 String _fullName; | 6295 String _fullName; |
| 6260 void foo() { | 6296 void foo() { |
| 6261 print('hi'); | 6297 print('hi'); |
| 6262 /*LINT*/if (_fullName == null) { | 6298 /*LINT*/if (_fullName == null) { |
| 6263 _fullName = getFullUserName(this); | 6299 _fullName = getFullUserName(this); |
| 6264 } | 6300 } |
| 6265 print('hi'); | 6301 print('hi'); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6589 @override | 6625 @override |
| 6590 final AnalysisError error; | 6626 final AnalysisError error; |
| 6591 | 6627 |
| 6592 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, | 6628 _DartFixContextImpl(this.resourceProvider, this.analysisDriver, |
| 6593 this.astProvider, this.unit, this.error); | 6629 this.astProvider, this.unit, this.error); |
| 6594 | 6630 |
| 6595 @override | 6631 @override |
| 6596 GetTopLevelDeclarations get getTopLevelDeclarations => | 6632 GetTopLevelDeclarations get getTopLevelDeclarations => |
| 6597 analysisDriver.getTopLevelNameDeclarations; | 6633 analysisDriver.getTopLevelNameDeclarations; |
| 6598 } | 6634 } |
| OLD | NEW |