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

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

Issue 2144763002: Issue 26249. Quick Assist to convert getters into final fields. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Don't suggest when there is the corresponding setter in the class. Created 4 years, 5 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/assist_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/assist_test.dart
diff --git a/pkg/analysis_server/test/services/correction/assist_test.dart b/pkg/analysis_server/test/services/correction/assist_test.dart
index 680de778f1ecabab5fce7bb49bfa5d168f03475a..445acacab5e75b6b41a9d85772c778d928a6ec8e 100644
--- a/pkg/analysis_server/test/services/correction/assist_test.dart
+++ b/pkg/analysis_server/test/services/correction/assist_test.dart
@@ -1432,6 +1432,177 @@ class A {
''');
}
+ test_convertToFinalField_BAD_hasSetter_inThisClass() async {
+ resolveTestUnit('''
+class A {
+ int get foo => null;
+ void set foo(_) {}
+}
+''');
+ await assertNoAssistAt('get foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
+ }
+
+ test_convertToFinalField_BAD_notExpressionBody() async {
+ resolveTestUnit('''
+class A {
+ int get foo {
+ int v = 1 + 2;
+ return v + 3;
+ }
+}
+''');
+ await assertNoAssistAt('get foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
+ }
+
+ test_convertToFinalField_BAD_notGetter() async {
+ resolveTestUnit('''
+class A {
+ int foo() => 42;
+}
+''');
+ await assertNoAssistAt('foo', DartAssistKind.CONVERT_INTO_FINAL_FIELD);
+ }
+
+ test_convertToFinalField_OK_blockBody_onlyReturnStatement() async {
+ resolveTestUnit('''
+class A {
+ int get foo {
+ return 1 + 2;
+ }
+}
+''');
+ await assertHasAssistAt(
+ 'get foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final int foo = 1 + 2;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_hasOverride() async {
+ resolveTestUnit('''
+const myAnnotation = const Object();
+class A {
+ @myAnnotation
+ int get foo => 42;
+}
+''');
+ await assertHasAssistAt(
+ 'get foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+const myAnnotation = const Object();
+class A {
+ @myAnnotation
+ final int foo = 42;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_hasSetter_inSuper() async {
+ resolveTestUnit('''
+class A {
+ void set foo(_) {}
+}
+class B extends A {
+ int get foo => null;
+}
+''');
+ await assertHasAssistAt(
+ 'get foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ void set foo(_) {}
+}
+class B extends A {
+ final int foo;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_notNull() async {
+ resolveTestUnit('''
+class A {
+ int get foo => 1 + 2;
+}
+''');
+ await assertHasAssistAt(
+ 'get foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final int foo = 1 + 2;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_null() async {
+ resolveTestUnit('''
+class A {
+ int get foo => null;
+}
+''');
+ await assertHasAssistAt(
+ 'get foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final int foo;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_onName() async {
+ resolveTestUnit('''
+class A {
+ int get foo => 42;
+}
+''');
+ await assertHasAssistAt(
+ 'foo',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final int foo = 42;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_onReturnType_parameterized() async {
+ resolveTestUnit('''
+class A {
+ List<int> get foo => null;
+}
+''');
+ await assertHasAssistAt(
+ 'nt> get',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final List<int> foo;
+}
+''');
+ }
+
+ test_convertToFinalField_OK_onReturnType_simple() async {
+ resolveTestUnit('''
+class A {
+ int get foo => 42;
+}
+''');
+ await assertHasAssistAt(
+ 'int get',
+ DartAssistKind.CONVERT_INTO_FINAL_FIELD,
+ '''
+class A {
+ final int foo = 42;
+}
+''');
+ }
+
test_convertToForIndex_BAD_bodyNotBlock() async {
resolveTestUnit('''
main(List<String> items) {
« no previous file with comments | « pkg/analysis_server/lib/src/services/correction/assist_internal.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698