@@ -16,9 +16,12 @@ import Decorators._
16
16
import ast .Trees ._
17
17
import TreeTransforms .TransformerInfo
18
18
19
- /** The preceding lambda lift and flatten phases move symbols to different scopes
20
- * and rename them. This miniphase cleans up afterwards and makes sure that all
21
- * class scopes contain the symbols defined in them.
19
+ /** Makes private methods static, provided they not deferred, accessors, or static,
20
+ * by rewriting a method `m` in class `C` as follows:
21
+ *
22
+ * private def m(ps) = e
23
+ *
24
+ * --> private static def($this: C, ps) = [this -> $this] e
22
25
*/
23
26
class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
24
27
import ast .tpd ._
@@ -28,7 +31,7 @@ class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
28
31
private val Immovable = Deferred | Accessor | JavaStatic
29
32
30
33
def shouldBeStatic (sd : SymDenotation )(implicit ctx : Context ) =
31
- sd.current(ctx.withPhase(thisTransform)).asInstanceOf [ SymDenotation ]
34
+ sd.current(ctx.withPhase(thisTransform)).asSymDenotation
32
35
.is(PrivateMethod , butNot = Immovable ) &&
33
36
(sd.owner.is(Trait ) || sd.is(NotJavaPrivate ))
34
37
@@ -68,6 +71,10 @@ class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
68
71
if (shouldBeStatic(ctx.owner.enclosingMethod)) ref(thisParam).withPos(tree.pos)
69
72
else tree
70
73
74
+ /** Rwrites a call to a method `m` which is made static as folows:
75
+ *
76
+ * qual.m(args) --> m(qual, args)
77
+ */
71
78
override def transformApply (tree : Apply )(implicit ctx : Context , info : TransformerInfo ) =
72
79
tree.fun match {
73
80
case fun @ Select (qual, name) if shouldBeStatic(fun.symbol) =>
0 commit comments