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

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

Issue 806933002: Issue 21883. Add checks if type parameters can be used. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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
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:analysis_server/src/services/index/index.dart'; 9 import 'package:analysis_server/src/services/index/index.dart';
10 import 'package:analysis_server/src/services/index/local_memory_index.dart'; 10 import 'package:analysis_server/src/services/index/local_memory_index.dart';
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 class A { 226 class A {
227 A.named(int i, double d) { 227 A.named(int i, double d) {
228 } 228 }
229 229
230 method() {} 230 method() {}
231 } 231 }
232 main() { 232 main() {
233 new A.named(1, 2.0); 233 new A.named(1, 2.0);
234 } 234 }
235 '''); 235 ''');
236 _assertLinkedGroup( 236 _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']);
237 change.linkedEditGroups[0],
238 ['named(int ', 'named(1']);
239 } 237 }
240 238
241 void test_createConstructorSuperExplicit() { 239 void test_createConstructorSuperExplicit() {
242 _indexTestUnit(''' 240 _indexTestUnit('''
243 class A { 241 class A {
244 A(bool p1, int p2, double p3, String p4, {p5}); 242 A(bool p1, int p2, double p3, String p4, {p5});
245 } 243 }
246 class B extends A { 244 class B extends A {
247 B() {} 245 B() {}
248 } 246 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 class A { 519 class A {
522 var test; 520 var test;
523 521
524 main() { 522 main() {
525 test; 523 test;
526 } 524 }
527 } 525 }
528 '''); 526 ''');
529 } 527 }
530 528
529 void test_createField_setter_generic_BAD() {
530 _indexTestUnit('''
531 class A {
532 }
533 class B<T> {
534 List<T> items;
535 main(A a) {
536 a.test = items;
537 }
538 }
539 ''');
540 assertHasFix(FixKind.CREATE_FIELD, '''
541 class A {
542 List test;
543 }
544 class B<T> {
545 List<T> items;
546 main(A a) {
547 a.test = items;
548 }
549 }
550 ''');
551 }
552
553 void test_createField_setter_generic_OK_local() {
554 _indexTestUnit('''
555 class A<T> {
556 List<T> items;
557
558 main(A a) {
559 test = items;
560 }
561 }
562 ''');
563 assertHasFix(FixKind.CREATE_FIELD, '''
564 class A<T> {
565 List<T> items;
566
567 List<T> test;
568
569 main(A a) {
570 test = items;
571 }
572 }
573 ''');
574 }
575
531 void test_createField_setter_qualified_instance_hasField() { 576 void test_createField_setter_qualified_instance_hasField() {
532 _indexTestUnit(''' 577 _indexTestUnit('''
533 class A { 578 class A {
534 int aaa; 579 int aaa;
535 int zzz; 580 int zzz;
536 581
537 existingMethod() {} 582 existingMethod() {}
538 } 583 }
539 main(A a) { 584 main(A a) {
540 a.test = 5; 585 a.test = 5;
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 main() { 1867 main() {
1823 int v = myUndefinedFunction(1, 2.0, '3'); 1868 int v = myUndefinedFunction(1, 2.0, '3');
1824 } 1869 }
1825 } 1870 }
1826 1871
1827 int myUndefinedFunction(int i, double d, String s) { 1872 int myUndefinedFunction(int i, double d, String s) {
1828 } 1873 }
1829 '''); 1874 ''');
1830 } 1875 }
1831 1876
1877 void test_undefinedFunction_create_generic_BAD() {
1878 _indexTestUnit('''
1879 class A<T> {
1880 Map<int, T> items;
1881 main() {
1882 process(items);
1883 }
1884 }
1885 ''');
1886 assertHasFix(FixKind.CREATE_FUNCTION, '''
1887 class A<T> {
1888 Map<int, T> items;
1889 main() {
1890 process(items);
1891 }
1892 }
1893
1894 void process(Map items) {
1895 }
1896 ''');
1897 }
1898
1899 void test_undefinedFunction_create_generic_OK() {
1900 _indexTestUnit('''
1901 class A {
1902 List<int> items;
1903 main() {
1904 process(items);
1905 }
1906 }
1907 ''');
1908 assertHasFix(FixKind.CREATE_FUNCTION, '''
1909 class A {
1910 List<int> items;
1911 main() {
1912 process(items);
1913 }
1914 }
1915
1916 void process(List<int> items) {
1917 }
1918 ''');
1919 }
1920
1832 void test_undefinedFunction_create_returnType_bool_expressions() { 1921 void test_undefinedFunction_create_returnType_bool_expressions() {
1833 assert_undefinedFunction_create_returnType_bool("!test();"); 1922 assert_undefinedFunction_create_returnType_bool("!test();");
1834 assert_undefinedFunction_create_returnType_bool("b && test();"); 1923 assert_undefinedFunction_create_returnType_bool("b && test();");
1835 assert_undefinedFunction_create_returnType_bool("test() && b;"); 1924 assert_undefinedFunction_create_returnType_bool("test() && b;");
1836 assert_undefinedFunction_create_returnType_bool("b || test();"); 1925 assert_undefinedFunction_create_returnType_bool("b || test();");
1837 assert_undefinedFunction_create_returnType_bool("test() || b;"); 1926 assert_undefinedFunction_create_returnType_bool("test() || b;");
1838 } 1927 }
1839 1928
1840 void test_undefinedFunction_create_returnType_bool_statements() { 1929 void test_undefinedFunction_create_returnType_bool_statements() {
1841 assert_undefinedFunction_create_returnType_bool("assert ( test() );"); 1930 assert_undefinedFunction_create_returnType_bool("assert ( test() );");
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 } 2072 }
1984 '''); 2073 ''');
1985 assertHasFix(FixKind.CHANGE_TO, ''' 2074 assertHasFix(FixKind.CHANGE_TO, '''
1986 myFunction() {} 2075 myFunction() {}
1987 main() { 2076 main() {
1988 myFunction(); 2077 myFunction();
1989 } 2078 }
1990 '''); 2079 ''');
1991 } 2080 }
1992 2081
2082 void test_undefinedMethod_create_generic_BAD() {
2083 _indexTestUnit('''
2084 class A<T> {
2085 B b;
2086 Map<int, T> items;
2087 main() {
2088 b.process(items);
2089 }
2090 }
2091
2092 class B {
2093 }
2094 ''');
2095 assertHasFix(FixKind.CREATE_METHOD, '''
2096 class A<T> {
2097 B b;
2098 Map<int, T> items;
2099 main() {
2100 b.process(items);
2101 }
2102 }
2103
2104 class B {
2105 void process(Map items) {
2106 }
2107 }
2108 ''');
2109 }
2110
2111 void test_undefinedMethod_create_generic_OK_literal() {
2112 _indexTestUnit('''
2113 class A {
2114 B b;
2115 List<int> items;
2116 main() {
2117 b.process(items);
2118 }
2119 }
2120
2121 class B {
2122 }
2123 ''');
2124 assertHasFix(FixKind.CREATE_METHOD, '''
2125 class A {
2126 B b;
2127 List<int> items;
2128 main() {
2129 b.process(items);
2130 }
2131 }
2132
2133 class B {
2134 void process(List<int> items) {
2135 }
2136 }
2137 ''');
2138 }
2139
2140 void test_undefinedMethod_create_generic_OK_local() {
2141 _indexTestUnit('''
2142 class A<T> {
2143 List<T> items;
2144 main() {
2145 process(items);
2146 }
2147 }
2148 ''');
2149 assertHasFix(FixKind.CREATE_METHOD, '''
2150 class A<T> {
2151 List<T> items;
2152 main() {
2153 process(items);
2154 }
2155
2156 void process(List<T> items) {
2157 }
2158 }
2159 ''');
2160 }
2161
1993 void test_undefinedMethod_createQualified_fromClass() { 2162 void test_undefinedMethod_createQualified_fromClass() {
1994 _indexTestUnit(''' 2163 _indexTestUnit('''
1995 class A { 2164 class A {
1996 } 2165 }
1997 main() { 2166 main() {
1998 A.myUndefinedMethod(); 2167 A.myUndefinedMethod();
1999 } 2168 }
2000 '''); 2169 ''');
2001 assertHasFix(FixKind.CREATE_METHOD, ''' 2170 assertHasFix(FixKind.CREATE_METHOD, '''
2002 class A { 2171 class A {
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 positions.add(new Position(testFile, offset)); 2517 positions.add(new Position(testFile, offset));
2349 } 2518 }
2350 return positions; 2519 return positions;
2351 } 2520 }
2352 2521
2353 void _indexTestUnit(String code) { 2522 void _indexTestUnit(String code) {
2354 resolveTestUnit(code); 2523 resolveTestUnit(code);
2355 index.indexUnit(context, testUnit); 2524 index.indexUnit(context, testUnit);
2356 } 2525 }
2357 } 2526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698