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

Unified Diff: pkg/analysis_server/test/services/correction/fix_test.dart

Issue 875193002: Issue 22150. Quick fix to add a getter, in addition to create a field. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/fix_internal.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c3592214a2db867c8810849ccf4f51eca7ddda04..3ca13a611ca212017e86f741e4a5713aa680e477 100644
--- a/pkg/analysis_server/test/services/correction/fix_test.dart
+++ b/pkg/analysis_server/test/services/correction/fix_test.dart
@@ -488,7 +488,7 @@ f(String s) {}
''');
}
- void test_createField_getter_unqualified_instance_assignmentLhs() {
+ void test_createField_getter_unqualified_instance_assignmentRhs() {
_indexTestUnit('''
class A {
main() {
@@ -694,6 +694,160 @@ import 'my_file.dart';
expect(fileEdit.edits[0].replacement, contains('library my.file;'));
}
+ void test_createGetter_multiLevel() {
+ _indexTestUnit('''
+class A {
+}
+class B {
+ A a;
+}
+class C {
+ B b;
+}
+main(C c) {
+ int v = c.b.a.test;
+}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ int get test => null;
+}
+class B {
+ A a;
+}
+class C {
+ B b;
+}
+main(C c) {
+ int v = c.b.a.test;
+}
+''');
+ }
+
+ void test_createGetter_qualified_instance() {
+ _indexTestUnit('''
+class A {
+}
+main(A a) {
+ int v = a.test;
+}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ int get test => null;
+}
+main(A a) {
+ int v = a.test;
+}
+''');
+ }
+
+ void test_createGetter_qualified_instance_dynamicType() {
+ _indexTestUnit('''
+class A {
+ B b;
+ void f(Object p) {
+ p == b.test;
+ }
+}
+class B {
+}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ B b;
+ void f(Object p) {
+ p == b.test;
+ }
+}
+class B {
+ get test => null;
+}
+''');
+ }
+
+ void test_createGetter_setterContext() {
+ _indexTestUnit('''
+class A {
+}
+main(A a) {
+ a.test = 42;
+}
+''');
+ assertNoFix(FixKind.CREATE_GETTER);
+ }
+
+ void test_createGetter_unqualified_instance_asInvocationArgument() {
+ _indexTestUnit('''
+class A {
+ main() {
+ f(test);
+ }
+}
+f(String s) {}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ String get test => null;
+
+ main() {
+ f(test);
+ }
+}
+f(String s) {}
+''');
+ }
+
+ void test_createGetter_unqualified_instance_assignmentLhs() {
+ _indexTestUnit('''
+class A {
+ main() {
+ test = 42;
+ }
+}
+''');
+ assertNoFix(FixKind.CREATE_GETTER);
+ }
+
+ void test_createGetter_unqualified_instance_assignmentRhs() {
+ _indexTestUnit('''
+class A {
+ main() {
+ int v = test;
+ }
+}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ int get test => null;
+
+ main() {
+ int v = test;
+ }
+}
+''');
+ }
+
+ void test_createGetter_unqualified_instance_asStatement() {
+ _indexTestUnit('''
+class A {
+ main() {
+ test;
+ }
+}
+''');
+ // TODO
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ get test => null;
+
+ main() {
+ test;
+ }
+}
+''');
+ }
+
void test_createLocalVariable_read_typeAssignment() {
_indexTestUnit('''
main() {
@@ -1096,6 +1250,35 @@ class B extends A {
''');
}
+ void test_creatGetter_location_afterLastGetter() {
+ _indexTestUnit('''
+class A {
+ int existingField;
+
+ int get existingGetter => null;
+
+ existingMethod() {}
+}
+main(A a) {
+ int v = a.test;
+}
+''');
+ assertHasFix(FixKind.CREATE_GETTER, '''
+class A {
+ int existingField;
+
+ int get existingGetter => null;
+
+ int get test => null;
+
+ existingMethod() {}
+}
+main(A a) {
+ int v = a.test;
+}
+''');
+ }
+
void test_creationFunction_forFunctionType_cascadeSecond() {
_indexTestUnit('''
class A {
« 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