@@ -16,9 +16,12 @@ import Decorators._
1616import ast .Trees ._
1717import TreeTransforms .TransformerInfo
1818
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
2225 */
2326class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
2427 import ast .tpd ._
@@ -28,7 +31,7 @@ class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
2831 private val Immovable = Deferred | Accessor | JavaStatic
2932
3033 def shouldBeStatic (sd : SymDenotation )(implicit ctx : Context ) =
31- sd.current(ctx.withPhase(thisTransform)).asInstanceOf [ SymDenotation ]
34+ sd.current(ctx.withPhase(thisTransform)).asSymDenotation
3235 .is(PrivateMethod , butNot = Immovable ) &&
3336 (sd.owner.is(Trait ) || sd.is(NotJavaPrivate ))
3437
@@ -68,6 +71,10 @@ class PrivateToStatic extends MiniPhase with SymTransformer { thisTransform =>
6871 if (shouldBeStatic(ctx.owner.enclosingMethod)) ref(thisParam).withPos(tree.pos)
6972 else tree
7073
74+ /** Rwrites a call to a method `m` which is made static as folows:
75+ *
76+ * qual.m(args) --> m(qual, args)
77+ */
7178 override def transformApply (tree : Apply )(implicit ctx : Context , info : TransformerInfo ) =
7279 tree.fun match {
7380 case fun @ Select (qual, name) if shouldBeStatic(fun.symbol) =>
0 commit comments