| 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'; | 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/protocol/protocol.dart' | 11 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 11 hide AnalysisError; | 12 hide AnalysisError; |
| 12 import 'package:analysis_server/src/services/correction/fix.dart'; | 13 import 'package:analysis_server/src/services/correction/fix.dart'; |
| 13 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'; |
| 14 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; | 16 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| 15 import 'package:analyzer/error/error.dart'; | 17 import 'package:analyzer/error/error.dart'; |
| 16 import 'package:analyzer/file_system/file_system.dart'; | 18 import 'package:analyzer/file_system/file_system.dart'; |
| 17 import 'package:analyzer/source/package_map_resolver.dart'; | 19 import 'package:analyzer/source/package_map_resolver.dart'; |
| 18 import 'package:analyzer/src/error/codes.dart'; | 20 import 'package:analyzer/src/error/codes.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart'; |
| 19 import 'package:analyzer/src/generated/parser.dart'; | 22 import 'package:analyzer/src/generated/parser.dart'; |
| 20 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 21 import 'package:test/test.dart'; | 24 import 'package:test/test.dart'; |
| 22 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 25 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 23 | 26 |
| 24 import '../../abstract_context.dart'; | 27 import '../../abstract_context.dart'; |
| 25 import '../../abstract_single_unit.dart'; | 28 import '../../abstract_single_unit.dart'; |
| 26 | 29 |
| 27 main() { | 30 main() { |
| 28 defineReflectiveSuite(() { | 31 defineReflectiveSuite(() { |
| 29 defineReflectiveTests(FixProcessorTest); | 32 defineReflectiveTests(FixProcessorTest); |
| 33 defineReflectiveTests(FixProcessorTest_Driver); |
| 30 defineReflectiveTests(LintFixTest); | 34 defineReflectiveTests(LintFixTest); |
| 31 }); | 35 }); |
| 32 } | 36 } |
| 33 | 37 |
| 34 typedef bool AnalysisErrorFilter(AnalysisError error); | 38 typedef bool AnalysisErrorFilter(AnalysisError error); |
| 35 | 39 |
| 36 /** | 40 /** |
| 37 * Base class for fix processor tests. | 41 * Base class for fix processor tests. |
| 38 */ | 42 */ |
| 39 class BaseFixProcessorTest extends AbstractSingleUnitTest { | 43 class BaseFixProcessorTest extends AbstractSingleUnitTest { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 65 bool b = true; | 69 bool b = true; |
| 66 $lineWithTest | 70 $lineWithTest |
| 67 } | 71 } |
| 68 | 72 |
| 69 bool test() { | 73 bool test() { |
| 70 } | 74 } |
| 71 '''); | 75 '''); |
| 72 } | 76 } |
| 73 | 77 |
| 74 assertHasFix(FixKind kind, String expected) async { | 78 assertHasFix(FixKind kind, String expected) async { |
| 75 AnalysisError error = _findErrorToFix(); | 79 AnalysisError error = await _findErrorToFix(); |
| 76 fix = await _assertHasFix(kind, error); | 80 fix = await _assertHasFix(kind, error); |
| 77 change = fix.change; | 81 change = fix.change; |
| 78 // apply to "file" | 82 // apply to "file" |
| 79 List<SourceFileEdit> fileEdits = change.edits; | 83 List<SourceFileEdit> fileEdits = change.edits; |
| 80 expect(fileEdits, hasLength(1)); | 84 expect(fileEdits, hasLength(1)); |
| 81 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 85 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| 82 // verify | 86 // verify |
| 83 expect(resultCode, expected); | 87 expect(resultCode, expected); |
| 84 } | 88 } |
| 85 | 89 |
| 86 assertNoFix(FixKind kind) async { | 90 assertNoFix(FixKind kind) async { |
| 87 AnalysisError error = _findErrorToFix(); | 91 AnalysisError error = await _findErrorToFix(); |
| 88 List<Fix> fixes = await _computeFixes(error); | 92 List<Fix> fixes = await _computeFixes(error); |
| 89 for (Fix fix in fixes) { | 93 for (Fix fix in fixes) { |
| 90 if (fix.kind == kind) { | 94 if (fix.kind == kind) { |
| 91 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); | 95 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); |
| 92 } | 96 } |
| 93 } | 97 } |
| 94 } | 98 } |
| 95 | 99 |
| 96 Position expectedPosition(String search) { | 100 Position expectedPosition(String search) { |
| 97 int offset = resultCode.indexOf(search); | 101 int offset = resultCode.indexOf(search); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 expect(group.positions, unorderedEquals(expectedPositions)); | 141 expect(group.positions, unorderedEquals(expectedPositions)); |
| 138 if (expectedSuggestions != null) { | 142 if (expectedSuggestions != null) { |
| 139 expect(group.suggestions, unorderedEquals(expectedSuggestions)); | 143 expect(group.suggestions, unorderedEquals(expectedSuggestions)); |
| 140 } | 144 } |
| 141 } | 145 } |
| 142 | 146 |
| 143 /** | 147 /** |
| 144 * Computes fixes for the given [error] in [testUnit]. | 148 * Computes fixes for the given [error] in [testUnit]. |
| 145 */ | 149 */ |
| 146 Future<List<Fix>> _computeFixes(AnalysisError error) async { | 150 Future<List<Fix>> _computeFixes(AnalysisError error) async { |
| 147 FixContextImpl fixContext = new FixContextImpl(provider, context, error); | 151 if (enableNewAnalysisDriver) { |
| 148 DefaultFixContributor contributor = new DefaultFixContributor(); | 152 DartFixContext fixContext = new _DartFixContextImpl( |
| 149 return contributor.computeFixes(fixContext); | 153 provider, |
| 154 driver.getTopLevelNameDeclarations, |
| 155 resolutionMap.elementDeclaredByCompilationUnit(testUnit).context, |
| 156 testUnit, |
| 157 error); |
| 158 return await new DefaultFixContributor().internalComputeFixes(fixContext); |
| 159 } else { |
| 160 FixContextImpl fixContext = new FixContextImpl(provider, context, error); |
| 161 DefaultFixContributor contributor = new DefaultFixContributor(); |
| 162 return contributor.computeFixes(fixContext); |
| 163 } |
| 150 } | 164 } |
| 151 | 165 |
| 152 /** | 166 /** |
| 153 * Configures the [SourceFactory] to have the `my_pkg` package in | 167 * Configures the [SourceFactory] to have the `my_pkg` package in |
| 154 * `/packages/my_pkg/lib` folder. | 168 * `/packages/my_pkg/lib` folder. |
| 155 */ | 169 */ |
| 156 void _configureMyPkg(Map<String, String> pathToCode) { | 170 void _configureMyPkg(Map<String, String> pathToCode) { |
| 157 pathToCode.forEach((path, code) { | 171 pathToCode.forEach((path, code) { |
| 158 provider.newFile('$myPkgLibPath/$path', code); | 172 provider.newFile('$myPkgLibPath/$path', code); |
| 159 }); | 173 }); |
| 160 // configure SourceFactory | 174 // configure SourceFactory |
| 161 Folder myPkgFolder = provider.getResource(myPkgLibPath); | 175 Folder myPkgFolder = provider.getResource(myPkgLibPath); |
| 162 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 176 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 163 'my_pkg': [myPkgFolder] | 177 'my_pkg': [myPkgFolder] |
| 164 }); | 178 }); |
| 165 context.sourceFactory = new SourceFactory( | 179 context.sourceFactory = new SourceFactory( |
| 166 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); | 180 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
| 167 // force 'my_pkg' resolution | 181 // force 'my_pkg' resolution |
| 168 addSource( | 182 addSource( |
| 169 '/tmp/other.dart', | 183 '/tmp/other.dart', |
| 170 pathToCode.keys | 184 pathToCode.keys |
| 171 .map((path) => "import 'package:my_pkg/$path';") | 185 .map((path) => "import 'package:my_pkg/$path';") |
| 172 .join('\n')); | 186 .join('\n')); |
| 173 } | 187 } |
| 174 | 188 |
| 175 AnalysisError _findErrorToFix() { | 189 Future<AnalysisError> _findErrorToFix() async { |
| 176 List<AnalysisError> errors = context.computeErrors(testSource); | 190 List<AnalysisError> errors; |
| 191 if (enableNewAnalysisDriver) { |
| 192 errors = (await driver.getResult(testFile)).errors; |
| 193 } else { |
| 194 errors = context.computeErrors(testSource); |
| 195 } |
| 177 if (errorFilter != null) { | 196 if (errorFilter != null) { |
| 178 errors = errors.where(errorFilter).toList(); | 197 errors = errors.where(errorFilter).toList(); |
| 179 } | 198 } |
| 180 expect(errors, hasLength(1)); | 199 expect(errors, hasLength(1)); |
| 181 return errors[0]; | 200 return errors[0]; |
| 182 } | 201 } |
| 183 | 202 |
| 184 List<Position> _findResultPositions(List<String> searchStrings) { | 203 List<Position> _findResultPositions(List<String> searchStrings) { |
| 185 List<Position> positions = <Position>[]; | 204 List<Position> positions = <Position>[]; |
| 186 for (String search in searchStrings) { | 205 for (String search in searchStrings) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // Comment second. | 426 // Comment second. |
| 408 | 427 |
| 409 class A {} | 428 class A {} |
| 410 '''; | 429 '''; |
| 411 addSource('/part.dart', partCode); | 430 addSource('/part.dart', partCode); |
| 412 await resolveTestUnit(''' | 431 await resolveTestUnit(''' |
| 413 library my.lib; | 432 library my.lib; |
| 414 part 'part.dart'; | 433 part 'part.dart'; |
| 415 '''); | 434 '''); |
| 416 _performAnalysis(); | 435 _performAnalysis(); |
| 417 AnalysisError error = _findErrorToFix(); | 436 AnalysisError error = await _findErrorToFix(); |
| 418 fix = await _assertHasFix(DartFixKind.ADD_PART_OF, error); | 437 fix = await _assertHasFix(DartFixKind.ADD_PART_OF, error); |
| 419 change = fix.change; | 438 change = fix.change; |
| 420 // apply to "file" | 439 // apply to "file" |
| 421 List<SourceFileEdit> fileEdits = change.edits; | 440 List<SourceFileEdit> fileEdits = change.edits; |
| 422 expect(fileEdits, hasLength(1)); | 441 expect(fileEdits, hasLength(1)); |
| 423 SourceFileEdit fileEdit = change.edits[0]; | 442 SourceFileEdit fileEdit = change.edits[0]; |
| 424 expect(fileEdit.file, '/part.dart'); | 443 expect(fileEdit.file, '/part.dart'); |
| 425 expect( | 444 expect( |
| 426 SourceEdit.applySequence(partCode, fileEdit.edits), | 445 SourceEdit.applySequence(partCode, fileEdit.edits), |
| 427 r''' | 446 r''' |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 '''; | 901 '''; |
| 883 addSource('/lib.dart', libCode); | 902 addSource('/lib.dart', libCode); |
| 884 await resolveTestUnit(''' | 903 await resolveTestUnit(''' |
| 885 import 'lib.dart' as lib; | 904 import 'lib.dart' as lib; |
| 886 | 905 |
| 887 main() { | 906 main() { |
| 888 lib.A a = null; | 907 lib.A a = null; |
| 889 lib.Test t = null; | 908 lib.Test t = null; |
| 890 } | 909 } |
| 891 '''); | 910 '''); |
| 892 AnalysisError error = _findErrorToFix(); | 911 AnalysisError error = await _findErrorToFix(); |
| 893 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); | 912 fix = await _assertHasFix(DartFixKind.CREATE_CLASS, error); |
| 894 change = fix.change; | 913 change = fix.change; |
| 895 // apply to "lib.dart" | 914 // apply to "lib.dart" |
| 896 List<SourceFileEdit> fileEdits = change.edits; | 915 List<SourceFileEdit> fileEdits = change.edits; |
| 897 expect(fileEdits, hasLength(1)); | 916 expect(fileEdits, hasLength(1)); |
| 898 SourceFileEdit fileEdit = change.edits[0]; | 917 SourceFileEdit fileEdit = change.edits[0]; |
| 899 expect(fileEdit.file, '/lib.dart'); | 918 expect(fileEdit.file, '/lib.dart'); |
| 900 expect( | 919 expect( |
| 901 SourceEdit.applySequence(libCode, fileEdit.edits), | 920 SourceEdit.applySequence(libCode, fileEdit.edits), |
| 902 r''' | 921 r''' |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 } | 1784 } |
| 1766 } | 1785 } |
| 1767 '''); | 1786 '''); |
| 1768 } | 1787 } |
| 1769 | 1788 |
| 1770 test_createFile_forImport() async { | 1789 test_createFile_forImport() async { |
| 1771 testFile = '/my/project/bin/test.dart'; | 1790 testFile = '/my/project/bin/test.dart'; |
| 1772 await resolveTestUnit(''' | 1791 await resolveTestUnit(''' |
| 1773 import 'my_file.dart'; | 1792 import 'my_file.dart'; |
| 1774 '''); | 1793 '''); |
| 1775 AnalysisError error = _findErrorToFix(); | 1794 AnalysisError error = await _findErrorToFix(); |
| 1776 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1795 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1777 change = fix.change; | 1796 change = fix.change; |
| 1778 // validate change | 1797 // validate change |
| 1779 List<SourceFileEdit> fileEdits = change.edits; | 1798 List<SourceFileEdit> fileEdits = change.edits; |
| 1780 expect(fileEdits, hasLength(1)); | 1799 expect(fileEdits, hasLength(1)); |
| 1781 SourceFileEdit fileEdit = change.edits[0]; | 1800 SourceFileEdit fileEdit = change.edits[0]; |
| 1782 expect(fileEdit.file, '/my/project/bin/my_file.dart'); | 1801 expect(fileEdit.file, '/my/project/bin/my_file.dart'); |
| 1783 expect(fileEdit.fileStamp, -1); | 1802 expect(fileEdit.fileStamp, -1); |
| 1784 expect(fileEdit.edits, hasLength(1)); | 1803 expect(fileEdit.edits, hasLength(1)); |
| 1785 expect(fileEdit.edits[0].replacement, contains('library my_file;')); | 1804 expect(fileEdit.edits[0].replacement, contains('library my_file;')); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1802 await assertNoFix(DartFixKind.CREATE_FILE); | 1821 await assertNoFix(DartFixKind.CREATE_FILE); |
| 1803 } | 1822 } |
| 1804 | 1823 |
| 1805 test_createFile_forImport_inPackage_lib() async { | 1824 test_createFile_forImport_inPackage_lib() async { |
| 1806 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1825 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1807 testFile = '/projects/my_package/lib/test.dart'; | 1826 testFile = '/projects/my_package/lib/test.dart'; |
| 1808 provider.newFolder('/projects/my_package/lib'); | 1827 provider.newFolder('/projects/my_package/lib'); |
| 1809 await resolveTestUnit(''' | 1828 await resolveTestUnit(''' |
| 1810 import 'a/bb/c_cc/my_lib.dart'; | 1829 import 'a/bb/c_cc/my_lib.dart'; |
| 1811 '''); | 1830 '''); |
| 1812 AnalysisError error = _findErrorToFix(); | 1831 AnalysisError error = await _findErrorToFix(); |
| 1813 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1832 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1814 change = fix.change; | 1833 change = fix.change; |
| 1815 // validate change | 1834 // validate change |
| 1816 List<SourceFileEdit> fileEdits = change.edits; | 1835 List<SourceFileEdit> fileEdits = change.edits; |
| 1817 expect(fileEdits, hasLength(1)); | 1836 expect(fileEdits, hasLength(1)); |
| 1818 SourceFileEdit fileEdit = change.edits[0]; | 1837 SourceFileEdit fileEdit = change.edits[0]; |
| 1819 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); | 1838 expect(fileEdit.file, '/projects/my_package/lib/a/bb/c_cc/my_lib.dart'); |
| 1820 expect(fileEdit.fileStamp, -1); | 1839 expect(fileEdit.fileStamp, -1); |
| 1821 expect(fileEdit.edits, hasLength(1)); | 1840 expect(fileEdit.edits, hasLength(1)); |
| 1822 expect(fileEdit.edits[0].replacement, | 1841 expect(fileEdit.edits[0].replacement, |
| 1823 contains('library my_package.a.bb.c_cc.my_lib;')); | 1842 contains('library my_package.a.bb.c_cc.my_lib;')); |
| 1824 } | 1843 } |
| 1825 | 1844 |
| 1826 test_createFile_forImport_inPackage_test() async { | 1845 test_createFile_forImport_inPackage_test() async { |
| 1827 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); | 1846 provider.newFile('/projects/my_package/pubspec.yaml', 'name: my_package'); |
| 1828 testFile = '/projects/my_package/test/misc/test_all.dart'; | 1847 testFile = '/projects/my_package/test/misc/test_all.dart'; |
| 1829 await resolveTestUnit(''' | 1848 await resolveTestUnit(''' |
| 1830 import 'a/bb/my_lib.dart'; | 1849 import 'a/bb/my_lib.dart'; |
| 1831 '''); | 1850 '''); |
| 1832 AnalysisError error = _findErrorToFix(); | 1851 AnalysisError error = await _findErrorToFix(); |
| 1833 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1852 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1834 change = fix.change; | 1853 change = fix.change; |
| 1835 // validate change | 1854 // validate change |
| 1836 List<SourceFileEdit> fileEdits = change.edits; | 1855 List<SourceFileEdit> fileEdits = change.edits; |
| 1837 expect(fileEdits, hasLength(1)); | 1856 expect(fileEdits, hasLength(1)); |
| 1838 SourceFileEdit fileEdit = change.edits[0]; | 1857 SourceFileEdit fileEdit = change.edits[0]; |
| 1839 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); | 1858 expect(fileEdit.file, '/projects/my_package/test/misc/a/bb/my_lib.dart'); |
| 1840 expect(fileEdit.fileStamp, -1); | 1859 expect(fileEdit.fileStamp, -1); |
| 1841 expect(fileEdit.edits, hasLength(1)); | 1860 expect(fileEdit.edits, hasLength(1)); |
| 1842 expect(fileEdit.edits[0].replacement, | 1861 expect(fileEdit.edits[0].replacement, |
| 1843 contains('library my_package.test.misc.a.bb.my_lib;')); | 1862 contains('library my_package.test.misc.a.bb.my_lib;')); |
| 1844 } | 1863 } |
| 1845 | 1864 |
| 1846 test_createFile_forPart() async { | 1865 test_createFile_forPart() async { |
| 1847 testFile = '/my/project/bin/test.dart'; | 1866 testFile = '/my/project/bin/test.dart'; |
| 1848 await resolveTestUnit(''' | 1867 await resolveTestUnit(''' |
| 1849 library my.lib; | 1868 library my.lib; |
| 1850 part 'my_part.dart'; | 1869 part 'my_part.dart'; |
| 1851 '''); | 1870 '''); |
| 1852 AnalysisError error = _findErrorToFix(); | 1871 AnalysisError error = await _findErrorToFix(); |
| 1853 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1872 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1854 change = fix.change; | 1873 change = fix.change; |
| 1855 // validate change | 1874 // validate change |
| 1856 List<SourceFileEdit> fileEdits = change.edits; | 1875 List<SourceFileEdit> fileEdits = change.edits; |
| 1857 expect(fileEdits, hasLength(1)); | 1876 expect(fileEdits, hasLength(1)); |
| 1858 SourceFileEdit fileEdit = change.edits[0]; | 1877 SourceFileEdit fileEdit = change.edits[0]; |
| 1859 expect(fileEdit.file, '/my/project/bin/my_part.dart'); | 1878 expect(fileEdit.file, '/my/project/bin/my_part.dart'); |
| 1860 expect(fileEdit.fileStamp, -1); | 1879 expect(fileEdit.fileStamp, -1); |
| 1861 expect(fileEdit.edits, hasLength(1)); | 1880 expect(fileEdit.edits, hasLength(1)); |
| 1862 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 1881 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1876 ''', | 1895 ''', |
| 1877 Uri.parse('package:my/test.dart')); | 1896 Uri.parse('package:my/test.dart')); |
| 1878 // configure SourceFactory | 1897 // configure SourceFactory |
| 1879 UriResolver pkgResolver = new PackageMapUriResolver(provider, { | 1898 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 1880 'my': <Folder>[provider.getResource('/my/lib')], | 1899 'my': <Folder>[provider.getResource('/my/lib')], |
| 1881 }); | 1900 }); |
| 1882 context.sourceFactory = new SourceFactory( | 1901 context.sourceFactory = new SourceFactory( |
| 1883 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); | 1902 [AbstractContextTest.SDK_RESOLVER, pkgResolver, resourceResolver]); |
| 1884 // prepare fix | 1903 // prepare fix |
| 1885 testUnit = await resolveLibraryUnit(testSource); | 1904 testUnit = await resolveLibraryUnit(testSource); |
| 1886 AnalysisError error = _findErrorToFix(); | 1905 AnalysisError error = await _findErrorToFix(); |
| 1887 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); | 1906 fix = await _assertHasFix(DartFixKind.CREATE_FILE, error); |
| 1888 change = fix.change; | 1907 change = fix.change; |
| 1889 // validate change | 1908 // validate change |
| 1890 List<SourceFileEdit> fileEdits = change.edits; | 1909 List<SourceFileEdit> fileEdits = change.edits; |
| 1891 expect(fileEdits, hasLength(1)); | 1910 expect(fileEdits, hasLength(1)); |
| 1892 SourceFileEdit fileEdit = change.edits[0]; | 1911 SourceFileEdit fileEdit = change.edits[0]; |
| 1893 expect(fileEdit.file, '/my/lib/my_part.dart'); | 1912 expect(fileEdit.file, '/my/lib/my_part.dart'); |
| 1894 expect(fileEdit.fileStamp, -1); | 1913 expect(fileEdit.fileStamp, -1); |
| 1895 expect(fileEdit.edits, hasLength(1)); | 1914 expect(fileEdit.edits, hasLength(1)); |
| 1896 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); | 1915 expect(fileEdit.edits[0].replacement, contains('part of my.lib;')); |
| (...skipping 3193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5090 library test3; | 5109 library test3; |
| 5091 class E {} | 5110 class E {} |
| 5092 '''); | 5111 '''); |
| 5093 await resolveTestUnit(''' | 5112 await resolveTestUnit(''' |
| 5094 library test; | 5113 library test; |
| 5095 import 'test2.dart' as aaa; | 5114 import 'test2.dart' as aaa; |
| 5096 main(aaa.D d, aaa.E e) { | 5115 main(aaa.D d, aaa.E e) { |
| 5097 d.foo(e); | 5116 d.foo(e); |
| 5098 } | 5117 } |
| 5099 '''); | 5118 '''); |
| 5100 AnalysisError error = _findErrorToFix(); | 5119 AnalysisError error = await _findErrorToFix(); |
| 5101 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5120 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 5102 change = fix.change; | 5121 change = fix.change; |
| 5103 // apply to "test2.dart" | 5122 // apply to "test2.dart" |
| 5104 List<SourceFileEdit> fileEdits = change.edits; | 5123 List<SourceFileEdit> fileEdits = change.edits; |
| 5105 expect(fileEdits, hasLength(1)); | 5124 expect(fileEdits, hasLength(1)); |
| 5106 SourceFileEdit fileEdit = change.edits[0]; | 5125 SourceFileEdit fileEdit = change.edits[0]; |
| 5107 expect(fileEdit.file, '/test2.dart'); | 5126 expect(fileEdit.file, '/test2.dart'); |
| 5108 expect( | 5127 expect( |
| 5109 SourceEdit.applySequence(code2, fileEdit.edits), | 5128 SourceEdit.applySequence(code2, fileEdit.edits), |
| 5110 r''' | 5129 r''' |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5125 class E {} | 5144 class E {} |
| 5126 '''; | 5145 '''; |
| 5127 addSource('/test2.dart', code2); | 5146 addSource('/test2.dart', code2); |
| 5128 await resolveTestUnit(''' | 5147 await resolveTestUnit(''' |
| 5129 library test; | 5148 library test; |
| 5130 import 'test2.dart' as test2; | 5149 import 'test2.dart' as test2; |
| 5131 main(test2.D d, test2.E e) { | 5150 main(test2.D d, test2.E e) { |
| 5132 d.foo(e); | 5151 d.foo(e); |
| 5133 } | 5152 } |
| 5134 '''); | 5153 '''); |
| 5135 AnalysisError error = _findErrorToFix(); | 5154 AnalysisError error = await _findErrorToFix(); |
| 5136 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); | 5155 fix = await _assertHasFix(DartFixKind.CREATE_METHOD, error); |
| 5137 change = fix.change; | 5156 change = fix.change; |
| 5138 // apply to "test2.dart" | 5157 // apply to "test2.dart" |
| 5139 List<SourceFileEdit> fileEdits = change.edits; | 5158 List<SourceFileEdit> fileEdits = change.edits; |
| 5140 expect(fileEdits, hasLength(1)); | 5159 expect(fileEdits, hasLength(1)); |
| 5141 SourceFileEdit fileEdit = change.edits[0]; | 5160 SourceFileEdit fileEdit = change.edits[0]; |
| 5142 expect(fileEdit.file, '/test2.dart'); | 5161 expect(fileEdit.file, '/test2.dart'); |
| 5143 expect( | 5162 expect( |
| 5144 SourceEdit.applySequence(code2, fileEdit.edits), | 5163 SourceEdit.applySequence(code2, fileEdit.edits), |
| 5145 r''' | 5164 r''' |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5346 import 'dart:math' as pref; | 5365 import 'dart:math' as pref; |
| 5347 main() { | 5366 main() { |
| 5348 print(pref.E); | 5367 print(pref.E); |
| 5349 print(pref.PI); | 5368 print(pref.PI); |
| 5350 } | 5369 } |
| 5351 '''); | 5370 '''); |
| 5352 } | 5371 } |
| 5353 } | 5372 } |
| 5354 | 5373 |
| 5355 @reflectiveTest | 5374 @reflectiveTest |
| 5375 class FixProcessorTest_Driver extends FixProcessorTest { |
| 5376 @override |
| 5377 bool get enableNewAnalysisDriver => true; |
| 5378 |
| 5379 @failingTest |
| 5380 @override |
| 5381 test_addFieldFormalParameters_hasRequiredParameter() { |
| 5382 return test_addFieldFormalParameters_hasRequiredParameter(); |
| 5383 } |
| 5384 |
| 5385 @failingTest |
| 5386 @override |
| 5387 test_addFieldFormalParameters_noParameters() { |
| 5388 return test_addFieldFormalParameters_noParameters(); |
| 5389 } |
| 5390 |
| 5391 @failingTest |
| 5392 @override |
| 5393 test_addFieldFormalParameters_noRequiredParameter() { |
| 5394 return test_addFieldFormalParameters_noRequiredParameter(); |
| 5395 } |
| 5396 |
| 5397 @failingTest |
| 5398 @override |
| 5399 test_addPartOfDirective() { |
| 5400 return test_addPartOfDirective(); |
| 5401 } |
| 5402 |
| 5403 @failingTest |
| 5404 @override |
| 5405 test_addSync_blockFunctionBody() { |
| 5406 return test_addSync_blockFunctionBody(); |
| 5407 } |
| 5408 |
| 5409 @failingTest |
| 5410 @override |
| 5411 test_createFile_forPart_inPackageLib() { |
| 5412 return test_createFile_forPart_inPackageLib(); |
| 5413 } |
| 5414 |
| 5415 @failingTest |
| 5416 @override |
| 5417 test_importLibraryPackage_preferDirectOverExport() { |
| 5418 return test_importLibraryPackage_preferDirectOverExport(); |
| 5419 } |
| 5420 |
| 5421 @failingTest |
| 5422 @override |
| 5423 test_importLibraryPackage_preferDirectOverExport_src() { |
| 5424 return test_importLibraryPackage_preferDirectOverExport_src(); |
| 5425 } |
| 5426 |
| 5427 @failingTest |
| 5428 @override |
| 5429 test_importLibraryPackage_preferPublicOverPrivate() { |
| 5430 return test_importLibraryPackage_preferPublicOverPrivate(); |
| 5431 } |
| 5432 |
| 5433 @failingTest |
| 5434 @override |
| 5435 test_importLibraryProject_withClass_annotation() { |
| 5436 return test_importLibraryProject_withClass_annotation(); |
| 5437 } |
| 5438 |
| 5439 @failingTest |
| 5440 @override |
| 5441 test_importLibraryProject_withClass_constInstanceCreation() { |
| 5442 return test_importLibraryProject_withClass_constInstanceCreation(); |
| 5443 } |
| 5444 |
| 5445 @failingTest |
| 5446 @override |
| 5447 test_importLibraryProject_withClass_hasOtherLibraryWithPrefix() { |
| 5448 return test_importLibraryProject_withClass_hasOtherLibraryWithPrefix(); |
| 5449 } |
| 5450 |
| 5451 @failingTest |
| 5452 @override |
| 5453 test_importLibraryProject_withClass_inParentFolder() { |
| 5454 return test_importLibraryProject_withClass_inParentFolder(); |
| 5455 } |
| 5456 |
| 5457 @failingTest |
| 5458 @override |
| 5459 test_importLibraryProject_withClass_inRelativeFolder() { |
| 5460 return test_importLibraryProject_withClass_inRelativeFolder(); |
| 5461 } |
| 5462 |
| 5463 @failingTest |
| 5464 @override |
| 5465 test_importLibraryProject_withClass_inSameFolder() { |
| 5466 return test_importLibraryProject_withClass_inSameFolder(); |
| 5467 } |
| 5468 |
| 5469 @failingTest |
| 5470 @override |
| 5471 test_importLibraryProject_withFunction() { |
| 5472 return test_importLibraryProject_withFunction(); |
| 5473 } |
| 5474 |
| 5475 @failingTest |
| 5476 @override |
| 5477 test_importLibraryProject_withFunction_unresolvedMethod() { |
| 5478 return test_importLibraryProject_withFunction_unresolvedMethod(); |
| 5479 } |
| 5480 |
| 5481 @failingTest |
| 5482 @override |
| 5483 test_importLibraryProject_withFunctionTypeAlias() { |
| 5484 return test_importLibraryProject_withFunctionTypeAlias(); |
| 5485 } |
| 5486 |
| 5487 @failingTest |
| 5488 @override |
| 5489 test_importLibraryProject_withTopLevelVariable() { |
| 5490 return test_importLibraryProject_withTopLevelVariable(); |
| 5491 } |
| 5492 |
| 5493 @failingTest |
| 5494 @override |
| 5495 test_importLibrarySdk_withClass_itemOfList() { |
| 5496 return test_importLibrarySdk_withClass_itemOfList(); |
| 5497 } |
| 5498 |
| 5499 @failingTest |
| 5500 @override |
| 5501 test_importLibrarySdk_withTopLevelVariable() { |
| 5502 return test_importLibrarySdk_withTopLevelVariable(); |
| 5503 } |
| 5504 |
| 5505 @failingTest |
| 5506 @override |
| 5507 test_importLibrarySdk_withTopLevelVariable_annotation() { |
| 5508 return test_importLibrarySdk_withTopLevelVariable_annotation(); |
| 5509 } |
| 5510 |
| 5511 @failingTest |
| 5512 @override |
| 5513 test_importLibraryShow_project() { |
| 5514 return test_importLibraryShow_project(); |
| 5515 } |
| 5516 |
| 5517 @failingTest |
| 5518 @override |
| 5519 test_noException_1() { |
| 5520 return test_noException_1(); |
| 5521 } |
| 5522 |
| 5523 @failingTest |
| 5524 @override |
| 5525 test_replaceImportUri_inProject() { |
| 5526 return test_replaceImportUri_inProject(); |
| 5527 } |
| 5528 |
| 5529 @failingTest |
| 5530 @override |
| 5531 test_replaceImportUri_package() { |
| 5532 return test_replaceImportUri_package(); |
| 5533 } |
| 5534 } |
| 5535 |
| 5536 @reflectiveTest |
| 5356 class LintFixTest extends BaseFixProcessorTest { | 5537 class LintFixTest extends BaseFixProcessorTest { |
| 5357 AnalysisError error; | 5538 AnalysisError error; |
| 5358 | 5539 |
| 5359 Future applyFix(FixKind kind) async { | 5540 Future applyFix(FixKind kind) async { |
| 5360 fix = await _assertHasFix(kind, error); | 5541 fix = await _assertHasFix(kind, error); |
| 5361 change = fix.change; | 5542 change = fix.change; |
| 5362 // apply to "file" | 5543 // apply to "file" |
| 5363 List<SourceFileEdit> fileEdits = change.edits; | 5544 List<SourceFileEdit> fileEdits = change.edits; |
| 5364 expect(fileEdits, hasLength(1)); | 5545 expect(fileEdits, hasLength(1)); |
| 5365 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); | 5546 resultCode = SourceEdit.applySequence(testCode, change.edits[0].edits); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5572 var v = 42; | 5753 var v = 42; |
| 5573 print('v: $v'); | 5754 print('v: $v'); |
| 5574 } | 5755 } |
| 5575 '''); | 5756 '''); |
| 5576 } | 5757 } |
| 5577 | 5758 |
| 5578 void verifyResult(String expectedResult) { | 5759 void verifyResult(String expectedResult) { |
| 5579 expect(resultCode, expectedResult); | 5760 expect(resultCode, expectedResult); |
| 5580 } | 5761 } |
| 5581 } | 5762 } |
| 5763 |
| 5764 class _DartFixContextImpl implements DartFixContext { |
| 5765 @override |
| 5766 final ResourceProvider resourceProvider; |
| 5767 |
| 5768 @override |
| 5769 final GetTopLevelDeclarations getTopLevelDeclarations; |
| 5770 |
| 5771 @override |
| 5772 final AnalysisContext analysisContext; |
| 5773 |
| 5774 @override |
| 5775 final CompilationUnit unit; |
| 5776 |
| 5777 @override |
| 5778 final AnalysisError error; |
| 5779 |
| 5780 _DartFixContextImpl(this.resourceProvider, this.getTopLevelDeclarations, |
| 5781 this.analysisContext, this.unit, this.error); |
| 5782 } |
| OLD | NEW |