This repository was archived by the owner on Sep 3, 2020. It is now read-only.
File tree 2 files changed +66
-3
lines changed
main/scala/scala/tools/refactoring/implementations
test/scala/scala/tools/refactoring/tests/implementations
2 files changed +66
-3
lines changed Original file line number Diff line number Diff line change @@ -35,20 +35,32 @@ abstract class ImplementMethods extends MultiStageRefactoring with analysis.Inde
35
35
}
36
36
}
37
37
38
+ private def templateAncestry (template : Template ): List [Template ] =
39
+ template :: {
40
+ for {
41
+ parent <- template.parents
42
+ parentImp <- index.declaration(parent.symbol).toList collect {
43
+ case ClassDef (_, _, _, impl) => impl
44
+ }
45
+ ancenstor <- templateAncestry(parentImp)
46
+ } yield ancenstor
47
+ }
48
+
38
49
override def prepare (s : Selection ): Either [PreparationError , PreparationResult ] = {
39
50
40
51
41
52
// Expand the selection to the concrete type when a kind was initially selected.
42
53
val maybeSelectedTemplate = (s:: s.expandToNextEnclosingTree.toList) flatMap { sel : Selection =>
43
54
index.declaration(sel.enclosingTree.symbol)
44
55
} collectFirst {
45
- case templateDeclaration : ClassDef => templateDeclaration
56
+ case templateDeclaration : ClassDef => templateDeclaration.impl
46
57
}
47
58
48
59
// Get a sequence of methods found in the selected mixed trait.
49
60
val methodsToImplement = for {
50
- selectedTemplateDeclaration <- maybeSelectedTemplate.toList
51
- unimplementedMethod <- selectedTemplateDeclaration.impl.body collect {
61
+ selectedTemplate <- maybeSelectedTemplate.toList
62
+ selectedDeclaration <- templateAncestry(selectedTemplate)
63
+ unimplementedMethod <- selectedDeclaration.body collect {
52
64
case methodDeclaration : DefDef if methodDeclaration.rhs.isEmpty =>
53
65
methodDeclaration
54
66
}
Original file line number Diff line number Diff line change @@ -223,4 +223,55 @@ class ImplementMethodsTest extends TestHelper with TestRefactoring {
223
223
} applyRefactoring implementMethods
224
224
225
225
226
+ @ Test
227
+ def implementMethodFromAncestry () = new FileSet () {
228
+ """
229
+ |package implementMethods
230
+ |
231
+ |trait R {
232
+ | def k: Unit
233
+ |}
234
+ |
235
+ |trait T {
236
+ | def f(x: Int): String
237
+ |}
238
+ |
239
+ |trait S extends T {
240
+ | def g(x: Int): Int
241
+ |}
242
+ |
243
+ |object Obj extends /*(*/S/*)*/ with R {
244
+ | val x: Int = ???
245
+ |}
246
+ """ .stripMargin becomes
247
+ """
248
+ |package implementMethods
249
+ |
250
+ |trait R {
251
+ | def k: Unit
252
+ |}
253
+ |
254
+ |trait T {
255
+ | def f(x: Int): String
256
+ |}
257
+ |
258
+ |trait S extends T {
259
+ | def g(x: Int): Int
260
+ |}
261
+ |
262
+ |object Obj extends /*(*/S/*)*/ with R {
263
+ | val x: Int = ???
264
+ |
265
+ | def g(x: Int): Int = {
266
+ | ???
267
+ | }
268
+ |
269
+ | def f(x: Int): String = {
270
+ | ???
271
+ | }
272
+ |}
273
+ """ .stripMargin
274
+
275
+ } applyRefactoring implementMethods
276
+
226
277
}
You can’t perform that action at this time.
0 commit comments