Skip to content

Commit 787ce48

Browse files
committed
Fix creating static forwarders for inherited methods
We should create static forwarders for the methods inherited on the companion object, not on the class itself.
1 parent 1e75c74 commit 787ce48

File tree

4 files changed

+15
-33
lines changed

4 files changed

+15
-33
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")
188+
182189
private def inheritedMethods(sym: global.Symbol, exclude: Set[String]): Seq[MethodInfo] = {
183190
import global._
184191
sym.ancestors.reverse
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
package akka.actor.typed;
22
public abstract class DispatcherSelector extends akka.actor.typed.Props {
33
static private java.lang.Object readResolve () { throw new RuntimeException(); }
4-
static public abstract boolean canEqual (Object that) ;
5-
static public abstract boolean equals (Object that) ;
6-
static public abstract Object productElement (int n) ;
7-
static public abstract int productArity () ;
8-
static public scala.collection.Iterator<java.lang.Object> productIterator () { throw new RuntimeException(); }
9-
static public java.lang.String productPrefix () { throw new RuntimeException(); }
10-
static public java.lang.String productElementName (int n) { throw new RuntimeException(); }
11-
static public scala.collection.Iterator<java.lang.String> productElementNames () { throw new RuntimeException(); }
12-
static public abstract akka.actor.typed.Props next () ;
134
public DispatcherSelector () { throw new RuntimeException(); }
145
}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ index b0dd497..4950950 100644
155155
}
156156
--- target/expected_output/basic/akka/rk/buh/is/it/CompressionProtocol.java
157157
+++ target/expected_output/basic/akka/rk/buh/is/it/CompressionProtocol.java
158-
@@ -9,6 +9,7 @@
159-
static public akka.rk.buh.is.it.CompressionProtocol.Events.HeavyHitterDetected apply (Object key, int id, long count) { throw new RuntimeException(); }
160-
static public scala.Option<scala.Tuple3<java.lang.Object, java.lang.Object, java.lang.Object>> unapply (akka.rk.buh.is.it.CompressionProtocol.Events.HeavyHitterDetected x$0) { throw new RuntimeException(); }
161-
static private java.lang.Object readResolve () { throw new RuntimeException(); }
162-
+ static public scala.collection.Iterator<java.lang.String> productElementNames () { throw new RuntimeException(); }
163-
public Object key () { throw new RuntimeException(); }
164-
public int id () { throw new RuntimeException(); }
165-
public long count () { throw new RuntimeException(); }
166158
@@ -23,6 +24,7 @@
167159
public java.lang.String productPrefix () { throw new RuntimeException(); }
168160
public int productArity () { throw new RuntimeException(); }
@@ -173,14 +165,6 @@ index b0dd497..4950950 100644
173165
public int hashCode () { throw new RuntimeException(); }
174166
--- target/expected_output/basic/akka/rk/buh/is/it/EWMA.java
175167
+++ target/expected_output/basic/akka/rk/buh/is/it/EWMA.java
176-
@@ -28,6 +28,7 @@
177-
static public akka.rk.buh.is.it.EWMA apply (double value, double alpha) { throw new RuntimeException(); }
178-
static public scala.Option<scala.Tuple2<java.lang.Object, java.lang.Object>> unapply (akka.rk.buh.is.it.EWMA x$0) { throw new RuntimeException(); }
179-
static private java.lang.Object readResolve () { throw new RuntimeException(); }
180-
+ static public scala.collection.Iterator<java.lang.String> productElementNames () { throw new RuntimeException(); }
181-
public double value () { throw new RuntimeException(); }
182-
public double alpha () { throw new RuntimeException(); }
183-
// not preceding
184168
@@ -48,6 +49,7 @@
185169
public java.lang.String productPrefix () { throw new RuntimeException(); }
186170
public int productArity () { throw new RuntimeException(); }

0 commit comments

Comments
 (0)