Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 2753123003: Add quick-fix to convert child: to children: (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.correction.fix; 5 library test.services.correction.fix;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; 9 import 'package:analysis_server/plugin/edit/fix/fix_core.dart';
10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart'; 10 import 'package:analysis_server/plugin/edit/fix/fix_dart.dart';
11 import 'package:analysis_server/plugin/protocol/protocol.dart' 11 import 'package:analysis_server/plugin/protocol/protocol.dart'
12 hide AnalysisError; 12 hide AnalysisError;
13 import 'package:analysis_server/src/services/correction/fix.dart'; 13 import 'package:analysis_server/src/services/correction/fix.dart';
14 import 'package:analysis_server/src/services/correction/fix_internal.dart'; 14 import 'package:analysis_server/src/services/correction/fix_internal.dart';
15 import 'package:analyzer/dart/ast/ast.dart'; 15 import 'package:analyzer/dart/ast/ast.dart';
16 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 16 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
17 import 'package:analyzer/error/error.dart'; 17 import 'package:analyzer/error/error.dart';
18 import 'package:analyzer/file_system/file_system.dart'; 18 import 'package:analyzer/file_system/file_system.dart';
19 import 'package:analyzer/source/package_map_resolver.dart'; 19 import 'package:analyzer/source/package_map_resolver.dart';
20 import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart'; 20 import 'package:analyzer/src/dart/analysis/ast_provider_driver.dart';
21 import 'package:analyzer/src/dart/element/ast_provider.dart'; 21 import 'package:analyzer/src/dart/element/ast_provider.dart';
22 import 'package:analyzer/src/error/codes.dart'; 22 import 'package:analyzer/src/error/codes.dart';
23 import 'package:analyzer/src/generated/engine.dart'; 23 import 'package:analyzer/src/generated/engine.dart';
24 import 'package:analyzer/src/generated/parser.dart'; 24 import 'package:analyzer/src/generated/parser.dart';
25 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
26 import 'package:test/test.dart'; 26 import 'package:test/test.dart';
27 import 'package:test_reflective_loader/test_reflective_loader.dart'; 27 import 'package:test_reflective_loader/test_reflective_loader.dart';
28 28
29 import '../../abstract_single_unit.dart'; 29 import '../../abstract_single_unit.dart';
30 import 'flutter_util.dart';
30 31
31 main() { 32 main() {
32 defineReflectiveSuite(() { 33 defineReflectiveSuite(() {
33 defineReflectiveTests(FixProcessorTest); 34 defineReflectiveTests(FixProcessorTest);
34 defineReflectiveTests(LintFixTest); 35 defineReflectiveTests(LintFixTest);
35 defineReflectiveTests(FixProcessorTest_Driver); 36 defineReflectiveTests(FixProcessorTest_Driver);
36 defineReflectiveTests(LintFixTest_Driver); 37 defineReflectiveTests(LintFixTest_Driver);
37 }); 38 });
38 } 39 }
39 40
40 typedef bool AnalysisErrorFilter(AnalysisError error); 41 typedef bool AnalysisErrorFilter(AnalysisError error);
41 42
42 /** 43 /**
43 * Base class for fix processor tests. 44 * Base class for fix processor tests.
44 */ 45 */
45 class BaseFixProcessorTest extends AbstractSingleUnitTest { 46 class BaseFixProcessorTest extends AbstractSingleUnitTest {
46 AnalysisErrorFilter errorFilter = (AnalysisError error) { 47 AnalysisErrorFilter errorFilter = (AnalysisError error) {
47 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE && 48 return error.errorCode != HintCode.UNUSED_CATCH_CLAUSE &&
48 error.errorCode != HintCode.UNUSED_CATCH_STACK && 49 error.errorCode != HintCode.UNUSED_CATCH_STACK &&
49 error.errorCode != HintCode.UNUSED_ELEMENT && 50 error.errorCode != HintCode.UNUSED_ELEMENT &&
50 error.errorCode != HintCode.UNUSED_FIELD && 51 error.errorCode != HintCode.UNUSED_FIELD &&
51 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE; 52 error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
52 }; 53 };
53 54
54 String myPkgLibPath = '/packages/my_pkg/lib'; 55 String myPkgLibPath = '/packages/my_pkg/lib';
55 56
57 String flutterPkgLibPath = '/packages/flutter/lib';
58
56 Fix fix; 59 Fix fix;
57 SourceChange change; 60 SourceChange change;
58 String resultCode; 61 String resultCode;
59 62
60 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async { 63 assert_undefinedFunction_create_returnType_bool(String lineWithTest) async {
61 await resolveTestUnit(''' 64 await resolveTestUnit('''
62 main() { 65 main() {
63 bool b = true; 66 bool b = true;
64 $lineWithTest 67 $lineWithTest
65 } 68 }
(...skipping 5314 matching lines...) Expand 10 before | Expand all | Expand 10 after
5380 ''' 5383 '''
5381 class A { 5384 class A {
5382 myMethod() {} 5385 myMethod() {}
5383 main() { 5386 main() {
5384 myMethod(); 5387 myMethod();
5385 } 5388 }
5386 } 5389 }
5387 '''); 5390 ''');
5388 } 5391 }
5389 5392
5393 test_undefinedParameter_convertFlutterChild_invalidList() async {
5394 _configureFlutterPkg({
5395 'src/widgets/framework.dart': flutter_framework_code,
5396 });
5397 await resolveTestUnit('''
5398 import 'package:flutter/src/widgets/framework.dart';
5399 build() {
5400 return new Container(
5401 child: new Row(
5402 child: <Widget>[
5403 new Transform(),
5404 null,
5405 new AspectRatio(),
5406 ],
5407 ),
5408 );
5409 }
5410 ''');
5411 await assertNoFix(DartFixKind.CONVERT_FLUTTER_CHILD);
5412 }
5413
5414 test_undefinedParameter_convertFlutterChild_OK_hasList() async {
5415 _configureFlutterPkg({
5416 'src/widgets/framework.dart': flutter_framework_code,
5417 });
5418 await resolveTestUnit('''
5419 import 'package:flutter/src/widgets/framework.dart';
5420 build() {
5421 return new Container(
5422 child: new Row(
5423 child: [
5424 new Transform(),
5425 new ClipRect.rect(),
5426 new AspectRatio(),
5427 ],
5428 ),
5429 );
5430 }
5431 ''');
5432 await assertHasFix(
5433 DartFixKind.CONVERT_FLUTTER_CHILD,
5434 '''
5435 import 'package:flutter/src/widgets/framework.dart';
5436 build() {
5437 return new Container(
5438 child: new Row(
5439 children: <Widget>[
5440 new Transform(),
5441 new ClipRect.rect(),
5442 new AspectRatio(),
5443 ],
5444 ),
5445 );
5446 }
5447 ''');
5448 }
5449
5450 test_undefinedParameter_convertFlutterChild_OK_hasTypedList() async {
5451 _configureFlutterPkg({
5452 'src/widgets/framework.dart': flutter_framework_code,
5453 });
5454 await resolveTestUnit('''
5455 import 'package:flutter/src/widgets/framework.dart';
5456 build() {
5457 return new Container(
5458 child: new Row(
5459 child: <Widget>[
5460 new Transform(),
5461 new ClipRect.rect(),
5462 new AspectRatio(),
5463 ],
5464 ),
5465 );
5466 }
5467 ''');
5468 await assertHasFix(
5469 DartFixKind.CONVERT_FLUTTER_CHILD,
5470 '''
5471 import 'package:flutter/src/widgets/framework.dart';
5472 build() {
5473 return new Container(
5474 child: new Row(
5475 children: <Widget>[
5476 new Transform(),
5477 new ClipRect.rect(),
5478 new AspectRatio(),
5479 ],
5480 ),
5481 );
5482 }
5483 ''');
5484 }
5485
5486 test_undefinedParameter_convertFlutterChild_OK_multiLine() async {
5487 _configureFlutterPkg({
5488 'src/widgets/framework.dart': flutter_framework_code,
5489 });
5490 await resolveTestUnit('''
5491 import 'package:flutter/src/widgets/framework.dart';
5492 build() {
5493 return new Scaffold(
5494 body: new Row(
5495 child: new Container(
5496 width: 200.0,
5497 height: 300.0,
5498 ),
5499 ),
5500 );
5501 }
5502 ''');
5503 await assertHasFix(
5504 DartFixKind.CONVERT_FLUTTER_CHILD,
5505 '''
5506 import 'package:flutter/src/widgets/framework.dart';
5507 build() {
5508 return new Scaffold(
5509 body: new Row(
5510 children: <Widget>[
5511 new Container(
5512 width: 200.0,
5513 height: 300.0,
5514 ),
5515 ],
5516 ),
5517 );
5518 }
5519 ''');
5520 }
5521
5390 test_undefinedSetter_useSimilar_hint() async { 5522 test_undefinedSetter_useSimilar_hint() async {
5391 await resolveTestUnit(''' 5523 await resolveTestUnit('''
5392 class A { 5524 class A {
5393 int myField; 5525 int myField;
5394 } 5526 }
5395 main(A a) { 5527 main(A a) {
5396 var x = a; 5528 var x = a;
5397 x.myFild = 42; 5529 x.myFild = 42;
5398 } 5530 }
5399 '''); 5531 ''');
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
5517 library meta; 5649 library meta;
5518 5650
5519 const Required required = const Required(); 5651 const Required required = const Required();
5520 5652
5521 class Required { 5653 class Required {
5522 final String reason; 5654 final String reason;
5523 const Required([this.reason]); 5655 const Required([this.reason]);
5524 } 5656 }
5525 '''); 5657 ''');
5526 } 5658 }
5659
5660 /**
5661 * Configures the [SourceFactory] to have the `flutter` package in
5662 * `/packages/flutter/lib` folder.
5663 */
5664 void _configureFlutterPkg(Map<String, String> pathToCode) {
5665 pathToCode.forEach((path, code) {
5666 provider.newFile('$flutterPkgLibPath/$path', code);
5667 });
5668 // configure SourceFactory
5669 Folder myPkgFolder = provider.getResource(flutterPkgLibPath);
5670 UriResolver pkgResolver = new PackageMapUriResolver(provider, {
5671 'flutter': [myPkgFolder]
5672 });
5673 SourceFactory sourceFactory = new SourceFactory(
5674 [new DartUriResolver(sdk), pkgResolver, resourceResolver]);
5675 if (enableNewAnalysisDriver) {
5676 driver.configure(sourceFactory: sourceFactory);
5677 } else {
5678 context.sourceFactory = sourceFactory;
5679 }
5680 // force 'flutter' resolution
5681 addSource(
5682 '/tmp/other.dart',
5683 pathToCode.keys
5684 .map((path) => "import 'package:flutter/$path';")
5685 .join('\n'));
5686 }
5527 } 5687 }
5528 5688
5529 @reflectiveTest 5689 @reflectiveTest
5530 class FixProcessorTest_Driver extends FixProcessorTest { 5690 class FixProcessorTest_Driver extends FixProcessorTest {
5531 @override 5691 @override
5532 bool get enableNewAnalysisDriver => true; 5692 bool get enableNewAnalysisDriver => true;
5533 5693
5534 @failingTest 5694 @failingTest
5535 @override 5695 @override
5536 test_importLibrarySdk_withClass_AsExpression() { 5696 test_importLibrarySdk_withClass_AsExpression() {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
5842 6002
5843 @override 6003 @override
5844 final CompilationUnit unit; 6004 final CompilationUnit unit;
5845 6005
5846 @override 6006 @override
5847 final AnalysisError error; 6007 final AnalysisError error;
5848 6008
5849 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, 6009 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations,
5850 this.analysisContext, this.astProvider, this.unit, this.error); 6010 this.analysisContext, this.astProvider, this.unit, this.error);
5851 } 6011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698