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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/test/services/correction/fix_test.dart
diff --git a/pkg/analysis_server/test/services/correction/fix_test.dart b/pkg/analysis_server/test/services/correction/fix_test.dart
index 625be28a14f37a5b6cd18bff6f61d6274ec05f12..794b2847db6d15c1ce4bb194a887e1e21a388e4a 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -233,9 +233,7 @@ main() {
new A.named(1, 2.0);
}
''');
- _assertLinkedGroup(
- change.linkedEditGroups[0],
- ['named(int ', 'named(1']);
+ _assertLinkedGroup(change.linkedEditGroups[0], ['named(int ', 'named(1']);
}
void test_createConstructorSuperExplicit() {
@@ -528,6 +526,53 @@ class A {
''');
}
+ void test_createField_setter_generic_BAD() {
+ _indexTestUnit('''
+class A {
+}
+class B<T> {
+ List<T> items;
+ main(A a) {
+ a.test = items;
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_FIELD, '''
+class A {
+ List test;
+}
+class B<T> {
+ List<T> items;
+ main(A a) {
+ a.test = items;
+ }
+}
+''');
+ }
+
+ void test_createField_setter_generic_OK_local() {
+ _indexTestUnit('''
+class A<T> {
+ List<T> items;
+
+ main(A a) {
+ test = items;
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_FIELD, '''
+class A<T> {
+ List<T> items;
+
+ List<T> test;
+
+ main(A a) {
+ test = items;
+ }
+}
+''');
+ }
+
void test_createField_setter_qualified_instance_hasField() {
_indexTestUnit('''
class A {
@@ -1829,6 +1874,50 @@ int myUndefinedFunction(int i, double d, String s) {
''');
}
+ void test_undefinedFunction_create_generic_BAD() {
+ _indexTestUnit('''
+class A<T> {
+ Map<int, T> items;
+ main() {
+ process(items);
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_FUNCTION, '''
+class A<T> {
+ Map<int, T> items;
+ main() {
+ process(items);
+ }
+}
+
+void process(Map items) {
+}
+''');
+ }
+
+ void test_undefinedFunction_create_generic_OK() {
+ _indexTestUnit('''
+class A {
+ List<int> items;
+ main() {
+ process(items);
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_FUNCTION, '''
+class A {
+ List<int> items;
+ main() {
+ process(items);
+ }
+}
+
+void process(List<int> items) {
+}
+''');
+ }
+
void test_undefinedFunction_create_returnType_bool_expressions() {
assert_undefinedFunction_create_returnType_bool("!test();");
assert_undefinedFunction_create_returnType_bool("b && test();");
@@ -1990,6 +2079,86 @@ main() {
''');
}
+ void test_undefinedMethod_create_generic_BAD() {
+ _indexTestUnit('''
+class A<T> {
+ B b;
+ Map<int, T> items;
+ main() {
+ b.process(items);
+ }
+}
+
+class B {
+}
+''');
+ assertHasFix(FixKind.CREATE_METHOD, '''
+class A<T> {
+ B b;
+ Map<int, T> items;
+ main() {
+ b.process(items);
+ }
+}
+
+class B {
+ void process(Map items) {
+ }
+}
+''');
+ }
+
+ void test_undefinedMethod_create_generic_OK_literal() {
+ _indexTestUnit('''
+class A {
+ B b;
+ List<int> items;
+ main() {
+ b.process(items);
+ }
+}
+
+class B {
+}
+''');
+ assertHasFix(FixKind.CREATE_METHOD, '''
+class A {
+ B b;
+ List<int> items;
+ main() {
+ b.process(items);
+ }
+}
+
+class B {
+ void process(List<int> items) {
+ }
+}
+''');
+ }
+
+ void test_undefinedMethod_create_generic_OK_local() {
+ _indexTestUnit('''
+class A<T> {
+ List<T> items;
+ main() {
+ process(items);
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_METHOD, '''
+class A<T> {
+ List<T> items;
+ main() {
+ process(items);
+ }
+
+ void process(List<T> items) {
+ }
+}
+''');
+ }
+
void test_undefinedMethod_createQualified_fromClass() {
_indexTestUnit('''
class A {

Powered by Google App Engine
This is Rietveld 408576698