| 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'; |
| 8 |
| 7 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/edit/fix/fix_dart.dart'; |
| 8 import 'package:analysis_server/plugin/protocol/protocol.dart' | 11 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 9 hide AnalysisError; | 12 hide AnalysisError; |
| 10 import 'package:analysis_server/src/services/correction/fix.dart'; | 13 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 11 import 'package:analysis_server/src/services/correction/fix_internal.dart'; | 14 import 'package:analysis_server/src/services/correction/fix_internal.dart'; |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 15 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/source/package_map_resolver.dart'; | 16 import 'package:analyzer/source/package_map_resolver.dart'; |
| 14 import 'package:analyzer/src/generated/error.dart'; | 17 import 'package:analyzer/src/generated/error.dart'; |
| 15 import 'package:analyzer/src/generated/parser.dart'; | 18 import 'package:analyzer/src/generated/parser.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 19 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 20 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 error.errorCode != HintCode.UNUSED_CATCH_STACK && | 38 error.errorCode != HintCode.UNUSED_CATCH_STACK && |
| 36 error.errorCode != HintCode.UNUSED_ELEMENT && | 39 error.errorCode != HintCode.UNUSED_ELEMENT && |
| 37 error.errorCode != HintCode.UNUSED_FIELD && | 40 error.errorCode != HintCode.UNUSED_FIELD && |
| 38 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; | 41 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 Fix fix; | 44 Fix fix; |
| 42 SourceChange change; | 45 SourceChange change; |
| 43 String resultCode; | 46 String resultCode; |
| 44 | 47 |
| 45 void assert_undefinedFunction_create_returnType_bool(String lineWithTest) { | 48 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { |
| 46 resolveTestUnit(''' | 49 resolveTestUnit(''' |
| 47 main() { | 50 main() { |
| 48 bool b = true; | 51 bool b = true; |
| 49 $lineWithTest | 52 $lineWithTest |
| 50 } | 53 } |
| 51 '''); | 54 '''); |
| 52 assertHasFix( | 55 await assertHasFix( |
| 53 DartFixKind.CREATE_FUNCTION, | 56 DartFixKind.CREATE_FUNCTION, |
| 54 ''' | 57 ''' |
| 55 main() { | 58 main() { |
| 56 bool b = true; | 59 bool b = true; |
| 57 $lineWithTest | 60 $lineWithTest |
| 58 } | 61 } |
| 59 | 62 |
| 60 bool test() { | 63 bool test() { |
| 61 } | 64 } |
| 62 '''); | 65 '''); |
| 63 } | 66 } |
| 64 | 67 |
| 65 void assertHasFix(FixKind kind, String expected) { | 68 assertHasFix(FixKind kind, String expected) async { |
| 66 AnalysisError error = _findErrorToFix(); | 69 AnalysisError error = _findErrorToFix(); |
| 67 fix = _assertHasFix(kind, error); | 70 fix = await _assertHasFix(kind, error); |
| 68 change = fix.change; | 71 change = fix.change; |
| 69 // apply to "file" | 72 // apply to "file" |
| 70 List<SourceFileEdit> fileEdits = change.edits; | 73 List<SourceFileEdit> fileEdits = change.edits; |
| 71 expect(fileEdits, hasLength(1)); | 74 expect(fileEdits, hasLength(1)); |
| 72 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 75 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 73 // verify | 76 // verify |
| 74 expect(resultCode, expected); | 77 expect(resultCode, expected); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void assertNoFix(FixKind kind) { | 80 assertNoFix(FixKind kind) async { |
| 78 AnalysisError error = _findErrorToFix(); | 81 AnalysisError error = _findErrorToFix(); |
| 79 List<Fix> fixes = _computeFixes(error); | 82 List<Fix> fixes = await _computeFixes(error); |
| 80 for (Fix fix in fixes) { | 83 for (Fix fix in fixes) { |
| 81 if (fix.kind == kind) { | 84 if (fix.kind == kind) { |
| 82 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); | 85 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); |
| 83 } | 86 } |
| 84 } | 87 } |
| 85 } | 88 } |
| 86 | 89 |
| 87 Position expectedPosition(String search) { | 90 Position expectedPosition(String search) { |
| 88 int offset = resultCode.indexOf(search); | 91 int offset = resultCode.indexOf(search); |
| 89 return new Position(testFile, offset); | 92 return new Position(testFile, offset); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 return values.map((value) { | 105 return values.map((value) { |
| 103 return new LinkedEditSuggestion(value, kind); | 106 return new LinkedEditSuggestion(value, kind); |
| 104 }).toList(); | 107 }).toList(); |
| 105 } | 108 } |
| 106 | 109 |
| 107 void setUp() { | 110 void setUp() { |
| 108 super.setUp(); | 111 super.setUp(); |
| 109 verifyNoTestUnitErrors = false; | 112 verifyNoTestUnitErrors = false; |
| 110 } | 113 } |
| 111 | 114 |
| 112 void test_addFieldFormalParameters_hasRequiredParameter() { | 115 test_addFieldFormalParameters_hasRequiredParameter() async { |
| 113 resolveTestUnit(''' | 116 resolveTestUnit(''' |
| 114 class Test { | 117 class Test { |
| 115 final int a; | 118 final int a; |
| 116 final int b; | 119 final int b; |
| 117 final int c; | 120 final int c; |
| 118 Test(this.a); | 121 Test(this.a); |
| 119 } | 122 } |
| 120 '''); | 123 '''); |
| 121 assertHasFix( | 124 await assertHasFix( |
| 122 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 125 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 123 ''' | 126 ''' |
| 124 class Test { | 127 class Test { |
| 125 final int a; | 128 final int a; |
| 126 final int b; | 129 final int b; |
| 127 final int c; | 130 final int c; |
| 128 Test(this.a, this.b, this.c); | 131 Test(this.a, this.b, this.c); |
| 129 } | 132 } |
| 130 '''); | 133 '''); |
| 131 } | 134 } |
| 132 | 135 |
| 133 void test_addFieldFormalParameters_noParameters() { | 136 test_addFieldFormalParameters_noParameters() async { |
| 134 resolveTestUnit(''' | 137 resolveTestUnit(''' |
| 135 class Test { | 138 class Test { |
| 136 final int a; | 139 final int a; |
| 137 final int b; | 140 final int b; |
| 138 final int c; | 141 final int c; |
| 139 Test(); | 142 Test(); |
| 140 } | 143 } |
| 141 '''); | 144 '''); |
| 142 assertHasFix( | 145 await assertHasFix( |
| 143 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 146 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 144 ''' | 147 ''' |
| 145 class Test { | 148 class Test { |
| 146 final int a; | 149 final int a; |
| 147 final int b; | 150 final int b; |
| 148 final int c; | 151 final int c; |
| 149 Test(this.a, this.b, this.c); | 152 Test(this.a, this.b, this.c); |
| 150 } | 153 } |
| 151 '''); | 154 '''); |
| 152 } | 155 } |
| 153 | 156 |
| 154 void test_addFieldFormalParameters_noRequiredParameter() { | 157 test_addFieldFormalParameters_noRequiredParameter() async { |
| 155 resolveTestUnit(''' | 158 resolveTestUnit(''' |
| 156 class Test { | 159 class Test { |
| 157 final int a; | 160 final int a; |
| 158 final int b; | 161 final int b; |
| 159 final int c; | 162 final int c; |
| 160 Test([this.c]); | 163 Test([this.c]); |
| 161 } | 164 } |
| 162 '''); | 165 '''); |
| 163 assertHasFix( | 166 await assertHasFix( |
| 164 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, | 167 DartFixKind.ADD_FIELD_FORMAL_PARAMETERS, |
| 165 ''' | 168 ''' |
| 166 class Test { | 169 class Test { |
| 167 final int a; | 170 final int a; |
| 168 final int b; | 171 final int b; |
| 169 final int c; | 172 final int c; |
| 170 Test(this.a, this.b, [this.c]); | 173 Test(this.a, this.b, [this.c]); |
| 171 } | 174 } |
| 172 '''); | 175 '''); |
| 173 } | 176 } |
| 174 | 177 |
| 175 void test_addMissingParameter_function_positional_hasZero() { | 178 test_addMissingParameter_function_positional_hasZero() async { |
| 176 resolveTestUnit(''' | 179 resolveTestUnit(''' |
| 177 test() {} | 180 test() {} |
| 178 main() { | 181 main() { |
| 179 test(1); | 182 test(1); |
| 180 } | 183 } |
| 181 '''); | 184 '''); |
| 182 assertHasFix( | 185 await assertHasFix( |
| 183 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | 186 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, |
| 184 ''' | 187 ''' |
| 185 test([int i]) {} | 188 test([int i]) {} |
| 186 main() { | 189 main() { |
| 187 test(1); | 190 test(1); |
| 188 } | 191 } |
| 189 '''); | 192 '''); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void test_addMissingParameter_function_required_hasOne() { | 195 test_addMissingParameter_function_required_hasOne() async { |
| 193 resolveTestUnit(''' | 196 resolveTestUnit(''' |
| 194 test(int a) {} | 197 test(int a) {} |
| 195 main() { | 198 main() { |
| 196 test(1, 2.0); | 199 test(1, 2.0); |
| 197 } | 200 } |
| 198 '''); | 201 '''); |
| 199 assertHasFix( | 202 await assertHasFix( |
| 200 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 203 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 201 ''' | 204 ''' |
| 202 test(int a, double d) {} | 205 test(int a, double d) {} |
| 203 main() { | 206 main() { |
| 204 test(1, 2.0); | 207 test(1, 2.0); |
| 205 } | 208 } |
| 206 '''); | 209 '''); |
| 207 } | 210 } |
| 208 | 211 |
| 209 void test_addMissingParameter_function_required_hasZero() { | 212 test_addMissingParameter_function_required_hasZero() async { |
| 210 resolveTestUnit(''' | 213 resolveTestUnit(''' |
| 211 test() {} | 214 test() {} |
| 212 main() { | 215 main() { |
| 213 test(1); | 216 test(1); |
| 214 } | 217 } |
| 215 '''); | 218 '''); |
| 216 assertHasFix( | 219 await assertHasFix( |
| 217 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 220 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 218 ''' | 221 ''' |
| 219 test(int i) {} | 222 test(int i) {} |
| 220 main() { | 223 main() { |
| 221 test(1); | 224 test(1); |
| 222 } | 225 } |
| 223 '''); | 226 '''); |
| 224 } | 227 } |
| 225 | 228 |
| 226 void test_addMissingParameter_method_positional_hasOne() { | 229 test_addMissingParameter_method_positional_hasOne() async { |
| 227 resolveTestUnit(''' | 230 resolveTestUnit(''' |
| 228 class A { | 231 class A { |
| 229 test(int a) {} | 232 test(int a) {} |
| 230 main() { | 233 main() { |
| 231 test(1, 2.0); | 234 test(1, 2.0); |
| 232 } | 235 } |
| 233 } | 236 } |
| 234 '''); | 237 '''); |
| 235 assertHasFix( | 238 await assertHasFix( |
| 236 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, | 239 DartFixKind.ADD_MISSING_PARAMETER_POSITIONAL, |
| 237 ''' | 240 ''' |
| 238 class A { | 241 class A { |
| 239 test(int a, [double d]) {} | 242 test(int a, [double d]) {} |
| 240 main() { | 243 main() { |
| 241 test(1, 2.0); | 244 test(1, 2.0); |
| 242 } | 245 } |
| 243 } | 246 } |
| 244 '''); | 247 '''); |
| 245 } | 248 } |
| 246 | 249 |
| 247 void test_addMissingParameter_method_required_hasOne() { | 250 test_addMissingParameter_method_required_hasOne() async { |
| 248 resolveTestUnit(''' | 251 resolveTestUnit(''' |
| 249 class A { | 252 class A { |
| 250 test(int a) {} | 253 test(int a) {} |
| 251 main() { | 254 main() { |
| 252 test(1, 2.0); | 255 test(1, 2.0); |
| 253 } | 256 } |
| 254 } | 257 } |
| 255 '''); | 258 '''); |
| 256 assertHasFix( | 259 await assertHasFix( |
| 257 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 260 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 258 ''' | 261 ''' |
| 259 class A { | 262 class A { |
| 260 test(int a, double d) {} | 263 test(int a, double d) {} |
| 261 main() { | 264 main() { |
| 262 test(1, 2.0); | 265 test(1, 2.0); |
| 263 } | 266 } |
| 264 } | 267 } |
| 265 '''); | 268 '''); |
| 266 } | 269 } |
| 267 | 270 |
| 268 void test_addMissingParameter_method_required_hasZero() { | 271 test_addMissingParameter_method_required_hasZero() async { |
| 269 resolveTestUnit(''' | 272 resolveTestUnit(''' |
| 270 class A { | 273 class A { |
| 271 test() {} | 274 test() {} |
| 272 main() { | 275 main() { |
| 273 test(1); | 276 test(1); |
| 274 } | 277 } |
| 275 } | 278 } |
| 276 '''); | 279 '''); |
| 277 assertHasFix( | 280 await assertHasFix( |
| 278 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, | 281 DartFixKind.ADD_MISSING_PARAMETER_REQUIRED, |
| 279 ''' | 282 ''' |
| 280 class A { | 283 class A { |
| 281 test(int i) {} | 284 test(int i) {} |
| 282 main() { | 285 main() { |
| 283 test(1); | 286 test(1); |
| 284 } | 287 } |
| 285 } | 288 } |
| 286 '''); | 289 '''); |
| 287 } | 290 } |
| 288 | 291 |
| 289 void test_addPartOfDirective() { | 292 test_addPartOfDirective() async { |
| 290 String partCode = r''' | 293 String partCode = r''' |
| 291 // Comment first. | 294 // Comment first. |
| 292 // Comment second. | 295 // Comment second. |
| 293 | 296 |
| 294 class A {} | 297 class A {} |
| 295 '''; | 298 '''; |
| 296 addSource('/part.dart', partCode); | 299 addSource('/part.dart', partCode); |
| 297 resolveTestUnit(''' | 300 resolveTestUnit(''' |
| 298 library my.lib; | 301 library my.lib; |
| 299 part 'part.dart'; | 302 part 'part.dart'; |
| 300 '''); | 303 '''); |
| 301 _performAnalysis(); | 304 _performAnalysis(); |
| 302 AnalysisError error = _findErrorToFix(); | 305 AnalysisError error = _findErrorToFix(); |
| 303 fix = _assertHasFix(DartFixKind.ADD_PART_OF, error); | 306 fix = await _assertHasFix(DartFixKind.ADD_PART_OF, error); |
| 304 change = fix.change; | 307 change = fix.change; |
| 305 // apply to "file" | 308 // apply to "file" |
| 306 List<SourceFileEdit> fileEdits = change.edits; | 309 List<SourceFileEdit> fileEdits = change.edits; |
| 307 expect(fileEdits, hasLength(1)); | 310 expect(fileEdits, hasLength(1)); |
| 308 SourceFileEdit fileEdit = change.edits[0]; | 311 SourceFileEdit fileEdit = change.edits[0]; |
| 309 expect(fileEdit.file, '/part.dart'); | 312 expect(fileEdit.file, '/part.dart'); |
| 310 expect( | 313 expect( |
| 311 SourceEdit.applySequence(partCode, fileEdit.edits), | 314 SourceEdit.applySequence(partCode, fileEdit.edits), |
| 312 r''' | 315 r''' |
| 313 // Comment first. | 316 // Comment first. |
| 314 // Comment second. | 317 // Comment second. |
| 315 | 318 |
| 316 part of my.lib; | 319 part of my.lib; |
| 317 | 320 |
| 318 class A {} | 321 class A {} |
| 319 '''); | 322 '''); |
| 320 } | 323 } |
| 321 | 324 |
| 322 void test_addSync_BAD_nullFunctionBody() { | 325 test_addSync_BAD_nullFunctionBody() async { |
| 323 resolveTestUnit(''' | 326 resolveTestUnit(''' |
| 324 var F = await; | 327 var F = await; |
| 325 '''); | 328 '''); |
| 326 assertNoFix(DartFixKind.ADD_ASYNC); | 329 await assertNoFix(DartFixKind.ADD_ASYNC); |
| 327 } | 330 } |
| 328 | 331 |
| 329 void test_addSync_blockFunctionBody() { | 332 test_addSync_blockFunctionBody() async { |
| 330 resolveTestUnit(''' | 333 resolveTestUnit(''' |
| 331 foo() {} | 334 foo() {} |
| 332 main() { | 335 main() { |
| 333 await foo(); | 336 await foo(); |
| 334 } | 337 } |
| 335 '''); | 338 '''); |
| 336 List<AnalysisError> errors = context.computeErrors(testSource); | 339 List<AnalysisError> errors = context.computeErrors(testSource); |
| 337 expect(errors, hasLength(2)); | 340 expect(errors, hasLength(2)); |
| 338 String message1 = "Expected to find ';'"; | 341 String message1 = "Expected to find ';'"; |
| 339 String message2 = "Undefined name 'await'"; | 342 String message2 = "Undefined name 'await'"; |
| 340 expect(errors.map((e) => e.message), unorderedEquals([message1, message2])); | 343 expect(errors.map((e) => e.message), unorderedEquals([message1, message2])); |
| 341 for (AnalysisError error in errors) { | 344 for (AnalysisError error in errors) { |
| 342 if (error.message == message1) { | 345 if (error.message == message1) { |
| 343 List<Fix> fixes = _computeFixes(error); | 346 List<Fix> fixes = await _computeFixes(error); |
| 344 expect(fixes, isEmpty); | 347 expect(fixes, isEmpty); |
| 345 } | 348 } |
| 346 if (error.message == message2) { | 349 if (error.message == message2) { |
| 347 List<Fix> fixes = _computeFixes(error); | 350 List<Fix> fixes = await _computeFixes(error); |
| 348 // has exactly one fix | 351 // has exactly one fix |
| 349 expect(fixes, hasLength(1)); | 352 expect(fixes, hasLength(1)); |
| 350 Fix fix = fixes[0]; | 353 Fix fix = fixes[0]; |
| 351 expect(fix.kind, DartFixKind.ADD_ASYNC); | 354 expect(fix.kind, DartFixKind.ADD_ASYNC); |
| 352 // apply to "file" | 355 // apply to "file" |
| 353 List<SourceFileEdit> fileEdits = fix.change.edits; | 356 List<SourceFileEdit> fileEdits = fix.change.edits; |
| 354 expect(fileEdits, hasLength(1)); | 357 expect(fileEdits, hasLength(1)); |
| 355 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); | 358 resultCode = SourceEdit.applySequence(testCode, fileEdits[0].edits); |
| 356 // verify | 359 // verify |
| 357 expect( | 360 expect( |
| 358 resultCode, | 361 resultCode, |
| 359 ''' | 362 ''' |
| 360 foo() {} | 363 foo() {} |
| 361 main() async { | 364 main() async { |
| 362 await foo(); | 365 await foo(); |
| 363 } | 366 } |
| 364 '''); | 367 '''); |
| 365 } | 368 } |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 369 void test_addSync_expressionFunctionBody() { | 372 test_addSync_expressionFunctionBody() async { |
| 370 errorFilter = (AnalysisError error) { | 373 errorFilter = (AnalysisError error) { |
| 371 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 374 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 372 }; | 375 }; |
| 373 resolveTestUnit(''' | 376 resolveTestUnit(''' |
| 374 foo() {} | 377 foo() {} |
| 375 main() => await foo(); | 378 main() => await foo(); |
| 376 '''); | 379 '''); |
| 377 assertHasFix( | 380 await assertHasFix( |
| 378 DartFixKind.ADD_ASYNC, | 381 DartFixKind.ADD_ASYNC, |
| 379 ''' | 382 ''' |
| 380 foo() {} | 383 foo() {} |
| 381 main() async => await foo(); | 384 main() async => await foo(); |
| 382 '''); | 385 '''); |
| 383 } | 386 } |
| 384 | 387 |
| 385 void test_boolean() { | 388 test_boolean() async { |
| 386 resolveTestUnit(''' | 389 resolveTestUnit(''' |
| 387 main() { | 390 main() { |
| 388 boolean v; | 391 boolean v; |
| 389 } | 392 } |
| 390 '''); | 393 '''); |
| 391 assertHasFix( | 394 await assertHasFix( |
| 392 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, | 395 DartFixKind.REPLACE_BOOLEAN_WITH_BOOL, |
| 393 ''' | 396 ''' |
| 394 main() { | 397 main() { |
| 395 bool v; | 398 bool v; |
| 396 } | 399 } |
| 397 '''); | 400 '''); |
| 398 } | 401 } |
| 399 | 402 |
| 400 void test_canBeNullAfterNullAware_chain() { | 403 test_canBeNullAfterNullAware_chain() async { |
| 401 resolveTestUnit(''' | 404 resolveTestUnit(''' |
| 402 main(x) { | 405 main(x) { |
| 403 x?.a.b.c; | 406 x?.a.b.c; |
| 404 } | 407 } |
| 405 '''); | 408 '''); |
| 406 assertHasFix( | 409 await assertHasFix( |
| 407 DartFixKind.REPLACE_WITH_NULL_AWARE, | 410 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 408 ''' | 411 ''' |
| 409 main(x) { | 412 main(x) { |
| 410 x?.a?.b?.c; | 413 x?.a?.b?.c; |
| 411 } | 414 } |
| 412 '''); | 415 '''); |
| 413 } | 416 } |
| 414 | 417 |
| 415 void test_canBeNullAfterNullAware_methodInvocation() { | 418 test_canBeNullAfterNullAware_methodInvocation() async { |
| 416 resolveTestUnit(''' | 419 resolveTestUnit(''' |
| 417 main(x) { | 420 main(x) { |
| 418 x?.a.b(); | 421 x?.a.b(); |
| 419 } | 422 } |
| 420 '''); | 423 '''); |
| 421 assertHasFix( | 424 await assertHasFix( |
| 422 DartFixKind.REPLACE_WITH_NULL_AWARE, | 425 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 423 ''' | 426 ''' |
| 424 main(x) { | 427 main(x) { |
| 425 x?.a?.b(); | 428 x?.a?.b(); |
| 426 } | 429 } |
| 427 '''); | 430 '''); |
| 428 } | 431 } |
| 429 | 432 |
| 430 void test_canBeNullAfterNullAware_propertyAccess() { | 433 test_canBeNullAfterNullAware_propertyAccess() async { |
| 431 resolveTestUnit(''' | 434 resolveTestUnit(''' |
| 432 main(x) { | 435 main(x) { |
| 433 x?.a().b; | 436 x?.a().b; |
| 434 } | 437 } |
| 435 '''); | 438 '''); |
| 436 assertHasFix( | 439 await assertHasFix( |
| 437 DartFixKind.REPLACE_WITH_NULL_AWARE, | 440 DartFixKind.REPLACE_WITH_NULL_AWARE, |
| 438 ''' | 441 ''' |
| 439 main(x) { | 442 main(x) { |
| 440 x?.a()?.b; | 443 x?.a()?.b; |
| 441 } | 444 } |
| 442 '''); | 445 '''); |
| 443 } | 446 } |
| 444 | 447 |
| 445 void test_changeToStaticAccess_method() { | 448 test_changeToStaticAccess_method() async { |
| 446 resolveTestUnit(''' | 449 resolveTestUnit(''' |
| 447 class A { | 450 class A { |
| 448 static foo() {} | 451 static foo() {} |
| 449 } | 452 } |
| 450 main(A a) { | 453 main(A a) { |
| 451 a.foo(); | 454 a.foo(); |
| 452 } | 455 } |
| 453 '''); | 456 '''); |
| 454 assertHasFix( | 457 await assertHasFix( |
| 455 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 458 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 456 ''' | 459 ''' |
| 457 class A { | 460 class A { |
| 458 static foo() {} | 461 static foo() {} |
| 459 } | 462 } |
| 460 main(A a) { | 463 main(A a) { |
| 461 A.foo(); | 464 A.foo(); |
| 462 } | 465 } |
| 463 '''); | 466 '''); |
| 464 } | 467 } |
| 465 | 468 |
| 466 void test_changeToStaticAccess_method_importType() { | 469 test_changeToStaticAccess_method_importType() async { |
| 467 addSource( | 470 addSource( |
| 468 '/libA.dart', | 471 '/libA.dart', |
| 469 r''' | 472 r''' |
| 470 library libA; | 473 library libA; |
| 471 class A { | 474 class A { |
| 472 static foo() {} | 475 static foo() {} |
| 473 } | 476 } |
| 474 '''); | 477 '''); |
| 475 addSource( | 478 addSource( |
| 476 '/libB.dart', | 479 '/libB.dart', |
| 477 r''' | 480 r''' |
| 478 library libB; | 481 library libB; |
| 479 import 'libA.dart'; | 482 import 'libA.dart'; |
| 480 class B extends A {} | 483 class B extends A {} |
| 481 '''); | 484 '''); |
| 482 resolveTestUnit(''' | 485 resolveTestUnit(''' |
| 483 import 'libB.dart'; | 486 import 'libB.dart'; |
| 484 main(B b) { | 487 main(B b) { |
| 485 b.foo(); | 488 b.foo(); |
| 486 } | 489 } |
| 487 '''); | 490 '''); |
| 488 assertHasFix( | 491 await assertHasFix( |
| 489 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 492 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 490 ''' | 493 ''' |
| 491 import 'libB.dart'; | 494 import 'libB.dart'; |
| 492 import 'libA.dart'; | 495 import 'libA.dart'; |
| 493 main(B b) { | 496 main(B b) { |
| 494 A.foo(); | 497 A.foo(); |
| 495 } | 498 } |
| 496 '''); | 499 '''); |
| 497 } | 500 } |
| 498 | 501 |
| 499 void test_changeToStaticAccess_method_prefixLibrary() { | 502 test_changeToStaticAccess_method_prefixLibrary() async { |
| 500 resolveTestUnit(''' | 503 resolveTestUnit(''' |
| 501 import 'dart:async' as pref; | 504 import 'dart:async' as pref; |
| 502 main(pref.Future f) { | 505 main(pref.Future f) { |
| 503 f.wait([]); | 506 f.wait([]); |
| 504 } | 507 } |
| 505 '''); | 508 '''); |
| 506 assertHasFix( | 509 await assertHasFix( |
| 507 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 510 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 508 ''' | 511 ''' |
| 509 import 'dart:async' as pref; | 512 import 'dart:async' as pref; |
| 510 main(pref.Future f) { | 513 main(pref.Future f) { |
| 511 pref.Future.wait([]); | 514 pref.Future.wait([]); |
| 512 } | 515 } |
| 513 '''); | 516 '''); |
| 514 } | 517 } |
| 515 | 518 |
| 516 void test_changeToStaticAccess_property() { | 519 test_changeToStaticAccess_property() async { |
| 517 resolveTestUnit(''' | 520 resolveTestUnit(''' |
| 518 class A { | 521 class A { |
| 519 static get foo => 42; | 522 static get foo => 42; |
| 520 } | 523 } |
| 521 main(A a) { | 524 main(A a) { |
| 522 a.foo; | 525 a.foo; |
| 523 } | 526 } |
| 524 '''); | 527 '''); |
| 525 assertHasFix( | 528 await assertHasFix( |
| 526 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 529 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 527 ''' | 530 ''' |
| 528 class A { | 531 class A { |
| 529 static get foo => 42; | 532 static get foo => 42; |
| 530 } | 533 } |
| 531 main(A a) { | 534 main(A a) { |
| 532 A.foo; | 535 A.foo; |
| 533 } | 536 } |
| 534 '''); | 537 '''); |
| 535 } | 538 } |
| 536 | 539 |
| 537 void test_changeToStaticAccess_property_importType() { | 540 test_changeToStaticAccess_property_importType() async { |
| 538 addSource( | 541 addSource( |
| 539 '/libA.dart', | 542 '/libA.dart', |
| 540 r''' | 543 r''' |
| 541 library libA; | 544 library libA; |
| 542 class A { | 545 class A { |
| 543 static get foo => null; | 546 static get foo => null; |
| 544 } | 547 } |
| 545 '''); | 548 '''); |
| 546 addSource( | 549 addSource( |
| 547 '/libB.dart', | 550 '/libB.dart', |
| 548 r''' | 551 r''' |
| 549 library libB; | 552 library libB; |
| 550 import 'libA.dart'; | 553 import 'libA.dart'; |
| 551 class B extends A {} | 554 class B extends A {} |
| 552 '''); | 555 '''); |
| 553 resolveTestUnit(''' | 556 resolveTestUnit(''' |
| 554 import 'libB.dart'; | 557 import 'libB.dart'; |
| 555 main(B b) { | 558 main(B b) { |
| 556 b.foo; | 559 b.foo; |
| 557 } | 560 } |
| 558 '''); | 561 '''); |
| 559 assertHasFix( | 562 await assertHasFix( |
| 560 DartFixKind.CHANGE_TO_STATIC_ACCESS, | 563 DartFixKind.CHANGE_TO_STATIC_ACCESS, |
| 561 ''' | 564 ''' |
| 562 import 'libB.dart'; | 565 import 'libB.dart'; |
| 563 import 'libA.dart'; | 566 import 'libA.dart'; |
| 564 main(B b) { | 567 main(B b) { |
| 565 A.foo; | 568 A.foo; |
| 566 } | 569 } |
| 567 '''); | 570 '''); |
| 568 } | 571 } |
| 569 | 572 |
| 570 void test_createClass() { | 573 test_createClass() async { |
| 571 resolveTestUnit(''' | 574 resolveTestUnit(''' |
| 572 main() { | 575 main() { |
| 573 Test v = null; | 576 Test v = null; |
| 574 } | 577 } |
| 575 '''); | 578 '''); |
| 576 assertHasFix( | 579 await assertHasFix( |
| 577 DartFixKind.CREATE_CLASS, | 580 DartFixKind.CREATE_CLASS, |
| 578 ''' | 581 ''' |
| 579 main() { | 582 main() { |
| 580 Test v = null; | 583 Test v = null; |
| 581 } | 584 } |
| 582 | 585 |
| 583 class Test { | 586 class Test { |
| 584 } | 587 } |
| 585 '''); | 588 '''); |
| 586 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 589 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 587 } | 590 } |
| 588 | 591 |
| 589 void test_createClass_BAD_hasUnresolvedPrefix() { | 592 test_createClass_BAD_hasUnresolvedPrefix() async { |
| 590 resolveTestUnit(''' | 593 resolveTestUnit(''' |
| 591 main() { | 594 main() { |
| 592 prefix.Test v = null; | 595 prefix.Test v = null; |
| 593 } | 596 } |
| 594 '''); | 597 '''); |
| 595 assertNoFix(DartFixKind.CREATE_CLASS); | 598 await assertNoFix(DartFixKind.CREATE_CLASS); |
| 596 } | 599 } |
| 597 | 600 |
| 598 void test_createClass_inLibraryOfPrefix() { | 601 test_createClass_inLibraryOfPrefix() async { |
| 599 String libCode = r''' | 602 String libCode = r''' |
| 600 library my.lib; | 603 library my.lib; |
| 601 | 604 |
| 602 class A {} | 605 class A {} |
| 603 '''; | 606 '''; |
| 604 addSource('/lib.dart', libCode); | 607 addSource('/lib.dart', libCode); |
| 605 resolveTestUnit(''' | 608 resolveTestUnit(''' |
| 606 import 'lib.dart' as lib; | 609 import 'lib.dart' as lib; |
| 607 | 610 |
| 608 main() { | 611 main() { |
| 609 lib.A a = null; | 612 lib.A a = null; |
| 610 lib.Test t = null; | 613 lib.Test t = null; |
| 611 } | 614 } |
| 612 '''); | 615 '''); |
| 613 AnalysisError error = _findErrorToFix(); | 616 AnalysisError error = _findErrorToFix(); |
| 614 fix = _assertHasFix(DartFixKind.CREATE_CLASS, error); | 617 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); |
| 615 change = fix.change; | 618 change = fix.change; |
| 616 // apply to "lib.dart" | 619 // apply to "lib.dart" |
| 617 List<SourceFileEdit> fileEdits = change.edits; | 620 List<SourceFileEdit> fileEdits = change.edits; |
| 618 expect(fileEdits, hasLength(1)); | 621 expect(fileEdits, hasLength(1)); |
| 619 SourceFileEdit fileEdit = change.edits[0]; | 622 SourceFileEdit fileEdit = change.edits[0]; |
| 620 expect(fileEdit.file, '/lib.dart'); | 623 expect(fileEdit.file, '/lib.dart'); |
| 621 expect( | 624 expect( |
| 622 SourceEdit.applySequence(libCode, fileEdit.edits), | 625 SourceEdit.applySequence(libCode, fileEdit.edits), |
| 623 r''' | 626 r''' |
| 624 library my.lib; | 627 library my.lib; |
| 625 | 628 |
| 626 class A {} | 629 class A {} |
| 627 | 630 |
| 628 class Test { | 631 class Test { |
| 629 } | 632 } |
| 630 '''); | 633 '''); |
| 631 expect(change.linkedEditGroups, isEmpty); | 634 expect(change.linkedEditGroups, isEmpty); |
| 632 } | 635 } |
| 633 | 636 |
| 634 void test_createClass_innerLocalFunction() { | 637 test_createClass_innerLocalFunction() async { |
| 635 resolveTestUnit(''' | 638 resolveTestUnit(''' |
| 636 f() { | 639 f() { |
| 637 g() { | 640 g() { |
| 638 Test v = null; | 641 Test v = null; |
| 639 } | 642 } |
| 640 } | 643 } |
| 641 '''); | 644 '''); |
| 642 assertHasFix( | 645 await assertHasFix( |
| 643 DartFixKind.CREATE_CLASS, | 646 DartFixKind.CREATE_CLASS, |
| 644 ''' | 647 ''' |
| 645 f() { | 648 f() { |
| 646 g() { | 649 g() { |
| 647 Test v = null; | 650 Test v = null; |
| 648 } | 651 } |
| 649 } | 652 } |
| 650 | 653 |
| 651 class Test { | 654 class Test { |
| 652 } | 655 } |
| 653 '''); | 656 '''); |
| 654 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); | 657 _assertLinkedGroup(change.linkedEditGroups[0], ['Test v =', 'Test {']); |
| 655 } | 658 } |
| 656 | 659 |
| 657 void test_createClass_itemOfList() { | 660 test_createClass_itemOfList() async { |
| 658 resolveTestUnit(''' | 661 resolveTestUnit(''' |
| 659 main() { | 662 main() { |
| 660 var a = [Test]; | 663 var a = [Test]; |
| 661 } | 664 } |
| 662 '''); | 665 '''); |
| 663 assertHasFix( | 666 await assertHasFix( |
| 664 DartFixKind.CREATE_CLASS, | 667 DartFixKind.CREATE_CLASS, |
| 665 ''' | 668 ''' |
| 666 main() { | 669 main() { |
| 667 var a = [Test]; | 670 var a = [Test]; |
| 668 } | 671 } |
| 669 | 672 |
| 670 class Test { | 673 class Test { |
| 671 } | 674 } |
| 672 '''); | 675 '''); |
| 673 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); | 676 _assertLinkedGroup(change.linkedEditGroups[0], ['Test];', 'Test {']); |
| 674 } | 677 } |
| 675 | 678 |
| 676 void test_createClass_itemOfList_inAnnotation() { | 679 test_createClass_itemOfList_inAnnotation() async { |
| 677 errorFilter = (AnalysisError error) { | 680 errorFilter = (AnalysisError error) { |
| 678 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 681 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 679 }; | 682 }; |
| 680 resolveTestUnit(''' | 683 resolveTestUnit(''' |
| 681 class MyAnnotation { | 684 class MyAnnotation { |
| 682 const MyAnnotation(a, b); | 685 const MyAnnotation(a, b); |
| 683 } | 686 } |
| 684 @MyAnnotation(int, const [Test]) | 687 @MyAnnotation(int, const [Test]) |
| 685 main() {} | 688 main() {} |
| 686 '''); | 689 '''); |
| 687 assertHasFix( | 690 await assertHasFix( |
| 688 DartFixKind.CREATE_CLASS, | 691 DartFixKind.CREATE_CLASS, |
| 689 ''' | 692 ''' |
| 690 class MyAnnotation { | 693 class MyAnnotation { |
| 691 const MyAnnotation(a, b); | 694 const MyAnnotation(a, b); |
| 692 } | 695 } |
| 693 @MyAnnotation(int, const [Test]) | 696 @MyAnnotation(int, const [Test]) |
| 694 main() {} | 697 main() {} |
| 695 | 698 |
| 696 class Test { | 699 class Test { |
| 697 } | 700 } |
| 698 '''); | 701 '''); |
| 699 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); | 702 _assertLinkedGroup(change.linkedEditGroups[0], ['Test])', 'Test {']); |
| 700 } | 703 } |
| 701 | 704 |
| 702 void test_createConstructor_forFinalFields() { | 705 test_createConstructor_forFinalFields() async { |
| 703 errorFilter = (AnalysisError error) { | 706 errorFilter = (AnalysisError error) { |
| 704 return error.message.contains("'a'"); | 707 return error.message.contains("'a'"); |
| 705 }; | 708 }; |
| 706 resolveTestUnit(''' | 709 resolveTestUnit(''' |
| 707 class Test { | 710 class Test { |
| 708 final int a; | 711 final int a; |
| 709 final int b = 2; | 712 final int b = 2; |
| 710 final int c; | 713 final int c; |
| 711 } | 714 } |
| 712 '''); | 715 '''); |
| 713 assertHasFix( | 716 await assertHasFix( |
| 714 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, | 717 DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS, |
| 715 ''' | 718 ''' |
| 716 class Test { | 719 class Test { |
| 717 final int a; | 720 final int a; |
| 718 final int b = 2; | 721 final int b = 2; |
| 719 final int c; | 722 final int c; |
| 720 | 723 |
| 721 Test(this.a, this.c); | 724 Test(this.a, this.c); |
| 722 } | 725 } |
| 723 '''); | 726 '''); |
| 724 } | 727 } |
| 725 | 728 |
| 726 void test_createConstructor_insteadOfSyntheticDefault() { | 729 test_createConstructor_insteadOfSyntheticDefault() async { |
| 727 resolveTestUnit(''' | 730 resolveTestUnit(''' |
| 728 class A { | 731 class A { |
| 729 int field; | 732 int field; |
| 730 | 733 |
| 731 method() {} | 734 method() {} |
| 732 } | 735 } |
| 733 main() { | 736 main() { |
| 734 new A(1, 2.0); | 737 new A(1, 2.0); |
| 735 } | 738 } |
| 736 '''); | 739 '''); |
| 737 assertHasFix( | 740 await assertHasFix( |
| 738 DartFixKind.CREATE_CONSTRUCTOR, | 741 DartFixKind.CREATE_CONSTRUCTOR, |
| 739 ''' | 742 ''' |
| 740 class A { | 743 class A { |
| 741 int field; | 744 int field; |
| 742 | 745 |
| 743 A(int i, double d) { | 746 A(int i, double d) { |
| 744 } | 747 } |
| 745 | 748 |
| 746 method() {} | 749 method() {} |
| 747 } | 750 } |
| 748 main() { | 751 main() { |
| 749 new A(1, 2.0); | 752 new A(1, 2.0); |
| 750 } | 753 } |
| 751 '''); | 754 '''); |
| 752 } | 755 } |
| 753 | 756 |
| 754 void test_createConstructor_named() { | 757 test_createConstructor_named() async { |
| 755 resolveTestUnit(''' | 758 resolveTestUnit(''' |
| 756 class A { | 759 class A { |
| 757 method() {} | 760 method() {} |
| 758 } | 761 } |
| 759 main() { | 762 main() { |
| 760 new A.named(1, 2.0); | 763 new A.named(1, 2.0); |
| 761 } | 764 } |
| 762 '''); | 765 '''); |
| 763 assertHasFix( | 766 await assertHasFix( |
| 764 DartFixKind.CREATE_CONSTRUCTOR, | 767 DartFixKind.CREATE_CONSTRUCTOR, |
| 765 ''' | 768 ''' |
| 766 class A { | 769 class A { |
| 767 A.named(int i, double d) { | 770 A.named(int i, double d) { |
| 768 } | 771 } |
| 769 | 772 |
| 770 method() {} | 773 method() {} |
| 771 } | 774 } |
| 772 main() { | 775 main() { |
| 773 new A.named(1, 2.0); | 776 new A.named(1, 2.0); |
| 774 } | 777 } |
| 775 '''); | 778 '''); |
| 776 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); | 779 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']); |
| 777 } | 780 } |
| 778 | 781 |
| 779 void test_createConstructorForFinalFields_inTopLevelMethod() { | 782 test_createConstructorForFinalFields_inTopLevelMethod() async { |
| 780 resolveTestUnit(''' | 783 resolveTestUnit(''' |
| 781 main() { | 784 main() { |
| 782 final int v; | 785 final int v; |
| 783 } | 786 } |
| 784 '''); | 787 '''); |
| 785 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); | 788 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); |
| 786 } | 789 } |
| 787 | 790 |
| 788 void test_createConstructorForFinalFields_topLevelField() { | 791 test_createConstructorForFinalFields_topLevelField() async { |
| 789 resolveTestUnit(''' | 792 resolveTestUnit(''' |
| 790 final int v; | 793 final int v; |
| 791 '''); | 794 '''); |
| 792 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); | 795 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_FOR_FINAL_FIELDS); |
| 793 } | 796 } |
| 794 | 797 |
| 795 void test_createConstructorSuperExplicit() { | 798 test_createConstructorSuperExplicit() async { |
| 796 resolveTestUnit(''' | 799 resolveTestUnit(''' |
| 797 class A { | 800 class A { |
| 798 A(bool p1, int p2, double p3, String p4, {p5}); | 801 A(bool p1, int p2, double p3, String p4, {p5}); |
| 799 } | 802 } |
| 800 class B extends A { | 803 class B extends A { |
| 801 B() {} | 804 B() {} |
| 802 } | 805 } |
| 803 '''); | 806 '''); |
| 804 assertHasFix( | 807 await assertHasFix( |
| 805 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 808 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 806 ''' | 809 ''' |
| 807 class A { | 810 class A { |
| 808 A(bool p1, int p2, double p3, String p4, {p5}); | 811 A(bool p1, int p2, double p3, String p4, {p5}); |
| 809 } | 812 } |
| 810 class B extends A { | 813 class B extends A { |
| 811 B() : super(false, 0, 0.0, '') {} | 814 B() : super(false, 0, 0.0, '') {} |
| 812 } | 815 } |
| 813 '''); | 816 '''); |
| 814 } | 817 } |
| 815 | 818 |
| 816 void test_createConstructorSuperExplicit_hasInitializers() { | 819 test_createConstructorSuperExplicit_hasInitializers() async { |
| 817 resolveTestUnit(''' | 820 resolveTestUnit(''' |
| 818 class A { | 821 class A { |
| 819 A(int p); | 822 A(int p); |
| 820 } | 823 } |
| 821 class B extends A { | 824 class B extends A { |
| 822 int field; | 825 int field; |
| 823 B() : field = 42 {} | 826 B() : field = 42 {} |
| 824 } | 827 } |
| 825 '''); | 828 '''); |
| 826 assertHasFix( | 829 await assertHasFix( |
| 827 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 830 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 828 ''' | 831 ''' |
| 829 class A { | 832 class A { |
| 830 A(int p); | 833 A(int p); |
| 831 } | 834 } |
| 832 class B extends A { | 835 class B extends A { |
| 833 int field; | 836 int field; |
| 834 B() : field = 42, super(0) {} | 837 B() : field = 42, super(0) {} |
| 835 } | 838 } |
| 836 '''); | 839 '''); |
| 837 } | 840 } |
| 838 | 841 |
| 839 void test_createConstructorSuperExplicit_named() { | 842 test_createConstructorSuperExplicit_named() async { |
| 840 resolveTestUnit(''' | 843 resolveTestUnit(''' |
| 841 class A { | 844 class A { |
| 842 A.named(int p); | 845 A.named(int p); |
| 843 } | 846 } |
| 844 class B extends A { | 847 class B extends A { |
| 845 B() {} | 848 B() {} |
| 846 } | 849 } |
| 847 '''); | 850 '''); |
| 848 assertHasFix( | 851 await assertHasFix( |
| 849 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 852 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 850 ''' | 853 ''' |
| 851 class A { | 854 class A { |
| 852 A.named(int p); | 855 A.named(int p); |
| 853 } | 856 } |
| 854 class B extends A { | 857 class B extends A { |
| 855 B() : super.named(0) {} | 858 B() : super.named(0) {} |
| 856 } | 859 } |
| 857 '''); | 860 '''); |
| 858 } | 861 } |
| 859 | 862 |
| 860 void test_createConstructorSuperExplicit_named_private() { | 863 test_createConstructorSuperExplicit_named_private() async { |
| 861 resolveTestUnit(''' | 864 resolveTestUnit(''' |
| 862 class A { | 865 class A { |
| 863 A._named(int p); | 866 A._named(int p); |
| 864 } | 867 } |
| 865 class B extends A { | 868 class B extends A { |
| 866 B() {} | 869 B() {} |
| 867 } | 870 } |
| 868 '''); | 871 '''); |
| 869 assertNoFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); | 872 await assertNoFix(DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); |
| 870 } | 873 } |
| 871 | 874 |
| 872 void test_createConstructorSuperExplicit_typeArgument() { | 875 test_createConstructorSuperExplicit_typeArgument() async { |
| 873 resolveTestUnit(''' | 876 resolveTestUnit(''' |
| 874 class A<T> { | 877 class A<T> { |
| 875 A(T p); | 878 A(T p); |
| 876 } | 879 } |
| 877 class B extends A<int> { | 880 class B extends A<int> { |
| 878 B(); | 881 B(); |
| 879 } | 882 } |
| 880 '''); | 883 '''); |
| 881 assertHasFix( | 884 await assertHasFix( |
| 882 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, | 885 DartFixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION, |
| 883 ''' | 886 ''' |
| 884 class A<T> { | 887 class A<T> { |
| 885 A(T p); | 888 A(T p); |
| 886 } | 889 } |
| 887 class B extends A<int> { | 890 class B extends A<int> { |
| 888 B() : super(0); | 891 B() : super(0); |
| 889 } | 892 } |
| 890 '''); | 893 '''); |
| 891 } | 894 } |
| 892 | 895 |
| 893 void test_createConstructorSuperImplicit() { | 896 test_createConstructorSuperImplicit() async { |
| 894 resolveTestUnit(''' | 897 resolveTestUnit(''' |
| 895 class A { | 898 class A { |
| 896 A(p1, int p2, List<String> p3, [int p4]); | 899 A(p1, int p2, List<String> p3, [int p4]); |
| 897 } | 900 } |
| 898 class B extends A { | 901 class B extends A { |
| 899 int existingField; | 902 int existingField; |
| 900 | 903 |
| 901 void existingMethod() {} | 904 void existingMethod() {} |
| 902 } | 905 } |
| 903 '''); | 906 '''); |
| 904 assertHasFix( | 907 await assertHasFix( |
| 905 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 908 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 906 ''' | 909 ''' |
| 907 class A { | 910 class A { |
| 908 A(p1, int p2, List<String> p3, [int p4]); | 911 A(p1, int p2, List<String> p3, [int p4]); |
| 909 } | 912 } |
| 910 class B extends A { | 913 class B extends A { |
| 911 int existingField; | 914 int existingField; |
| 912 | 915 |
| 913 B(p1, int p2, List<String> p3) : super(p1, p2, p3); | 916 B(p1, int p2, List<String> p3) : super(p1, p2, p3); |
| 914 | 917 |
| 915 void existingMethod() {} | 918 void existingMethod() {} |
| 916 } | 919 } |
| 917 '''); | 920 '''); |
| 918 } | 921 } |
| 919 | 922 |
| 920 void test_createConstructorSuperImplicit_fieldInitializer() { | 923 test_createConstructorSuperImplicit_fieldInitializer() async { |
| 921 resolveTestUnit(''' | 924 resolveTestUnit(''' |
| 922 class A { | 925 class A { |
| 923 int _field; | 926 int _field; |
| 924 A(this._field); | 927 A(this._field); |
| 925 } | 928 } |
| 926 class B extends A { | 929 class B extends A { |
| 927 int existingField; | 930 int existingField; |
| 928 | 931 |
| 929 void existingMethod() {} | 932 void existingMethod() {} |
| 930 } | 933 } |
| 931 '''); | 934 '''); |
| 932 assertHasFix( | 935 await assertHasFix( |
| 933 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 936 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 934 ''' | 937 ''' |
| 935 class A { | 938 class A { |
| 936 int _field; | 939 int _field; |
| 937 A(this._field); | 940 A(this._field); |
| 938 } | 941 } |
| 939 class B extends A { | 942 class B extends A { |
| 940 int existingField; | 943 int existingField; |
| 941 | 944 |
| 942 B(int field) : super(field); | 945 B(int field) : super(field); |
| 943 | 946 |
| 944 void existingMethod() {} | 947 void existingMethod() {} |
| 945 } | 948 } |
| 946 '''); | 949 '''); |
| 947 } | 950 } |
| 948 | 951 |
| 949 void test_createConstructorSuperImplicit_importType() { | 952 test_createConstructorSuperImplicit_importType() async { |
| 950 addSource( | 953 addSource( |
| 951 '/libA.dart', | 954 '/libA.dart', |
| 952 r''' | 955 r''' |
| 953 library libA; | 956 library libA; |
| 954 class A {} | 957 class A {} |
| 955 '''); | 958 '''); |
| 956 addSource( | 959 addSource( |
| 957 '/libB.dart', | 960 '/libB.dart', |
| 958 r''' | 961 r''' |
| 959 library libB; | 962 library libB; |
| 960 import 'libA.dart'; | 963 import 'libA.dart'; |
| 961 class B { | 964 class B { |
| 962 B(A a); | 965 B(A a); |
| 963 } | 966 } |
| 964 '''); | 967 '''); |
| 965 resolveTestUnit(''' | 968 resolveTestUnit(''' |
| 966 import 'libB.dart'; | 969 import 'libB.dart'; |
| 967 class C extends B { | 970 class C extends B { |
| 968 } | 971 } |
| 969 '''); | 972 '''); |
| 970 assertHasFix( | 973 await assertHasFix( |
| 971 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 974 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 972 ''' | 975 ''' |
| 973 import 'libB.dart'; | 976 import 'libB.dart'; |
| 974 import 'libA.dart'; | 977 import 'libA.dart'; |
| 975 class C extends B { | 978 class C extends B { |
| 976 C(A a) : super(a); | 979 C(A a) : super(a); |
| 977 } | 980 } |
| 978 '''); | 981 '''); |
| 979 } | 982 } |
| 980 | 983 |
| 981 void test_createConstructorSuperImplicit_named() { | 984 test_createConstructorSuperImplicit_named() async { |
| 982 resolveTestUnit(''' | 985 resolveTestUnit(''' |
| 983 class A { | 986 class A { |
| 984 A.named(p1, int p2); | 987 A.named(p1, int p2); |
| 985 } | 988 } |
| 986 class B extends A { | 989 class B extends A { |
| 987 int existingField; | 990 int existingField; |
| 988 | 991 |
| 989 void existingMethod() {} | 992 void existingMethod() {} |
| 990 } | 993 } |
| 991 '''); | 994 '''); |
| 992 assertHasFix( | 995 await assertHasFix( |
| 993 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 996 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 994 ''' | 997 ''' |
| 995 class A { | 998 class A { |
| 996 A.named(p1, int p2); | 999 A.named(p1, int p2); |
| 997 } | 1000 } |
| 998 class B extends A { | 1001 class B extends A { |
| 999 int existingField; | 1002 int existingField; |
| 1000 | 1003 |
| 1001 B.named(p1, int p2) : super.named(p1, p2); | 1004 B.named(p1, int p2) : super.named(p1, p2); |
| 1002 | 1005 |
| 1003 void existingMethod() {} | 1006 void existingMethod() {} |
| 1004 } | 1007 } |
| 1005 '''); | 1008 '''); |
| 1006 } | 1009 } |
| 1007 | 1010 |
| 1008 void test_createConstructorSuperImplicit_private() { | 1011 test_createConstructorSuperImplicit_private() async { |
| 1009 resolveTestUnit(''' | 1012 resolveTestUnit(''' |
| 1010 class A { | 1013 class A { |
| 1011 A._named(p); | 1014 A._named(p); |
| 1012 } | 1015 } |
| 1013 class B extends A { | 1016 class B extends A { |
| 1014 } | 1017 } |
| 1015 '''); | 1018 '''); |
| 1016 assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER); | 1019 await assertNoFix(DartFixKind.CREATE_CONSTRUCTOR_SUPER); |
| 1017 } | 1020 } |
| 1018 | 1021 |
| 1019 void test_createConstructorSuperImplicit_typeArgument() { | 1022 test_createConstructorSuperImplicit_typeArgument() async { |
| 1020 resolveTestUnit(''' | 1023 resolveTestUnit(''' |
| 1021 class C<T> { | 1024 class C<T> { |
| 1022 final T x; | 1025 final T x; |
| 1023 C(this.x); | 1026 C(this.x); |
| 1024 } | 1027 } |
| 1025 class D extends C<int> { | 1028 class D extends C<int> { |
| 1026 }'''); | 1029 }'''); |
| 1027 assertHasFix( | 1030 await assertHasFix( |
| 1028 DartFixKind.CREATE_CONSTRUCTOR_SUPER, | 1031 DartFixKind.CREATE_CONSTRUCTOR_SUPER, |
| 1029 ''' | 1032 ''' |
| 1030 class C<T> { | 1033 class C<T> { |
| 1031 final T x; | 1034 final T x; |
| 1032 C(this.x); | 1035 C(this.x); |
| 1033 } | 1036 } |
| 1034 class D extends C<int> { | 1037 class D extends C<int> { |
| 1035 D(int x) : super(x); | 1038 D(int x) : super(x); |
| 1036 }'''); | 1039 }'''); |
| 1037 } | 1040 } |
| 1038 | 1041 |
| 1039 void test_createField_BAD_inEnum() { | 1042 test_createField_BAD_inEnum() async { |
| 1040 resolveTestUnit(''' | 1043 resolveTestUnit(''' |
| 1041 enum MyEnum { | 1044 enum MyEnum { |
| 1042 AAA, BBB | 1045 AAA, BBB |
| 1043 } | 1046 } |
| 1044 main() { | 1047 main() { |
| 1045 MyEnum.foo; | 1048 MyEnum.foo; |
| 1046 } | 1049 } |
| 1047 '''); | 1050 '''); |
| 1048 assertNoFix(DartFixKind.CREATE_FIELD); | 1051 await assertNoFix(DartFixKind.CREATE_FIELD); |
| 1049 } | 1052 } |
| 1050 | 1053 |
| 1051 void test_createField_BAD_inSDK() { | 1054 test_createField_BAD_inSDK() async { |
| 1052 resolveTestUnit(''' | 1055 resolveTestUnit(''' |
| 1053 main(List p) { | 1056 main(List p) { |
| 1054 p.foo = 1; | 1057 p.foo = 1; |
| 1055 } | 1058 } |
| 1056 '''); | 1059 '''); |
| 1057 assertNoFix(DartFixKind.CREATE_FIELD); | 1060 await assertNoFix(DartFixKind.CREATE_FIELD); |
| 1058 } | 1061 } |
| 1059 | 1062 |
| 1060 void test_createField_getter_multiLevel() { | 1063 test_createField_getter_multiLevel() async { |
| 1061 resolveTestUnit(''' | 1064 resolveTestUnit(''' |
| 1062 class A { | 1065 class A { |
| 1063 } | 1066 } |
| 1064 class B { | 1067 class B { |
| 1065 A a; | 1068 A a; |
| 1066 } | 1069 } |
| 1067 class C { | 1070 class C { |
| 1068 B b; | 1071 B b; |
| 1069 } | 1072 } |
| 1070 main(C c) { | 1073 main(C c) { |
| 1071 int v = c.b.a.test; | 1074 int v = c.b.a.test; |
| 1072 } | 1075 } |
| 1073 '''); | 1076 '''); |
| 1074 assertHasFix( | 1077 await assertHasFix( |
| 1075 DartFixKind.CREATE_FIELD, | 1078 DartFixKind.CREATE_FIELD, |
| 1076 ''' | 1079 ''' |
| 1077 class A { | 1080 class A { |
| 1078 int test; | 1081 int test; |
| 1079 } | 1082 } |
| 1080 class B { | 1083 class B { |
| 1081 A a; | 1084 A a; |
| 1082 } | 1085 } |
| 1083 class C { | 1086 class C { |
| 1084 B b; | 1087 B b; |
| 1085 } | 1088 } |
| 1086 main(C c) { | 1089 main(C c) { |
| 1087 int v = c.b.a.test; | 1090 int v = c.b.a.test; |
| 1088 } | 1091 } |
| 1089 '''); | 1092 '''); |
| 1090 } | 1093 } |
| 1091 | 1094 |
| 1092 void test_createField_getter_qualified_instance() { | 1095 test_createField_getter_qualified_instance() async { |
| 1093 resolveTestUnit(''' | 1096 resolveTestUnit(''' |
| 1094 class A { | 1097 class A { |
| 1095 } | 1098 } |
| 1096 main(A a) { | 1099 main(A a) { |
| 1097 int v = a.test; | 1100 int v = a.test; |
| 1098 } | 1101 } |
| 1099 '''); | 1102 '''); |
| 1100 assertHasFix( | 1103 await assertHasFix( |
| 1101 DartFixKind.CREATE_FIELD, | 1104 DartFixKind.CREATE_FIELD, |
| 1102 ''' | 1105 ''' |
| 1103 class A { | 1106 class A { |
| 1104 int test; | 1107 int test; |
| 1105 } | 1108 } |
| 1106 main(A a) { | 1109 main(A a) { |
| 1107 int v = a.test; | 1110 int v = a.test; |
| 1108 } | 1111 } |
| 1109 '''); | 1112 '''); |
| 1110 } | 1113 } |
| 1111 | 1114 |
| 1112 void test_createField_getter_qualified_instance_dynamicType() { | 1115 test_createField_getter_qualified_instance_dynamicType() async { |
| 1113 resolveTestUnit(''' | 1116 resolveTestUnit(''' |
| 1114 class A { | 1117 class A { |
| 1115 B b; | 1118 B b; |
| 1116 void f(Object p) { | 1119 void f(Object p) { |
| 1117 p == b.test; | 1120 p == b.test; |
| 1118 } | 1121 } |
| 1119 } | 1122 } |
| 1120 class B { | 1123 class B { |
| 1121 } | 1124 } |
| 1122 '''); | 1125 '''); |
| 1123 assertHasFix( | 1126 await assertHasFix( |
| 1124 DartFixKind.CREATE_FIELD, | 1127 DartFixKind.CREATE_FIELD, |
| 1125 ''' | 1128 ''' |
| 1126 class A { | 1129 class A { |
| 1127 B b; | 1130 B b; |
| 1128 void f(Object p) { | 1131 void f(Object p) { |
| 1129 p == b.test; | 1132 p == b.test; |
| 1130 } | 1133 } |
| 1131 } | 1134 } |
| 1132 class B { | 1135 class B { |
| 1133 var test; | 1136 var test; |
| 1134 } | 1137 } |
| 1135 '''); | 1138 '''); |
| 1136 } | 1139 } |
| 1137 | 1140 |
| 1138 void test_createField_getter_unqualified_instance_asInvocationArgument() { | 1141 test_createField_getter_unqualified_instance_asInvocationArgument() async { |
| 1139 resolveTestUnit(''' | 1142 resolveTestUnit(''' |
| 1140 class A { | 1143 class A { |
| 1141 main() { | 1144 main() { |
| 1142 f(test); | 1145 f(test); |
| 1143 } | 1146 } |
| 1144 } | 1147 } |
| 1145 f(String s) {} | 1148 f(String s) {} |
| 1146 '''); | 1149 '''); |
| 1147 assertHasFix( | 1150 await assertHasFix( |
| 1148 DartFixKind.CREATE_FIELD, | 1151 DartFixKind.CREATE_FIELD, |
| 1149 ''' | 1152 ''' |
| 1150 class A { | 1153 class A { |
| 1151 String test; | 1154 String test; |
| 1152 | 1155 |
| 1153 main() { | 1156 main() { |
| 1154 f(test); | 1157 f(test); |
| 1155 } | 1158 } |
| 1156 } | 1159 } |
| 1157 f(String s) {} | 1160 f(String s) {} |
| 1158 '''); | 1161 '''); |
| 1159 } | 1162 } |
| 1160 | 1163 |
| 1161 void test_createField_getter_unqualified_instance_assignmentRhs() { | 1164 test_createField_getter_unqualified_instance_assignmentRhs() async { |
| 1162 resolveTestUnit(''' | 1165 resolveTestUnit(''' |
| 1163 class A { | 1166 class A { |
| 1164 main() { | 1167 main() { |
| 1165 int v = test; | 1168 int v = test; |
| 1166 } | 1169 } |
| 1167 } | 1170 } |
| 1168 '''); | 1171 '''); |
| 1169 assertHasFix( | 1172 await assertHasFix( |
| 1170 DartFixKind.CREATE_FIELD, | 1173 DartFixKind.CREATE_FIELD, |
| 1171 ''' | 1174 ''' |
| 1172 class A { | 1175 class A { |
| 1173 int test; | 1176 int test; |
| 1174 | 1177 |
| 1175 main() { | 1178 main() { |
| 1176 int v = test; | 1179 int v = test; |
| 1177 } | 1180 } |
| 1178 } | 1181 } |
| 1179 '''); | 1182 '''); |
| 1180 } | 1183 } |
| 1181 | 1184 |
| 1182 void test_createField_getter_unqualified_instance_asStatement() { | 1185 test_createField_getter_unqualified_instance_asStatement() async { |
| 1183 resolveTestUnit(''' | 1186 resolveTestUnit(''' |
| 1184 class A { | 1187 class A { |
| 1185 main() { | 1188 main() { |
| 1186 test; | 1189 test; |
| 1187 } | 1190 } |
| 1188 } | 1191 } |
| 1189 '''); | 1192 '''); |
| 1190 assertHasFix( | 1193 await assertHasFix( |
| 1191 DartFixKind.CREATE_FIELD, | 1194 DartFixKind.CREATE_FIELD, |
| 1192 ''' | 1195 ''' |
| 1193 class A { | 1196 class A { |
| 1194 var test; | 1197 var test; |
| 1195 | 1198 |
| 1196 main() { | 1199 main() { |
| 1197 test; | 1200 test; |
| 1198 } | 1201 } |
| 1199 } | 1202 } |
| 1200 '''); | 1203 '''); |
| 1201 } | 1204 } |
| 1202 | 1205 |
| 1203 void test_createField_hint() { | 1206 test_createField_hint() async { |
| 1204 resolveTestUnit(''' | 1207 resolveTestUnit(''' |
| 1205 class A { | 1208 class A { |
| 1206 } | 1209 } |
| 1207 main(A a) { | 1210 main(A a) { |
| 1208 var x = a; | 1211 var x = a; |
| 1209 int v = x.test; | 1212 int v = x.test; |
| 1210 } | 1213 } |
| 1211 '''); | 1214 '''); |
| 1212 assertHasFix( | 1215 await assertHasFix( |
| 1213 DartFixKind.CREATE_FIELD, | 1216 DartFixKind.CREATE_FIELD, |
| 1214 ''' | 1217 ''' |
| 1215 class A { | 1218 class A { |
| 1216 int test; | 1219 int test; |
| 1217 } | 1220 } |
| 1218 main(A a) { | 1221 main(A a) { |
| 1219 var x = a; | 1222 var x = a; |
| 1220 int v = x.test; | 1223 int v = x.test; |
| 1221 } | 1224 } |
| 1222 '''); | 1225 '''); |
| 1223 } | 1226 } |
| 1224 | 1227 |
| 1225 void test_createField_hint_setter() { | 1228 test_createField_hint_setter() async { |
| 1226 resolveTestUnit(''' | 1229 resolveTestUnit(''' |
| 1227 class A { | 1230 class A { |
| 1228 } | 1231 } |
| 1229 main(A a) { | 1232 main(A a) { |
| 1230 var x = a; | 1233 var x = a; |
| 1231 x.test = 0; | 1234 x.test = 0; |
| 1232 } | 1235 } |
| 1233 '''); | 1236 '''); |
| 1234 assertHasFix( | 1237 await assertHasFix( |
| 1235 DartFixKind.CREATE_FIELD, | 1238 DartFixKind.CREATE_FIELD, |
| 1236 ''' | 1239 ''' |
| 1237 class A { | 1240 class A { |
| 1238 int test; | 1241 int test; |
| 1239 } | 1242 } |
| 1240 main(A a) { | 1243 main(A a) { |
| 1241 var x = a; | 1244 var x = a; |
| 1242 x.test = 0; | 1245 x.test = 0; |
| 1243 } | 1246 } |
| 1244 '''); | 1247 '''); |
| 1245 } | 1248 } |
| 1246 | 1249 |
| 1247 void test_createField_importType() { | 1250 test_createField_importType() async { |
| 1248 addSource( | 1251 addSource( |
| 1249 '/libA.dart', | 1252 '/libA.dart', |
| 1250 r''' | 1253 r''' |
| 1251 library libA; | 1254 library libA; |
| 1252 class A {} | 1255 class A {} |
| 1253 '''); | 1256 '''); |
| 1254 addSource( | 1257 addSource( |
| 1255 '/libB.dart', | 1258 '/libB.dart', |
| 1256 r''' | 1259 r''' |
| 1257 library libB; | 1260 library libB; |
| 1258 import 'libA.dart'; | 1261 import 'libA.dart'; |
| 1259 A getA() => null; | 1262 A getA() => null; |
| 1260 '''); | 1263 '''); |
| 1261 resolveTestUnit(''' | 1264 resolveTestUnit(''' |
| 1262 import 'libB.dart'; | 1265 import 'libB.dart'; |
| 1263 class C { | 1266 class C { |
| 1264 } | 1267 } |
| 1265 main(C c) { | 1268 main(C c) { |
| 1266 c.test = getA(); | 1269 c.test = getA(); |
| 1267 } | 1270 } |
| 1268 '''); | 1271 '''); |
| 1269 assertHasFix( | 1272 await assertHasFix( |
| 1270 DartFixKind.CREATE_FIELD, | 1273 DartFixKind.CREATE_FIELD, |
| 1271 ''' | 1274 ''' |
| 1272 import 'libB.dart'; | 1275 import 'libB.dart'; |
| 1273 import 'libA.dart'; | 1276 import 'libA.dart'; |
| 1274 class C { | 1277 class C { |
| 1275 A test; | 1278 A test; |
| 1276 } | 1279 } |
| 1277 main(C c) { | 1280 main(C c) { |
| 1278 c.test = getA(); | 1281 c.test = getA(); |
| 1279 } | 1282 } |
| 1280 '''); | 1283 '''); |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 void test_createField_setter_generic_BAD() { | 1286 test_createField_setter_generic_BAD() async { |
| 1284 resolveTestUnit(''' | 1287 resolveTestUnit(''' |
| 1285 class A { | 1288 class A { |
| 1286 } | 1289 } |
| 1287 class B<T> { | 1290 class B<T> { |
| 1288 List<T> items; | 1291 List<T> items; |
| 1289 main(A a) { | 1292 main(A a) { |
| 1290 a.test = items; | 1293 a.test = items; |
| 1291 } | 1294 } |
| 1292 } | 1295 } |
| 1293 '''); | 1296 '''); |
| 1294 assertHasFix( | 1297 await assertHasFix( |
| 1295 DartFixKind.CREATE_FIELD, | 1298 DartFixKind.CREATE_FIELD, |
| 1296 ''' | 1299 ''' |
| 1297 class A { | 1300 class A { |
| 1298 List test; | 1301 List test; |
| 1299 } | 1302 } |
| 1300 class B<T> { | 1303 class B<T> { |
| 1301 List<T> items; | 1304 List<T> items; |
| 1302 main(A a) { | 1305 main(A a) { |
| 1303 a.test = items; | 1306 a.test = items; |
| 1304 } | 1307 } |
| 1305 } | 1308 } |
| 1306 '''); | 1309 '''); |
| 1307 } | 1310 } |
| 1308 | 1311 |
| 1309 void test_createField_setter_generic_OK_local() { | 1312 test_createField_setter_generic_OK_local() async { |
| 1310 resolveTestUnit(''' | 1313 resolveTestUnit(''' |
| 1311 class A<T> { | 1314 class A<T> { |
| 1312 List<T> items; | 1315 List<T> items; |
| 1313 | 1316 |
| 1314 main(A a) { | 1317 main(A a) { |
| 1315 test = items; | 1318 test = items; |
| 1316 } | 1319 } |
| 1317 } | 1320 } |
| 1318 '''); | 1321 '''); |
| 1319 assertHasFix( | 1322 await assertHasFix( |
| 1320 DartFixKind.CREATE_FIELD, | 1323 DartFixKind.CREATE_FIELD, |
| 1321 ''' | 1324 ''' |
| 1322 class A<T> { | 1325 class A<T> { |
| 1323 List<T> items; | 1326 List<T> items; |
| 1324 | 1327 |
| 1325 List<T> test; | 1328 List<T> test; |
| 1326 | 1329 |
| 1327 main(A a) { | 1330 main(A a) { |
| 1328 test = items; | 1331 test = items; |
| 1329 } | 1332 } |
| 1330 } | 1333 } |
| 1331 '''); | 1334 '''); |
| 1332 } | 1335 } |
| 1333 | 1336 |
| 1334 void test_createField_setter_qualified_instance_hasField() { | 1337 test_createField_setter_qualified_instance_hasField() async { |
| 1335 resolveTestUnit(''' | 1338 resolveTestUnit(''' |
| 1336 class A { | 1339 class A { |
| 1337 int aaa; | 1340 int aaa; |
| 1338 int zzz; | 1341 int zzz; |
| 1339 | 1342 |
| 1340 existingMethod() {} | 1343 existingMethod() {} |
| 1341 } | 1344 } |
| 1342 main(A a) { | 1345 main(A a) { |
| 1343 a.test = 5; | 1346 a.test = 5; |
| 1344 } | 1347 } |
| 1345 '''); | 1348 '''); |
| 1346 assertHasFix( | 1349 await assertHasFix( |
| 1347 DartFixKind.CREATE_FIELD, | 1350 DartFixKind.CREATE_FIELD, |
| 1348 ''' | 1351 ''' |
| 1349 class A { | 1352 class A { |
| 1350 int aaa; | 1353 int aaa; |
| 1351 int zzz; | 1354 int zzz; |
| 1352 | 1355 |
| 1353 int test; | 1356 int test; |
| 1354 | 1357 |
| 1355 existingMethod() {} | 1358 existingMethod() {} |
| 1356 } | 1359 } |
| 1357 main(A a) { | 1360 main(A a) { |
| 1358 a.test = 5; | 1361 a.test = 5; |
| 1359 } | 1362 } |
| 1360 '''); | 1363 '''); |
| 1361 } | 1364 } |
| 1362 | 1365 |
| 1363 void test_createField_setter_qualified_instance_hasMethod() { | 1366 test_createField_setter_qualified_instance_hasMethod() async { |
| 1364 resolveTestUnit(''' | 1367 resolveTestUnit(''' |
| 1365 class A { | 1368 class A { |
| 1366 existingMethod() {} | 1369 existingMethod() {} |
| 1367 } | 1370 } |
| 1368 main(A a) { | 1371 main(A a) { |
| 1369 a.test = 5; | 1372 a.test = 5; |
| 1370 } | 1373 } |
| 1371 '''); | 1374 '''); |
| 1372 assertHasFix( | 1375 await assertHasFix( |
| 1373 DartFixKind.CREATE_FIELD, | 1376 DartFixKind.CREATE_FIELD, |
| 1374 ''' | 1377 ''' |
| 1375 class A { | 1378 class A { |
| 1376 int test; | 1379 int test; |
| 1377 | 1380 |
| 1378 existingMethod() {} | 1381 existingMethod() {} |
| 1379 } | 1382 } |
| 1380 main(A a) { | 1383 main(A a) { |
| 1381 a.test = 5; | 1384 a.test = 5; |
| 1382 } | 1385 } |
| 1383 '''); | 1386 '''); |
| 1384 } | 1387 } |
| 1385 | 1388 |
| 1386 void test_createField_setter_qualified_static() { | 1389 test_createField_setter_qualified_static() async { |
| 1387 resolveTestUnit(''' | 1390 resolveTestUnit(''' |
| 1388 class A { | 1391 class A { |
| 1389 } | 1392 } |
| 1390 main() { | 1393 main() { |
| 1391 A.test = 5; | 1394 A.test = 5; |
| 1392 } | 1395 } |
| 1393 '''); | 1396 '''); |
| 1394 assertHasFix( | 1397 await assertHasFix( |
| 1395 DartFixKind.CREATE_FIELD, | 1398 DartFixKind.CREATE_FIELD, |
| 1396 ''' | 1399 ''' |
| 1397 class A { | 1400 class A { |
| 1398 static int test; | 1401 static int test; |
| 1399 } | 1402 } |
| 1400 main() { | 1403 main() { |
| 1401 A.test = 5; | 1404 A.test = 5; |
| 1402 } | 1405 } |
| 1403 '''); | 1406 '''); |
| 1404 } | 1407 } |
| 1405 | 1408 |
| 1406 void test_createField_setter_unqualified_instance() { | 1409 test_createField_setter_unqualified_instance() async { |
| 1407 resolveTestUnit(''' | 1410 resolveTestUnit(''' |
| 1408 class A { | 1411 class A { |
| 1409 main() { | 1412 main() { |
| 1410 test = 5; | 1413 test = 5; |
| 1411 } | 1414 } |
| 1412 } | 1415 } |
| 1413 '''); | 1416 '''); |
| 1414 assertHasFix( | 1417 await assertHasFix( |
| 1415 DartFixKind.CREATE_FIELD, | 1418 DartFixKind.CREATE_FIELD, |
| 1416 ''' | 1419 ''' |
| 1417 class A { | 1420 class A { |
| 1418 int test; | 1421 int test; |
| 1419 | 1422 |
| 1420 main() { | 1423 main() { |
| 1421 test = 5; | 1424 test = 5; |
| 1422 } | 1425 } |
| 1423 } | 1426 } |
| 1424 '''); | 1427 '''); |
| 1425 } | 1428 } |
| 1426 | 1429 |
| 1427 void test_createField_setter_unqualified_static() { | 1430 test_createField_setter_unqualified_static() async { |
| 1428 resolveTestUnit(''' | 1431 resolveTestUnit(''' |
| 1429 class A { | 1432 class A { |
| 1430 static main() { | 1433 static main() { |
| 1431 test = 5; | 1434 test = 5; |
| 1432 } | 1435 } |
| 1433 } | 1436 } |
| 1434 '''); | 1437 '''); |
| 1435 assertHasFix( | 1438 await assertHasFix( |
| 1436 DartFixKind.CREATE_FIELD, | 1439 DartFixKind.CREATE_FIELD, |
| 1437 ''' | 1440 ''' |
| 1438 class A { | 1441 class A { |
| 1439 static int test; | 1442 static int test; |
| 1440 | 1443 |
| 1441 static main() { | 1444 static main() { |
| 1442 test = 5; | 1445 test = 5; |
| 1443 } | 1446 } |
| 1444 } | 1447 } |
| 1445 '''); | 1448 '''); |
| 1446 } | 1449 } |
| 1447 | 1450 |
| 1448 void test_createFile_forImport() { | 1451 test_createFile_forImport() async { |
| 1449 testFile = '/my/project/bin/test.dart'; | 1452 testFile = '/my/project/bin/test.dart'; |
| 1450 resolveTestUnit(''' | 1453 resolveTestUnit(''' |
| 1451 import 'my_file.dart'; | 1454 import 'my_file.dart'; |
| 1452 '''); | 1455 '''); |
| 1453 AnalysisError error = _findErrorToFix(); | 1456 AnalysisError error = _findErrorToFix(); |
| 1454 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); | 1457 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1455 change = fix.change; | 1458 change = fix.change; |
| 1456 // validate change | 1459 // validate change |
| 1457 List<SourceFileEdit> fileEdits = change.edits; | 1460 List<SourceFileEdit> fileEdits = change.edits; |
| 1458 expect(fileEdits, hasLength(1)); | 1461 expect(fileEdits, hasLength(1)); |
| 1459 SourceFileEdit fileEdit = change.edits[0]; | 1462 SourceFileEdit fileEdit = change.edits[0]; |
| 1460 expect(fileEdit.file, '/my/project/bin/my_file.dart'); | 1463 expect(fileEdit.file, '/my/project/bin/my_file.dart'); |
| 1461 expect(fileEdit.fileStamp, -1); | 1464 expect(fileEdit.fileStamp, -1); |
| 1462 expect(fileEdit.edits, hasLength(1)); | 1465 expect(fileEdit.edits, hasLength(1)); |
| 1463 expect(fileEdit.edits[0].replacement, contains('library my_file;')); | 1466 expect(fileEdit.edits[0].replacement, contains('library my_file;')); |
| 1464 } | 1467 } |
| 1465 | 1468 |
| 1466 void test_createFile_forImport_inPackage_lib() { | 1469 test_createFile_forImport_inPackage_lib() async { |
| 1467 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1470 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1468 testFile = '/projects/my_package/lib/test.dart'; | 1471 testFile = '/projects/my_package/lib/test.dart'; |
| 1469 provider.newFolder('/projects/my_package/lib'); | 1472 provider.newFolder('/projects/my_package/lib'); |
| 1470 resolveTestUnit(''' | 1473 resolveTestUnit(''' |
| 1471 import 'a/bb/c_cc/my_lib.dart'; | 1474 import 'a/bb/c_cc/my_lib.dart'; |
| 1472 '''); | 1475 '''); |
| 1473 AnalysisError error = _findErrorToFix(); | 1476 AnalysisError error = _findErrorToFix(); |
| 1474 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); | 1477 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1475 change = fix.change; | 1478 change = fix.change; |
| 1476 // validate change | 1479 // validate change |
| 1477 List<SourceFileEdit> fileEdits = change.edits; | 1480 List<SourceFileEdit> fileEdits = change.edits; |
| 1478 expect(fileEdits, hasLength(1)); | 1481 expect(fileEdits, hasLength(1)); |
| 1479 SourceFileEdit fileEdit = change.edits[0]; | 1482 SourceFileEdit fileEdit = change.edits[0]; |
| 1480 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); | 1483 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); |
| 1481 expect(fileEdit.fileStamp, -1); | 1484 expect(fileEdit.fileStamp, -1); |
| 1482 expect(fileEdit.edits, hasLength(1)); | 1485 expect(fileEdit.edits, hasLength(1)); |
| 1483 expect(fileEdit.edits[0].replacement, | 1486 expect(fileEdit.edits[0].replacement, |
| 1484 contains('library my_package.a.bb.c_cc.my_lib;')); | 1487 contains('library my_package.a.bb.c_cc.my_lib;')); |
| 1485 } | 1488 } |
| 1486 | 1489 |
| 1487 void test_createFile_forImport_inPackage_test() { | 1490 test_createFile_forImport_inPackage_test() async { |
| 1488 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1491 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1489 testFile = '/projects/my_package/test/misc/test_all.dart'; | 1492 testFile = '/projects/my_package/test/misc/test_all.dart'; |
| 1490 resolveTestUnit(''' | 1493 resolveTestUnit(''' |
| 1491 import 'a/bb/my_lib.dart'; | 1494 import 'a/bb/my_lib.dart'; |
| 1492 '''); | 1495 '''); |
| 1493 AnalysisError error = _findErrorToFix(); | 1496 AnalysisError error = _findErrorToFix(); |
| 1494 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); | 1497 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1495 change = fix.change; | 1498 change = fix.change; |
| 1496 // validate change | 1499 // validate change |
| 1497 List<SourceFileEdit> fileEdits = change.edits; | 1500 List<SourceFileEdit> fileEdits = change.edits; |
| 1498 expect(fileEdits, hasLength(1)); | 1501 expect(fileEdits, hasLength(1)); |
| 1499 SourceFileEdit fileEdit = change.edits[0]; | 1502 SourceFileEdit fileEdit = change.edits[0]; |
| 1500 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); | 1503 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); |
| 1501 expect(fileEdit.fileStamp, -1); | 1504 expect(fileEdit.fileStamp, -1); |
| 1502 expect(fileEdit.edits, hasLength(1)); | 1505 expect(fileEdit.edits, hasLength(1)); |
| 1503 expect(fileEdit.edits[0].replacement, | 1506 expect(fileEdit.edits[0].replacement, |
| 1504 contains('library my_package.test.misc.a.bb.my_lib;')); | 1507 contains('library my_package.test.misc.a.bb.my_lib;')); |
| 1505 } | 1508 } |
| 1506 | 1509 |
| 1507 void test_createFile_forPart() { | 1510 test_createFile_forPart() async { |
| 1508 testFile = '/my/project/bin/test.dart'; | 1511 testFile = '/my/project/bin/test.dart'; |
| 1509 resolveTestUnit(''' | 1512 resolveTestUnit(''' |
| 1510 library my.lib; | 1513 library my.lib; |
| 1511 part 'my_part.dart'; | 1514 part 'my_part.dart'; |
| 1512 '''); | 1515 '''); |
| 1513 AnalysisError error = _findErrorToFix(); | 1516 AnalysisError error = _findErrorToFix(); |
| 1514 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); | 1517 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1515 change = fix.change; | 1518 change = fix.change; |
| 1516 // validate change | 1519 // validate change |
| 1517 List<SourceFileEdit> fileEdits = change.edits; | 1520 List<SourceFileEdit> fileEdits = change.edits; |
| 1518 expect(fileEdits, hasLength(1)); | 1521 expect(fileEdits, hasLength(1)); |
| 1519 SourceFileEdit fileEdit = change.edits[0]; | 1522 SourceFileEdit fileEdit = change.edits[0]; |
| 1520 expect(fileEdit.file, '/my/project/bin/my_part.dart'); | 1523 expect(fileEdit.file, '/my/project/bin/my_part.dart'); |
| 1521 expect(fileEdit.fileStamp, -1); | 1524 expect(fileEdit.fileStamp, -1); |
| 1522 expect(fileEdit.edits, hasLength(1)); | 1525 expect(fileEdit.edits, hasLength(1)); |
| 1523 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 1526 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
| 1524 } | 1527 } |
| 1525 | 1528 |
| 1526 void test_createFile_forPart_inPackageLib() { | 1529 test_createFile_forPart_inPackageLib() async { |
| 1527 provider.newFile( | 1530 provider.newFile( |
| 1528 '/my/pubspec.yaml', | 1531 '/my/pubspec.yaml', |
| 1529 r''' | 1532 r''' |
| 1530 name: my_test | 1533 name: my_test |
| 1531 '''); | 1534 '''); |
| 1532 testFile = '/my/lib/test.dart'; | 1535 testFile = '/my/lib/test.dart'; |
| 1533 addTestSource( | 1536 addTestSource( |
| 1534 ''' | 1537 ''' |
| 1535 library my.lib; | 1538 library my.lib; |
| 1536 part 'my_part.dart'; | 1539 part 'my_part.dart'; |
| 1537 ''', | 1540 ''', |
| 1538 Uri.parse('package:my/test.dart')); | 1541 Uri.parse('package:my/test.dart')); |
| 1539 // configure SourceFactory | 1542 // configure SourceFactory |
| 1540 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 1543 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 1541 'my': [provider.getResource('/my/lib')], | 1544 'my': [provider.getResource('/my/lib')], |
| 1542 }); | 1545 }); |
| 1543 context.sourceFactory = new SourceFactory( | 1546 context.sourceFactory = new SourceFactory( |
| 1544 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); | 1547 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
| 1545 // prepare fix | 1548 // prepare fix |
| 1546 testUnit = resolveLibraryUnit(testSource); | 1549 testUnit = resolveLibraryUnit(testSource); |
| 1547 AnalysisError error = _findErrorToFix(); | 1550 AnalysisError error = _findErrorToFix(); |
| 1548 fix = _assertHasFix(DartFixKind.CREATE_FILE, error); | 1551 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1549 change = fix.change; | 1552 change = fix.change; |
| 1550 // validate change | 1553 // validate change |
| 1551 List<SourceFileEdit> fileEdits = change.edits; | 1554 List<SourceFileEdit> fileEdits = change.edits; |
| 1552 expect(fileEdits, hasLength(1)); | 1555 expect(fileEdits, hasLength(1)); |
| 1553 SourceFileEdit fileEdit = change.edits[0]; | 1556 SourceFileEdit fileEdit = change.edits[0]; |
| 1554 expect(fileEdit.file, '/my/lib/my_part.dart'); | 1557 expect(fileEdit.file, '/my/lib/my_part.dart'); |
| 1555 expect(fileEdit.fileStamp, -1); | 1558 expect(fileEdit.fileStamp, -1); |
| 1556 expect(fileEdit.edits, hasLength(1)); | 1559 expect(fileEdit.edits, hasLength(1)); |
| 1557 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 1560 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
| 1558 } | 1561 } |
| 1559 | 1562 |
| 1560 void test_createGetter_BAD_inSDK() { | 1563 test_createGetter_BAD_inSDK() async { |
| 1561 resolveTestUnit(''' | 1564 resolveTestUnit(''' |
| 1562 main(List p) { | 1565 main(List p) { |
| 1563 int v = p.foo; | 1566 int v = p.foo; |
| 1564 } | 1567 } |
| 1565 '''); | 1568 '''); |
| 1566 assertNoFix(DartFixKind.CREATE_GETTER); | 1569 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 1567 } | 1570 } |
| 1568 | 1571 |
| 1569 void test_createGetter_hint_getter() { | 1572 test_createGetter_hint_getter() async { |
| 1570 resolveTestUnit(''' | 1573 resolveTestUnit(''' |
| 1571 class A { | 1574 class A { |
| 1572 } | 1575 } |
| 1573 main(A a) { | 1576 main(A a) { |
| 1574 var x = a; | 1577 var x = a; |
| 1575 int v = x.test; | 1578 int v = x.test; |
| 1576 } | 1579 } |
| 1577 '''); | 1580 '''); |
| 1578 assertHasFix( | 1581 await assertHasFix( |
| 1579 DartFixKind.CREATE_GETTER, | 1582 DartFixKind.CREATE_GETTER, |
| 1580 ''' | 1583 ''' |
| 1581 class A { | 1584 class A { |
| 1582 int get test => null; | 1585 int get test => null; |
| 1583 } | 1586 } |
| 1584 main(A a) { | 1587 main(A a) { |
| 1585 var x = a; | 1588 var x = a; |
| 1586 int v = x.test; | 1589 int v = x.test; |
| 1587 } | 1590 } |
| 1588 '''); | 1591 '''); |
| 1589 } | 1592 } |
| 1590 | 1593 |
| 1591 void test_createGetter_location_afterLastGetter() { | 1594 test_createGetter_location_afterLastGetter() async { |
| 1592 resolveTestUnit(''' | 1595 resolveTestUnit(''' |
| 1593 class A { | 1596 class A { |
| 1594 int existingField; | 1597 int existingField; |
| 1595 | 1598 |
| 1596 int get existingGetter => null; | 1599 int get existingGetter => null; |
| 1597 | 1600 |
| 1598 existingMethod() {} | 1601 existingMethod() {} |
| 1599 } | 1602 } |
| 1600 main(A a) { | 1603 main(A a) { |
| 1601 int v = a.test; | 1604 int v = a.test; |
| 1602 } | 1605 } |
| 1603 '''); | 1606 '''); |
| 1604 assertHasFix( | 1607 await assertHasFix( |
| 1605 DartFixKind.CREATE_GETTER, | 1608 DartFixKind.CREATE_GETTER, |
| 1606 ''' | 1609 ''' |
| 1607 class A { | 1610 class A { |
| 1608 int existingField; | 1611 int existingField; |
| 1609 | 1612 |
| 1610 int get existingGetter => null; | 1613 int get existingGetter => null; |
| 1611 | 1614 |
| 1612 int get test => null; | 1615 int get test => null; |
| 1613 | 1616 |
| 1614 existingMethod() {} | 1617 existingMethod() {} |
| 1615 } | 1618 } |
| 1616 main(A a) { | 1619 main(A a) { |
| 1617 int v = a.test; | 1620 int v = a.test; |
| 1618 } | 1621 } |
| 1619 '''); | 1622 '''); |
| 1620 } | 1623 } |
| 1621 | 1624 |
| 1622 void test_createGetter_multiLevel() { | 1625 test_createGetter_multiLevel() async { |
| 1623 resolveTestUnit(''' | 1626 resolveTestUnit(''' |
| 1624 class A { | 1627 class A { |
| 1625 } | 1628 } |
| 1626 class B { | 1629 class B { |
| 1627 A a; | 1630 A a; |
| 1628 } | 1631 } |
| 1629 class C { | 1632 class C { |
| 1630 B b; | 1633 B b; |
| 1631 } | 1634 } |
| 1632 main(C c) { | 1635 main(C c) { |
| 1633 int v = c.b.a.test; | 1636 int v = c.b.a.test; |
| 1634 } | 1637 } |
| 1635 '''); | 1638 '''); |
| 1636 assertHasFix( | 1639 await assertHasFix( |
| 1637 DartFixKind.CREATE_GETTER, | 1640 DartFixKind.CREATE_GETTER, |
| 1638 ''' | 1641 ''' |
| 1639 class A { | 1642 class A { |
| 1640 int get test => null; | 1643 int get test => null; |
| 1641 } | 1644 } |
| 1642 class B { | 1645 class B { |
| 1643 A a; | 1646 A a; |
| 1644 } | 1647 } |
| 1645 class C { | 1648 class C { |
| 1646 B b; | 1649 B b; |
| 1647 } | 1650 } |
| 1648 main(C c) { | 1651 main(C c) { |
| 1649 int v = c.b.a.test; | 1652 int v = c.b.a.test; |
| 1650 } | 1653 } |
| 1651 '''); | 1654 '''); |
| 1652 } | 1655 } |
| 1653 | 1656 |
| 1654 void test_createGetter_qualified_instance() { | 1657 test_createGetter_qualified_instance() async { |
| 1655 resolveTestUnit(''' | 1658 resolveTestUnit(''' |
| 1656 class A { | 1659 class A { |
| 1657 } | 1660 } |
| 1658 main(A a) { | 1661 main(A a) { |
| 1659 int v = a.test; | 1662 int v = a.test; |
| 1660 } | 1663 } |
| 1661 '''); | 1664 '''); |
| 1662 assertHasFix( | 1665 await assertHasFix( |
| 1663 DartFixKind.CREATE_GETTER, | 1666 DartFixKind.CREATE_GETTER, |
| 1664 ''' | 1667 ''' |
| 1665 class A { | 1668 class A { |
| 1666 int get test => null; | 1669 int get test => null; |
| 1667 } | 1670 } |
| 1668 main(A a) { | 1671 main(A a) { |
| 1669 int v = a.test; | 1672 int v = a.test; |
| 1670 } | 1673 } |
| 1671 '''); | 1674 '''); |
| 1672 } | 1675 } |
| 1673 | 1676 |
| 1674 void test_createGetter_qualified_instance_dynamicType() { | 1677 test_createGetter_qualified_instance_dynamicType() async { |
| 1675 resolveTestUnit(''' | 1678 resolveTestUnit(''' |
| 1676 class A { | 1679 class A { |
| 1677 B b; | 1680 B b; |
| 1678 void f(Object p) { | 1681 void f(Object p) { |
| 1679 p == b.test; | 1682 p == b.test; |
| 1680 } | 1683 } |
| 1681 } | 1684 } |
| 1682 class B { | 1685 class B { |
| 1683 } | 1686 } |
| 1684 '''); | 1687 '''); |
| 1685 assertHasFix( | 1688 await assertHasFix( |
| 1686 DartFixKind.CREATE_GETTER, | 1689 DartFixKind.CREATE_GETTER, |
| 1687 ''' | 1690 ''' |
| 1688 class A { | 1691 class A { |
| 1689 B b; | 1692 B b; |
| 1690 void f(Object p) { | 1693 void f(Object p) { |
| 1691 p == b.test; | 1694 p == b.test; |
| 1692 } | 1695 } |
| 1693 } | 1696 } |
| 1694 class B { | 1697 class B { |
| 1695 get test => null; | 1698 get test => null; |
| 1696 } | 1699 } |
| 1697 '''); | 1700 '''); |
| 1698 } | 1701 } |
| 1699 | 1702 |
| 1700 void test_createGetter_setterContext() { | 1703 test_createGetter_setterContext() async { |
| 1701 resolveTestUnit(''' | 1704 resolveTestUnit(''' |
| 1702 class A { | 1705 class A { |
| 1703 } | 1706 } |
| 1704 main(A a) { | 1707 main(A a) { |
| 1705 a.test = 42; | 1708 a.test = 42; |
| 1706 } | 1709 } |
| 1707 '''); | 1710 '''); |
| 1708 assertNoFix(DartFixKind.CREATE_GETTER); | 1711 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 1709 } | 1712 } |
| 1710 | 1713 |
| 1711 void test_createGetter_unqualified_instance_asInvocationArgument() { | 1714 test_createGetter_unqualified_instance_asInvocationArgument() async { |
| 1712 resolveTestUnit(''' | 1715 resolveTestUnit(''' |
| 1713 class A { | 1716 class A { |
| 1714 main() { | 1717 main() { |
| 1715 f(test); | 1718 f(test); |
| 1716 } | 1719 } |
| 1717 } | 1720 } |
| 1718 f(String s) {} | 1721 f(String s) {} |
| 1719 '''); | 1722 '''); |
| 1720 assertHasFix( | 1723 await assertHasFix( |
| 1721 DartFixKind.CREATE_GETTER, | 1724 DartFixKind.CREATE_GETTER, |
| 1722 ''' | 1725 ''' |
| 1723 class A { | 1726 class A { |
| 1724 String get test => null; | 1727 String get test => null; |
| 1725 | 1728 |
| 1726 main() { | 1729 main() { |
| 1727 f(test); | 1730 f(test); |
| 1728 } | 1731 } |
| 1729 } | 1732 } |
| 1730 f(String s) {} | 1733 f(String s) {} |
| 1731 '''); | 1734 '''); |
| 1732 } | 1735 } |
| 1733 | 1736 |
| 1734 void test_createGetter_unqualified_instance_assignmentLhs() { | 1737 test_createGetter_unqualified_instance_assignmentLhs() async { |
| 1735 resolveTestUnit(''' | 1738 resolveTestUnit(''' |
| 1736 class A { | 1739 class A { |
| 1737 main() { | 1740 main() { |
| 1738 test = 42; | 1741 test = 42; |
| 1739 } | 1742 } |
| 1740 } | 1743 } |
| 1741 '''); | 1744 '''); |
| 1742 assertNoFix(DartFixKind.CREATE_GETTER); | 1745 await assertNoFix(DartFixKind.CREATE_GETTER); |
| 1743 } | 1746 } |
| 1744 | 1747 |
| 1745 void test_createGetter_unqualified_instance_assignmentRhs() { | 1748 test_createGetter_unqualified_instance_assignmentRhs() async { |
| 1746 resolveTestUnit(''' | 1749 resolveTestUnit(''' |
| 1747 class A { | 1750 class A { |
| 1748 main() { | 1751 main() { |
| 1749 int v = test; | 1752 int v = test; |
| 1750 } | 1753 } |
| 1751 } | 1754 } |
| 1752 '''); | 1755 '''); |
| 1753 assertHasFix( | 1756 await assertHasFix( |
| 1754 DartFixKind.CREATE_GETTER, | 1757 DartFixKind.CREATE_GETTER, |
| 1755 ''' | 1758 ''' |
| 1756 class A { | 1759 class A { |
| 1757 int get test => null; | 1760 int get test => null; |
| 1758 | 1761 |
| 1759 main() { | 1762 main() { |
| 1760 int v = test; | 1763 int v = test; |
| 1761 } | 1764 } |
| 1762 } | 1765 } |
| 1763 '''); | 1766 '''); |
| 1764 } | 1767 } |
| 1765 | 1768 |
| 1766 void test_createGetter_unqualified_instance_asStatement() { | 1769 test_createGetter_unqualified_instance_asStatement() async { |
| 1767 resolveTestUnit(''' | 1770 resolveTestUnit(''' |
| 1768 class A { | 1771 class A { |
| 1769 main() { | 1772 main() { |
| 1770 test; | 1773 test; |
| 1771 } | 1774 } |
| 1772 } | 1775 } |
| 1773 '''); | 1776 '''); |
| 1774 assertHasFix( | 1777 await assertHasFix( |
| 1775 DartFixKind.CREATE_GETTER, | 1778 DartFixKind.CREATE_GETTER, |
| 1776 ''' | 1779 ''' |
| 1777 class A { | 1780 class A { |
| 1778 get test => null; | 1781 get test => null; |
| 1779 | 1782 |
| 1780 main() { | 1783 main() { |
| 1781 test; | 1784 test; |
| 1782 } | 1785 } |
| 1783 } | 1786 } |
| 1784 '''); | 1787 '''); |
| 1785 } | 1788 } |
| 1786 | 1789 |
| 1787 void test_createLocalVariable_functionType_named() { | 1790 test_createLocalVariable_functionType_named() async { |
| 1788 resolveTestUnit(''' | 1791 resolveTestUnit(''' |
| 1789 typedef MY_FUNCTION(int p); | 1792 typedef MY_FUNCTION(int p); |
| 1790 foo(MY_FUNCTION f) {} | 1793 foo(MY_FUNCTION f) {} |
| 1791 main() { | 1794 main() { |
| 1792 foo(bar); | 1795 foo(bar); |
| 1793 } | 1796 } |
| 1794 '''); | 1797 '''); |
| 1795 assertHasFix( | 1798 await assertHasFix( |
| 1796 DartFixKind.CREATE_LOCAL_VARIABLE, | 1799 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1797 ''' | 1800 ''' |
| 1798 typedef MY_FUNCTION(int p); | 1801 typedef MY_FUNCTION(int p); |
| 1799 foo(MY_FUNCTION f) {} | 1802 foo(MY_FUNCTION f) {} |
| 1800 main() { | 1803 main() { |
| 1801 MY_FUNCTION bar; | 1804 MY_FUNCTION bar; |
| 1802 foo(bar); | 1805 foo(bar); |
| 1803 } | 1806 } |
| 1804 '''); | 1807 '''); |
| 1805 } | 1808 } |
| 1806 | 1809 |
| 1807 void test_createLocalVariable_functionType_synthetic() { | 1810 test_createLocalVariable_functionType_synthetic() async { |
| 1808 resolveTestUnit(''' | 1811 resolveTestUnit(''' |
| 1809 foo(f(int p)) {} | 1812 foo(f(int p)) {} |
| 1810 main() { | 1813 main() { |
| 1811 foo(bar); | 1814 foo(bar); |
| 1812 } | 1815 } |
| 1813 '''); | 1816 '''); |
| 1814 assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); | 1817 await assertNoFix(DartFixKind.CREATE_LOCAL_VARIABLE); |
| 1815 } | 1818 } |
| 1816 | 1819 |
| 1817 void test_createLocalVariable_read_typeAssignment() { | 1820 test_createLocalVariable_read_typeAssignment() async { |
| 1818 resolveTestUnit(''' | 1821 resolveTestUnit(''' |
| 1819 main() { | 1822 main() { |
| 1820 int a = test; | 1823 int a = test; |
| 1821 } | 1824 } |
| 1822 '''); | 1825 '''); |
| 1823 assertHasFix( | 1826 await assertHasFix( |
| 1824 DartFixKind.CREATE_LOCAL_VARIABLE, | 1827 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1825 ''' | 1828 ''' |
| 1826 main() { | 1829 main() { |
| 1827 int test; | 1830 int test; |
| 1828 int a = test; | 1831 int a = test; |
| 1829 } | 1832 } |
| 1830 '''); | 1833 '''); |
| 1831 } | 1834 } |
| 1832 | 1835 |
| 1833 void test_createLocalVariable_read_typeCondition() { | 1836 test_createLocalVariable_read_typeCondition() async { |
| 1834 resolveTestUnit(''' | 1837 resolveTestUnit(''' |
| 1835 main() { | 1838 main() { |
| 1836 if (!test) { | 1839 if (!test) { |
| 1837 print(42); | 1840 print(42); |
| 1838 } | 1841 } |
| 1839 } | 1842 } |
| 1840 '''); | 1843 '''); |
| 1841 assertHasFix( | 1844 await assertHasFix( |
| 1842 DartFixKind.CREATE_LOCAL_VARIABLE, | 1845 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1843 ''' | 1846 ''' |
| 1844 main() { | 1847 main() { |
| 1845 bool test; | 1848 bool test; |
| 1846 if (!test) { | 1849 if (!test) { |
| 1847 print(42); | 1850 print(42); |
| 1848 } | 1851 } |
| 1849 } | 1852 } |
| 1850 '''); | 1853 '''); |
| 1851 } | 1854 } |
| 1852 | 1855 |
| 1853 void test_createLocalVariable_read_typeInvocationArgument() { | 1856 test_createLocalVariable_read_typeInvocationArgument() async { |
| 1854 resolveTestUnit(''' | 1857 resolveTestUnit(''' |
| 1855 main() { | 1858 main() { |
| 1856 f(test); | 1859 f(test); |
| 1857 } | 1860 } |
| 1858 f(String p) {} | 1861 f(String p) {} |
| 1859 '''); | 1862 '''); |
| 1860 assertHasFix( | 1863 await assertHasFix( |
| 1861 DartFixKind.CREATE_LOCAL_VARIABLE, | 1864 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1862 ''' | 1865 ''' |
| 1863 main() { | 1866 main() { |
| 1864 String test; | 1867 String test; |
| 1865 f(test); | 1868 f(test); |
| 1866 } | 1869 } |
| 1867 f(String p) {} | 1870 f(String p) {} |
| 1868 '''); | 1871 '''); |
| 1869 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); | 1872 _assertLinkedGroup(change.linkedEditGroups[0], ['String test;']); |
| 1870 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); | 1873 _assertLinkedGroup(change.linkedEditGroups[1], ['test;', 'test);']); |
| 1871 } | 1874 } |
| 1872 | 1875 |
| 1873 void test_createLocalVariable_read_typeInvocationTarget() { | 1876 test_createLocalVariable_read_typeInvocationTarget() async { |
| 1874 resolveTestUnit(''' | 1877 resolveTestUnit(''' |
| 1875 main() { | 1878 main() { |
| 1876 test.add('hello'); | 1879 test.add('hello'); |
| 1877 } | 1880 } |
| 1878 '''); | 1881 '''); |
| 1879 assertHasFix( | 1882 await assertHasFix( |
| 1880 DartFixKind.CREATE_LOCAL_VARIABLE, | 1883 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1881 ''' | 1884 ''' |
| 1882 main() { | 1885 main() { |
| 1883 var test; | 1886 var test; |
| 1884 test.add('hello'); | 1887 test.add('hello'); |
| 1885 } | 1888 } |
| 1886 '''); | 1889 '''); |
| 1887 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); | 1890 _assertLinkedGroup(change.linkedEditGroups[0], ['test;', 'test.add(']); |
| 1888 } | 1891 } |
| 1889 | 1892 |
| 1890 void test_createLocalVariable_write_assignment() { | 1893 test_createLocalVariable_write_assignment() async { |
| 1891 resolveTestUnit(''' | 1894 resolveTestUnit(''' |
| 1892 main() { | 1895 main() { |
| 1893 test = 42; | 1896 test = 42; |
| 1894 } | 1897 } |
| 1895 '''); | 1898 '''); |
| 1896 assertHasFix( | 1899 await assertHasFix( |
| 1897 DartFixKind.CREATE_LOCAL_VARIABLE, | 1900 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1898 ''' | 1901 ''' |
| 1899 main() { | 1902 main() { |
| 1900 var test = 42; | 1903 var test = 42; |
| 1901 } | 1904 } |
| 1902 '''); | 1905 '''); |
| 1903 } | 1906 } |
| 1904 | 1907 |
| 1905 void test_createLocalVariable_write_assignment_compound() { | 1908 test_createLocalVariable_write_assignment_compound() async { |
| 1906 resolveTestUnit(''' | 1909 resolveTestUnit(''' |
| 1907 main() { | 1910 main() { |
| 1908 test += 42; | 1911 test += 42; |
| 1909 } | 1912 } |
| 1910 '''); | 1913 '''); |
| 1911 assertHasFix( | 1914 await assertHasFix( |
| 1912 DartFixKind.CREATE_LOCAL_VARIABLE, | 1915 DartFixKind.CREATE_LOCAL_VARIABLE, |
| 1913 ''' | 1916 ''' |
| 1914 main() { | 1917 main() { |
| 1915 int test; | 1918 int test; |
| 1916 test += 42; | 1919 test += 42; |
| 1917 } | 1920 } |
| 1918 '''); | 1921 '''); |
| 1919 } | 1922 } |
| 1920 | 1923 |
| 1921 void test_createMissingOverrides_functionTypeAlias() { | 1924 test_createMissingOverrides_functionTypeAlias() async { |
| 1922 resolveTestUnit(''' | 1925 resolveTestUnit(''' |
| 1923 typedef int Binary(int left, int right); | 1926 typedef int Binary(int left, int right); |
| 1924 | 1927 |
| 1925 abstract class Emulator { | 1928 abstract class Emulator { |
| 1926 void performBinary(Binary binary); | 1929 void performBinary(Binary binary); |
| 1927 } | 1930 } |
| 1928 | 1931 |
| 1929 class MyEmulator extends Emulator { | 1932 class MyEmulator extends Emulator { |
| 1930 } | 1933 } |
| 1931 '''); | 1934 '''); |
| 1932 assertHasFix( | 1935 await assertHasFix( |
| 1933 DartFixKind.CREATE_MISSING_OVERRIDES, | 1936 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 1934 ''' | 1937 ''' |
| 1935 typedef int Binary(int left, int right); | 1938 typedef int Binary(int left, int right); |
| 1936 | 1939 |
| 1937 abstract class Emulator { | 1940 abstract class Emulator { |
| 1938 void performBinary(Binary binary); | 1941 void performBinary(Binary binary); |
| 1939 } | 1942 } |
| 1940 | 1943 |
| 1941 class MyEmulator extends Emulator { | 1944 class MyEmulator extends Emulator { |
| 1942 @override | 1945 @override |
| 1943 void performBinary(Binary binary) { | 1946 void performBinary(Binary binary) { |
| 1944 // TODO: implement performBinary | 1947 // TODO: implement performBinary |
| 1945 } | 1948 } |
| 1946 } | 1949 } |
| 1947 '''); | 1950 '''); |
| 1948 } | 1951 } |
| 1949 | 1952 |
| 1950 void test_createMissingOverrides_functionTypedParameter() { | 1953 test_createMissingOverrides_functionTypedParameter() async { |
| 1951 resolveTestUnit(''' | 1954 resolveTestUnit(''' |
| 1952 abstract class A { | 1955 abstract class A { |
| 1953 forEach(int f(double p1, String p2)); | 1956 forEach(int f(double p1, String p2)); |
| 1954 } | 1957 } |
| 1955 | 1958 |
| 1956 class B extends A { | 1959 class B extends A { |
| 1957 } | 1960 } |
| 1958 '''); | 1961 '''); |
| 1959 assertHasFix( | 1962 await assertHasFix( |
| 1960 DartFixKind.CREATE_MISSING_OVERRIDES, | 1963 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 1961 ''' | 1964 ''' |
| 1962 abstract class A { | 1965 abstract class A { |
| 1963 forEach(int f(double p1, String p2)); | 1966 forEach(int f(double p1, String p2)); |
| 1964 } | 1967 } |
| 1965 | 1968 |
| 1966 class B extends A { | 1969 class B extends A { |
| 1967 @override | 1970 @override |
| 1968 forEach(int f(double p1, String p2)) { | 1971 forEach(int f(double p1, String p2)) { |
| 1969 // TODO: implement forEach | 1972 // TODO: implement forEach |
| 1970 } | 1973 } |
| 1971 } | 1974 } |
| 1972 '''); | 1975 '''); |
| 1973 } | 1976 } |
| 1974 | 1977 |
| 1975 void test_createMissingOverrides_generics_typeArguments() { | 1978 test_createMissingOverrides_generics_typeArguments() async { |
| 1976 resolveTestUnit(''' | 1979 resolveTestUnit(''' |
| 1977 class Iterator<T> { | 1980 class Iterator<T> { |
| 1978 } | 1981 } |
| 1979 | 1982 |
| 1980 abstract class IterableMixin<T> { | 1983 abstract class IterableMixin<T> { |
| 1981 Iterator<T> get iterator; | 1984 Iterator<T> get iterator; |
| 1982 } | 1985 } |
| 1983 | 1986 |
| 1984 class Test extends IterableMixin<int> { | 1987 class Test extends IterableMixin<int> { |
| 1985 } | 1988 } |
| 1986 '''); | 1989 '''); |
| 1987 assertHasFix( | 1990 await assertHasFix( |
| 1988 DartFixKind.CREATE_MISSING_OVERRIDES, | 1991 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 1989 ''' | 1992 ''' |
| 1990 class Iterator<T> { | 1993 class Iterator<T> { |
| 1991 } | 1994 } |
| 1992 | 1995 |
| 1993 abstract class IterableMixin<T> { | 1996 abstract class IterableMixin<T> { |
| 1994 Iterator<T> get iterator; | 1997 Iterator<T> get iterator; |
| 1995 } | 1998 } |
| 1996 | 1999 |
| 1997 class Test extends IterableMixin<int> { | 2000 class Test extends IterableMixin<int> { |
| 1998 // TODO: implement iterator | 2001 // TODO: implement iterator |
| 1999 @override | 2002 @override |
| 2000 Iterator<int> get iterator => null; | 2003 Iterator<int> get iterator => null; |
| 2001 } | 2004 } |
| 2002 '''); | 2005 '''); |
| 2003 } | 2006 } |
| 2004 | 2007 |
| 2005 void test_createMissingOverrides_generics_typeParameters() { | 2008 test_createMissingOverrides_generics_typeParameters() async { |
| 2006 resolveTestUnit(''' | 2009 resolveTestUnit(''' |
| 2007 abstract class ItemProvider<T> { | 2010 abstract class ItemProvider<T> { |
| 2008 List<T> getItems(); | 2011 List<T> getItems(); |
| 2009 } | 2012 } |
| 2010 | 2013 |
| 2011 class Test<V> extends ItemProvider<V> { | 2014 class Test<V> extends ItemProvider<V> { |
| 2012 } | 2015 } |
| 2013 '''); | 2016 '''); |
| 2014 assertHasFix( | 2017 await assertHasFix( |
| 2015 DartFixKind.CREATE_MISSING_OVERRIDES, | 2018 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2016 ''' | 2019 ''' |
| 2017 abstract class ItemProvider<T> { | 2020 abstract class ItemProvider<T> { |
| 2018 List<T> getItems(); | 2021 List<T> getItems(); |
| 2019 } | 2022 } |
| 2020 | 2023 |
| 2021 class Test<V> extends ItemProvider<V> { | 2024 class Test<V> extends ItemProvider<V> { |
| 2022 @override | 2025 @override |
| 2023 List<V> getItems() { | 2026 List<V> getItems() { |
| 2024 // TODO: implement getItems | 2027 // TODO: implement getItems |
| 2025 } | 2028 } |
| 2026 } | 2029 } |
| 2027 '''); | 2030 '''); |
| 2028 } | 2031 } |
| 2029 | 2032 |
| 2030 void test_createMissingOverrides_getter() { | 2033 test_createMissingOverrides_getter() async { |
| 2031 resolveTestUnit(''' | 2034 resolveTestUnit(''' |
| 2032 abstract class A { | 2035 abstract class A { |
| 2033 get g1; | 2036 get g1; |
| 2034 int get g2; | 2037 int get g2; |
| 2035 } | 2038 } |
| 2036 | 2039 |
| 2037 class B extends A { | 2040 class B extends A { |
| 2038 } | 2041 } |
| 2039 '''); | 2042 '''); |
| 2040 assertHasFix( | 2043 await assertHasFix( |
| 2041 DartFixKind.CREATE_MISSING_OVERRIDES, | 2044 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2042 ''' | 2045 ''' |
| 2043 abstract class A { | 2046 abstract class A { |
| 2044 get g1; | 2047 get g1; |
| 2045 int get g2; | 2048 int get g2; |
| 2046 } | 2049 } |
| 2047 | 2050 |
| 2048 class B extends A { | 2051 class B extends A { |
| 2049 // TODO: implement g1 | 2052 // TODO: implement g1 |
| 2050 @override | 2053 @override |
| 2051 get g1 => null; | 2054 get g1 => null; |
| 2052 | 2055 |
| 2053 // TODO: implement g2 | 2056 // TODO: implement g2 |
| 2054 @override | 2057 @override |
| 2055 int get g2 => null; | 2058 int get g2 => null; |
| 2056 } | 2059 } |
| 2057 '''); | 2060 '''); |
| 2058 } | 2061 } |
| 2059 | 2062 |
| 2060 void test_createMissingOverrides_importPrefix() { | 2063 test_createMissingOverrides_importPrefix() async { |
| 2061 resolveTestUnit(''' | 2064 resolveTestUnit(''' |
| 2062 import 'dart:async' as aaa; | 2065 import 'dart:async' as aaa; |
| 2063 abstract class A { | 2066 abstract class A { |
| 2064 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2067 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
| 2065 } | 2068 } |
| 2066 | 2069 |
| 2067 class B extends A { | 2070 class B extends A { |
| 2068 } | 2071 } |
| 2069 '''); | 2072 '''); |
| 2070 assertHasFix( | 2073 await assertHasFix( |
| 2071 DartFixKind.CREATE_MISSING_OVERRIDES, | 2074 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2072 ''' | 2075 ''' |
| 2073 import 'dart:async' as aaa; | 2076 import 'dart:async' as aaa; |
| 2074 abstract class A { | 2077 abstract class A { |
| 2075 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | 2078 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); |
| 2076 } | 2079 } |
| 2077 | 2080 |
| 2078 class B extends A { | 2081 class B extends A { |
| 2079 @override | 2082 @override |
| 2080 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { | 2083 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { |
| 2081 // TODO: implement g | 2084 // TODO: implement g |
| 2082 } | 2085 } |
| 2083 } | 2086 } |
| 2084 '''); | 2087 '''); |
| 2085 } | 2088 } |
| 2086 | 2089 |
| 2087 void test_createMissingOverrides_mergeToField_getterSetter() { | 2090 test_createMissingOverrides_mergeToField_getterSetter() async { |
| 2088 resolveTestUnit(''' | 2091 resolveTestUnit(''' |
| 2089 class A { | 2092 class A { |
| 2090 int ma; | 2093 int ma; |
| 2091 void mb() {} | 2094 void mb() {} |
| 2092 double mc; | 2095 double mc; |
| 2093 } | 2096 } |
| 2094 | 2097 |
| 2095 class B implements A { | 2098 class B implements A { |
| 2096 } | 2099 } |
| 2097 '''); | 2100 '''); |
| 2098 assertHasFix( | 2101 await assertHasFix( |
| 2099 DartFixKind.CREATE_MISSING_OVERRIDES, | 2102 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2100 ''' | 2103 ''' |
| 2101 class A { | 2104 class A { |
| 2102 int ma; | 2105 int ma; |
| 2103 void mb() {} | 2106 void mb() {} |
| 2104 double mc; | 2107 double mc; |
| 2105 } | 2108 } |
| 2106 | 2109 |
| 2107 class B implements A { | 2110 class B implements A { |
| 2108 int ma; | 2111 int ma; |
| 2109 | 2112 |
| 2110 double mc; | 2113 double mc; |
| 2111 | 2114 |
| 2112 @override | 2115 @override |
| 2113 void mb() { | 2116 void mb() { |
| 2114 // TODO: implement mb | 2117 // TODO: implement mb |
| 2115 } | 2118 } |
| 2116 } | 2119 } |
| 2117 '''); | 2120 '''); |
| 2118 } | 2121 } |
| 2119 | 2122 |
| 2120 void test_createMissingOverrides_method() { | 2123 test_createMissingOverrides_method() async { |
| 2121 resolveTestUnit(''' | 2124 resolveTestUnit(''' |
| 2122 abstract class A { | 2125 abstract class A { |
| 2123 m1(); | 2126 m1(); |
| 2124 int m2(); | 2127 int m2(); |
| 2125 String m3(int p1, double p2, Map<int, List<String>> p3); | 2128 String m3(int p1, double p2, Map<int, List<String>> p3); |
| 2126 String m4(p1, p2); | 2129 String m4(p1, p2); |
| 2127 String m5(p1, [int p2 = 2, int p3, p4 = 4]); | 2130 String m5(p1, [int p2 = 2, int p3, p4 = 4]); |
| 2128 String m6(p1, {int p2: 2, int p3, p4: 4}); | 2131 String m6(p1, {int p2: 2, int p3, p4: 4}); |
| 2129 } | 2132 } |
| 2130 | 2133 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 String m5(p1, [int p2 = 2, int p3, p4 = 4]) { | 2169 String m5(p1, [int p2 = 2, int p3, p4 = 4]) { |
| 2167 // TODO: implement m5 | 2170 // TODO: implement m5 |
| 2168 } | 2171 } |
| 2169 | 2172 |
| 2170 @override | 2173 @override |
| 2171 String m6(p1, {int p2: 2, int p3, p4: 4}) { | 2174 String m6(p1, {int p2: 2, int p3, p4: 4}) { |
| 2172 // TODO: implement m6 | 2175 // TODO: implement m6 |
| 2173 } | 2176 } |
| 2174 } | 2177 } |
| 2175 '''; | 2178 '''; |
| 2176 assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, expectedCode); | 2179 await assertHasFix(DartFixKind.CREATE_MISSING_OVERRIDES, expectedCode); |
| 2177 // end position should be on "m1", not on "m2", "m3", etc | 2180 // end position should be on "m1", not on "m2", "m3", etc |
| 2178 { | 2181 { |
| 2179 Position endPosition = change.selection; | 2182 Position endPosition = change.selection; |
| 2180 expect(endPosition, isNotNull); | 2183 expect(endPosition, isNotNull); |
| 2181 expect(endPosition.file, testFile); | 2184 expect(endPosition.file, testFile); |
| 2182 int endOffset = endPosition.offset; | 2185 int endOffset = endPosition.offset; |
| 2183 String endString = expectedCode.substring(endOffset, endOffset + 25); | 2186 String endString = expectedCode.substring(endOffset, endOffset + 25); |
| 2184 expect(endString, contains('m1')); | 2187 expect(endString, contains('m1')); |
| 2185 expect(endString, isNot(contains('m2'))); | 2188 expect(endString, isNot(contains('m2'))); |
| 2186 expect(endString, isNot(contains('m3'))); | 2189 expect(endString, isNot(contains('m3'))); |
| 2187 expect(endString, isNot(contains('m4'))); | 2190 expect(endString, isNot(contains('m4'))); |
| 2188 expect(endString, isNot(contains('m5'))); | 2191 expect(endString, isNot(contains('m5'))); |
| 2189 expect(endString, isNot(contains('m6'))); | 2192 expect(endString, isNot(contains('m6'))); |
| 2190 } | 2193 } |
| 2191 } | 2194 } |
| 2192 | 2195 |
| 2193 void test_createMissingOverrides_operator() { | 2196 test_createMissingOverrides_operator() async { |
| 2194 resolveTestUnit(''' | 2197 resolveTestUnit(''' |
| 2195 abstract class A { | 2198 abstract class A { |
| 2196 int operator [](int index); | 2199 int operator [](int index); |
| 2197 void operator []=(int index, String value); | 2200 void operator []=(int index, String value); |
| 2198 } | 2201 } |
| 2199 | 2202 |
| 2200 class B extends A { | 2203 class B extends A { |
| 2201 } | 2204 } |
| 2202 '''); | 2205 '''); |
| 2203 assertHasFix( | 2206 await assertHasFix( |
| 2204 DartFixKind.CREATE_MISSING_OVERRIDES, | 2207 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2205 ''' | 2208 ''' |
| 2206 abstract class A { | 2209 abstract class A { |
| 2207 int operator [](int index); | 2210 int operator [](int index); |
| 2208 void operator []=(int index, String value); | 2211 void operator []=(int index, String value); |
| 2209 } | 2212 } |
| 2210 | 2213 |
| 2211 class B extends A { | 2214 class B extends A { |
| 2212 @override | 2215 @override |
| 2213 int operator [](int index) { | 2216 int operator [](int index) { |
| 2214 // TODO: implement [] | 2217 // TODO: implement [] |
| 2215 } | 2218 } |
| 2216 | 2219 |
| 2217 @override | 2220 @override |
| 2218 void operator []=(int index, String value) { | 2221 void operator []=(int index, String value) { |
| 2219 // TODO: implement []= | 2222 // TODO: implement []= |
| 2220 } | 2223 } |
| 2221 } | 2224 } |
| 2222 '''); | 2225 '''); |
| 2223 } | 2226 } |
| 2224 | 2227 |
| 2225 void test_createMissingOverrides_setter() { | 2228 test_createMissingOverrides_setter() async { |
| 2226 resolveTestUnit(''' | 2229 resolveTestUnit(''' |
| 2227 abstract class A { | 2230 abstract class A { |
| 2228 set s1(x); | 2231 set s1(x); |
| 2229 set s2(int x); | 2232 set s2(int x); |
| 2230 void set s3(String x); | 2233 void set s3(String x); |
| 2231 } | 2234 } |
| 2232 | 2235 |
| 2233 class B extends A { | 2236 class B extends A { |
| 2234 } | 2237 } |
| 2235 '''); | 2238 '''); |
| 2236 assertHasFix( | 2239 await assertHasFix( |
| 2237 DartFixKind.CREATE_MISSING_OVERRIDES, | 2240 DartFixKind.CREATE_MISSING_OVERRIDES, |
| 2238 ''' | 2241 ''' |
| 2239 abstract class A { | 2242 abstract class A { |
| 2240 set s1(x); | 2243 set s1(x); |
| 2241 set s2(int x); | 2244 set s2(int x); |
| 2242 void set s3(String x); | 2245 void set s3(String x); |
| 2243 } | 2246 } |
| 2244 | 2247 |
| 2245 class B extends A { | 2248 class B extends A { |
| 2246 @override | 2249 @override |
| 2247 set s1(x) { | 2250 set s1(x) { |
| 2248 // TODO: implement s1 | 2251 // TODO: implement s1 |
| 2249 } | 2252 } |
| 2250 | 2253 |
| 2251 @override | 2254 @override |
| 2252 set s2(int x) { | 2255 set s2(int x) { |
| 2253 // TODO: implement s2 | 2256 // TODO: implement s2 |
| 2254 } | 2257 } |
| 2255 | 2258 |
| 2256 @override | 2259 @override |
| 2257 void set s3(String x) { | 2260 void set s3(String x) { |
| 2258 // TODO: implement s3 | 2261 // TODO: implement s3 |
| 2259 } | 2262 } |
| 2260 } | 2263 } |
| 2261 '''); | 2264 '''); |
| 2262 } | 2265 } |
| 2263 | 2266 |
| 2264 void test_createNoSuchMethod() { | 2267 test_createNoSuchMethod() async { |
| 2265 resolveTestUnit(''' | 2268 resolveTestUnit(''' |
| 2266 abstract class A { | 2269 abstract class A { |
| 2267 m1(); | 2270 m1(); |
| 2268 int m2(); | 2271 int m2(); |
| 2269 } | 2272 } |
| 2270 | 2273 |
| 2271 class B extends A { | 2274 class B extends A { |
| 2272 existing() {} | 2275 existing() {} |
| 2273 } | 2276 } |
| 2274 '''); | 2277 '''); |
| 2275 assertHasFix( | 2278 await assertHasFix( |
| 2276 DartFixKind.CREATE_NO_SUCH_METHOD, | 2279 DartFixKind.CREATE_NO_SUCH_METHOD, |
| 2277 ''' | 2280 ''' |
| 2278 abstract class A { | 2281 abstract class A { |
| 2279 m1(); | 2282 m1(); |
| 2280 int m2(); | 2283 int m2(); |
| 2281 } | 2284 } |
| 2282 | 2285 |
| 2283 class B extends A { | 2286 class B extends A { |
| 2284 existing() {} | 2287 existing() {} |
| 2285 | 2288 |
| 2286 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2289 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 2287 } | 2290 } |
| 2288 '''); | 2291 '''); |
| 2289 } | 2292 } |
| 2290 | 2293 |
| 2291 void test_creationFunction_forFunctionType_cascadeSecond() { | 2294 test_creationFunction_forFunctionType_cascadeSecond() async { |
| 2292 resolveTestUnit(''' | 2295 resolveTestUnit(''' |
| 2293 class A { | 2296 class A { |
| 2294 B ma() => null; | 2297 B ma() => null; |
| 2295 } | 2298 } |
| 2296 class B { | 2299 class B { |
| 2297 useFunction(int g(double a, String b)) {} | 2300 useFunction(int g(double a, String b)) {} |
| 2298 } | 2301 } |
| 2299 | 2302 |
| 2300 main() { | 2303 main() { |
| 2301 A a = new A(); | 2304 A a = new A(); |
| 2302 a..ma().useFunction(test); | 2305 a..ma().useFunction(test); |
| 2303 } | 2306 } |
| 2304 '''); | 2307 '''); |
| 2305 assertHasFix( | 2308 await assertHasFix( |
| 2306 DartFixKind.CREATE_FUNCTION, | 2309 DartFixKind.CREATE_FUNCTION, |
| 2307 ''' | 2310 ''' |
| 2308 class A { | 2311 class A { |
| 2309 B ma() => null; | 2312 B ma() => null; |
| 2310 } | 2313 } |
| 2311 class B { | 2314 class B { |
| 2312 useFunction(int g(double a, String b)) {} | 2315 useFunction(int g(double a, String b)) {} |
| 2313 } | 2316 } |
| 2314 | 2317 |
| 2315 main() { | 2318 main() { |
| 2316 A a = new A(); | 2319 A a = new A(); |
| 2317 a..ma().useFunction(test); | 2320 a..ma().useFunction(test); |
| 2318 } | 2321 } |
| 2319 | 2322 |
| 2320 int test(double a, String b) { | 2323 int test(double a, String b) { |
| 2321 } | 2324 } |
| 2322 '''); | 2325 '''); |
| 2323 } | 2326 } |
| 2324 | 2327 |
| 2325 void test_creationFunction_forFunctionType_coreFunction() { | 2328 test_creationFunction_forFunctionType_coreFunction() async { |
| 2326 resolveTestUnit(''' | 2329 resolveTestUnit(''' |
| 2327 main() { | 2330 main() { |
| 2328 useFunction(g: test); | 2331 useFunction(g: test); |
| 2329 } | 2332 } |
| 2330 useFunction({Function g}) {} | 2333 useFunction({Function g}) {} |
| 2331 '''); | 2334 '''); |
| 2332 assertHasFix( | 2335 await assertHasFix( |
| 2333 DartFixKind.CREATE_FUNCTION, | 2336 DartFixKind.CREATE_FUNCTION, |
| 2334 ''' | 2337 ''' |
| 2335 main() { | 2338 main() { |
| 2336 useFunction(g: test); | 2339 useFunction(g: test); |
| 2337 } | 2340 } |
| 2338 useFunction({Function g}) {} | 2341 useFunction({Function g}) {} |
| 2339 | 2342 |
| 2340 test() { | 2343 test() { |
| 2341 } | 2344 } |
| 2342 '''); | 2345 '''); |
| 2343 } | 2346 } |
| 2344 | 2347 |
| 2345 void test_creationFunction_forFunctionType_dynamicArgument() { | 2348 test_creationFunction_forFunctionType_dynamicArgument() async { |
| 2346 resolveTestUnit(''' | 2349 resolveTestUnit(''' |
| 2347 main() { | 2350 main() { |
| 2348 useFunction(test); | 2351 useFunction(test); |
| 2349 } | 2352 } |
| 2350 useFunction(int g(a, b)) {} | 2353 useFunction(int g(a, b)) {} |
| 2351 '''); | 2354 '''); |
| 2352 assertHasFix( | 2355 await assertHasFix( |
| 2353 DartFixKind.CREATE_FUNCTION, | 2356 DartFixKind.CREATE_FUNCTION, |
| 2354 ''' | 2357 ''' |
| 2355 main() { | 2358 main() { |
| 2356 useFunction(test); | 2359 useFunction(test); |
| 2357 } | 2360 } |
| 2358 useFunction(int g(a, b)) {} | 2361 useFunction(int g(a, b)) {} |
| 2359 | 2362 |
| 2360 int test(a, b) { | 2363 int test(a, b) { |
| 2361 } | 2364 } |
| 2362 '''); | 2365 '''); |
| 2363 } | 2366 } |
| 2364 | 2367 |
| 2365 void test_creationFunction_forFunctionType_function() { | 2368 test_creationFunction_forFunctionType_function() async { |
| 2366 resolveTestUnit(''' | 2369 resolveTestUnit(''' |
| 2367 main() { | 2370 main() { |
| 2368 useFunction(test); | 2371 useFunction(test); |
| 2369 } | 2372 } |
| 2370 useFunction(int g(double a, String b)) {} | 2373 useFunction(int g(double a, String b)) {} |
| 2371 '''); | 2374 '''); |
| 2372 assertHasFix( | 2375 await assertHasFix( |
| 2373 DartFixKind.CREATE_FUNCTION, | 2376 DartFixKind.CREATE_FUNCTION, |
| 2374 ''' | 2377 ''' |
| 2375 main() { | 2378 main() { |
| 2376 useFunction(test); | 2379 useFunction(test); |
| 2377 } | 2380 } |
| 2378 useFunction(int g(double a, String b)) {} | 2381 useFunction(int g(double a, String b)) {} |
| 2379 | 2382 |
| 2380 int test(double a, String b) { | 2383 int test(double a, String b) { |
| 2381 } | 2384 } |
| 2382 '''); | 2385 '''); |
| 2383 } | 2386 } |
| 2384 | 2387 |
| 2385 void test_creationFunction_forFunctionType_function_namedArgument() { | 2388 test_creationFunction_forFunctionType_function_namedArgument() async { |
| 2386 resolveTestUnit(''' | 2389 resolveTestUnit(''' |
| 2387 main() { | 2390 main() { |
| 2388 useFunction(g: test); | 2391 useFunction(g: test); |
| 2389 } | 2392 } |
| 2390 useFunction({int g(double a, String b)}) {} | 2393 useFunction({int g(double a, String b)}) {} |
| 2391 '''); | 2394 '''); |
| 2392 assertHasFix( | 2395 await assertHasFix( |
| 2393 DartFixKind.CREATE_FUNCTION, | 2396 DartFixKind.CREATE_FUNCTION, |
| 2394 ''' | 2397 ''' |
| 2395 main() { | 2398 main() { |
| 2396 useFunction(g: test); | 2399 useFunction(g: test); |
| 2397 } | 2400 } |
| 2398 useFunction({int g(double a, String b)}) {} | 2401 useFunction({int g(double a, String b)}) {} |
| 2399 | 2402 |
| 2400 int test(double a, String b) { | 2403 int test(double a, String b) { |
| 2401 } | 2404 } |
| 2402 '''); | 2405 '''); |
| 2403 } | 2406 } |
| 2404 | 2407 |
| 2405 void test_creationFunction_forFunctionType_importType() { | 2408 test_creationFunction_forFunctionType_importType() async { |
| 2406 addSource( | 2409 addSource( |
| 2407 '/libA.dart', | 2410 '/libA.dart', |
| 2408 r''' | 2411 r''' |
| 2409 library libA; | 2412 library libA; |
| 2410 class A {} | 2413 class A {} |
| 2411 '''); | 2414 '''); |
| 2412 addSource( | 2415 addSource( |
| 2413 '/libB.dart', | 2416 '/libB.dart', |
| 2414 r''' | 2417 r''' |
| 2415 library libB; | 2418 library libB; |
| 2416 import 'libA.dart'; | 2419 import 'libA.dart'; |
| 2417 useFunction(int g(A a)) {} | 2420 useFunction(int g(A a)) {} |
| 2418 '''); | 2421 '''); |
| 2419 resolveTestUnit(''' | 2422 resolveTestUnit(''' |
| 2420 import 'libB.dart'; | 2423 import 'libB.dart'; |
| 2421 main() { | 2424 main() { |
| 2422 useFunction(test); | 2425 useFunction(test); |
| 2423 } | 2426 } |
| 2424 '''); | 2427 '''); |
| 2425 assertHasFix( | 2428 await assertHasFix( |
| 2426 DartFixKind.CREATE_FUNCTION, | 2429 DartFixKind.CREATE_FUNCTION, |
| 2427 ''' | 2430 ''' |
| 2428 import 'libB.dart'; | 2431 import 'libB.dart'; |
| 2429 import 'libA.dart'; | 2432 import 'libA.dart'; |
| 2430 main() { | 2433 main() { |
| 2431 useFunction(test); | 2434 useFunction(test); |
| 2432 } | 2435 } |
| 2433 | 2436 |
| 2434 int test(A a) { | 2437 int test(A a) { |
| 2435 } | 2438 } |
| 2436 '''); | 2439 '''); |
| 2437 } | 2440 } |
| 2438 | 2441 |
| 2439 void test_creationFunction_forFunctionType_method_enclosingClass_static() { | 2442 test_creationFunction_forFunctionType_method_enclosingClass_static() async { |
| 2440 resolveTestUnit(''' | 2443 resolveTestUnit(''' |
| 2441 class A { | 2444 class A { |
| 2442 static foo() { | 2445 static foo() { |
| 2443 useFunction(test); | 2446 useFunction(test); |
| 2444 } | 2447 } |
| 2445 } | 2448 } |
| 2446 useFunction(int g(double a, String b)) {} | 2449 useFunction(int g(double a, String b)) {} |
| 2447 '''); | 2450 '''); |
| 2448 assertHasFix( | 2451 await assertHasFix( |
| 2449 DartFixKind.CREATE_METHOD, | 2452 DartFixKind.CREATE_METHOD, |
| 2450 ''' | 2453 ''' |
| 2451 class A { | 2454 class A { |
| 2452 static foo() { | 2455 static foo() { |
| 2453 useFunction(test); | 2456 useFunction(test); |
| 2454 } | 2457 } |
| 2455 | 2458 |
| 2456 static int test(double a, String b) { | 2459 static int test(double a, String b) { |
| 2457 } | 2460 } |
| 2458 } | 2461 } |
| 2459 useFunction(int g(double a, String b)) {} | 2462 useFunction(int g(double a, String b)) {} |
| 2460 '''); | 2463 '''); |
| 2461 } | 2464 } |
| 2462 | 2465 |
| 2463 void test_creationFunction_forFunctionType_method_enclosingClass_static2() { | 2466 test_creationFunction_forFunctionType_method_enclosingClass_static2() async { |
| 2464 resolveTestUnit(''' | 2467 resolveTestUnit(''' |
| 2465 class A { | 2468 class A { |
| 2466 var f; | 2469 var f; |
| 2467 A() : f = useFunction(test); | 2470 A() : f = useFunction(test); |
| 2468 } | 2471 } |
| 2469 useFunction(int g(double a, String b)) {} | 2472 useFunction(int g(double a, String b)) {} |
| 2470 '''); | 2473 '''); |
| 2471 assertHasFix( | 2474 await assertHasFix( |
| 2472 DartFixKind.CREATE_METHOD, | 2475 DartFixKind.CREATE_METHOD, |
| 2473 ''' | 2476 ''' |
| 2474 class A { | 2477 class A { |
| 2475 var f; | 2478 var f; |
| 2476 A() : f = useFunction(test); | 2479 A() : f = useFunction(test); |
| 2477 | 2480 |
| 2478 static int test(double a, String b) { | 2481 static int test(double a, String b) { |
| 2479 } | 2482 } |
| 2480 } | 2483 } |
| 2481 useFunction(int g(double a, String b)) {} | 2484 useFunction(int g(double a, String b)) {} |
| 2482 '''); | 2485 '''); |
| 2483 } | 2486 } |
| 2484 | 2487 |
| 2485 void test_creationFunction_forFunctionType_method_targetClass() { | 2488 test_creationFunction_forFunctionType_method_targetClass() async { |
| 2486 resolveTestUnit(''' | 2489 resolveTestUnit(''' |
| 2487 main(A a) { | 2490 main(A a) { |
| 2488 useFunction(a.test); | 2491 useFunction(a.test); |
| 2489 } | 2492 } |
| 2490 class A { | 2493 class A { |
| 2491 } | 2494 } |
| 2492 useFunction(int g(double a, String b)) {} | 2495 useFunction(int g(double a, String b)) {} |
| 2493 '''); | 2496 '''); |
| 2494 assertHasFix( | 2497 await assertHasFix( |
| 2495 DartFixKind.CREATE_METHOD, | 2498 DartFixKind.CREATE_METHOD, |
| 2496 ''' | 2499 ''' |
| 2497 main(A a) { | 2500 main(A a) { |
| 2498 useFunction(a.test); | 2501 useFunction(a.test); |
| 2499 } | 2502 } |
| 2500 class A { | 2503 class A { |
| 2501 int test(double a, String b) { | 2504 int test(double a, String b) { |
| 2502 } | 2505 } |
| 2503 } | 2506 } |
| 2504 useFunction(int g(double a, String b)) {} | 2507 useFunction(int g(double a, String b)) {} |
| 2505 '''); | 2508 '''); |
| 2506 } | 2509 } |
| 2507 | 2510 |
| 2508 void test_creationFunction_forFunctionType_method_targetClass_hasOtherMember()
{ | 2511 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() asyn
c { |
| 2509 resolveTestUnit(''' | 2512 resolveTestUnit(''' |
| 2510 main(A a) { | 2513 main(A a) { |
| 2511 useFunction(a.test); | 2514 useFunction(a.test); |
| 2512 } | 2515 } |
| 2513 class A { | 2516 class A { |
| 2514 m() {} | 2517 m() {} |
| 2515 } | 2518 } |
| 2516 useFunction(int g(double a, String b)) {} | 2519 useFunction(int g(double a, String b)) {} |
| 2517 '''); | 2520 '''); |
| 2518 assertHasFix( | 2521 await assertHasFix( |
| 2519 DartFixKind.CREATE_METHOD, | 2522 DartFixKind.CREATE_METHOD, |
| 2520 ''' | 2523 ''' |
| 2521 main(A a) { | 2524 main(A a) { |
| 2522 useFunction(a.test); | 2525 useFunction(a.test); |
| 2523 } | 2526 } |
| 2524 class A { | 2527 class A { |
| 2525 m() {} | 2528 m() {} |
| 2526 | 2529 |
| 2527 int test(double a, String b) { | 2530 int test(double a, String b) { |
| 2528 } | 2531 } |
| 2529 } | 2532 } |
| 2530 useFunction(int g(double a, String b)) {} | 2533 useFunction(int g(double a, String b)) {} |
| 2531 '''); | 2534 '''); |
| 2532 } | 2535 } |
| 2533 | 2536 |
| 2534 void test_creationFunction_forFunctionType_notFunctionType() { | 2537 test_creationFunction_forFunctionType_notFunctionType() async { |
| 2535 resolveTestUnit(''' | 2538 resolveTestUnit(''' |
| 2536 main(A a) { | 2539 main(A a) { |
| 2537 useFunction(a.test); | 2540 useFunction(a.test); |
| 2538 } | 2541 } |
| 2539 typedef A(); | 2542 typedef A(); |
| 2540 useFunction(g) {} | 2543 useFunction(g) {} |
| 2541 '''); | 2544 '''); |
| 2542 assertNoFix(DartFixKind.CREATE_METHOD); | 2545 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 2543 assertNoFix(DartFixKind.CREATE_FUNCTION); | 2546 await assertNoFix(DartFixKind.CREATE_FUNCTION); |
| 2544 } | 2547 } |
| 2545 | 2548 |
| 2546 void test_creationFunction_forFunctionType_unknownTarget() { | 2549 test_creationFunction_forFunctionType_unknownTarget() async { |
| 2547 resolveTestUnit(''' | 2550 resolveTestUnit(''' |
| 2548 main(A a) { | 2551 main(A a) { |
| 2549 useFunction(a.test); | 2552 useFunction(a.test); |
| 2550 } | 2553 } |
| 2551 class A { | 2554 class A { |
| 2552 } | 2555 } |
| 2553 useFunction(g) {} | 2556 useFunction(g) {} |
| 2554 '''); | 2557 '''); |
| 2555 assertNoFix(DartFixKind.CREATE_METHOD); | 2558 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 2556 } | 2559 } |
| 2557 | 2560 |
| 2558 void test_expectedToken_semicolon() { | 2561 test_expectedToken_semicolon() async { |
| 2559 resolveTestUnit(''' | 2562 resolveTestUnit(''' |
| 2560 main() { | 2563 main() { |
| 2561 print(0) | 2564 print(0) |
| 2562 } | 2565 } |
| 2563 '''); | 2566 '''); |
| 2564 assertHasFix( | 2567 await assertHasFix( |
| 2565 DartFixKind.INSERT_SEMICOLON, | 2568 DartFixKind.INSERT_SEMICOLON, |
| 2566 ''' | 2569 ''' |
| 2567 main() { | 2570 main() { |
| 2568 print(0); | 2571 print(0); |
| 2569 } | 2572 } |
| 2570 '''); | 2573 '''); |
| 2571 } | 2574 } |
| 2572 | 2575 |
| 2573 void test_illegalAsyncReturnType_asyncLibrary_import() { | 2576 test_illegalAsyncReturnType_asyncLibrary_import() async { |
| 2574 errorFilter = (AnalysisError error) { | 2577 errorFilter = (AnalysisError error) { |
| 2575 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 2578 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 2576 }; | 2579 }; |
| 2577 resolveTestUnit(''' | 2580 resolveTestUnit(''' |
| 2578 library main; | 2581 library main; |
| 2579 int main() async { | 2582 int main() async { |
| 2580 } | 2583 } |
| 2581 '''); | 2584 '''); |
| 2582 assertHasFix( | 2585 await assertHasFix( |
| 2583 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 2586 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 2584 ''' | 2587 ''' |
| 2585 library main; | 2588 library main; |
| 2586 import 'dart:async'; | 2589 import 'dart:async'; |
| 2587 Future<int> main() async { | 2590 Future<int> main() async { |
| 2588 } | 2591 } |
| 2589 '''); | 2592 '''); |
| 2590 } | 2593 } |
| 2591 | 2594 |
| 2592 void test_illegalAsyncReturnType_asyncLibrary_usePrefix() { | 2595 test_illegalAsyncReturnType_asyncLibrary_usePrefix() async { |
| 2593 errorFilter = (AnalysisError error) { | 2596 errorFilter = (AnalysisError error) { |
| 2594 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 2597 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 2595 }; | 2598 }; |
| 2596 resolveTestUnit(''' | 2599 resolveTestUnit(''' |
| 2597 import 'dart:async' as al; | 2600 import 'dart:async' as al; |
| 2598 int main() async { | 2601 int main() async { |
| 2599 } | 2602 } |
| 2600 '''); | 2603 '''); |
| 2601 assertHasFix( | 2604 await assertHasFix( |
| 2602 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 2605 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 2603 ''' | 2606 ''' |
| 2604 import 'dart:async' as al; | 2607 import 'dart:async' as al; |
| 2605 al.Future<int> main() async { | 2608 al.Future<int> main() async { |
| 2606 } | 2609 } |
| 2607 '''); | 2610 '''); |
| 2608 } | 2611 } |
| 2609 | 2612 |
| 2610 void test_illegalAsyncReturnType_complexTypeName() { | 2613 test_illegalAsyncReturnType_complexTypeName() async { |
| 2611 errorFilter = (AnalysisError error) { | 2614 errorFilter = (AnalysisError error) { |
| 2612 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 2615 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 2613 }; | 2616 }; |
| 2614 resolveTestUnit(''' | 2617 resolveTestUnit(''' |
| 2615 import 'dart:async'; | 2618 import 'dart:async'; |
| 2616 List<int> main() async { | 2619 List<int> main() async { |
| 2617 } | 2620 } |
| 2618 '''); | 2621 '''); |
| 2619 assertHasFix( | 2622 await assertHasFix( |
| 2620 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 2623 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 2621 ''' | 2624 ''' |
| 2622 import 'dart:async'; | 2625 import 'dart:async'; |
| 2623 Future<List<int>> main() async { | 2626 Future<List<int>> main() async { |
| 2624 } | 2627 } |
| 2625 '''); | 2628 '''); |
| 2626 } | 2629 } |
| 2627 | 2630 |
| 2628 void test_illegalAsyncReturnType_void() { | 2631 test_illegalAsyncReturnType_void() async { |
| 2629 errorFilter = (AnalysisError error) { | 2632 errorFilter = (AnalysisError error) { |
| 2630 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; | 2633 return error.errorCode == StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE; |
| 2631 }; | 2634 }; |
| 2632 resolveTestUnit(''' | 2635 resolveTestUnit(''' |
| 2633 import 'dart:async'; | 2636 import 'dart:async'; |
| 2634 void main() async { | 2637 void main() async { |
| 2635 } | 2638 } |
| 2636 '''); | 2639 '''); |
| 2637 assertHasFix( | 2640 await assertHasFix( |
| 2638 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, | 2641 DartFixKind.REPLACE_RETURN_TYPE_FUTURE, |
| 2639 ''' | 2642 ''' |
| 2640 import 'dart:async'; | 2643 import 'dart:async'; |
| 2641 Future main() async { | 2644 Future main() async { |
| 2642 } | 2645 } |
| 2643 '''); | 2646 '''); |
| 2644 } | 2647 } |
| 2645 | 2648 |
| 2646 void test_importLibraryPackage_withClass() { | 2649 test_importLibraryPackage_withClass() async { |
| 2647 _configureMyPkg(''' | 2650 _configureMyPkg(''' |
| 2648 library my_lib; | 2651 library my_lib; |
| 2649 class Test {} | 2652 class Test {} |
| 2650 '''); | 2653 '''); |
| 2651 // try to find a fix | 2654 // try to find a fix |
| 2652 resolveTestUnit(''' | 2655 resolveTestUnit(''' |
| 2653 main() { | 2656 main() { |
| 2654 Test test = null; | 2657 Test test = null; |
| 2655 } | 2658 } |
| 2656 '''); | 2659 '''); |
| 2657 performAllAnalysisTasks(); | 2660 performAllAnalysisTasks(); |
| 2658 assertHasFix( | 2661 await assertHasFix( |
| 2659 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2662 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2660 ''' | 2663 ''' |
| 2661 import 'package:my_pkg/my_lib.dart'; | 2664 import 'package:my_pkg/my_lib.dart'; |
| 2662 | 2665 |
| 2663 main() { | 2666 main() { |
| 2664 Test test = null; | 2667 Test test = null; |
| 2665 } | 2668 } |
| 2666 '''); | 2669 '''); |
| 2667 } | 2670 } |
| 2668 | 2671 |
| 2669 void test_importLibraryProject_withClass_annotation() { | 2672 test_importLibraryProject_withClass_annotation() async { |
| 2670 addSource( | 2673 addSource( |
| 2671 '/lib.dart', | 2674 '/lib.dart', |
| 2672 ''' | 2675 ''' |
| 2673 library lib; | 2676 library lib; |
| 2674 class Test { | 2677 class Test { |
| 2675 const Test(int p); | 2678 const Test(int p); |
| 2676 } | 2679 } |
| 2677 '''); | 2680 '''); |
| 2678 resolveTestUnit(''' | 2681 resolveTestUnit(''' |
| 2679 @Test(0) | 2682 @Test(0) |
| 2680 main() { | 2683 main() { |
| 2681 } | 2684 } |
| 2682 '''); | 2685 '''); |
| 2683 performAllAnalysisTasks(); | 2686 performAllAnalysisTasks(); |
| 2684 assertHasFix( | 2687 await assertHasFix( |
| 2685 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2688 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2686 ''' | 2689 ''' |
| 2687 import 'lib.dart'; | 2690 import 'lib.dart'; |
| 2688 | 2691 |
| 2689 @Test(0) | 2692 @Test(0) |
| 2690 main() { | 2693 main() { |
| 2691 } | 2694 } |
| 2692 '''); | 2695 '''); |
| 2693 } | 2696 } |
| 2694 | 2697 |
| 2695 void test_importLibraryProject_withClass_hasOtherLibraryWithPrefix() { | 2698 test_importLibraryProject_withClass_hasOtherLibraryWithPrefix() async { |
| 2696 testFile = '/project/bin/test.dart'; | 2699 testFile = '/project/bin/test.dart'; |
| 2697 addSource( | 2700 addSource( |
| 2698 '/project/bin/a.dart', | 2701 '/project/bin/a.dart', |
| 2699 ''' | 2702 ''' |
| 2700 library a; | 2703 library a; |
| 2701 class One {} | 2704 class One {} |
| 2702 '''); | 2705 '''); |
| 2703 addSource( | 2706 addSource( |
| 2704 '/project/bin/b.dart', | 2707 '/project/bin/b.dart', |
| 2705 ''' | 2708 ''' |
| 2706 library b; | 2709 library b; |
| 2707 class One {} | 2710 class One {} |
| 2708 class Two {} | 2711 class Two {} |
| 2709 '''); | 2712 '''); |
| 2710 resolveTestUnit(''' | 2713 resolveTestUnit(''' |
| 2711 import 'b.dart' show Two; | 2714 import 'b.dart' show Two; |
| 2712 main () { | 2715 main () { |
| 2713 new Two(); | 2716 new Two(); |
| 2714 new One(); | 2717 new One(); |
| 2715 } | 2718 } |
| 2716 '''); | 2719 '''); |
| 2717 performAllAnalysisTasks(); | 2720 performAllAnalysisTasks(); |
| 2718 assertHasFix( | 2721 await assertHasFix( |
| 2719 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2722 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2720 ''' | 2723 ''' |
| 2721 import 'b.dart' show Two; | 2724 import 'b.dart' show Two; |
| 2722 import 'a.dart'; | 2725 import 'a.dart'; |
| 2723 main () { | 2726 main () { |
| 2724 new Two(); | 2727 new Two(); |
| 2725 new One(); | 2728 new One(); |
| 2726 } | 2729 } |
| 2727 '''); | 2730 '''); |
| 2728 } | 2731 } |
| 2729 | 2732 |
| 2730 void test_importLibraryProject_withClass_inParentFolder() { | 2733 test_importLibraryProject_withClass_inParentFolder() async { |
| 2731 testFile = '/project/bin/test.dart'; | 2734 testFile = '/project/bin/test.dart'; |
| 2732 addSource( | 2735 addSource( |
| 2733 '/project/lib.dart', | 2736 '/project/lib.dart', |
| 2734 ''' | 2737 ''' |
| 2735 library lib; | 2738 library lib; |
| 2736 class Test {} | 2739 class Test {} |
| 2737 '''); | 2740 '''); |
| 2738 resolveTestUnit(''' | 2741 resolveTestUnit(''' |
| 2739 main() { | 2742 main() { |
| 2740 Test t = null; | 2743 Test t = null; |
| 2741 } | 2744 } |
| 2742 '''); | 2745 '''); |
| 2743 performAllAnalysisTasks(); | 2746 performAllAnalysisTasks(); |
| 2744 assertHasFix( | 2747 await assertHasFix( |
| 2745 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2748 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2746 ''' | 2749 ''' |
| 2747 import '../lib.dart'; | 2750 import '../lib.dart'; |
| 2748 | 2751 |
| 2749 main() { | 2752 main() { |
| 2750 Test t = null; | 2753 Test t = null; |
| 2751 } | 2754 } |
| 2752 '''); | 2755 '''); |
| 2753 } | 2756 } |
| 2754 | 2757 |
| 2755 void test_importLibraryProject_withClass_inRelativeFolder() { | 2758 test_importLibraryProject_withClass_inRelativeFolder() async { |
| 2756 testFile = '/project/bin/test.dart'; | 2759 testFile = '/project/bin/test.dart'; |
| 2757 addSource( | 2760 addSource( |
| 2758 '/project/lib/sub/folder/lib.dart', | 2761 '/project/lib/sub/folder/lib.dart', |
| 2759 ''' | 2762 ''' |
| 2760 library lib; | 2763 library lib; |
| 2761 class Test {} | 2764 class Test {} |
| 2762 '''); | 2765 '''); |
| 2763 resolveTestUnit(''' | 2766 resolveTestUnit(''' |
| 2764 main() { | 2767 main() { |
| 2765 Test t = null; | 2768 Test t = null; |
| 2766 } | 2769 } |
| 2767 '''); | 2770 '''); |
| 2768 performAllAnalysisTasks(); | 2771 performAllAnalysisTasks(); |
| 2769 assertHasFix( | 2772 await assertHasFix( |
| 2770 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2773 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2771 ''' | 2774 ''' |
| 2772 import '../lib/sub/folder/lib.dart'; | 2775 import '../lib/sub/folder/lib.dart'; |
| 2773 | 2776 |
| 2774 main() { | 2777 main() { |
| 2775 Test t = null; | 2778 Test t = null; |
| 2776 } | 2779 } |
| 2777 '''); | 2780 '''); |
| 2778 } | 2781 } |
| 2779 | 2782 |
| 2780 void test_importLibraryProject_withClass_inSameFolder() { | 2783 test_importLibraryProject_withClass_inSameFolder() async { |
| 2781 testFile = '/project/bin/test.dart'; | 2784 testFile = '/project/bin/test.dart'; |
| 2782 addSource( | 2785 addSource( |
| 2783 '/project/bin/lib.dart', | 2786 '/project/bin/lib.dart', |
| 2784 ''' | 2787 ''' |
| 2785 library lib; | 2788 library lib; |
| 2786 class Test {} | 2789 class Test {} |
| 2787 '''); | 2790 '''); |
| 2788 resolveTestUnit(''' | 2791 resolveTestUnit(''' |
| 2789 main() { | 2792 main() { |
| 2790 Test t = null; | 2793 Test t = null; |
| 2791 } | 2794 } |
| 2792 '''); | 2795 '''); |
| 2793 performAllAnalysisTasks(); | 2796 performAllAnalysisTasks(); |
| 2794 assertHasFix( | 2797 await assertHasFix( |
| 2795 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2798 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2796 ''' | 2799 ''' |
| 2797 import 'lib.dart'; | 2800 import 'lib.dart'; |
| 2798 | 2801 |
| 2799 main() { | 2802 main() { |
| 2800 Test t = null; | 2803 Test t = null; |
| 2801 } | 2804 } |
| 2802 '''); | 2805 '''); |
| 2803 } | 2806 } |
| 2804 | 2807 |
| 2805 void test_importLibraryProject_withFunction() { | 2808 test_importLibraryProject_withFunction() async { |
| 2806 addSource( | 2809 addSource( |
| 2807 '/lib.dart', | 2810 '/lib.dart', |
| 2808 ''' | 2811 ''' |
| 2809 library lib; | 2812 library lib; |
| 2810 myFunction() {} | 2813 myFunction() {} |
| 2811 '''); | 2814 '''); |
| 2812 resolveTestUnit(''' | 2815 resolveTestUnit(''' |
| 2813 main() { | 2816 main() { |
| 2814 myFunction(); | 2817 myFunction(); |
| 2815 } | 2818 } |
| 2816 '''); | 2819 '''); |
| 2817 performAllAnalysisTasks(); | 2820 performAllAnalysisTasks(); |
| 2818 assertHasFix( | 2821 await assertHasFix( |
| 2819 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2822 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2820 ''' | 2823 ''' |
| 2821 import 'lib.dart'; | 2824 import 'lib.dart'; |
| 2822 | 2825 |
| 2823 main() { | 2826 main() { |
| 2824 myFunction(); | 2827 myFunction(); |
| 2825 } | 2828 } |
| 2826 '''); | 2829 '''); |
| 2827 } | 2830 } |
| 2828 | 2831 |
| 2829 void test_importLibraryProject_withFunction_unresolvedMethod() { | 2832 test_importLibraryProject_withFunction_unresolvedMethod() async { |
| 2830 addSource( | 2833 addSource( |
| 2831 '/lib.dart', | 2834 '/lib.dart', |
| 2832 ''' | 2835 ''' |
| 2833 library lib; | 2836 library lib; |
| 2834 myFunction() {} | 2837 myFunction() {} |
| 2835 '''); | 2838 '''); |
| 2836 resolveTestUnit(''' | 2839 resolveTestUnit(''' |
| 2837 class A { | 2840 class A { |
| 2838 main() { | 2841 main() { |
| 2839 myFunction(); | 2842 myFunction(); |
| 2840 } | 2843 } |
| 2841 } | 2844 } |
| 2842 '''); | 2845 '''); |
| 2843 performAllAnalysisTasks(); | 2846 performAllAnalysisTasks(); |
| 2844 assertHasFix( | 2847 await assertHasFix( |
| 2845 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2848 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2846 ''' | 2849 ''' |
| 2847 import 'lib.dart'; | 2850 import 'lib.dart'; |
| 2848 | 2851 |
| 2849 class A { | 2852 class A { |
| 2850 main() { | 2853 main() { |
| 2851 myFunction(); | 2854 myFunction(); |
| 2852 } | 2855 } |
| 2853 } | 2856 } |
| 2854 '''); | 2857 '''); |
| 2855 } | 2858 } |
| 2856 | 2859 |
| 2857 void test_importLibraryProject_withFunctionTypeAlias() { | 2860 test_importLibraryProject_withFunctionTypeAlias() async { |
| 2858 testFile = '/project/bin/test.dart'; | 2861 testFile = '/project/bin/test.dart'; |
| 2859 addSource( | 2862 addSource( |
| 2860 '/project/bin/lib.dart', | 2863 '/project/bin/lib.dart', |
| 2861 ''' | 2864 ''' |
| 2862 library lib; | 2865 library lib; |
| 2863 typedef MyFunction(); | 2866 typedef MyFunction(); |
| 2864 '''); | 2867 '''); |
| 2865 resolveTestUnit(''' | 2868 resolveTestUnit(''' |
| 2866 main() { | 2869 main() { |
| 2867 MyFunction t = null; | 2870 MyFunction t = null; |
| 2868 } | 2871 } |
| 2869 '''); | 2872 '''); |
| 2870 performAllAnalysisTasks(); | 2873 performAllAnalysisTasks(); |
| 2871 assertHasFix( | 2874 await assertHasFix( |
| 2872 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2875 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2873 ''' | 2876 ''' |
| 2874 import 'lib.dart'; | 2877 import 'lib.dart'; |
| 2875 | 2878 |
| 2876 main() { | 2879 main() { |
| 2877 MyFunction t = null; | 2880 MyFunction t = null; |
| 2878 } | 2881 } |
| 2879 '''); | 2882 '''); |
| 2880 } | 2883 } |
| 2881 | 2884 |
| 2882 void test_importLibraryProject_withTopLevelVariable() { | 2885 test_importLibraryProject_withTopLevelVariable() async { |
| 2883 addSource( | 2886 addSource( |
| 2884 '/lib.dart', | 2887 '/lib.dart', |
| 2885 ''' | 2888 ''' |
| 2886 library lib; | 2889 library lib; |
| 2887 int MY_VAR = 42; | 2890 int MY_VAR = 42; |
| 2888 '''); | 2891 '''); |
| 2889 resolveTestUnit(''' | 2892 resolveTestUnit(''' |
| 2890 main() { | 2893 main() { |
| 2891 print(MY_VAR); | 2894 print(MY_VAR); |
| 2892 } | 2895 } |
| 2893 '''); | 2896 '''); |
| 2894 performAllAnalysisTasks(); | 2897 performAllAnalysisTasks(); |
| 2895 assertHasFix( | 2898 await assertHasFix( |
| 2896 DartFixKind.IMPORT_LIBRARY_PROJECT, | 2899 DartFixKind.IMPORT_LIBRARY_PROJECT, |
| 2897 ''' | 2900 ''' |
| 2898 import 'lib.dart'; | 2901 import 'lib.dart'; |
| 2899 | 2902 |
| 2900 main() { | 2903 main() { |
| 2901 print(MY_VAR); | 2904 print(MY_VAR); |
| 2902 } | 2905 } |
| 2903 '''); | 2906 '''); |
| 2904 } | 2907 } |
| 2905 | 2908 |
| 2906 void test_importLibrarySdk_withClass_AsExpression() { | 2909 test_importLibrarySdk_withClass_AsExpression() async { |
| 2907 resolveTestUnit(''' | 2910 resolveTestUnit(''' |
| 2908 main(p) { | 2911 main(p) { |
| 2909 p as Future; | 2912 p as Future; |
| 2910 } | 2913 } |
| 2911 '''); | 2914 '''); |
| 2912 assertHasFix( | 2915 await assertHasFix( |
| 2913 DartFixKind.IMPORT_LIBRARY_SDK, | 2916 DartFixKind.IMPORT_LIBRARY_SDK, |
| 2914 ''' | 2917 ''' |
| 2915 import 'dart:async'; | 2918 import 'dart:async'; |
| 2916 | 2919 |
| 2917 main(p) { | 2920 main(p) { |
| 2918 p as Future; | 2921 p as Future; |
| 2919 } | 2922 } |
| 2920 '''); | 2923 '''); |
| 2921 } | 2924 } |
| 2922 | 2925 |
| 2923 void test_importLibrarySdk_withClass_invocationTarget() { | 2926 test_importLibrarySdk_withClass_invocationTarget() async { |
| 2924 resolveTestUnit(''' | 2927 resolveTestUnit(''' |
| 2925 main() { | 2928 main() { |
| 2926 Future.wait(null); | 2929 Future.wait(null); |
| 2927 } | 2930 } |
| 2928 '''); | 2931 '''); |
| 2929 assertHasFix( | 2932 await assertHasFix( |
| 2930 DartFixKind.IMPORT_LIBRARY_SDK, | 2933 DartFixKind.IMPORT_LIBRARY_SDK, |
| 2931 ''' | 2934 ''' |
| 2932 import 'dart:async'; | 2935 import 'dart:async'; |
| 2933 | 2936 |
| 2934 main() { | 2937 main() { |
| 2935 Future.wait(null); | 2938 Future.wait(null); |
| 2936 } | 2939 } |
| 2937 '''); | 2940 '''); |
| 2938 } | 2941 } |
| 2939 | 2942 |
| 2940 void test_importLibrarySdk_withClass_IsExpression() { | 2943 test_importLibrarySdk_withClass_IsExpression() async { |
| 2941 resolveTestUnit(''' | 2944 resolveTestUnit(''' |
| 2942 main(p) { | 2945 main(p) { |
| 2943 p is Future; | 2946 p is Future; |
| 2944 } | 2947 } |
| 2945 '''); | 2948 '''); |
| 2946 assertHasFix( | 2949 await assertHasFix( |
| 2947 DartFixKind.IMPORT_LIBRARY_SDK, | 2950 DartFixKind.IMPORT_LIBRARY_SDK, |
| 2948 ''' | 2951 ''' |
| 2949 import 'dart:async'; | 2952 import 'dart:async'; |
| 2950 | 2953 |
| 2951 main(p) { | 2954 main(p) { |
| 2952 p is Future; | 2955 p is Future; |
| 2953 } | 2956 } |
| 2954 '''); | 2957 '''); |
| 2955 } | 2958 } |
| 2956 | 2959 |
| 2957 void test_importLibrarySdk_withClass_itemOfList() { | 2960 test_importLibrarySdk_withClass_itemOfList() async { |
| 2958 resolveTestUnit(''' | 2961 resolveTestUnit(''' |
| 2959 main() { | 2962 main() { |
| 2960 var a = [Future]; | 2963 var a = [Future]; |
| 2961 } | 2964 } |
| 2962 '''); | 2965 '''); |
| 2963 performAllAnalysisTasks(); | 2966 performAllAnalysisTasks(); |
| 2964 assertHasFix( | 2967 await assertHasFix( |
| 2965 DartFixKind.IMPORT_LIBRARY_SDK, | 2968 DartFixKind.IMPORT_LIBRARY_SDK, |
| 2966 ''' | 2969 ''' |
| 2967 import 'dart:async'; | 2970 import 'dart:async'; |
| 2968 | 2971 |
| 2969 main() { | 2972 main() { |
| 2970 var a = [Future]; | 2973 var a = [Future]; |
| 2971 } | 2974 } |
| 2972 '''); | 2975 '''); |
| 2973 } | 2976 } |
| 2974 | 2977 |
| 2975 void test_importLibrarySdk_withClass_itemOfList_inAnnotation() { | 2978 test_importLibrarySdk_withClass_itemOfList_inAnnotation() async { |
| 2976 errorFilter = (AnalysisError error) { | 2979 errorFilter = (AnalysisError error) { |
| 2977 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; | 2980 return error.errorCode == StaticWarningCode.UNDEFINED_IDENTIFIER; |
| 2978 }; | 2981 }; |
| 2979 resolveTestUnit(''' | 2982 resolveTestUnit(''' |
| 2980 class MyAnnotation { | 2983 class MyAnnotation { |
| 2981 const MyAnnotation(a, b); | 2984 const MyAnnotation(a, b); |
| 2982 } | 2985 } |
| 2983 @MyAnnotation(int, const [Future]) | 2986 @MyAnnotation(int, const [Future]) |
| 2984 main() {} | 2987 main() {} |
| 2985 '''); | 2988 '''); |
| 2986 assertHasFix( | 2989 await assertHasFix( |
| 2987 DartFixKind.IMPORT_LIBRARY_SDK, | 2990 DartFixKind.IMPORT_LIBRARY_SDK, |
| 2988 ''' | 2991 ''' |
| 2989 import 'dart:async'; | 2992 import 'dart:async'; |
| 2990 | 2993 |
| 2991 class MyAnnotation { | 2994 class MyAnnotation { |
| 2992 const MyAnnotation(a, b); | 2995 const MyAnnotation(a, b); |
| 2993 } | 2996 } |
| 2994 @MyAnnotation(int, const [Future]) | 2997 @MyAnnotation(int, const [Future]) |
| 2995 main() {} | 2998 main() {} |
| 2996 '''); | 2999 '''); |
| 2997 } | 3000 } |
| 2998 | 3001 |
| 2999 void test_importLibrarySdk_withClass_typeAnnotation() { | 3002 test_importLibrarySdk_withClass_typeAnnotation() async { |
| 3000 resolveTestUnit(''' | 3003 resolveTestUnit(''' |
| 3001 main() { | 3004 main() { |
| 3002 Future f = null; | 3005 Future f = null; |
| 3003 } | 3006 } |
| 3004 '''); | 3007 '''); |
| 3005 assertHasFix( | 3008 await assertHasFix( |
| 3006 DartFixKind.IMPORT_LIBRARY_SDK, | 3009 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3007 ''' | 3010 ''' |
| 3008 import 'dart:async'; | 3011 import 'dart:async'; |
| 3009 | 3012 |
| 3010 main() { | 3013 main() { |
| 3011 Future f = null; | 3014 Future f = null; |
| 3012 } | 3015 } |
| 3013 '''); | 3016 '''); |
| 3014 } | 3017 } |
| 3015 | 3018 |
| 3016 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() { | 3019 test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() async { |
| 3017 resolveTestUnit(''' | 3020 resolveTestUnit(''' |
| 3018 main() { | 3021 main() { |
| 3019 Future.wait; | 3022 Future.wait; |
| 3020 } | 3023 } |
| 3021 '''); | 3024 '''); |
| 3022 assertHasFix( | 3025 await assertHasFix( |
| 3023 DartFixKind.IMPORT_LIBRARY_SDK, | 3026 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3024 ''' | 3027 ''' |
| 3025 import 'dart:async'; | 3028 import 'dart:async'; |
| 3026 | 3029 |
| 3027 main() { | 3030 main() { |
| 3028 Future.wait; | 3031 Future.wait; |
| 3029 } | 3032 } |
| 3030 '''); | 3033 '''); |
| 3031 } | 3034 } |
| 3032 | 3035 |
| 3033 void test_importLibrarySdk_withClass_typeArgument() { | 3036 test_importLibrarySdk_withClass_typeArgument() async { |
| 3034 resolveTestUnit(''' | 3037 resolveTestUnit(''' |
| 3035 main() { | 3038 main() { |
| 3036 List<Future> futures = []; | 3039 List<Future> futures = []; |
| 3037 } | 3040 } |
| 3038 '''); | 3041 '''); |
| 3039 assertHasFix( | 3042 await assertHasFix( |
| 3040 DartFixKind.IMPORT_LIBRARY_SDK, | 3043 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3041 ''' | 3044 ''' |
| 3042 import 'dart:async'; | 3045 import 'dart:async'; |
| 3043 | 3046 |
| 3044 main() { | 3047 main() { |
| 3045 List<Future> futures = []; | 3048 List<Future> futures = []; |
| 3046 } | 3049 } |
| 3047 '''); | 3050 '''); |
| 3048 } | 3051 } |
| 3049 | 3052 |
| 3050 void test_importLibrarySdk_withTopLevelVariable() { | 3053 test_importLibrarySdk_withTopLevelVariable() async { |
| 3051 resolveTestUnit(''' | 3054 resolveTestUnit(''' |
| 3052 main() { | 3055 main() { |
| 3053 print(PI); | 3056 print(PI); |
| 3054 } | 3057 } |
| 3055 '''); | 3058 '''); |
| 3056 performAllAnalysisTasks(); | 3059 performAllAnalysisTasks(); |
| 3057 assertHasFix( | 3060 await assertHasFix( |
| 3058 DartFixKind.IMPORT_LIBRARY_SDK, | 3061 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3059 ''' | 3062 ''' |
| 3060 import 'dart:math'; | 3063 import 'dart:math'; |
| 3061 | 3064 |
| 3062 main() { | 3065 main() { |
| 3063 print(PI); | 3066 print(PI); |
| 3064 } | 3067 } |
| 3065 '''); | 3068 '''); |
| 3066 } | 3069 } |
| 3067 | 3070 |
| 3068 void test_importLibrarySdk_withTopLevelVariable_annotation() { | 3071 test_importLibrarySdk_withTopLevelVariable_annotation() async { |
| 3069 resolveTestUnit(''' | 3072 resolveTestUnit(''' |
| 3070 @PI | 3073 @PI |
| 3071 main() { | 3074 main() { |
| 3072 } | 3075 } |
| 3073 '''); | 3076 '''); |
| 3074 performAllAnalysisTasks(); | 3077 performAllAnalysisTasks(); |
| 3075 assertHasFix( | 3078 await assertHasFix( |
| 3076 DartFixKind.IMPORT_LIBRARY_SDK, | 3079 DartFixKind.IMPORT_LIBRARY_SDK, |
| 3077 ''' | 3080 ''' |
| 3078 import 'dart:math'; | 3081 import 'dart:math'; |
| 3079 | 3082 |
| 3080 @PI | 3083 @PI |
| 3081 main() { | 3084 main() { |
| 3082 } | 3085 } |
| 3083 '''); | 3086 '''); |
| 3084 } | 3087 } |
| 3085 | 3088 |
| 3086 void test_importLibraryShow() { | 3089 test_importLibraryShow() async { |
| 3087 resolveTestUnit(''' | 3090 resolveTestUnit(''' |
| 3088 import 'dart:async' show Stream; | 3091 import 'dart:async' show Stream; |
| 3089 main() { | 3092 main() { |
| 3090 Stream s = null; | 3093 Stream s = null; |
| 3091 Future f = null; | 3094 Future f = null; |
| 3092 } | 3095 } |
| 3093 '''); | 3096 '''); |
| 3094 assertHasFix( | 3097 await assertHasFix( |
| 3095 DartFixKind.IMPORT_LIBRARY_SHOW, | 3098 DartFixKind.IMPORT_LIBRARY_SHOW, |
| 3096 ''' | 3099 ''' |
| 3097 import 'dart:async' show Future, Stream; | 3100 import 'dart:async' show Future, Stream; |
| 3098 main() { | 3101 main() { |
| 3099 Stream s = null; | 3102 Stream s = null; |
| 3100 Future f = null; | 3103 Future f = null; |
| 3101 } | 3104 } |
| 3102 '''); | 3105 '''); |
| 3103 } | 3106 } |
| 3104 | 3107 |
| 3105 void test_isNotNull() { | 3108 test_isNotNull() async { |
| 3106 resolveTestUnit(''' | 3109 resolveTestUnit(''' |
| 3107 main(p) { | 3110 main(p) { |
| 3108 p is! Null; | 3111 p is! Null; |
| 3109 } | 3112 } |
| 3110 '''); | 3113 '''); |
| 3111 assertHasFix( | 3114 await assertHasFix( |
| 3112 DartFixKind.USE_NOT_EQ_NULL, | 3115 DartFixKind.USE_NOT_EQ_NULL, |
| 3113 ''' | 3116 ''' |
| 3114 main(p) { | 3117 main(p) { |
| 3115 p != null; | 3118 p != null; |
| 3116 } | 3119 } |
| 3117 '''); | 3120 '''); |
| 3118 } | 3121 } |
| 3119 | 3122 |
| 3120 void test_isNull() { | 3123 test_isNull() async { |
| 3121 resolveTestUnit(''' | 3124 resolveTestUnit(''' |
| 3122 main(p) { | 3125 main(p) { |
| 3123 p is Null; | 3126 p is Null; |
| 3124 } | 3127 } |
| 3125 '''); | 3128 '''); |
| 3126 assertHasFix( | 3129 await assertHasFix( |
| 3127 DartFixKind.USE_EQ_EQ_NULL, | 3130 DartFixKind.USE_EQ_EQ_NULL, |
| 3128 ''' | 3131 ''' |
| 3129 main(p) { | 3132 main(p) { |
| 3130 p == null; | 3133 p == null; |
| 3131 } | 3134 } |
| 3132 '''); | 3135 '''); |
| 3133 } | 3136 } |
| 3134 | 3137 |
| 3135 void test_makeEnclosingClassAbstract_declaresAbstractMethod() { | 3138 test_makeEnclosingClassAbstract_declaresAbstractMethod() async { |
| 3136 resolveTestUnit(''' | 3139 resolveTestUnit(''' |
| 3137 class A { | 3140 class A { |
| 3138 m(); | 3141 m(); |
| 3139 } | 3142 } |
| 3140 '''); | 3143 '''); |
| 3141 assertHasFix( | 3144 await assertHasFix( |
| 3142 DartFixKind.MAKE_CLASS_ABSTRACT, | 3145 DartFixKind.MAKE_CLASS_ABSTRACT, |
| 3143 ''' | 3146 ''' |
| 3144 abstract class A { | 3147 abstract class A { |
| 3145 m(); | 3148 m(); |
| 3146 } | 3149 } |
| 3147 '''); | 3150 '''); |
| 3148 } | 3151 } |
| 3149 | 3152 |
| 3150 void test_makeEnclosingClassAbstract_inheritsAbstractMethod() { | 3153 test_makeEnclosingClassAbstract_inheritsAbstractMethod() async { |
| 3151 resolveTestUnit(''' | 3154 resolveTestUnit(''' |
| 3152 abstract class A { | 3155 abstract class A { |
| 3153 m(); | 3156 m(); |
| 3154 } | 3157 } |
| 3155 class B extends A { | 3158 class B extends A { |
| 3156 } | 3159 } |
| 3157 '''); | 3160 '''); |
| 3158 assertHasFix( | 3161 await assertHasFix( |
| 3159 DartFixKind.MAKE_CLASS_ABSTRACT, | 3162 DartFixKind.MAKE_CLASS_ABSTRACT, |
| 3160 ''' | 3163 ''' |
| 3161 abstract class A { | 3164 abstract class A { |
| 3162 m(); | 3165 m(); |
| 3163 } | 3166 } |
| 3164 abstract class B extends A { | 3167 abstract class B extends A { |
| 3165 } | 3168 } |
| 3166 '''); | 3169 '''); |
| 3167 } | 3170 } |
| 3168 | 3171 |
| 3169 void test_noException_1() { | 3172 test_noException_1() async { |
| 3170 resolveTestUnit(''' | 3173 resolveTestUnit(''' |
| 3171 main(p) { | 3174 main(p) { |
| 3172 p i s Null; | 3175 p i s Null; |
| 3173 }'''); | 3176 }'''); |
| 3174 List<AnalysisError> errors = context.computeErrors(testSource); | 3177 List<AnalysisError> errors = context.computeErrors(testSource); |
| 3175 for (var error in errors) { | 3178 for (var error in errors) { |
| 3176 _computeFixes(error); | 3179 await _computeFixes(error); |
| 3177 } | 3180 } |
| 3178 } | 3181 } |
| 3179 | 3182 |
| 3180 void test_nonBoolCondition_addNotNull() { | 3183 test_nonBoolCondition_addNotNull() async { |
| 3181 resolveTestUnit(''' | 3184 resolveTestUnit(''' |
| 3182 main(String p) { | 3185 main(String p) { |
| 3183 if (p) { | 3186 if (p) { |
| 3184 print(p); | 3187 print(p); |
| 3185 } | 3188 } |
| 3186 } | 3189 } |
| 3187 '''); | 3190 '''); |
| 3188 assertHasFix( | 3191 await assertHasFix( |
| 3189 DartFixKind.ADD_NE_NULL, | 3192 DartFixKind.ADD_NE_NULL, |
| 3190 ''' | 3193 ''' |
| 3191 main(String p) { | 3194 main(String p) { |
| 3192 if (p != null) { | 3195 if (p != null) { |
| 3193 print(p); | 3196 print(p); |
| 3194 } | 3197 } |
| 3195 } | 3198 } |
| 3196 '''); | 3199 '''); |
| 3197 } | 3200 } |
| 3198 | 3201 |
| 3199 void test_removeDeadCode_condition() { | 3202 test_removeDeadCode_condition() async { |
| 3200 resolveTestUnit(''' | 3203 resolveTestUnit(''' |
| 3201 main(int p) { | 3204 main(int p) { |
| 3202 if (true || p > 5) { | 3205 if (true || p > 5) { |
| 3203 print(1); | 3206 print(1); |
| 3204 } | 3207 } |
| 3205 } | 3208 } |
| 3206 '''); | 3209 '''); |
| 3207 assertHasFix( | 3210 await assertHasFix( |
| 3208 DartFixKind.REMOVE_DEAD_CODE, | 3211 DartFixKind.REMOVE_DEAD_CODE, |
| 3209 ''' | 3212 ''' |
| 3210 main(int p) { | 3213 main(int p) { |
| 3211 if (true) { | 3214 if (true) { |
| 3212 print(1); | 3215 print(1); |
| 3213 } | 3216 } |
| 3214 } | 3217 } |
| 3215 '''); | 3218 '''); |
| 3216 } | 3219 } |
| 3217 | 3220 |
| 3218 void test_removeDeadCode_statements_one() { | 3221 test_removeDeadCode_statements_one() async { |
| 3219 resolveTestUnit(''' | 3222 resolveTestUnit(''' |
| 3220 int main() { | 3223 int main() { |
| 3221 print(0); | 3224 print(0); |
| 3222 return 42; | 3225 return 42; |
| 3223 print(1); | 3226 print(1); |
| 3224 } | 3227 } |
| 3225 '''); | 3228 '''); |
| 3226 assertHasFix( | 3229 await assertHasFix( |
| 3227 DartFixKind.REMOVE_DEAD_CODE, | 3230 DartFixKind.REMOVE_DEAD_CODE, |
| 3228 ''' | 3231 ''' |
| 3229 int main() { | 3232 int main() { |
| 3230 print(0); | 3233 print(0); |
| 3231 return 42; | 3234 return 42; |
| 3232 } | 3235 } |
| 3233 '''); | 3236 '''); |
| 3234 } | 3237 } |
| 3235 | 3238 |
| 3236 void test_removeDeadCode_statements_two() { | 3239 test_removeDeadCode_statements_two() async { |
| 3237 resolveTestUnit(''' | 3240 resolveTestUnit(''' |
| 3238 int main() { | 3241 int main() { |
| 3239 print(0); | 3242 print(0); |
| 3240 return 42; | 3243 return 42; |
| 3241 print(1); | 3244 print(1); |
| 3242 print(2); | 3245 print(2); |
| 3243 } | 3246 } |
| 3244 '''); | 3247 '''); |
| 3245 assertHasFix( | 3248 await assertHasFix( |
| 3246 DartFixKind.REMOVE_DEAD_CODE, | 3249 DartFixKind.REMOVE_DEAD_CODE, |
| 3247 ''' | 3250 ''' |
| 3248 int main() { | 3251 int main() { |
| 3249 print(0); | 3252 print(0); |
| 3250 return 42; | 3253 return 42; |
| 3251 } | 3254 } |
| 3252 '''); | 3255 '''); |
| 3253 } | 3256 } |
| 3254 | 3257 |
| 3255 void test_removeParentheses_inGetterDeclaration() { | 3258 test_removeParentheses_inGetterDeclaration() async { |
| 3256 resolveTestUnit(''' | 3259 resolveTestUnit(''' |
| 3257 class A { | 3260 class A { |
| 3258 int get foo() => 0; | 3261 int get foo() => 0; |
| 3259 } | 3262 } |
| 3260 '''); | 3263 '''); |
| 3261 assertHasFix( | 3264 await assertHasFix( |
| 3262 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, | 3265 DartFixKind.REMOVE_PARAMETERS_IN_GETTER_DECLARATION, |
| 3263 ''' | 3266 ''' |
| 3264 class A { | 3267 class A { |
| 3265 int get foo => 0; | 3268 int get foo => 0; |
| 3266 } | 3269 } |
| 3267 '''); | 3270 '''); |
| 3268 } | 3271 } |
| 3269 | 3272 |
| 3270 void test_removeParentheses_inGetterInvocation() { | 3273 test_removeParentheses_inGetterInvocation() async { |
| 3271 resolveTestUnit(''' | 3274 resolveTestUnit(''' |
| 3272 class A { | 3275 class A { |
| 3273 int get foo => 0; | 3276 int get foo => 0; |
| 3274 } | 3277 } |
| 3275 main(A a) { | 3278 main(A a) { |
| 3276 a.foo(); | 3279 a.foo(); |
| 3277 } | 3280 } |
| 3278 '''); | 3281 '''); |
| 3279 assertHasFix( | 3282 await assertHasFix( |
| 3280 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, | 3283 DartFixKind.REMOVE_PARENTHESIS_IN_GETTER_INVOCATION, |
| 3281 ''' | 3284 ''' |
| 3282 class A { | 3285 class A { |
| 3283 int get foo => 0; | 3286 int get foo => 0; |
| 3284 } | 3287 } |
| 3285 main(A a) { | 3288 main(A a) { |
| 3286 a.foo; | 3289 a.foo; |
| 3287 } | 3290 } |
| 3288 '''); | 3291 '''); |
| 3289 } | 3292 } |
| 3290 | 3293 |
| 3291 void test_removeUnnecessaryCast_assignment() { | 3294 test_removeUnnecessaryCast_assignment() async { |
| 3292 resolveTestUnit(''' | 3295 resolveTestUnit(''' |
| 3293 main(Object p) { | 3296 main(Object p) { |
| 3294 if (p is String) { | 3297 if (p is String) { |
| 3295 String v = ((p as String)); | 3298 String v = ((p as String)); |
| 3296 } | 3299 } |
| 3297 } | 3300 } |
| 3298 '''); | 3301 '''); |
| 3299 assertHasFix( | 3302 await assertHasFix( |
| 3300 DartFixKind.REMOVE_UNNECESSARY_CAST, | 3303 DartFixKind.REMOVE_UNNECESSARY_CAST, |
| 3301 ''' | 3304 ''' |
| 3302 main(Object p) { | 3305 main(Object p) { |
| 3303 if (p is String) { | 3306 if (p is String) { |
| 3304 String v = p; | 3307 String v = p; |
| 3305 } | 3308 } |
| 3306 } | 3309 } |
| 3307 '''); | 3310 '''); |
| 3308 } | 3311 } |
| 3309 | 3312 |
| 3310 void test_removeUnusedCatchClause() { | 3313 test_removeUnusedCatchClause() async { |
| 3311 errorFilter = (AnalysisError error) => true; | 3314 errorFilter = (AnalysisError error) => true; |
| 3312 resolveTestUnit(''' | 3315 resolveTestUnit(''' |
| 3313 main() { | 3316 main() { |
| 3314 try { | 3317 try { |
| 3315 throw 42; | 3318 throw 42; |
| 3316 } on int catch (e) { | 3319 } on int catch (e) { |
| 3317 } | 3320 } |
| 3318 } | 3321 } |
| 3319 '''); | 3322 '''); |
| 3320 assertHasFix( | 3323 await assertHasFix( |
| 3321 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, | 3324 DartFixKind.REMOVE_UNUSED_CATCH_CLAUSE, |
| 3322 ''' | 3325 ''' |
| 3323 main() { | 3326 main() { |
| 3324 try { | 3327 try { |
| 3325 throw 42; | 3328 throw 42; |
| 3326 } on int { | 3329 } on int { |
| 3327 } | 3330 } |
| 3328 } | 3331 } |
| 3329 '''); | 3332 '''); |
| 3330 } | 3333 } |
| 3331 | 3334 |
| 3332 void test_removeUnusedCatchStack() { | 3335 test_removeUnusedCatchStack() async { |
| 3333 errorFilter = (AnalysisError error) => true; | 3336 errorFilter = (AnalysisError error) => true; |
| 3334 resolveTestUnit(''' | 3337 resolveTestUnit(''' |
| 3335 main() { | 3338 main() { |
| 3336 try { | 3339 try { |
| 3337 throw 42; | 3340 throw 42; |
| 3338 } catch (e, stack) { | 3341 } catch (e, stack) { |
| 3339 } | 3342 } |
| 3340 } | 3343 } |
| 3341 '''); | 3344 '''); |
| 3342 assertHasFix( | 3345 await assertHasFix( |
| 3343 DartFixKind.REMOVE_UNUSED_CATCH_STACK, | 3346 DartFixKind.REMOVE_UNUSED_CATCH_STACK, |
| 3344 ''' | 3347 ''' |
| 3345 main() { | 3348 main() { |
| 3346 try { | 3349 try { |
| 3347 throw 42; | 3350 throw 42; |
| 3348 } catch (e) { | 3351 } catch (e) { |
| 3349 } | 3352 } |
| 3350 } | 3353 } |
| 3351 '''); | 3354 '''); |
| 3352 } | 3355 } |
| 3353 | 3356 |
| 3354 void test_removeUnusedImport() { | 3357 test_removeUnusedImport() async { |
| 3355 resolveTestUnit(''' | 3358 resolveTestUnit(''' |
| 3356 import 'dart:math'; | 3359 import 'dart:math'; |
| 3357 main() { | 3360 main() { |
| 3358 } | 3361 } |
| 3359 '''); | 3362 '''); |
| 3360 assertHasFix( | 3363 await assertHasFix( |
| 3361 DartFixKind.REMOVE_UNUSED_IMPORT, | 3364 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 3362 ''' | 3365 ''' |
| 3363 main() { | 3366 main() { |
| 3364 } | 3367 } |
| 3365 '''); | 3368 '''); |
| 3366 } | 3369 } |
| 3367 | 3370 |
| 3368 void test_removeUnusedImport_anotherImportOnLine() { | 3371 test_removeUnusedImport_anotherImportOnLine() async { |
| 3369 resolveTestUnit(''' | 3372 resolveTestUnit(''' |
| 3370 import 'dart:math'; import 'dart:async'; | 3373 import 'dart:math'; import 'dart:async'; |
| 3371 | 3374 |
| 3372 main() { | 3375 main() { |
| 3373 Future f; | 3376 Future f; |
| 3374 } | 3377 } |
| 3375 '''); | 3378 '''); |
| 3376 assertHasFix( | 3379 await assertHasFix( |
| 3377 DartFixKind.REMOVE_UNUSED_IMPORT, | 3380 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 3378 ''' | 3381 ''' |
| 3379 import 'dart:async'; | 3382 import 'dart:async'; |
| 3380 | 3383 |
| 3381 main() { | 3384 main() { |
| 3382 Future f; | 3385 Future f; |
| 3383 } | 3386 } |
| 3384 '''); | 3387 '''); |
| 3385 } | 3388 } |
| 3386 | 3389 |
| 3387 void test_removeUnusedImport_severalLines() { | 3390 test_removeUnusedImport_severalLines() async { |
| 3388 resolveTestUnit(''' | 3391 resolveTestUnit(''' |
| 3389 import | 3392 import |
| 3390 'dart:math'; | 3393 'dart:math'; |
| 3391 main() { | 3394 main() { |
| 3392 } | 3395 } |
| 3393 '''); | 3396 '''); |
| 3394 assertHasFix( | 3397 await assertHasFix( |
| 3395 DartFixKind.REMOVE_UNUSED_IMPORT, | 3398 DartFixKind.REMOVE_UNUSED_IMPORT, |
| 3396 ''' | 3399 ''' |
| 3397 main() { | 3400 main() { |
| 3398 } | 3401 } |
| 3399 '''); | 3402 '''); |
| 3400 } | 3403 } |
| 3401 | 3404 |
| 3402 void test_replaceImportUri_inProject() { | 3405 test_replaceImportUri_inProject() async { |
| 3403 testFile = '/project/bin/test.dart'; | 3406 testFile = '/project/bin/test.dart'; |
| 3404 addSource('/project/foo/bar/lib.dart', ''); | 3407 addSource('/project/foo/bar/lib.dart', ''); |
| 3405 resolveTestUnit(''' | 3408 resolveTestUnit(''' |
| 3406 import 'no/matter/lib.dart'; | 3409 import 'no/matter/lib.dart'; |
| 3407 '''); | 3410 '''); |
| 3408 performAllAnalysisTasks(); | 3411 performAllAnalysisTasks(); |
| 3409 assertHasFix( | 3412 await assertHasFix( |
| 3410 DartFixKind.REPLACE_IMPORT_URI, | 3413 DartFixKind.REPLACE_IMPORT_URI, |
| 3411 ''' | 3414 ''' |
| 3412 import '../foo/bar/lib.dart'; | 3415 import '../foo/bar/lib.dart'; |
| 3413 '''); | 3416 '''); |
| 3414 } | 3417 } |
| 3415 | 3418 |
| 3416 void test_replaceImportUri_package() { | 3419 test_replaceImportUri_package() async { |
| 3417 _configureMyPkg(''); | 3420 _configureMyPkg(''); |
| 3418 resolveTestUnit(''' | 3421 resolveTestUnit(''' |
| 3419 import 'no/matter/my_lib.dart'; | 3422 import 'no/matter/my_lib.dart'; |
| 3420 '''); | 3423 '''); |
| 3421 performAllAnalysisTasks(); | 3424 performAllAnalysisTasks(); |
| 3422 assertHasFix( | 3425 await assertHasFix( |
| 3423 DartFixKind.REPLACE_IMPORT_URI, | 3426 DartFixKind.REPLACE_IMPORT_URI, |
| 3424 ''' | 3427 ''' |
| 3425 import 'package:my_pkg/my_lib.dart'; | 3428 import 'package:my_pkg/my_lib.dart'; |
| 3426 '''); | 3429 '''); |
| 3427 } | 3430 } |
| 3428 | 3431 |
| 3429 void test_replaceVarWithDynamic() { | 3432 test_replaceVarWithDynamic() async { |
| 3430 errorFilter = (AnalysisError error) { | 3433 errorFilter = (AnalysisError error) { |
| 3431 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; | 3434 return error.errorCode == ParserErrorCode.VAR_AS_TYPE_NAME; |
| 3432 }; | 3435 }; |
| 3433 resolveTestUnit(''' | 3436 resolveTestUnit(''' |
| 3434 class A { | 3437 class A { |
| 3435 Map<String, var> m; | 3438 Map<String, var> m; |
| 3436 } | 3439 } |
| 3437 '''); | 3440 '''); |
| 3438 assertHasFix( | 3441 await assertHasFix( |
| 3439 DartFixKind.REPLACE_VAR_WITH_DYNAMIC, | 3442 DartFixKind.REPLACE_VAR_WITH_DYNAMIC, |
| 3440 ''' | 3443 ''' |
| 3441 class A { | 3444 class A { |
| 3442 Map<String, dynamic> m; | 3445 Map<String, dynamic> m; |
| 3443 } | 3446 } |
| 3444 '''); | 3447 '''); |
| 3445 } | 3448 } |
| 3446 | 3449 |
| 3447 void test_replaceWithConstInstanceCreation() { | 3450 test_replaceWithConstInstanceCreation() async { |
| 3448 resolveTestUnit(''' | 3451 resolveTestUnit(''' |
| 3449 class A { | 3452 class A { |
| 3450 const A(); | 3453 const A(); |
| 3451 } | 3454 } |
| 3452 const a = new A(); | 3455 const a = new A(); |
| 3453 '''); | 3456 '''); |
| 3454 assertHasFix( | 3457 await assertHasFix( |
| 3455 DartFixKind.USE_CONST, | 3458 DartFixKind.USE_CONST, |
| 3456 ''' | 3459 ''' |
| 3457 class A { | 3460 class A { |
| 3458 const A(); | 3461 const A(); |
| 3459 } | 3462 } |
| 3460 const a = const A(); | 3463 const a = const A(); |
| 3461 '''); | 3464 '''); |
| 3462 } | 3465 } |
| 3463 | 3466 |
| 3464 void test_undefinedClass_useSimilar_fromImport() { | 3467 test_undefinedClass_useSimilar_fromImport() async { |
| 3465 resolveTestUnit(''' | 3468 resolveTestUnit(''' |
| 3466 main() { | 3469 main() { |
| 3467 Stirng s = 'abc'; | 3470 Stirng s = 'abc'; |
| 3468 } | 3471 } |
| 3469 '''); | 3472 '''); |
| 3470 assertHasFix( | 3473 await assertHasFix( |
| 3471 DartFixKind.CHANGE_TO, | 3474 DartFixKind.CHANGE_TO, |
| 3472 ''' | 3475 ''' |
| 3473 main() { | 3476 main() { |
| 3474 String s = 'abc'; | 3477 String s = 'abc'; |
| 3475 } | 3478 } |
| 3476 '''); | 3479 '''); |
| 3477 } | 3480 } |
| 3478 | 3481 |
| 3479 void test_undefinedClass_useSimilar_fromThisLibrary() { | 3482 test_undefinedClass_useSimilar_fromThisLibrary() async { |
| 3480 resolveTestUnit(''' | 3483 resolveTestUnit(''' |
| 3481 class MyClass {} | 3484 class MyClass {} |
| 3482 main() { | 3485 main() { |
| 3483 MyCalss v = null; | 3486 MyCalss v = null; |
| 3484 } | 3487 } |
| 3485 '''); | 3488 '''); |
| 3486 assertHasFix( | 3489 await assertHasFix( |
| 3487 DartFixKind.CHANGE_TO, | 3490 DartFixKind.CHANGE_TO, |
| 3488 ''' | 3491 ''' |
| 3489 class MyClass {} | 3492 class MyClass {} |
| 3490 main() { | 3493 main() { |
| 3491 MyClass v = null; | 3494 MyClass v = null; |
| 3492 } | 3495 } |
| 3493 '''); | 3496 '''); |
| 3494 } | 3497 } |
| 3495 | 3498 |
| 3496 void test_undefinedFunction_create_dynamicArgument() { | 3499 test_undefinedFunction_create_dynamicArgument() async { |
| 3497 resolveTestUnit(''' | 3500 resolveTestUnit(''' |
| 3498 main() { | 3501 main() { |
| 3499 dynamic v; | 3502 dynamic v; |
| 3500 test(v); | 3503 test(v); |
| 3501 } | 3504 } |
| 3502 '''); | 3505 '''); |
| 3503 assertHasFix( | 3506 await assertHasFix( |
| 3504 DartFixKind.CREATE_FUNCTION, | 3507 DartFixKind.CREATE_FUNCTION, |
| 3505 ''' | 3508 ''' |
| 3506 main() { | 3509 main() { |
| 3507 dynamic v; | 3510 dynamic v; |
| 3508 test(v); | 3511 test(v); |
| 3509 } | 3512 } |
| 3510 | 3513 |
| 3511 void test(v) { | 3514 void test(v) { |
| 3512 } | 3515 } |
| 3513 '''); | 3516 '''); |
| 3514 } | 3517 } |
| 3515 | 3518 |
| 3516 void test_undefinedFunction_create_dynamicReturnType() { | 3519 test_undefinedFunction_create_dynamicReturnType() async { |
| 3517 resolveTestUnit(''' | 3520 resolveTestUnit(''' |
| 3518 main() { | 3521 main() { |
| 3519 dynamic v = test(); | 3522 dynamic v = test(); |
| 3520 } | 3523 } |
| 3521 '''); | 3524 '''); |
| 3522 assertHasFix( | 3525 await assertHasFix( |
| 3523 DartFixKind.CREATE_FUNCTION, | 3526 DartFixKind.CREATE_FUNCTION, |
| 3524 ''' | 3527 ''' |
| 3525 main() { | 3528 main() { |
| 3526 dynamic v = test(); | 3529 dynamic v = test(); |
| 3527 } | 3530 } |
| 3528 | 3531 |
| 3529 test() { | 3532 test() { |
| 3530 } | 3533 } |
| 3531 '''); | 3534 '''); |
| 3532 } | 3535 } |
| 3533 | 3536 |
| 3534 void test_undefinedFunction_create_fromFunction() { | 3537 test_undefinedFunction_create_fromFunction() async { |
| 3535 resolveTestUnit(''' | 3538 resolveTestUnit(''' |
| 3536 main() { | 3539 main() { |
| 3537 int v = myUndefinedFunction(1, 2.0, '3'); | 3540 int v = myUndefinedFunction(1, 2.0, '3'); |
| 3538 } | 3541 } |
| 3539 '''); | 3542 '''); |
| 3540 assertHasFix( | 3543 await assertHasFix( |
| 3541 DartFixKind.CREATE_FUNCTION, | 3544 DartFixKind.CREATE_FUNCTION, |
| 3542 ''' | 3545 ''' |
| 3543 main() { | 3546 main() { |
| 3544 int v = myUndefinedFunction(1, 2.0, '3'); | 3547 int v = myUndefinedFunction(1, 2.0, '3'); |
| 3545 } | 3548 } |
| 3546 | 3549 |
| 3547 int myUndefinedFunction(int i, double d, String s) { | 3550 int myUndefinedFunction(int i, double d, String s) { |
| 3548 } | 3551 } |
| 3549 '''); | 3552 '''); |
| 3550 } | 3553 } |
| 3551 | 3554 |
| 3552 void test_undefinedFunction_create_fromMethod() { | 3555 test_undefinedFunction_create_fromMethod() async { |
| 3553 resolveTestUnit(''' | 3556 resolveTestUnit(''' |
| 3554 class A { | 3557 class A { |
| 3555 main() { | 3558 main() { |
| 3556 int v = myUndefinedFunction(1, 2.0, '3'); | 3559 int v = myUndefinedFunction(1, 2.0, '3'); |
| 3557 } | 3560 } |
| 3558 } | 3561 } |
| 3559 '''); | 3562 '''); |
| 3560 assertHasFix( | 3563 await assertHasFix( |
| 3561 DartFixKind.CREATE_FUNCTION, | 3564 DartFixKind.CREATE_FUNCTION, |
| 3562 ''' | 3565 ''' |
| 3563 class A { | 3566 class A { |
| 3564 main() { | 3567 main() { |
| 3565 int v = myUndefinedFunction(1, 2.0, '3'); | 3568 int v = myUndefinedFunction(1, 2.0, '3'); |
| 3566 } | 3569 } |
| 3567 } | 3570 } |
| 3568 | 3571 |
| 3569 int myUndefinedFunction(int i, double d, String s) { | 3572 int myUndefinedFunction(int i, double d, String s) { |
| 3570 } | 3573 } |
| 3571 '''); | 3574 '''); |
| 3572 } | 3575 } |
| 3573 | 3576 |
| 3574 void test_undefinedFunction_create_generic_BAD() { | 3577 test_undefinedFunction_create_generic_BAD() async { |
| 3575 resolveTestUnit(''' | 3578 resolveTestUnit(''' |
| 3576 class A<T> { | 3579 class A<T> { |
| 3577 Map<int, T> items; | 3580 Map<int, T> items; |
| 3578 main() { | 3581 main() { |
| 3579 process(items); | 3582 process(items); |
| 3580 } | 3583 } |
| 3581 } | 3584 } |
| 3582 '''); | 3585 '''); |
| 3583 assertHasFix( | 3586 await assertHasFix( |
| 3584 DartFixKind.CREATE_FUNCTION, | 3587 DartFixKind.CREATE_FUNCTION, |
| 3585 ''' | 3588 ''' |
| 3586 class A<T> { | 3589 class A<T> { |
| 3587 Map<int, T> items; | 3590 Map<int, T> items; |
| 3588 main() { | 3591 main() { |
| 3589 process(items); | 3592 process(items); |
| 3590 } | 3593 } |
| 3591 } | 3594 } |
| 3592 | 3595 |
| 3593 void process(Map items) { | 3596 void process(Map items) { |
| 3594 } | 3597 } |
| 3595 '''); | 3598 '''); |
| 3596 } | 3599 } |
| 3597 | 3600 |
| 3598 void test_undefinedFunction_create_generic_OK() { | 3601 test_undefinedFunction_create_generic_OK() async { |
| 3599 resolveTestUnit(''' | 3602 resolveTestUnit(''' |
| 3600 class A { | 3603 class A { |
| 3601 List<int> items; | 3604 List<int> items; |
| 3602 main() { | 3605 main() { |
| 3603 process(items); | 3606 process(items); |
| 3604 } | 3607 } |
| 3605 } | 3608 } |
| 3606 '''); | 3609 '''); |
| 3607 assertHasFix( | 3610 await assertHasFix( |
| 3608 DartFixKind.CREATE_FUNCTION, | 3611 DartFixKind.CREATE_FUNCTION, |
| 3609 ''' | 3612 ''' |
| 3610 class A { | 3613 class A { |
| 3611 List<int> items; | 3614 List<int> items; |
| 3612 main() { | 3615 main() { |
| 3613 process(items); | 3616 process(items); |
| 3614 } | 3617 } |
| 3615 } | 3618 } |
| 3616 | 3619 |
| 3617 void process(List<int> items) { | 3620 void process(List<int> items) { |
| 3618 } | 3621 } |
| 3619 '''); | 3622 '''); |
| 3620 } | 3623 } |
| 3621 | 3624 |
| 3622 void test_undefinedFunction_create_importType() { | 3625 test_undefinedFunction_create_importType() async { |
| 3623 addSource( | 3626 addSource( |
| 3624 '/lib.dart', | 3627 '/lib.dart', |
| 3625 r''' | 3628 r''' |
| 3626 library lib; | 3629 library lib; |
| 3627 import 'dart:async'; | 3630 import 'dart:async'; |
| 3628 Future getFuture() => null; | 3631 Future getFuture() => null; |
| 3629 '''); | 3632 '''); |
| 3630 resolveTestUnit(''' | 3633 resolveTestUnit(''' |
| 3631 import 'lib.dart'; | 3634 import 'lib.dart'; |
| 3632 main() { | 3635 main() { |
| 3633 test(getFuture()); | 3636 test(getFuture()); |
| 3634 } | 3637 } |
| 3635 '''); | 3638 '''); |
| 3636 assertHasFix( | 3639 await assertHasFix( |
| 3637 DartFixKind.CREATE_FUNCTION, | 3640 DartFixKind.CREATE_FUNCTION, |
| 3638 ''' | 3641 ''' |
| 3639 import 'lib.dart'; | 3642 import 'lib.dart'; |
| 3640 import 'dart:async'; | 3643 import 'dart:async'; |
| 3641 main() { | 3644 main() { |
| 3642 test(getFuture()); | 3645 test(getFuture()); |
| 3643 } | 3646 } |
| 3644 | 3647 |
| 3645 void test(Future future) { | 3648 void test(Future future) { |
| 3646 } | 3649 } |
| 3647 '''); | 3650 '''); |
| 3648 } | 3651 } |
| 3649 | 3652 |
| 3650 void test_undefinedFunction_create_nullArgument() { | 3653 test_undefinedFunction_create_nullArgument() async { |
| 3651 resolveTestUnit(''' | 3654 resolveTestUnit(''' |
| 3652 main() { | 3655 main() { |
| 3653 test(null); | 3656 test(null); |
| 3654 } | 3657 } |
| 3655 '''); | 3658 '''); |
| 3656 assertHasFix( | 3659 await assertHasFix( |
| 3657 DartFixKind.CREATE_FUNCTION, | 3660 DartFixKind.CREATE_FUNCTION, |
| 3658 ''' | 3661 ''' |
| 3659 main() { | 3662 main() { |
| 3660 test(null); | 3663 test(null); |
| 3661 } | 3664 } |
| 3662 | 3665 |
| 3663 void test(arg0) { | 3666 void test(arg0) { |
| 3664 } | 3667 } |
| 3665 '''); | 3668 '''); |
| 3666 } | 3669 } |
| 3667 | 3670 |
| 3668 void test_undefinedFunction_create_returnType_bool_expressions() { | 3671 test_undefinedFunction_create_returnType_bool_expressions() async { |
| 3669 assert_undefinedFunction_create_returnType_bool("!test();"); | 3672 await assert_undefinedFunction_create_returnType_bool("!test();"); |
| 3670 assert_undefinedFunction_create_returnType_bool("b && test();"); | 3673 await assert_undefinedFunction_create_returnType_bool("b && test();"); |
| 3671 assert_undefinedFunction_create_returnType_bool("test() && b;"); | 3674 await assert_undefinedFunction_create_returnType_bool("test() && b;"); |
| 3672 assert_undefinedFunction_create_returnType_bool("b || test();"); | 3675 await assert_undefinedFunction_create_returnType_bool("b || test();"); |
| 3673 assert_undefinedFunction_create_returnType_bool("test() || b;"); | 3676 await assert_undefinedFunction_create_returnType_bool("test() || b;"); |
| 3674 } | 3677 } |
| 3675 | 3678 |
| 3676 void test_undefinedFunction_create_returnType_bool_statements() { | 3679 test_undefinedFunction_create_returnType_bool_statements() async { |
| 3677 assert_undefinedFunction_create_returnType_bool("assert ( test() );"); | 3680 await assert_undefinedFunction_create_returnType_bool("assert ( test() );"); |
| 3678 assert_undefinedFunction_create_returnType_bool("if ( test() ) {}"); | 3681 await assert_undefinedFunction_create_returnType_bool("if ( test() ) {}"); |
| 3679 assert_undefinedFunction_create_returnType_bool("while ( test() ) {}"); | 3682 await assert_undefinedFunction_create_returnType_bool( |
| 3680 assert_undefinedFunction_create_returnType_bool("do {} while ( test() );"); | 3683 "while ( test() ) {}"); |
| 3684 await assert_undefinedFunction_create_returnType_bool( |
| 3685 "do {} while ( test() );"); |
| 3681 } | 3686 } |
| 3682 | 3687 |
| 3683 void test_undefinedFunction_create_returnType_fromAssignment_eq() { | 3688 test_undefinedFunction_create_returnType_fromAssignment_eq() async { |
| 3684 resolveTestUnit(''' | 3689 resolveTestUnit(''' |
| 3685 main() { | 3690 main() { |
| 3686 int v; | 3691 int v; |
| 3687 v = myUndefinedFunction(); | 3692 v = myUndefinedFunction(); |
| 3688 } | 3693 } |
| 3689 '''); | 3694 '''); |
| 3690 assertHasFix( | 3695 await assertHasFix( |
| 3691 DartFixKind.CREATE_FUNCTION, | 3696 DartFixKind.CREATE_FUNCTION, |
| 3692 ''' | 3697 ''' |
| 3693 main() { | 3698 main() { |
| 3694 int v; | 3699 int v; |
| 3695 v = myUndefinedFunction(); | 3700 v = myUndefinedFunction(); |
| 3696 } | 3701 } |
| 3697 | 3702 |
| 3698 int myUndefinedFunction() { | 3703 int myUndefinedFunction() { |
| 3699 } | 3704 } |
| 3700 '''); | 3705 '''); |
| 3701 } | 3706 } |
| 3702 | 3707 |
| 3703 void test_undefinedFunction_create_returnType_fromAssignment_plusEq() { | 3708 test_undefinedFunction_create_returnType_fromAssignment_plusEq() async { |
| 3704 resolveTestUnit(''' | 3709 resolveTestUnit(''' |
| 3705 main() { | 3710 main() { |
| 3706 int v; | 3711 int v; |
| 3707 v += myUndefinedFunction(); | 3712 v += myUndefinedFunction(); |
| 3708 } | 3713 } |
| 3709 '''); | 3714 '''); |
| 3710 assertHasFix( | 3715 await assertHasFix( |
| 3711 DartFixKind.CREATE_FUNCTION, | 3716 DartFixKind.CREATE_FUNCTION, |
| 3712 ''' | 3717 ''' |
| 3713 main() { | 3718 main() { |
| 3714 int v; | 3719 int v; |
| 3715 v += myUndefinedFunction(); | 3720 v += myUndefinedFunction(); |
| 3716 } | 3721 } |
| 3717 | 3722 |
| 3718 num myUndefinedFunction() { | 3723 num myUndefinedFunction() { |
| 3719 } | 3724 } |
| 3720 '''); | 3725 '''); |
| 3721 } | 3726 } |
| 3722 | 3727 |
| 3723 void test_undefinedFunction_create_returnType_fromBinary_right() { | 3728 test_undefinedFunction_create_returnType_fromBinary_right() async { |
| 3724 resolveTestUnit(''' | 3729 resolveTestUnit(''' |
| 3725 main() { | 3730 main() { |
| 3726 0 + myUndefinedFunction(); | 3731 0 + myUndefinedFunction(); |
| 3727 } | 3732 } |
| 3728 '''); | 3733 '''); |
| 3729 assertHasFix( | 3734 await assertHasFix( |
| 3730 DartFixKind.CREATE_FUNCTION, | 3735 DartFixKind.CREATE_FUNCTION, |
| 3731 ''' | 3736 ''' |
| 3732 main() { | 3737 main() { |
| 3733 0 + myUndefinedFunction(); | 3738 0 + myUndefinedFunction(); |
| 3734 } | 3739 } |
| 3735 | 3740 |
| 3736 num myUndefinedFunction() { | 3741 num myUndefinedFunction() { |
| 3737 } | 3742 } |
| 3738 '''); | 3743 '''); |
| 3739 } | 3744 } |
| 3740 | 3745 |
| 3741 void test_undefinedFunction_create_returnType_fromInitializer() { | 3746 test_undefinedFunction_create_returnType_fromInitializer() async { |
| 3742 resolveTestUnit(''' | 3747 resolveTestUnit(''' |
| 3743 main() { | 3748 main() { |
| 3744 int v = myUndefinedFunction(); | 3749 int v = myUndefinedFunction(); |
| 3745 } | 3750 } |
| 3746 '''); | 3751 '''); |
| 3747 assertHasFix( | 3752 await assertHasFix( |
| 3748 DartFixKind.CREATE_FUNCTION, | 3753 DartFixKind.CREATE_FUNCTION, |
| 3749 ''' | 3754 ''' |
| 3750 main() { | 3755 main() { |
| 3751 int v = myUndefinedFunction(); | 3756 int v = myUndefinedFunction(); |
| 3752 } | 3757 } |
| 3753 | 3758 |
| 3754 int myUndefinedFunction() { | 3759 int myUndefinedFunction() { |
| 3755 } | 3760 } |
| 3756 '''); | 3761 '''); |
| 3757 } | 3762 } |
| 3758 | 3763 |
| 3759 void test_undefinedFunction_create_returnType_fromInvocationArgument() { | 3764 test_undefinedFunction_create_returnType_fromInvocationArgument() async { |
| 3760 resolveTestUnit(''' | 3765 resolveTestUnit(''' |
| 3761 foo(int p) {} | 3766 foo(int p) {} |
| 3762 main() { | 3767 main() { |
| 3763 foo( myUndefinedFunction() ); | 3768 foo( myUndefinedFunction() ); |
| 3764 } | 3769 } |
| 3765 '''); | 3770 '''); |
| 3766 assertHasFix( | 3771 await assertHasFix( |
| 3767 DartFixKind.CREATE_FUNCTION, | 3772 DartFixKind.CREATE_FUNCTION, |
| 3768 ''' | 3773 ''' |
| 3769 foo(int p) {} | 3774 foo(int p) {} |
| 3770 main() { | 3775 main() { |
| 3771 foo( myUndefinedFunction() ); | 3776 foo( myUndefinedFunction() ); |
| 3772 } | 3777 } |
| 3773 | 3778 |
| 3774 int myUndefinedFunction() { | 3779 int myUndefinedFunction() { |
| 3775 } | 3780 } |
| 3776 '''); | 3781 '''); |
| 3777 } | 3782 } |
| 3778 | 3783 |
| 3779 void test_undefinedFunction_create_returnType_fromReturn() { | 3784 test_undefinedFunction_create_returnType_fromReturn() async { |
| 3780 resolveTestUnit(''' | 3785 resolveTestUnit(''' |
| 3781 int main() { | 3786 int main() { |
| 3782 return myUndefinedFunction(); | 3787 return myUndefinedFunction(); |
| 3783 } | 3788 } |
| 3784 '''); | 3789 '''); |
| 3785 assertHasFix( | 3790 await assertHasFix( |
| 3786 DartFixKind.CREATE_FUNCTION, | 3791 DartFixKind.CREATE_FUNCTION, |
| 3787 ''' | 3792 ''' |
| 3788 int main() { | 3793 int main() { |
| 3789 return myUndefinedFunction(); | 3794 return myUndefinedFunction(); |
| 3790 } | 3795 } |
| 3791 | 3796 |
| 3792 int myUndefinedFunction() { | 3797 int myUndefinedFunction() { |
| 3793 } | 3798 } |
| 3794 '''); | 3799 '''); |
| 3795 } | 3800 } |
| 3796 | 3801 |
| 3797 void test_undefinedFunction_create_returnType_void() { | 3802 test_undefinedFunction_create_returnType_void() async { |
| 3798 resolveTestUnit(''' | 3803 resolveTestUnit(''' |
| 3799 main() { | 3804 main() { |
| 3800 myUndefinedFunction(); | 3805 myUndefinedFunction(); |
| 3801 } | 3806 } |
| 3802 '''); | 3807 '''); |
| 3803 assertHasFix( | 3808 await assertHasFix( |
| 3804 DartFixKind.CREATE_FUNCTION, | 3809 DartFixKind.CREATE_FUNCTION, |
| 3805 ''' | 3810 ''' |
| 3806 main() { | 3811 main() { |
| 3807 myUndefinedFunction(); | 3812 myUndefinedFunction(); |
| 3808 } | 3813 } |
| 3809 | 3814 |
| 3810 void myUndefinedFunction() { | 3815 void myUndefinedFunction() { |
| 3811 } | 3816 } |
| 3812 '''); | 3817 '''); |
| 3813 } | 3818 } |
| 3814 | 3819 |
| 3815 void test_undefinedFunction_useSimilar_fromImport() { | 3820 test_undefinedFunction_useSimilar_fromImport() async { |
| 3816 resolveTestUnit(''' | 3821 resolveTestUnit(''' |
| 3817 main() { | 3822 main() { |
| 3818 pritn(0); | 3823 pritn(0); |
| 3819 } | 3824 } |
| 3820 '''); | 3825 '''); |
| 3821 assertHasFix( | 3826 await assertHasFix( |
| 3822 DartFixKind.CHANGE_TO, | 3827 DartFixKind.CHANGE_TO, |
| 3823 ''' | 3828 ''' |
| 3824 main() { | 3829 main() { |
| 3825 print(0); | 3830 print(0); |
| 3826 } | 3831 } |
| 3827 '''); | 3832 '''); |
| 3828 } | 3833 } |
| 3829 | 3834 |
| 3830 void test_undefinedFunction_useSimilar_thisLibrary() { | 3835 test_undefinedFunction_useSimilar_thisLibrary() async { |
| 3831 resolveTestUnit(''' | 3836 resolveTestUnit(''' |
| 3832 myFunction() {} | 3837 myFunction() {} |
| 3833 main() { | 3838 main() { |
| 3834 myFuntcion(); | 3839 myFuntcion(); |
| 3835 } | 3840 } |
| 3836 '''); | 3841 '''); |
| 3837 assertHasFix( | 3842 await assertHasFix( |
| 3838 DartFixKind.CHANGE_TO, | 3843 DartFixKind.CHANGE_TO, |
| 3839 ''' | 3844 ''' |
| 3840 myFunction() {} | 3845 myFunction() {} |
| 3841 main() { | 3846 main() { |
| 3842 myFunction(); | 3847 myFunction(); |
| 3843 } | 3848 } |
| 3844 '''); | 3849 '''); |
| 3845 } | 3850 } |
| 3846 | 3851 |
| 3847 void test_undefinedGetter_useSimilar_hint() { | 3852 test_undefinedGetter_useSimilar_hint() async { |
| 3848 resolveTestUnit(''' | 3853 resolveTestUnit(''' |
| 3849 class A { | 3854 class A { |
| 3850 int myField; | 3855 int myField; |
| 3851 } | 3856 } |
| 3852 main(A a) { | 3857 main(A a) { |
| 3853 var x = a; | 3858 var x = a; |
| 3854 print(x.myFild); | 3859 print(x.myFild); |
| 3855 } | 3860 } |
| 3856 '''); | 3861 '''); |
| 3857 assertHasFix( | 3862 await assertHasFix( |
| 3858 DartFixKind.CHANGE_TO, | 3863 DartFixKind.CHANGE_TO, |
| 3859 ''' | 3864 ''' |
| 3860 class A { | 3865 class A { |
| 3861 int myField; | 3866 int myField; |
| 3862 } | 3867 } |
| 3863 main(A a) { | 3868 main(A a) { |
| 3864 var x = a; | 3869 var x = a; |
| 3865 print(x.myField); | 3870 print(x.myField); |
| 3866 } | 3871 } |
| 3867 '''); | 3872 '''); |
| 3868 } | 3873 } |
| 3869 | 3874 |
| 3870 void test_undefinedGetter_useSimilar_qualified() { | 3875 test_undefinedGetter_useSimilar_qualified() async { |
| 3871 resolveTestUnit(''' | 3876 resolveTestUnit(''' |
| 3872 class A { | 3877 class A { |
| 3873 int myField; | 3878 int myField; |
| 3874 } | 3879 } |
| 3875 main(A a) { | 3880 main(A a) { |
| 3876 print(a.myFild); | 3881 print(a.myFild); |
| 3877 } | 3882 } |
| 3878 '''); | 3883 '''); |
| 3879 assertHasFix( | 3884 await assertHasFix( |
| 3880 DartFixKind.CHANGE_TO, | 3885 DartFixKind.CHANGE_TO, |
| 3881 ''' | 3886 ''' |
| 3882 class A { | 3887 class A { |
| 3883 int myField; | 3888 int myField; |
| 3884 } | 3889 } |
| 3885 main(A a) { | 3890 main(A a) { |
| 3886 print(a.myField); | 3891 print(a.myField); |
| 3887 } | 3892 } |
| 3888 '''); | 3893 '''); |
| 3889 } | 3894 } |
| 3890 | 3895 |
| 3891 void test_undefinedGetter_useSimilar_qualified_static() { | 3896 test_undefinedGetter_useSimilar_qualified_static() async { |
| 3892 resolveTestUnit(''' | 3897 resolveTestUnit(''' |
| 3893 class A { | 3898 class A { |
| 3894 static int MY_NAME = 1; | 3899 static int MY_NAME = 1; |
| 3895 } | 3900 } |
| 3896 main() { | 3901 main() { |
| 3897 A.MY_NAM; | 3902 A.MY_NAM; |
| 3898 } | 3903 } |
| 3899 '''); | 3904 '''); |
| 3900 assertHasFix( | 3905 await assertHasFix( |
| 3901 DartFixKind.CHANGE_TO, | 3906 DartFixKind.CHANGE_TO, |
| 3902 ''' | 3907 ''' |
| 3903 class A { | 3908 class A { |
| 3904 static int MY_NAME = 1; | 3909 static int MY_NAME = 1; |
| 3905 } | 3910 } |
| 3906 main() { | 3911 main() { |
| 3907 A.MY_NAME; | 3912 A.MY_NAME; |
| 3908 } | 3913 } |
| 3909 '''); | 3914 '''); |
| 3910 } | 3915 } |
| 3911 | 3916 |
| 3912 void test_undefinedGetter_useSimilar_unqualified() { | 3917 test_undefinedGetter_useSimilar_unqualified() async { |
| 3913 resolveTestUnit(''' | 3918 resolveTestUnit(''' |
| 3914 class A { | 3919 class A { |
| 3915 int myField; | 3920 int myField; |
| 3916 main() { | 3921 main() { |
| 3917 print(myFild); | 3922 print(myFild); |
| 3918 } | 3923 } |
| 3919 } | 3924 } |
| 3920 '''); | 3925 '''); |
| 3921 assertHasFix( | 3926 await assertHasFix( |
| 3922 DartFixKind.CHANGE_TO, | 3927 DartFixKind.CHANGE_TO, |
| 3923 ''' | 3928 ''' |
| 3924 class A { | 3929 class A { |
| 3925 int myField; | 3930 int myField; |
| 3926 main() { | 3931 main() { |
| 3927 print(myField); | 3932 print(myField); |
| 3928 } | 3933 } |
| 3929 } | 3934 } |
| 3930 '''); | 3935 '''); |
| 3931 } | 3936 } |
| 3932 | 3937 |
| 3933 void test_undefinedMethod_create_BAD_inSDK() { | 3938 test_undefinedMethod_create_BAD_inSDK() async { |
| 3934 resolveTestUnit(''' | 3939 resolveTestUnit(''' |
| 3935 main() { | 3940 main() { |
| 3936 List.foo(); | 3941 List.foo(); |
| 3937 } | 3942 } |
| 3938 '''); | 3943 '''); |
| 3939 assertNoFix(DartFixKind.CREATE_METHOD); | 3944 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 3940 } | 3945 } |
| 3941 | 3946 |
| 3942 void test_undefinedMethod_create_generic_BAD_argumentType() { | 3947 test_undefinedMethod_create_generic_BAD_argumentType() async { |
| 3943 resolveTestUnit(''' | 3948 resolveTestUnit(''' |
| 3944 class A<T> { | 3949 class A<T> { |
| 3945 B b; | 3950 B b; |
| 3946 Map<int, T> items; | 3951 Map<int, T> items; |
| 3947 main() { | 3952 main() { |
| 3948 b.process(items); | 3953 b.process(items); |
| 3949 } | 3954 } |
| 3950 } | 3955 } |
| 3951 | 3956 |
| 3952 class B { | 3957 class B { |
| 3953 } | 3958 } |
| 3954 '''); | 3959 '''); |
| 3955 assertHasFix( | 3960 await assertHasFix( |
| 3956 DartFixKind.CREATE_METHOD, | 3961 DartFixKind.CREATE_METHOD, |
| 3957 ''' | 3962 ''' |
| 3958 class A<T> { | 3963 class A<T> { |
| 3959 B b; | 3964 B b; |
| 3960 Map<int, T> items; | 3965 Map<int, T> items; |
| 3961 main() { | 3966 main() { |
| 3962 b.process(items); | 3967 b.process(items); |
| 3963 } | 3968 } |
| 3964 } | 3969 } |
| 3965 | 3970 |
| 3966 class B { | 3971 class B { |
| 3967 void process(Map items) { | 3972 void process(Map items) { |
| 3968 } | 3973 } |
| 3969 } | 3974 } |
| 3970 '''); | 3975 '''); |
| 3971 } | 3976 } |
| 3972 | 3977 |
| 3973 void test_undefinedMethod_create_generic_BAD_returnType() { | 3978 test_undefinedMethod_create_generic_BAD_returnType() async { |
| 3974 resolveTestUnit(''' | 3979 resolveTestUnit(''' |
| 3975 class A<T> { | 3980 class A<T> { |
| 3976 main() { | 3981 main() { |
| 3977 T t = new B().compute(); | 3982 T t = new B().compute(); |
| 3978 } | 3983 } |
| 3979 } | 3984 } |
| 3980 | 3985 |
| 3981 class B { | 3986 class B { |
| 3982 } | 3987 } |
| 3983 '''); | 3988 '''); |
| 3984 assertHasFix( | 3989 await assertHasFix( |
| 3985 DartFixKind.CREATE_METHOD, | 3990 DartFixKind.CREATE_METHOD, |
| 3986 ''' | 3991 ''' |
| 3987 class A<T> { | 3992 class A<T> { |
| 3988 main() { | 3993 main() { |
| 3989 T t = new B().compute(); | 3994 T t = new B().compute(); |
| 3990 } | 3995 } |
| 3991 } | 3996 } |
| 3992 | 3997 |
| 3993 class B { | 3998 class B { |
| 3994 dynamic compute() { | 3999 dynamic compute() { |
| 3995 } | 4000 } |
| 3996 } | 4001 } |
| 3997 '''); | 4002 '''); |
| 3998 } | 4003 } |
| 3999 | 4004 |
| 4000 void test_undefinedMethod_create_generic_OK_literal() { | 4005 test_undefinedMethod_create_generic_OK_literal() async { |
| 4001 resolveTestUnit(''' | 4006 resolveTestUnit(''' |
| 4002 class A { | 4007 class A { |
| 4003 B b; | 4008 B b; |
| 4004 List<int> items; | 4009 List<int> items; |
| 4005 main() { | 4010 main() { |
| 4006 b.process(items); | 4011 b.process(items); |
| 4007 } | 4012 } |
| 4008 } | 4013 } |
| 4009 | 4014 |
| 4010 class B { | 4015 class B { |
| 4011 } | 4016 } |
| 4012 '''); | 4017 '''); |
| 4013 assertHasFix( | 4018 await assertHasFix( |
| 4014 DartFixKind.CREATE_METHOD, | 4019 DartFixKind.CREATE_METHOD, |
| 4015 ''' | 4020 ''' |
| 4016 class A { | 4021 class A { |
| 4017 B b; | 4022 B b; |
| 4018 List<int> items; | 4023 List<int> items; |
| 4019 main() { | 4024 main() { |
| 4020 b.process(items); | 4025 b.process(items); |
| 4021 } | 4026 } |
| 4022 } | 4027 } |
| 4023 | 4028 |
| 4024 class B { | 4029 class B { |
| 4025 void process(List<int> items) { | 4030 void process(List<int> items) { |
| 4026 } | 4031 } |
| 4027 } | 4032 } |
| 4028 '''); | 4033 '''); |
| 4029 } | 4034 } |
| 4030 | 4035 |
| 4031 void test_undefinedMethod_create_generic_OK_local() { | 4036 test_undefinedMethod_create_generic_OK_local() async { |
| 4032 resolveTestUnit(''' | 4037 resolveTestUnit(''' |
| 4033 class A<T> { | 4038 class A<T> { |
| 4034 List<T> items; | 4039 List<T> items; |
| 4035 main() { | 4040 main() { |
| 4036 process(items); | 4041 process(items); |
| 4037 } | 4042 } |
| 4038 } | 4043 } |
| 4039 '''); | 4044 '''); |
| 4040 assertHasFix( | 4045 await assertHasFix( |
| 4041 DartFixKind.CREATE_METHOD, | 4046 DartFixKind.CREATE_METHOD, |
| 4042 ''' | 4047 ''' |
| 4043 class A<T> { | 4048 class A<T> { |
| 4044 List<T> items; | 4049 List<T> items; |
| 4045 main() { | 4050 main() { |
| 4046 process(items); | 4051 process(items); |
| 4047 } | 4052 } |
| 4048 | 4053 |
| 4049 void process(List<T> items) { | 4054 void process(List<T> items) { |
| 4050 } | 4055 } |
| 4051 } | 4056 } |
| 4052 '''); | 4057 '''); |
| 4053 } | 4058 } |
| 4054 | 4059 |
| 4055 void test_undefinedMethod_createQualified_fromClass() { | 4060 test_undefinedMethod_createQualified_fromClass() async { |
| 4056 resolveTestUnit(''' | 4061 resolveTestUnit(''' |
| 4057 class A { | 4062 class A { |
| 4058 } | 4063 } |
| 4059 main() { | 4064 main() { |
| 4060 A.myUndefinedMethod(); | 4065 A.myUndefinedMethod(); |
| 4061 } | 4066 } |
| 4062 '''); | 4067 '''); |
| 4063 assertHasFix( | 4068 await assertHasFix( |
| 4064 DartFixKind.CREATE_METHOD, | 4069 DartFixKind.CREATE_METHOD, |
| 4065 ''' | 4070 ''' |
| 4066 class A { | 4071 class A { |
| 4067 static void myUndefinedMethod() { | 4072 static void myUndefinedMethod() { |
| 4068 } | 4073 } |
| 4069 } | 4074 } |
| 4070 main() { | 4075 main() { |
| 4071 A.myUndefinedMethod(); | 4076 A.myUndefinedMethod(); |
| 4072 } | 4077 } |
| 4073 '''); | 4078 '''); |
| 4074 } | 4079 } |
| 4075 | 4080 |
| 4076 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() { | 4081 test_undefinedMethod_createQualified_fromClass_hasOtherMember() async { |
| 4077 resolveTestUnit(''' | 4082 resolveTestUnit(''' |
| 4078 class A { | 4083 class A { |
| 4079 foo() {} | 4084 foo() {} |
| 4080 } | 4085 } |
| 4081 main() { | 4086 main() { |
| 4082 A.myUndefinedMethod(); | 4087 A.myUndefinedMethod(); |
| 4083 } | 4088 } |
| 4084 '''); | 4089 '''); |
| 4085 assertHasFix( | 4090 await assertHasFix( |
| 4086 DartFixKind.CREATE_METHOD, | 4091 DartFixKind.CREATE_METHOD, |
| 4087 ''' | 4092 ''' |
| 4088 class A { | 4093 class A { |
| 4089 foo() {} | 4094 foo() {} |
| 4090 | 4095 |
| 4091 static void myUndefinedMethod() { | 4096 static void myUndefinedMethod() { |
| 4092 } | 4097 } |
| 4093 } | 4098 } |
| 4094 main() { | 4099 main() { |
| 4095 A.myUndefinedMethod(); | 4100 A.myUndefinedMethod(); |
| 4096 } | 4101 } |
| 4097 '''); | 4102 '''); |
| 4098 } | 4103 } |
| 4099 | 4104 |
| 4100 void test_undefinedMethod_createQualified_fromInstance() { | 4105 test_undefinedMethod_createQualified_fromInstance() async { |
| 4101 resolveTestUnit(''' | 4106 resolveTestUnit(''' |
| 4102 class A { | 4107 class A { |
| 4103 } | 4108 } |
| 4104 main(A a) { | 4109 main(A a) { |
| 4105 a.myUndefinedMethod(); | 4110 a.myUndefinedMethod(); |
| 4106 } | 4111 } |
| 4107 '''); | 4112 '''); |
| 4108 assertHasFix( | 4113 await assertHasFix( |
| 4109 DartFixKind.CREATE_METHOD, | 4114 DartFixKind.CREATE_METHOD, |
| 4110 ''' | 4115 ''' |
| 4111 class A { | 4116 class A { |
| 4112 void myUndefinedMethod() { | 4117 void myUndefinedMethod() { |
| 4113 } | 4118 } |
| 4114 } | 4119 } |
| 4115 main(A a) { | 4120 main(A a) { |
| 4116 a.myUndefinedMethod(); | 4121 a.myUndefinedMethod(); |
| 4117 } | 4122 } |
| 4118 '''); | 4123 '''); |
| 4119 } | 4124 } |
| 4120 | 4125 |
| 4121 void test_undefinedMethod_createQualified_targetIsFunctionType() { | 4126 test_undefinedMethod_createQualified_targetIsFunctionType() async { |
| 4122 resolveTestUnit(''' | 4127 resolveTestUnit(''' |
| 4123 typedef A(); | 4128 typedef A(); |
| 4124 main() { | 4129 main() { |
| 4125 A.myUndefinedMethod(); | 4130 A.myUndefinedMethod(); |
| 4126 } | 4131 } |
| 4127 '''); | 4132 '''); |
| 4128 assertNoFix(DartFixKind.CREATE_METHOD); | 4133 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4129 } | 4134 } |
| 4130 | 4135 |
| 4131 void test_undefinedMethod_createQualified_targetIsUnresolved() { | 4136 test_undefinedMethod_createQualified_targetIsUnresolved() async { |
| 4132 resolveTestUnit(''' | 4137 resolveTestUnit(''' |
| 4133 main() { | 4138 main() { |
| 4134 NoSuchClass.myUndefinedMethod(); | 4139 NoSuchClass.myUndefinedMethod(); |
| 4135 } | 4140 } |
| 4136 '''); | 4141 '''); |
| 4137 assertNoFix(DartFixKind.CREATE_METHOD); | 4142 await assertNoFix(DartFixKind.CREATE_METHOD); |
| 4138 } | 4143 } |
| 4139 | 4144 |
| 4140 void test_undefinedMethod_createUnqualified_parameters() { | 4145 test_undefinedMethod_createUnqualified_parameters() async { |
| 4141 resolveTestUnit(''' | 4146 resolveTestUnit(''' |
| 4142 class A { | 4147 class A { |
| 4143 main() { | 4148 main() { |
| 4144 myUndefinedMethod(0, 1.0, '3'); | 4149 myUndefinedMethod(0, 1.0, '3'); |
| 4145 } | 4150 } |
| 4146 } | 4151 } |
| 4147 '''); | 4152 '''); |
| 4148 assertHasFix( | 4153 await assertHasFix( |
| 4149 DartFixKind.CREATE_METHOD, | 4154 DartFixKind.CREATE_METHOD, |
| 4150 ''' | 4155 ''' |
| 4151 class A { | 4156 class A { |
| 4152 main() { | 4157 main() { |
| 4153 myUndefinedMethod(0, 1.0, '3'); | 4158 myUndefinedMethod(0, 1.0, '3'); |
| 4154 } | 4159 } |
| 4155 | 4160 |
| 4156 void myUndefinedMethod(int i, double d, String s) { | 4161 void myUndefinedMethod(int i, double d, String s) { |
| 4157 } | 4162 } |
| 4158 } | 4163 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4176 ['double', 'num', 'Object', 'Comparable'])); | 4181 ['double', 'num', 'Object', 'Comparable'])); |
| 4177 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); | 4182 _assertLinkedGroup(change.linkedEditGroups[index++], ['d,']); |
| 4178 _assertLinkedGroup( | 4183 _assertLinkedGroup( |
| 4179 change.linkedEditGroups[index++], | 4184 change.linkedEditGroups[index++], |
| 4180 ['String s'], | 4185 ['String s'], |
| 4181 expectedSuggestions( | 4186 expectedSuggestions( |
| 4182 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable'])); | 4187 LinkedEditSuggestionKind.TYPE, ['String', 'Object', 'Comparable'])); |
| 4183 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); | 4188 _assertLinkedGroup(change.linkedEditGroups[index++], ['s)']); |
| 4184 } | 4189 } |
| 4185 | 4190 |
| 4186 void test_undefinedMethod_createUnqualified_returnType() { | 4191 test_undefinedMethod_createUnqualified_returnType() async { |
| 4187 resolveTestUnit(''' | 4192 resolveTestUnit(''' |
| 4188 class A { | 4193 class A { |
| 4189 main() { | 4194 main() { |
| 4190 int v = myUndefinedMethod(); | 4195 int v = myUndefinedMethod(); |
| 4191 } | 4196 } |
| 4192 } | 4197 } |
| 4193 '''); | 4198 '''); |
| 4194 assertHasFix( | 4199 await assertHasFix( |
| 4195 DartFixKind.CREATE_METHOD, | 4200 DartFixKind.CREATE_METHOD, |
| 4196 ''' | 4201 ''' |
| 4197 class A { | 4202 class A { |
| 4198 main() { | 4203 main() { |
| 4199 int v = myUndefinedMethod(); | 4204 int v = myUndefinedMethod(); |
| 4200 } | 4205 } |
| 4201 | 4206 |
| 4202 int myUndefinedMethod() { | 4207 int myUndefinedMethod() { |
| 4203 } | 4208 } |
| 4204 } | 4209 } |
| 4205 '''); | 4210 '''); |
| 4206 // linked positions | 4211 // linked positions |
| 4207 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); | 4212 _assertLinkedGroup(change.linkedEditGroups[0], ['int myUndefinedMethod(']); |
| 4208 _assertLinkedGroup(change.linkedEditGroups[1], | 4213 _assertLinkedGroup(change.linkedEditGroups[1], |
| 4209 ['myUndefinedMethod();', 'myUndefinedMethod() {']); | 4214 ['myUndefinedMethod();', 'myUndefinedMethod() {']); |
| 4210 } | 4215 } |
| 4211 | 4216 |
| 4212 void test_undefinedMethod_createUnqualified_staticFromField() { | 4217 test_undefinedMethod_createUnqualified_staticFromField() async { |
| 4213 resolveTestUnit(''' | 4218 resolveTestUnit(''' |
| 4214 class A { | 4219 class A { |
| 4215 static var f = myUndefinedMethod(); | 4220 static var f = myUndefinedMethod(); |
| 4216 } | 4221 } |
| 4217 '''); | 4222 '''); |
| 4218 assertHasFix( | 4223 await assertHasFix( |
| 4219 DartFixKind.CREATE_METHOD, | 4224 DartFixKind.CREATE_METHOD, |
| 4220 ''' | 4225 ''' |
| 4221 class A { | 4226 class A { |
| 4222 static var f = myUndefinedMethod(); | 4227 static var f = myUndefinedMethod(); |
| 4223 | 4228 |
| 4224 static myUndefinedMethod() { | 4229 static myUndefinedMethod() { |
| 4225 } | 4230 } |
| 4226 } | 4231 } |
| 4227 '''); | 4232 '''); |
| 4228 } | 4233 } |
| 4229 | 4234 |
| 4230 void test_undefinedMethod_createUnqualified_staticFromMethod() { | 4235 test_undefinedMethod_createUnqualified_staticFromMethod() async { |
| 4231 resolveTestUnit(''' | 4236 resolveTestUnit(''' |
| 4232 class A { | 4237 class A { |
| 4233 static main() { | 4238 static main() { |
| 4234 myUndefinedMethod(); | 4239 myUndefinedMethod(); |
| 4235 } | 4240 } |
| 4236 } | 4241 } |
| 4237 '''); | 4242 '''); |
| 4238 assertHasFix( | 4243 await assertHasFix( |
| 4239 DartFixKind.CREATE_METHOD, | 4244 DartFixKind.CREATE_METHOD, |
| 4240 ''' | 4245 ''' |
| 4241 class A { | 4246 class A { |
| 4242 static main() { | 4247 static main() { |
| 4243 myUndefinedMethod(); | 4248 myUndefinedMethod(); |
| 4244 } | 4249 } |
| 4245 | 4250 |
| 4246 static void myUndefinedMethod() { | 4251 static void myUndefinedMethod() { |
| 4247 } | 4252 } |
| 4248 } | 4253 } |
| 4249 '''); | 4254 '''); |
| 4250 } | 4255 } |
| 4251 | 4256 |
| 4252 void test_undefinedMethod_hint_createQualified_fromInstance() { | 4257 test_undefinedMethod_hint_createQualified_fromInstance() async { |
| 4253 resolveTestUnit(''' | 4258 resolveTestUnit(''' |
| 4254 class A { | 4259 class A { |
| 4255 } | 4260 } |
| 4256 main() { | 4261 main() { |
| 4257 var a = new A(); | 4262 var a = new A(); |
| 4258 a.myUndefinedMethod(); | 4263 a.myUndefinedMethod(); |
| 4259 } | 4264 } |
| 4260 '''); | 4265 '''); |
| 4261 assertHasFix( | 4266 await assertHasFix( |
| 4262 DartFixKind.CREATE_METHOD, | 4267 DartFixKind.CREATE_METHOD, |
| 4263 ''' | 4268 ''' |
| 4264 class A { | 4269 class A { |
| 4265 void myUndefinedMethod() { | 4270 void myUndefinedMethod() { |
| 4266 } | 4271 } |
| 4267 } | 4272 } |
| 4268 main() { | 4273 main() { |
| 4269 var a = new A(); | 4274 var a = new A(); |
| 4270 a.myUndefinedMethod(); | 4275 a.myUndefinedMethod(); |
| 4271 } | 4276 } |
| 4272 '''); | 4277 '''); |
| 4273 } | 4278 } |
| 4274 | 4279 |
| 4275 void test_undefinedMethod_parameterType_differentPrefixInTargetUnit() { | 4280 test_undefinedMethod_parameterType_differentPrefixInTargetUnit() async { |
| 4276 String code2 = r''' | 4281 String code2 = r''' |
| 4277 library test2; | 4282 library test2; |
| 4278 import 'test3.dart' as bbb; | 4283 import 'test3.dart' as bbb; |
| 4279 export 'test3.dart'; | 4284 export 'test3.dart'; |
| 4280 class D { | 4285 class D { |
| 4281 } | 4286 } |
| 4282 '''; | 4287 '''; |
| 4283 addSource('/test2.dart', code2); | 4288 addSource('/test2.dart', code2); |
| 4284 addSource( | 4289 addSource( |
| 4285 '/test3.dart', | 4290 '/test3.dart', |
| 4286 r''' | 4291 r''' |
| 4287 library test3; | 4292 library test3; |
| 4288 class E {} | 4293 class E {} |
| 4289 '''); | 4294 '''); |
| 4290 resolveTestUnit(''' | 4295 resolveTestUnit(''' |
| 4291 library test; | 4296 library test; |
| 4292 import 'test2.dart' as aaa; | 4297 import 'test2.dart' as aaa; |
| 4293 main(aaa.D d, aaa.E e) { | 4298 main(aaa.D d, aaa.E e) { |
| 4294 d.foo(e); | 4299 d.foo(e); |
| 4295 } | 4300 } |
| 4296 '''); | 4301 '''); |
| 4297 AnalysisError error = _findErrorToFix(); | 4302 AnalysisError error = _findErrorToFix(); |
| 4298 fix = _assertHasFix(DartFixKind.CREATE_METHOD, error); | 4303 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 4299 change = fix.change; | 4304 change = fix.change; |
| 4300 // apply to "test2.dart" | 4305 // apply to "test2.dart" |
| 4301 List<SourceFileEdit> fileEdits = change.edits; | 4306 List<SourceFileEdit> fileEdits = change.edits; |
| 4302 expect(fileEdits, hasLength(1)); | 4307 expect(fileEdits, hasLength(1)); |
| 4303 SourceFileEdit fileEdit = change.edits[0]; | 4308 SourceFileEdit fileEdit = change.edits[0]; |
| 4304 expect(fileEdit.file, '/test2.dart'); | 4309 expect(fileEdit.file, '/test2.dart'); |
| 4305 expect( | 4310 expect( |
| 4306 SourceEdit.applySequence(code2, fileEdit.edits), | 4311 SourceEdit.applySequence(code2, fileEdit.edits), |
| 4307 r''' | 4312 r''' |
| 4308 library test2; | 4313 library test2; |
| 4309 import 'test3.dart' as bbb; | 4314 import 'test3.dart' as bbb; |
| 4310 export 'test3.dart'; | 4315 export 'test3.dart'; |
| 4311 class D { | 4316 class D { |
| 4312 void foo(bbb.E e) { | 4317 void foo(bbb.E e) { |
| 4313 } | 4318 } |
| 4314 } | 4319 } |
| 4315 '''); | 4320 '''); |
| 4316 } | 4321 } |
| 4317 | 4322 |
| 4318 void test_undefinedMethod_parameterType_inTargetUnit() { | 4323 test_undefinedMethod_parameterType_inTargetUnit() async { |
| 4319 String code2 = r''' | 4324 String code2 = r''' |
| 4320 library test2; | 4325 library test2; |
| 4321 class D { | 4326 class D { |
| 4322 } | 4327 } |
| 4323 class E {} | 4328 class E {} |
| 4324 '''; | 4329 '''; |
| 4325 addSource('/test2.dart', code2); | 4330 addSource('/test2.dart', code2); |
| 4326 resolveTestUnit(''' | 4331 resolveTestUnit(''' |
| 4327 library test; | 4332 library test; |
| 4328 import 'test2.dart' as test2; | 4333 import 'test2.dart' as test2; |
| 4329 main(test2.D d, test2.E e) { | 4334 main(test2.D d, test2.E e) { |
| 4330 d.foo(e); | 4335 d.foo(e); |
| 4331 } | 4336 } |
| 4332 '''); | 4337 '''); |
| 4333 AnalysisError error = _findErrorToFix(); | 4338 AnalysisError error = _findErrorToFix(); |
| 4334 fix = _assertHasFix(DartFixKind.CREATE_METHOD, error); | 4339 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 4335 change = fix.change; | 4340 change = fix.change; |
| 4336 // apply to "test2.dart" | 4341 // apply to "test2.dart" |
| 4337 List<SourceFileEdit> fileEdits = change.edits; | 4342 List<SourceFileEdit> fileEdits = change.edits; |
| 4338 expect(fileEdits, hasLength(1)); | 4343 expect(fileEdits, hasLength(1)); |
| 4339 SourceFileEdit fileEdit = change.edits[0]; | 4344 SourceFileEdit fileEdit = change.edits[0]; |
| 4340 expect(fileEdit.file, '/test2.dart'); | 4345 expect(fileEdit.file, '/test2.dart'); |
| 4341 expect( | 4346 expect( |
| 4342 SourceEdit.applySequence(code2, fileEdit.edits), | 4347 SourceEdit.applySequence(code2, fileEdit.edits), |
| 4343 r''' | 4348 r''' |
| 4344 library test2; | 4349 library test2; |
| 4345 class D { | 4350 class D { |
| 4346 void foo(E e) { | 4351 void foo(E e) { |
| 4347 } | 4352 } |
| 4348 } | 4353 } |
| 4349 class E {} | 4354 class E {} |
| 4350 '''); | 4355 '''); |
| 4351 } | 4356 } |
| 4352 | 4357 |
| 4353 void test_undefinedMethod_useSimilar_ignoreOperators() { | 4358 test_undefinedMethod_useSimilar_ignoreOperators() async { |
| 4354 resolveTestUnit(''' | 4359 resolveTestUnit(''' |
| 4355 main(Object object) { | 4360 main(Object object) { |
| 4356 object.then(); | 4361 object.then(); |
| 4357 } | 4362 } |
| 4358 '''); | 4363 '''); |
| 4359 assertNoFix(DartFixKind.CHANGE_TO); | 4364 await assertNoFix(DartFixKind.CHANGE_TO); |
| 4360 } | 4365 } |
| 4361 | 4366 |
| 4362 void test_undefinedMethod_useSimilar_qualified() { | 4367 test_undefinedMethod_useSimilar_qualified() async { |
| 4363 resolveTestUnit(''' | 4368 resolveTestUnit(''' |
| 4364 class A { | 4369 class A { |
| 4365 myMethod() {} | 4370 myMethod() {} |
| 4366 } | 4371 } |
| 4367 main() { | 4372 main() { |
| 4368 A a = new A(); | 4373 A a = new A(); |
| 4369 a.myMehtod(); | 4374 a.myMehtod(); |
| 4370 } | 4375 } |
| 4371 '''); | 4376 '''); |
| 4372 assertHasFix( | 4377 await assertHasFix( |
| 4373 DartFixKind.CHANGE_TO, | 4378 DartFixKind.CHANGE_TO, |
| 4374 ''' | 4379 ''' |
| 4375 class A { | 4380 class A { |
| 4376 myMethod() {} | 4381 myMethod() {} |
| 4377 } | 4382 } |
| 4378 main() { | 4383 main() { |
| 4379 A a = new A(); | 4384 A a = new A(); |
| 4380 a.myMethod(); | 4385 a.myMethod(); |
| 4381 } | 4386 } |
| 4382 '''); | 4387 '''); |
| 4383 } | 4388 } |
| 4384 | 4389 |
| 4385 void test_undefinedMethod_useSimilar_unqualified_superClass() { | 4390 test_undefinedMethod_useSimilar_unqualified_superClass() async { |
| 4386 resolveTestUnit(''' | 4391 resolveTestUnit(''' |
| 4387 class A { | 4392 class A { |
| 4388 myMethod() {} | 4393 myMethod() {} |
| 4389 } | 4394 } |
| 4390 class B extends A { | 4395 class B extends A { |
| 4391 main() { | 4396 main() { |
| 4392 myMehtod(); | 4397 myMehtod(); |
| 4393 } | 4398 } |
| 4394 } | 4399 } |
| 4395 '''); | 4400 '''); |
| 4396 assertHasFix( | 4401 await assertHasFix( |
| 4397 DartFixKind.CHANGE_TO, | 4402 DartFixKind.CHANGE_TO, |
| 4398 ''' | 4403 ''' |
| 4399 class A { | 4404 class A { |
| 4400 myMethod() {} | 4405 myMethod() {} |
| 4401 } | 4406 } |
| 4402 class B extends A { | 4407 class B extends A { |
| 4403 main() { | 4408 main() { |
| 4404 myMethod(); | 4409 myMethod(); |
| 4405 } | 4410 } |
| 4406 } | 4411 } |
| 4407 '''); | 4412 '''); |
| 4408 } | 4413 } |
| 4409 | 4414 |
| 4410 void test_undefinedMethod_useSimilar_unqualified_thisClass() { | 4415 test_undefinedMethod_useSimilar_unqualified_thisClass() async { |
| 4411 resolveTestUnit(''' | 4416 resolveTestUnit(''' |
| 4412 class A { | 4417 class A { |
| 4413 myMethod() {} | 4418 myMethod() {} |
| 4414 main() { | 4419 main() { |
| 4415 myMehtod(); | 4420 myMehtod(); |
| 4416 } | 4421 } |
| 4417 } | 4422 } |
| 4418 '''); | 4423 '''); |
| 4419 assertHasFix( | 4424 await assertHasFix( |
| 4420 DartFixKind.CHANGE_TO, | 4425 DartFixKind.CHANGE_TO, |
| 4421 ''' | 4426 ''' |
| 4422 class A { | 4427 class A { |
| 4423 myMethod() {} | 4428 myMethod() {} |
| 4424 main() { | 4429 main() { |
| 4425 myMethod(); | 4430 myMethod(); |
| 4426 } | 4431 } |
| 4427 } | 4432 } |
| 4428 '''); | 4433 '''); |
| 4429 } | 4434 } |
| 4430 | 4435 |
| 4431 void test_undefinedSetter_useSimilar_hint() { | 4436 test_undefinedSetter_useSimilar_hint() async { |
| 4432 resolveTestUnit(''' | 4437 resolveTestUnit(''' |
| 4433 class A { | 4438 class A { |
| 4434 int myField; | 4439 int myField; |
| 4435 } | 4440 } |
| 4436 main(A a) { | 4441 main(A a) { |
| 4437 var x = a; | 4442 var x = a; |
| 4438 x.myFild = 42; | 4443 x.myFild = 42; |
| 4439 } | 4444 } |
| 4440 '''); | 4445 '''); |
| 4441 assertHasFix( | 4446 await assertHasFix( |
| 4442 DartFixKind.CHANGE_TO, | 4447 DartFixKind.CHANGE_TO, |
| 4443 ''' | 4448 ''' |
| 4444 class A { | 4449 class A { |
| 4445 int myField; | 4450 int myField; |
| 4446 } | 4451 } |
| 4447 main(A a) { | 4452 main(A a) { |
| 4448 var x = a; | 4453 var x = a; |
| 4449 x.myField = 42; | 4454 x.myField = 42; |
| 4450 } | 4455 } |
| 4451 '''); | 4456 '''); |
| 4452 } | 4457 } |
| 4453 | 4458 |
| 4454 void test_undefinedSetter_useSimilar_qualified() { | 4459 test_undefinedSetter_useSimilar_qualified() async { |
| 4455 resolveTestUnit(''' | 4460 resolveTestUnit(''' |
| 4456 class A { | 4461 class A { |
| 4457 int myField; | 4462 int myField; |
| 4458 } | 4463 } |
| 4459 main(A a) { | 4464 main(A a) { |
| 4460 a.myFild = 42; | 4465 a.myFild = 42; |
| 4461 } | 4466 } |
| 4462 '''); | 4467 '''); |
| 4463 assertHasFix( | 4468 await assertHasFix( |
| 4464 DartFixKind.CHANGE_TO, | 4469 DartFixKind.CHANGE_TO, |
| 4465 ''' | 4470 ''' |
| 4466 class A { | 4471 class A { |
| 4467 int myField; | 4472 int myField; |
| 4468 } | 4473 } |
| 4469 main(A a) { | 4474 main(A a) { |
| 4470 a.myField = 42; | 4475 a.myField = 42; |
| 4471 } | 4476 } |
| 4472 '''); | 4477 '''); |
| 4473 } | 4478 } |
| 4474 | 4479 |
| 4475 void test_undefinedSetter_useSimilar_unqualified() { | 4480 test_undefinedSetter_useSimilar_unqualified() async { |
| 4476 resolveTestUnit(''' | 4481 resolveTestUnit(''' |
| 4477 class A { | 4482 class A { |
| 4478 int myField; | 4483 int myField; |
| 4479 main() { | 4484 main() { |
| 4480 myFild = 42; | 4485 myFild = 42; |
| 4481 } | 4486 } |
| 4482 } | 4487 } |
| 4483 '''); | 4488 '''); |
| 4484 assertHasFix( | 4489 await assertHasFix( |
| 4485 DartFixKind.CHANGE_TO, | 4490 DartFixKind.CHANGE_TO, |
| 4486 ''' | 4491 ''' |
| 4487 class A { | 4492 class A { |
| 4488 int myField; | 4493 int myField; |
| 4489 main() { | 4494 main() { |
| 4490 myField = 42; | 4495 myField = 42; |
| 4491 } | 4496 } |
| 4492 } | 4497 } |
| 4493 '''); | 4498 '''); |
| 4494 } | 4499 } |
| 4495 | 4500 |
| 4496 void test_useEffectiveIntegerDivision() { | 4501 test_useEffectiveIntegerDivision() async { |
| 4497 resolveTestUnit(''' | 4502 resolveTestUnit(''' |
| 4498 main() { | 4503 main() { |
| 4499 var a = 5; | 4504 var a = 5; |
| 4500 var b = 2; | 4505 var b = 2; |
| 4501 print((a / b).toInt()); | 4506 print((a / b).toInt()); |
| 4502 } | 4507 } |
| 4503 '''); | 4508 '''); |
| 4504 assertHasFix( | 4509 await assertHasFix( |
| 4505 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, | 4510 DartFixKind.USE_EFFECTIVE_INTEGER_DIVISION, |
| 4506 ''' | 4511 ''' |
| 4507 main() { | 4512 main() { |
| 4508 var a = 5; | 4513 var a = 5; |
| 4509 var b = 2; | 4514 var b = 2; |
| 4510 print(a ~/ b); | 4515 print(a ~/ b); |
| 4511 } | 4516 } |
| 4512 '''); | 4517 '''); |
| 4513 } | 4518 } |
| 4514 | 4519 |
| 4515 void test_useImportPrefix_withClass() { | 4520 test_useImportPrefix_withClass() async { |
| 4516 resolveTestUnit(''' | 4521 resolveTestUnit(''' |
| 4517 import 'dart:async' as pref; | 4522 import 'dart:async' as pref; |
| 4518 main() { | 4523 main() { |
| 4519 pref.Stream s = null; | 4524 pref.Stream s = null; |
| 4520 Future f = null; | 4525 Future f = null; |
| 4521 } | 4526 } |
| 4522 '''); | 4527 '''); |
| 4523 assertHasFix( | 4528 await assertHasFix( |
| 4524 DartFixKind.IMPORT_LIBRARY_PREFIX, | 4529 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 4525 ''' | 4530 ''' |
| 4526 import 'dart:async' as pref; | 4531 import 'dart:async' as pref; |
| 4527 main() { | 4532 main() { |
| 4528 pref.Stream s = null; | 4533 pref.Stream s = null; |
| 4529 pref.Future f = null; | 4534 pref.Future f = null; |
| 4530 } | 4535 } |
| 4531 '''); | 4536 '''); |
| 4532 } | 4537 } |
| 4533 | 4538 |
| 4534 void test_useImportPrefix_withTopLevelVariable() { | 4539 test_useImportPrefix_withTopLevelVariable() async { |
| 4535 resolveTestUnit(''' | 4540 resolveTestUnit(''' |
| 4536 import 'dart:math' as pref; | 4541 import 'dart:math' as pref; |
| 4537 main() { | 4542 main() { |
| 4538 print(pref.E); | 4543 print(pref.E); |
| 4539 print(PI); | 4544 print(PI); |
| 4540 } | 4545 } |
| 4541 '''); | 4546 '''); |
| 4542 assertHasFix( | 4547 await assertHasFix( |
| 4543 DartFixKind.IMPORT_LIBRARY_PREFIX, | 4548 DartFixKind.IMPORT_LIBRARY_PREFIX, |
| 4544 ''' | 4549 ''' |
| 4545 import 'dart:math' as pref; | 4550 import 'dart:math' as pref; |
| 4546 main() { | 4551 main() { |
| 4547 print(pref.E); | 4552 print(pref.E); |
| 4548 print(pref.PI); | 4553 print(pref.PI); |
| 4549 } | 4554 } |
| 4550 '''); | 4555 '''); |
| 4551 } | 4556 } |
| 4552 | 4557 |
| 4553 /** | 4558 /** |
| 4554 * Computes fixes and verifies that there is a fix of the given kind. | 4559 * Computes fixes and verifies that there is a fix of the given kind. |
| 4555 */ | 4560 */ |
| 4556 Fix _assertHasFix(FixKind kind, AnalysisError error) { | 4561 Future<Fix> _assertHasFix(FixKind kind, AnalysisError error) async { |
| 4557 List<Fix> fixes = _computeFixes(error); | 4562 List<Fix> fixes = await _computeFixes(error); |
| 4558 for (Fix fix in fixes) { | 4563 for (Fix fix in fixes) { |
| 4559 if (fix.kind == kind) { | 4564 if (fix.kind == kind) { |
| 4560 return fix; | 4565 return fix; |
| 4561 } | 4566 } |
| 4562 } | 4567 } |
| 4563 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); | 4568 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); |
| 4564 } | 4569 } |
| 4565 | 4570 |
| 4566 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings, | 4571 void _assertLinkedGroup(LinkedEditGroup group, List<String> expectedStrings, |
| 4567 [List<LinkedEditSuggestion> expectedSuggestions]) { | 4572 [List<LinkedEditSuggestion> expectedSuggestions]) { |
| 4568 List<Position> expectedPositions = _findResultPositions(expectedStrings); | 4573 List<Position> expectedPositions = _findResultPositions(expectedStrings); |
| 4569 expect(group.positions, unorderedEquals(expectedPositions)); | 4574 expect(group.positions, unorderedEquals(expectedPositions)); |
| 4570 if (expectedSuggestions != null) { | 4575 if (expectedSuggestions != null) { |
| 4571 expect(group.suggestions, unorderedEquals(expectedSuggestions)); | 4576 expect(group.suggestions, unorderedEquals(expectedSuggestions)); |
| 4572 } | 4577 } |
| 4573 } | 4578 } |
| 4574 | 4579 |
| 4575 /** | 4580 /** |
| 4576 * Computes fixes for the given [error] in [testUnit]. | 4581 * Computes fixes for the given [error] in [testUnit]. |
| 4577 */ | 4582 */ |
| 4578 List<Fix> _computeFixes(AnalysisError error) { | 4583 Future<List<Fix>> _computeFixes(AnalysisError error) async { |
| 4579 FixProcessor processor = new FixProcessor(provider, testUnit, error); | 4584 DartFixContext dartContext = new DartFixContextImpl( |
| 4585 new FixContextImpl(provider, context, error), testUnit); |
| 4586 FixProcessor processor = new FixProcessor(dartContext); |
| 4580 return processor.compute(); | 4587 return processor.compute(); |
| 4581 } | 4588 } |
| 4582 | 4589 |
| 4583 /** | 4590 /** |
| 4584 * Configures the [SourceFactory] to have the `my_pkg` package in | 4591 * Configures the [SourceFactory] to have the `my_pkg` package in |
| 4585 * `/packages/my_pkg/lib` folder. | 4592 * `/packages/my_pkg/lib` folder. |
| 4586 */ | 4593 */ |
| 4587 void _configureMyPkg(String myLibCode) { | 4594 void _configureMyPkg(String myLibCode) { |
| 4588 provider.newFile('/packages/my_pkg/lib/my_lib.dart', myLibCode); | 4595 provider.newFile('/packages/my_pkg/lib/my_lib.dart', myLibCode); |
| 4589 // configure SourceFactory | 4596 // configure SourceFactory |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4612 int offset = resultCode.indexOf(search); | 4619 int offset = resultCode.indexOf(search); |
| 4613 positions.add(new Position(testFile, offset)); | 4620 positions.add(new Position(testFile, offset)); |
| 4614 } | 4621 } |
| 4615 return positions; | 4622 return positions; |
| 4616 } | 4623 } |
| 4617 | 4624 |
| 4618 void _performAnalysis() { | 4625 void _performAnalysis() { |
| 4619 while (context.performAnalysisTask().hasMoreWork); | 4626 while (context.performAnalysisTask().hasMoreWork); |
| 4620 } | 4627 } |
| 4621 } | 4628 } |
| OLD | NEW |