@@ -8,7 +8,7 @@ import org.hamcrest.Matchers.hasSize
8
8
import org.junit.Assert.assertThat
9
9
import org.junit.Test
10
10
11
- class ImplementAbstractFunctionsQuickFixTest : SingleFileTestFixture (" quickfixes" , " SomeSubclass.kt" ) {
11
+ class ImplementAbstractMembersQuickFixTest : SingleFileTestFixture (" quickfixes" , " SomeSubclass.kt" ) {
12
12
@Test
13
13
fun `gets workspace edit for all abstract methods when none are implemented` () {
14
14
val diagnostic = Diagnostic (range(3 , 1 , 3 , 19 ), " " )
@@ -90,7 +90,7 @@ class ImplementAbstractFunctionsQuickFixTest : SingleFileTestFixture("quickfixes
90
90
}
91
91
}
92
92
93
- class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture (" quickfixes" , " samefile.kt" ) {
93
+ class ImplementAbstractMembersQuickFixSameFileTest : SingleFileTestFixture (" quickfixes" , " samefile.kt" ) {
94
94
@Test
95
95
fun `should find no code actions` () {
96
96
val only = listOf (CodeActionKind .QuickFix )
@@ -111,7 +111,7 @@ class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture("qu
111
111
assertThat(codeActionResult, hasSize(1 ))
112
112
val codeAction = codeActionResult[0 ].right
113
113
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
114
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
114
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
115
115
assertThat(codeAction.diagnostics, equalTo(listOf (diagnostics[0 ])))
116
116
117
117
val textEdit = codeAction.edit.changes
@@ -134,7 +134,7 @@ class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture("qu
134
134
assertThat(codeActionResult, hasSize(1 ))
135
135
val codeAction = codeActionResult[0 ].right
136
136
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
137
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
137
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
138
138
139
139
val textEdit = codeAction.edit.changes
140
140
val key = workspaceRoot.resolve(file).toUri().toString()
@@ -160,7 +160,7 @@ class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture("qu
160
160
assertThat(codeActionResult, hasSize(1 ))
161
161
val codeAction = codeActionResult[0 ].right
162
162
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
163
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
163
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
164
164
165
165
val textEdit = codeAction.edit.changes
166
166
val key = workspaceRoot.resolve(file).toUri().toString()
@@ -182,7 +182,7 @@ class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture("qu
182
182
assertThat(codeActionResult, hasSize(1 ))
183
183
val codeAction = codeActionResult[0 ].right
184
184
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
185
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
185
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
186
186
187
187
val textEdit = codeAction.edit.changes
188
188
val key = workspaceRoot.resolve(file).toUri().toString()
@@ -193,9 +193,57 @@ class ImplementAbstractFunctionsQuickFixSameFileTest : SingleFileTestFixture("qu
193
193
assertThat(functionToImplementEdit?.range, equalTo(range(25 , 48 , 25 , 48 )))
194
194
assertThat(functionToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override fun myMethod(myStr: String?): String? { }" ))
195
195
}
196
+
197
+ @Test
198
+ fun `should find abstract variable and function` () {
199
+ val only = listOf (CodeActionKind .QuickFix )
200
+ val codeActionParams = codeActionParams(file, 35 , 1 , 35 , 18 , diagnostics, only)
201
+
202
+ val codeActionResult = languageServer.textDocumentService.codeAction(codeActionParams).get()
203
+
204
+ assertThat(codeActionResult, hasSize(1 ))
205
+ val codeAction = codeActionResult[0 ].right
206
+ assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
207
+ assertThat(codeAction.title, equalTo(" Implement abstract members" ))
208
+
209
+ val textEdit = codeAction.edit.changes
210
+ val key = workspaceRoot.resolve(file).toUri().toString()
211
+ assertThat(textEdit.containsKey(key), equalTo(true ))
212
+ assertThat(textEdit[key], hasSize(2 ))
213
+
214
+ val firstMemberToImplementEdit = textEdit[key]?.get(0 )
215
+ assertThat(firstMemberToImplementEdit?.range, equalTo(range(35 , 35 , 35 , 35 )))
216
+ assertThat(firstMemberToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override val name: String = TODO(\" SET VALUE\" )" ))
217
+
218
+ val secondMemberToImplementEdit = textEdit[key]?.get(1 )
219
+ assertThat(secondMemberToImplementEdit?.range, equalTo(range(35 , 35 , 35 , 35 )))
220
+ assertThat(secondMemberToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override fun myFun() { }" ))
221
+ }
222
+
223
+ @Test
224
+ fun `should find abstract function when variable is already implemented` () {
225
+ val only = listOf (CodeActionKind .QuickFix )
226
+ val codeActionParams = codeActionParams(file, 37 , 1 , 37 , 17 , diagnostics, only)
227
+
228
+ val codeActionResult = languageServer.textDocumentService.codeAction(codeActionParams).get()
229
+
230
+ assertThat(codeActionResult, hasSize(1 ))
231
+ val codeAction = codeActionResult[0 ].right
232
+ assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
233
+ assertThat(codeAction.title, equalTo(" Implement abstract members" ))
234
+
235
+ val textEdit = codeAction.edit.changes
236
+ val key = workspaceRoot.resolve(file).toUri().toString()
237
+ assertThat(textEdit.containsKey(key), equalTo(true ))
238
+ assertThat(textEdit[key], hasSize(1 ))
239
+
240
+ val memberToImplementEdit = textEdit[key]?.get(0 )
241
+ assertThat(memberToImplementEdit?.range, equalTo(range(38 , 31 , 38 , 31 )))
242
+ assertThat(memberToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override fun myFun() { }" ))
243
+ }
196
244
}
197
245
198
- class ImplementAbstractFunctionsQuickFixExternalLibraryTest : SingleFileTestFixture (" quickfixes" , " standardlib.kt" ) {
246
+ class ImplementAbstractMembersQuickFixExternalLibraryTest : SingleFileTestFixture (" quickfixes" , " standardlib.kt" ) {
199
247
@Test
200
248
fun `should find one abstract method from Runnable to implement` () {
201
249
val only = listOf (CodeActionKind .QuickFix )
@@ -206,7 +254,7 @@ class ImplementAbstractFunctionsQuickFixExternalLibraryTest : SingleFileTestFixt
206
254
assertThat(codeActionResult, hasSize(1 ))
207
255
val codeAction = codeActionResult[0 ].right
208
256
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
209
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
257
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
210
258
211
259
val textEdit = codeAction.edit.changes
212
260
val key = workspaceRoot.resolve(file).toUri().toString()
@@ -228,7 +276,7 @@ class ImplementAbstractFunctionsQuickFixExternalLibraryTest : SingleFileTestFixt
228
276
assertThat(codeActionResult, hasSize(1 ))
229
277
val codeAction = codeActionResult[0 ].right
230
278
assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
231
- assertThat(codeAction.title, equalTo(" Implement abstract functions " ))
279
+ assertThat(codeAction.title, equalTo(" Implement abstract members " ))
232
280
233
281
val textEdit = codeAction.edit.changes
234
282
val key = workspaceRoot.resolve(file).toUri().toString()
@@ -239,4 +287,30 @@ class ImplementAbstractFunctionsQuickFixExternalLibraryTest : SingleFileTestFixt
239
287
assertThat(functionToImplementEdit?.range, equalTo(range(7 , 42 , 7 , 42 )))
240
288
assertThat(functionToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override fun compare(p0: String, p1: String): Int { }" ))
241
289
}
290
+
291
+ @Test
292
+ fun `should find abstract members for AbstractList` () {
293
+ val only = listOf (CodeActionKind .QuickFix )
294
+ val codeActionParams = codeActionParams(file, 9 , 1 , 9 , 13 , diagnostics, only)
295
+
296
+ val codeActionResult = languageServer.textDocumentService.codeAction(codeActionParams).get()
297
+
298
+ assertThat(codeActionResult, hasSize(1 ))
299
+ val codeAction = codeActionResult[0 ].right
300
+ assertThat(codeAction.kind, equalTo(CodeActionKind .QuickFix ))
301
+ assertThat(codeAction.title, equalTo(" Implement abstract members" ))
302
+
303
+ val textEdit = codeAction.edit.changes
304
+ val key = workspaceRoot.resolve(file).toUri().toString()
305
+ assertThat(textEdit.containsKey(key), equalTo(true ))
306
+ assertThat(textEdit[key], hasSize(2 ))
307
+
308
+ val firstMemberToImplementEdit = textEdit[key]?.get(0 )
309
+ assertThat(firstMemberToImplementEdit?.range, equalTo(range(9 , 40 , 9 , 40 )))
310
+ assertThat(firstMemberToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override val size: Int = TODO(\" SET VALUE\" )" ))
311
+
312
+ val secondMemberToImplementEdit = textEdit[key]?.get(1 )
313
+ assertThat(secondMemberToImplementEdit?.range, equalTo(range(9 , 40 , 9 , 40 )))
314
+ assertThat(secondMemberToImplementEdit?.newText, equalTo(System .lineSeparator() + System .lineSeparator() + " override fun get(index: Int): String { }" ))
315
+ }
242
316
}
0 commit comments