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

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: 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
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..27c8a35bfa75cf6c50d9a219c0cb034ee9d06c47 100644
--- a/pkg/analysis_server/test/services/correction/assist_test.dart
+++ b/pkg/analysis_server/test/services/correction/assist_test.dart
@@ -1432,6 +1432,127 @@ class A {
''');
}
+ test_convertToFinalField_BAD_notExpressionBody() async {
Brian Wilkerson 2016/07/12 19:52:24 What about class A { int get foo => 3; set fo
scheglov 2016/07/12 20:26:28 Thank you. Fixed.
+ resolveTestUnit('''
+class A {
+ int get foo {
+ int v = 1 + 2;
+ return v + 3;
+ }
+}
+''');
+ await assertNoAssist(DartAssistKind.CONVERT_INTO_FINAL_FIELD);
+ }
+
+ test_convertToFinalField_BAD_notGetter() async {
+ resolveTestUnit('''
+class A {
+ int foo() => 42;
+}
+''');
+ await assertNoAssist(DartAssistKind.CONVERT_INTO_FINAL_FIELD);
+ }
+
+ 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_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) {

Powered by Google App Engine
This is Rietveld 408576698