Skip to content

Commit fbe5d21

Browse files
authored
Merge pull request #156 from lightbend/fixDispatcherSelector
Fix creating static forwarders for inherited methods
2 parents 82a46ea + c679b23 commit fbe5d21

File tree

23 files changed

+467
-30
lines changed

23 files changed

+467
-30
lines changed

plugin/src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ trait BasicTransform { this: TransformCake ⇒
1717

1818
def newTransformUnit(unit: CompilationUnit): Unit = {
1919
superTransformUnit(unit)
20-
for (c flatten(classes.flatMap(liftInterface))) {
20+
for (c flattenObjects(classes.flatMap(liftInterface))) {
2121
val out = file(c.file)
2222
try {
2323
if (c.pckg != "<empty>") out.println(s"package ${c.pckg};")

plugin/src/main/scala/com/typesafe/genjavadoc/Output.scala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ trait Output { this: TransformCake ⇒
8888
*
8989
* The first two parts are to be applied recursively to nested objects.
9090
*/
91-
def flatten(c: Vector[ClassInfo], forwarders: Boolean = true, staticScope: Boolean = true): Vector[ClassInfo] = {
91+
def flattenObjects(c: Vector[ClassInfo], forwarders: Boolean = true, staticScope: Boolean = true): Vector[ClassInfo] = {
9292
val (obj: Vector[ClassInfo], cls: Vector[ClassInfo]) = c collect PreFilter partition (_.module)
9393
val classes = cls.map(c c.name -> c).toMap
9494
val objects = obj.map(o o.name -> o).toMap
@@ -99,7 +99,7 @@ trait Output { this: TransformCake ⇒
9999
case (Some(o), Some(c)) merge(o, c, forwarders, staticScope)
100100
case (Some(o), None) if forwarders merge(o, fabricateCompanion(o), forwarders, staticScope)
101101
case (Some(o), None) Vector(mangleModule(o, addMODULE = forwarders, pruneClasses = false))
102-
case (None, Some(c)) Vector(c.copy(members = flatten(c.classMembers) ++ c.methodMembers.sortBy(_.name)))
102+
case (None, Some(c)) Vector(c.copy(members = flattenObjects(c.classMembers) ++ c.methodMembers.sortBy(_.name)))
103103
case (None, None) ???
104104
}
105105
}
@@ -131,7 +131,7 @@ trait Output { this: TransformCake ⇒
131131

132132
val members = moduleInstance ++: (
133133
if (pruneClasses) obj.methodMembers
134-
else flatten(obj.classMembers) ++ obj.methodMembers
134+
else flattenObjects(obj.classMembers) ++ obj.methodMembers
135135
)
136136

137137
val (com: Seq[String], moduleMembers: Vector[Templ]) = members.foldLeft((obj.comment, Vector.empty[Templ]))((p, mem) mem match {
@@ -163,11 +163,11 @@ trait Output { this: TransformCake ⇒
163163
case m: MethodInfo if !(m.name == obj.name) && !cls.members.exists(_.name == m.name)
164164
m.copy(pattern = n "static " + m.pattern(n))
165165
}
166-
val exclude = (direct.iterator ++ methods.iterator).map(_.name).toSet ++ this.javaKeywords
167-
direct ++ inheritedMethods(cls.sym, exclude)
166+
val exclude = (direct.iterator ++ methods.iterator).map(_.name).toSet ++ this.javaKeywords ++ excludedForwarders
167+
direct ++ inheritedMethods(obj.sym, exclude)
168168
}
169-
val nestedClasses = flatten(classes, forwarders = false, staticScope = false)
170-
val nestedStaticClasses = flatten(staticClasses, forwarders = false, staticScope = staticScope)
169+
val nestedClasses = flattenObjects(classes, forwarders = false, staticScope = false)
170+
val nestedStaticClasses = flattenObjects(staticClasses, forwarders = false, staticScope = staticScope)
171171
if (forwarders) {
172172
val base = cls.copy(members = nestedClasses ++ nestedStaticClasses ++ staticMethods ++ methods)
173173
val mod = mangleModule(obj, addMODULE = forwarders, pruneClasses = true)
@@ -179,6 +179,13 @@ trait Output { this: TransformCake ⇒
179179
}
180180
}
181181

182+
private val excludedForwarders =
183+
// For case classes, there is a generated companion object that
184+
// implements `AbstractFunctionN`, but static forwarders are not created
185+
// on the class for the methods on the companion object inherited from
186+
// that:
187+
Seq("curried", "tupled", "compose", "andThen")
188+
182189
private def inheritedMethods(sym: global.Symbol, exclude: Set[String]): Seq[MethodInfo] = {
183190
import global._
184191
sym.ancestors.reverse
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package akka.actor;
2+
public class Identify$ extends scala.runtime.AbstractFunction1<java.lang.Object, akka.actor.Identify> implements scala.Serializable {
3+
/**
4+
* Static reference to the singleton instance of this Scala object.
5+
*/
6+
public static final Identify$ MODULE$ = null;
7+
public Identify$ () { throw new RuntimeException(); }
8+
public final java.lang.String toString () { throw new RuntimeException(); }
9+
public akka.actor.Identify apply (Object messageId) { throw new RuntimeException(); }
10+
public scala.Option<java.lang.Object> unapply (akka.actor.Identify x$0) { throw new RuntimeException(); }
11+
private java.lang.Object readResolve () { throw new RuntimeException(); }
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package akka.actor;
2+
public final class Identify implements scala.Product, scala.Serializable {
3+
static public akka.actor.Identify apply (Object messageId) { throw new RuntimeException(); }
4+
static public scala.Option<java.lang.Object> unapply (akka.actor.Identify x$0) { throw new RuntimeException(); }
5+
static private java.lang.Object readResolve () { throw new RuntimeException(); }
6+
public Object messageId () { throw new RuntimeException(); }
7+
// not preceding
8+
public Identify (Object messageId) { throw new RuntimeException(); }
9+
public akka.actor.Identify copy (Object messageId) { throw new RuntimeException(); }
10+
public Object copy$default$1 () { throw new RuntimeException(); }
11+
// not preceding
12+
public java.lang.String productPrefix () { throw new RuntimeException(); }
13+
public int productArity () { throw new RuntimeException(); }
14+
public Object productElement (int x$1) { throw new RuntimeException(); }
15+
public scala.collection.Iterator<java.lang.Object> productIterator () { throw new RuntimeException(); }
16+
public boolean canEqual (Object x$1) { throw new RuntimeException(); }
17+
public int hashCode () { throw new RuntimeException(); }
18+
public java.lang.String toString () { throw new RuntimeException(); }
19+
public boolean equals (Object x$1) { throw new RuntimeException(); }
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package akka.actor.typed;
2+
public class DispatcherSelector$ implements scala.Serializable {
3+
/**
4+
* Static reference to the singleton instance of this Scala object.
5+
*/
6+
public static final DispatcherSelector$ MODULE$ = null;
7+
public DispatcherSelector$ () { throw new RuntimeException(); }
8+
private java.lang.Object readResolve () { throw new RuntimeException(); }
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package akka.actor.typed;
2+
public abstract class DispatcherSelector extends akka.actor.typed.Props {
3+
static private java.lang.Object readResolve () { throw new RuntimeException(); }
4+
public DispatcherSelector () { throw new RuntimeException(); }
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package akka.actor.typed;
2+
public abstract class Props implements scala.Product, scala.Serializable {
3+
public Props () { throw new RuntimeException(); }
4+
public abstract akka.actor.typed.Props next () ;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package akka.actor
2+
3+
@SerialVersionUID(1L)
4+
final case class Identify(messageId: Any) // extends AutoReceivedMessage with NotInfluenceReceiveTimeout
5+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package akka.actor.typed
2+
3+
abstract class Props private[akka] () extends Product with Serializable {
4+
private[akka] def next: Props
5+
}
6+
7+
sealed abstract class DispatcherSelector extends Props
8+
9+
object DispatcherSelector

plugin/src/test/resources/patches/2.12.0.patch

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,36 @@
5151
- */
5252
- public akka.rk.buh.is.it.A.D$ D () { throw new RuntimeException(); }
5353
}
54+
--- target/expected_output/basic/akka/actor/Identify.java
55+
+++ target/expected_output/basic/akka/actor/Identify.java
56+
@@ -3,6 +3,30 @@
57+
static public akka.actor.Identify apply (Object messageId) { throw new RuntimeException(); }
58+
static public scala.Option<java.lang.Object> unapply (akka.actor.Identify x$0) { throw new RuntimeException(); }
59+
static private java.lang.Object readResolve () { throw new RuntimeException(); }
60+
+ static public boolean apply$mcZD$sp (double v1) { throw new RuntimeException(); }
61+
+ static public double apply$mcDD$sp (double v1) { throw new RuntimeException(); }
62+
+ static public float apply$mcFD$sp (double v1) { throw new RuntimeException(); }
63+
+ static public int apply$mcID$sp (double v1) { throw new RuntimeException(); }
64+
+ static public long apply$mcJD$sp (double v1) { throw new RuntimeException(); }
65+
+ static public void apply$mcVD$sp (double v1) { throw new RuntimeException(); }
66+
+ static public boolean apply$mcZF$sp (float v1) { throw new RuntimeException(); }
67+
+ static public double apply$mcDF$sp (float v1) { throw new RuntimeException(); }
68+
+ static public float apply$mcFF$sp (float v1) { throw new RuntimeException(); }
69+
+ static public int apply$mcIF$sp (float v1) { throw new RuntimeException(); }
70+
+ static public long apply$mcJF$sp (float v1) { throw new RuntimeException(); }
71+
+ static public void apply$mcVF$sp (float v1) { throw new RuntimeException(); }
72+
+ static public boolean apply$mcZI$sp (int v1) { throw new RuntimeException(); }
73+
+ static public double apply$mcDI$sp (int v1) { throw new RuntimeException(); }
74+
+ static public float apply$mcFI$sp (int v1) { throw new RuntimeException(); }
75+
+ static public int apply$mcII$sp (int v1) { throw new RuntimeException(); }
76+
+ static public long apply$mcJI$sp (int v1) { throw new RuntimeException(); }
77+
+ static public void apply$mcVI$sp (int v1) { throw new RuntimeException(); }
78+
+ static public boolean apply$mcZJ$sp (long v1) { throw new RuntimeException(); }
79+
+ static public double apply$mcDJ$sp (long v1) { throw new RuntimeException(); }
80+
+ static public float apply$mcFJ$sp (long v1) { throw new RuntimeException(); }
81+
+ static public int apply$mcIJ$sp (long v1) { throw new RuntimeException(); }
82+
+ static public long apply$mcJJ$sp (long v1) { throw new RuntimeException(); }
83+
+ static public void apply$mcVJ$sp (long v1) { throw new RuntimeException(); }
84+
public Object messageId () { throw new RuntimeException(); }
85+
// not preceding
86+
public Identify (Object messageId) { throw new RuntimeException(); }

0 commit comments

Comments
 (0)