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

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

Issue 965013002: Issue 22593. Quick fix 'import library' for typedefs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'package:analysis_server/src/protocol.dart' hide AnalysisError; 7 import 'package:analysis_server/src/protocol.dart' hide AnalysisError;
8 import 'package:analysis_server/src/services/correction/fix.dart'; 8 import 'package:analysis_server/src/services/correction/fix.dart';
9 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/source/package_map_resolver.dart'; 10 import 'package:analyzer/source/package_map_resolver.dart';
(...skipping 1722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 print(0) 1733 print(0)
1734 } 1734 }
1735 '''); 1735 ''');
1736 assertHasFix(FixKind.INSERT_SEMICOLON, ''' 1736 assertHasFix(FixKind.INSERT_SEMICOLON, '''
1737 main() { 1737 main() {
1738 print(0); 1738 print(0);
1739 } 1739 }
1740 '''); 1740 ''');
1741 } 1741 }
1742 1742
1743 void test_importLibraryPackage_withType() { 1743 void test_importLibraryPackage_withClass() {
1744 _configureMyPkg(''' 1744 _configureMyPkg('''
1745 library my_lib; 1745 library my_lib;
1746 class Test {} 1746 class Test {}
1747 '''); 1747 ''');
1748 // try to find a fix 1748 // try to find a fix
1749 resolveTestUnit(''' 1749 resolveTestUnit('''
1750 main() { 1750 main() {
1751 Test test = null; 1751 Test test = null;
1752 } 1752 }
1753 '''); 1753 ''');
1754 performAllAnalysisTasks(); 1754 performAllAnalysisTasks();
1755 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1755 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1756 import 'package:my_pkg/my_lib.dart'; 1756 import 'package:my_pkg/my_lib.dart';
1757 1757
1758 main() { 1758 main() {
1759 Test test = null; 1759 Test test = null;
1760 } 1760 }
1761 '''); 1761 ''');
1762 } 1762 }
1763 1763
1764 void test_importLibraryPrefix_withTopLevelVariable() { 1764 void test_importLibraryPrefix_withClass() {
1765 resolveTestUnit('''
1766 import 'dart:math' as pref;
1767 main() {
1768 print(pref.E);
1769 print(PI);
1770 }
1771 ''');
1772 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, '''
1773 import 'dart:math' as pref;
1774 main() {
1775 print(pref.E);
1776 print(pref.PI);
1777 }
1778 ''');
1779 }
1780
1781 void test_importLibraryPrefix_withType() {
1782 resolveTestUnit(''' 1765 resolveTestUnit('''
1783 import 'dart:async' as pref; 1766 import 'dart:async' as pref;
1784 main() { 1767 main() {
1785 pref.Stream s = null; 1768 pref.Stream s = null;
1786 Future f = null; 1769 Future f = null;
1787 } 1770 }
1788 '''); 1771 ''');
1789 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' 1772 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, '''
1790 import 'dart:async' as pref; 1773 import 'dart:async' as pref;
1791 main() { 1774 main() {
1792 pref.Stream s = null; 1775 pref.Stream s = null;
1793 pref.Future f = null; 1776 pref.Future f = null;
1794 } 1777 }
1795 '''); 1778 ''');
1796 } 1779 }
1797 1780
1798 void test_importLibraryProject_withFunction() { 1781 void test_importLibraryPrefix_withTopLevelVariable() {
1799 addSource('/lib.dart', '''
1800 library lib;
1801 myFunction() {}
1802 ''');
1803 resolveTestUnit(''' 1782 resolveTestUnit('''
1783 import 'dart:math' as pref;
1804 main() { 1784 main() {
1805 myFunction(); 1785 print(pref.E);
1786 print(PI);
1806 } 1787 }
1807 '''); 1788 ''');
1808 performAllAnalysisTasks(); 1789 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, '''
1809 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1790 import 'dart:math' as pref;
1810 import 'lib.dart';
1811
1812 main() { 1791 main() {
1813 myFunction(); 1792 print(pref.E);
1793 print(pref.PI);
1814 } 1794 }
1815 '''); 1795 ''');
1816 } 1796 }
1817 1797
1818 void test_importLibraryProject_withFunction_unresolvedMethod() { 1798 void test_importLibraryProject_withClass_annotation() {
1819 addSource('/lib.dart', '''
1820 library lib;
1821 myFunction() {}
1822 ''');
1823 resolveTestUnit('''
1824 class A {
1825 main() {
1826 myFunction();
1827 }
1828 }
1829 ''');
1830 performAllAnalysisTasks();
1831 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1832 import 'lib.dart';
1833
1834 class A {
1835 main() {
1836 myFunction();
1837 }
1838 }
1839 ''');
1840 }
1841
1842 void test_importLibraryProject_withTopLevelVariable() {
1843 addSource('/lib.dart', '''
1844 library lib;
1845 int MY_VAR = 42;
1846 ''');
1847 resolveTestUnit('''
1848 main() {
1849 print(MY_VAR);
1850 }
1851 ''');
1852 performAllAnalysisTasks();
1853 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1854 import 'lib.dart';
1855
1856 main() {
1857 print(MY_VAR);
1858 }
1859 ''');
1860 }
1861
1862 void test_importLibraryProject_withType_annotation() {
1863 addSource('/lib.dart', ''' 1799 addSource('/lib.dart', '''
1864 library lib; 1800 library lib;
1865 class Test { 1801 class Test {
1866 const Test(int p); 1802 const Test(int p);
1867 } 1803 }
1868 '''); 1804 ''');
1869 resolveTestUnit(''' 1805 resolveTestUnit('''
1870 @Test(0) 1806 @Test(0)
1871 main() { 1807 main() {
1872 } 1808 }
1873 '''); 1809 ''');
1874 performAllAnalysisTasks(); 1810 performAllAnalysisTasks();
1875 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1811 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1876 import 'lib.dart'; 1812 import 'lib.dart';
1877 1813
1878 @Test(0) 1814 @Test(0)
1879 main() { 1815 main() {
1880 } 1816 }
1881 '''); 1817 ''');
1882 } 1818 }
1883 1819
1884 void test_importLibraryProject_withType_inParentFolder() { 1820 void test_importLibraryProject_withClass_inParentFolder() {
1885 testFile = '/project/bin/test.dart'; 1821 testFile = '/project/bin/test.dart';
1886 addSource('/project/lib.dart', ''' 1822 addSource('/project/lib.dart', '''
1887 library lib; 1823 library lib;
1888 class Test {} 1824 class Test {}
1889 '''); 1825 ''');
1826 resolveTestUnit('''
1827 main() {
1828 Test t = null;
1829 }
1830 ''');
1831 performAllAnalysisTasks();
1832 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1833 import '../lib.dart';
1834
1835 main() {
1836 Test t = null;
1837 }
1838 ''');
1839 }
1840
1841 void test_importLibraryProject_withClass_inRelativeFolder() {
1842 testFile = '/project/bin/test.dart';
1843 addSource('/project/lib/sub/folder/lib.dart', '''
1844 library lib;
1845 class Test {}
1846 ''');
1847 resolveTestUnit('''
1848 main() {
1849 Test t = null;
1850 }
1851 ''');
1852 performAllAnalysisTasks();
1853 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1854 import '../lib/sub/folder/lib.dart';
1855
1856 main() {
1857 Test t = null;
1858 }
1859 ''');
1860 }
1861
1862 void test_importLibraryProject_withClass_inSameFolder() {
1863 testFile = '/project/bin/test.dart';
1864 addSource('/project/bin/lib.dart', '''
1865 library lib;
1866 class Test {}
1867 ''');
1890 resolveTestUnit(''' 1868 resolveTestUnit('''
1891 main() { 1869 main() {
1892 Test t = null; 1870 Test t = null;
1893 } 1871 }
1894 '''); 1872 ''');
1895 performAllAnalysisTasks(); 1873 performAllAnalysisTasks();
1896 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1874 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1897 import '../lib.dart'; 1875 import 'lib.dart';
1898 1876
1899 main() { 1877 main() {
1900 Test t = null; 1878 Test t = null;
1901 } 1879 }
1902 '''); 1880 ''');
1903 } 1881 }
1904 1882
1905 void test_importLibraryProject_withType_inRelativeFolder() { 1883 void test_importLibraryProject_withFunction() {
1906 testFile = '/project/bin/test.dart'; 1884 addSource('/lib.dart', '''
1907 addSource('/project/lib/sub/folder/lib.dart', '''
1908 library lib; 1885 library lib;
1909 class Test {} 1886 myFunction() {}
1910 '''); 1887 ''');
1911 resolveTestUnit(''' 1888 resolveTestUnit('''
1912 main() { 1889 main() {
1913 Test t = null; 1890 myFunction();
1914 }
1915 ''');
1916 performAllAnalysisTasks();
1917 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1918 import '../lib/sub/folder/lib.dart';
1919
1920 main() {
1921 Test t = null;
1922 }
1923 ''');
1924 }
1925
1926 void test_importLibraryProject_withType_inSameFolder() {
1927 testFile = '/project/bin/test.dart';
1928 addSource('/project/bin/lib.dart', '''
1929 library lib;
1930 class Test {}
1931 ''');
1932 resolveTestUnit('''
1933 main() {
1934 Test t = null;
1935 } 1891 }
1936 '''); 1892 ''');
1937 performAllAnalysisTasks(); 1893 performAllAnalysisTasks();
1938 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' 1894 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1939 import 'lib.dart'; 1895 import 'lib.dart';
1940 1896
1941 main() { 1897 main() {
1942 Test t = null; 1898 myFunction();
1943 } 1899 }
1944 '''); 1900 ''');
1945 } 1901 }
1946 1902
1947 void test_importLibrarySdk_withTopLevelVariable() { 1903 void test_importLibraryProject_withFunction_unresolvedMethod() {
1904 addSource('/lib.dart', '''
1905 library lib;
1906 myFunction() {}
1907 ''');
1948 resolveTestUnit(''' 1908 resolveTestUnit('''
1949 main() { 1909 class A {
1950 print(PI); 1910 main() {
1911 myFunction();
1912 }
1951 } 1913 }
1952 '''); 1914 ''');
1953 performAllAnalysisTasks(); 1915 performAllAnalysisTasks();
1954 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1916 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1955 import 'dart:math'; 1917 import 'lib.dart';
1956 1918
1957 main() { 1919 class A {
1958 print(PI); 1920 main() {
1921 myFunction();
1922 }
1959 } 1923 }
1960 '''); 1924 ''');
1961 } 1925 }
1962 1926
1963 void test_importLibrarySdk_withTopLevelVariable_annotation() { 1927 void test_importLibraryProject_withFunctionTypeAlias() {
1928 testFile = '/project/bin/test.dart';
1929 addSource('/project/bin/lib.dart', '''
1930 library lib;
1931 typedef MyFunction();
1932 ''');
1964 resolveTestUnit(''' 1933 resolveTestUnit('''
1965 @PI
1966 main() { 1934 main() {
1935 MyFunction t = null;
1967 } 1936 }
1968 '''); 1937 ''');
1969 performAllAnalysisTasks(); 1938 performAllAnalysisTasks();
1970 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1939 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1971 import 'dart:math'; 1940 import 'lib.dart';
1972 1941
1973 @PI
1974 main() { 1942 main() {
1943 MyFunction t = null;
1975 } 1944 }
1976 '''); 1945 ''');
1977 } 1946 }
1978 1947
1979 void test_importLibrarySdk_withType_AsExpression() { 1948 void test_importLibraryProject_withTopLevelVariable() {
1949 addSource('/lib.dart', '''
1950 library lib;
1951 int MY_VAR = 42;
1952 ''');
1953 resolveTestUnit('''
1954 main() {
1955 print(MY_VAR);
1956 }
1957 ''');
1958 performAllAnalysisTasks();
1959 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, '''
1960 import 'lib.dart';
1961
1962 main() {
1963 print(MY_VAR);
1964 }
1965 ''');
1966 }
1967
1968 void test_importLibrarySdk_withClass_AsExpression() {
1980 resolveTestUnit(''' 1969 resolveTestUnit('''
1981 main(p) { 1970 main(p) {
1982 p as Future; 1971 p as Future;
1983 } 1972 }
1984 '''); 1973 ''');
1985 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1974 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
1986 import 'dart:async'; 1975 import 'dart:async';
1987 1976
1988 main(p) { 1977 main(p) {
1989 p as Future; 1978 p as Future;
1990 } 1979 }
1991 '''); 1980 ''');
1992 } 1981 }
1993 1982
1994 void test_importLibrarySdk_withType_invocationTarget() { 1983 void test_importLibrarySdk_withClass_invocationTarget() {
1995 resolveTestUnit(''' 1984 resolveTestUnit('''
1996 main() { 1985 main() {
1997 Future.wait(null); 1986 Future.wait(null);
1998 } 1987 }
1999 '''); 1988 ''');
2000 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 1989 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2001 import 'dart:async'; 1990 import 'dart:async';
2002 1991
2003 main() { 1992 main() {
2004 Future.wait(null); 1993 Future.wait(null);
2005 } 1994 }
2006 '''); 1995 ''');
2007 } 1996 }
2008 1997
2009 void test_importLibrarySdk_withType_IsExpression() { 1998 void test_importLibrarySdk_withClass_IsExpression() {
2010 resolveTestUnit(''' 1999 resolveTestUnit('''
2011 main(p) { 2000 main(p) {
2012 p is Future; 2001 p is Future;
2013 } 2002 }
2014 '''); 2003 ''');
2015 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2004 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2016 import 'dart:async'; 2005 import 'dart:async';
2017 2006
2018 main(p) { 2007 main(p) {
2019 p is Future; 2008 p is Future;
2020 } 2009 }
2021 '''); 2010 ''');
2022 } 2011 }
2023 2012
2024 void test_importLibrarySdk_withType_typeAnnotation() { 2013 void test_importLibrarySdk_withClass_typeAnnotation() {
2025 resolveTestUnit(''' 2014 resolveTestUnit('''
2026 main() { 2015 main() {
2027 Future f = null; 2016 Future f = null;
2028 } 2017 }
2029 '''); 2018 ''');
2030 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2019 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2031 import 'dart:async'; 2020 import 'dart:async';
2032 2021
2033 main() { 2022 main() {
2034 Future f = null; 2023 Future f = null;
2035 } 2024 }
2036 '''); 2025 ''');
2037 } 2026 }
2038 2027
2039 void test_importLibrarySdk_withType_typeAnnotation_PrefixedIdentifier() { 2028 void test_importLibrarySdk_withClass_typeAnnotation_PrefixedIdentifier() {
2040 resolveTestUnit(''' 2029 resolveTestUnit('''
2041 main() { 2030 main() {
2042 Future.wait; 2031 Future.wait;
2043 } 2032 }
2044 '''); 2033 ''');
2045 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2034 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2046 import 'dart:async'; 2035 import 'dart:async';
2047 2036
2048 main() { 2037 main() {
2049 Future.wait; 2038 Future.wait;
2050 } 2039 }
2051 '''); 2040 ''');
2052 } 2041 }
2053 2042
2054 void test_importLibrarySdk_withType_typeArgument() { 2043 void test_importLibrarySdk_withClass_typeArgument() {
2055 resolveTestUnit(''' 2044 resolveTestUnit('''
2056 main() { 2045 main() {
2057 List<Future> futures = []; 2046 List<Future> futures = [];
2058 } 2047 }
2059 '''); 2048 ''');
2060 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' 2049 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2061 import 'dart:async'; 2050 import 'dart:async';
2062 2051
2063 main() { 2052 main() {
2064 List<Future> futures = []; 2053 List<Future> futures = [];
2065 } 2054 }
2066 '''); 2055 ''');
2067 } 2056 }
2068 2057
2058 void test_importLibrarySdk_withTopLevelVariable() {
2059 resolveTestUnit('''
2060 main() {
2061 print(PI);
2062 }
2063 ''');
2064 performAllAnalysisTasks();
2065 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2066 import 'dart:math';
2067
2068 main() {
2069 print(PI);
2070 }
2071 ''');
2072 }
2073
2074 void test_importLibrarySdk_withTopLevelVariable_annotation() {
2075 resolveTestUnit('''
2076 @PI
2077 main() {
2078 }
2079 ''');
2080 performAllAnalysisTasks();
2081 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, '''
2082 import 'dart:math';
2083
2084 @PI
2085 main() {
2086 }
2087 ''');
2088 }
2089
2069 void test_importLibraryShow() { 2090 void test_importLibraryShow() {
2070 resolveTestUnit(''' 2091 resolveTestUnit('''
2071 import 'dart:async' show Stream; 2092 import 'dart:async' show Stream;
2072 main() { 2093 main() {
2073 Stream s = null; 2094 Stream s = null;
2074 Future f = null; 2095 Future f = null;
2075 } 2096 }
2076 '''); 2097 ''');
2077 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, ''' 2098 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, '''
2078 import 'dart:async' show Future, Stream; 2099 import 'dart:async' show Future, Stream;
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after
3070 3091
3071 List<Position> _findResultPositions(List<String> searchStrings) { 3092 List<Position> _findResultPositions(List<String> searchStrings) {
3072 List<Position> positions = <Position>[]; 3093 List<Position> positions = <Position>[];
3073 for (String search in searchStrings) { 3094 for (String search in searchStrings) {
3074 int offset = resultCode.indexOf(search); 3095 int offset = resultCode.indexOf(search);
3075 positions.add(new Position(testFile, offset)); 3096 positions.add(new Position(testFile, offset));
3076 } 3097 }
3077 return positions; 3098 return positions;
3078 } 3099 }
3079 } 3100 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698