Skip to content

Commit 59212c6

Browse files
committed
Avoid nested interfaces in classes with the same name
1 parent 0ae0a53 commit 59212c6

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ trait AST { this: TransformCake ⇒
3939
ret
4040
}
4141

42+
def classMembers = members.collect { case classInfo: ClassInfo => classInfo }
43+
def methodMembers = members.collect { case methodInfo: MethodInfo => methodInfo }
44+
4245
override def toString =
4346
s"ClassInfo($name, ${pattern("XXXXX", "AAAAA")}, module=$module, pckg=$pckg, ${filepattern("FFFFFF")}, interface=$interface, static=$static)" +
4447
comment.mkString("\n ", "\n ", "\n ") + members.mkString("\n ")

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

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

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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ trait Output { this: TransformCake ⇒
5555
}
5656
}
5757

58+
/**
59+
* Lift nested interfaces with the same name as their parent class to the parent
60+
* level, as Java does not allow this, mangling their name accordingly
61+
*
62+
* Also applied recursively to members
63+
*/
64+
def liftInterface(c: ClassInfo): Seq[ClassInfo] = {
65+
c.members.find {
66+
case member: ClassInfo => member.name == c.name && member.interface
67+
case _ => false
68+
} match {
69+
case Some(nestedInterface: ClassInfo) =>
70+
Seq(
71+
c.copy(members = c.classMembers.filterNot(_ == nestedInterface).flatMap(liftInterface) ++ c.methodMembers),
72+
nestedInterface.copy(name = s"${nestedInterface.name}$$${nestedInterface.name}")
73+
)
74+
case _ =>
75+
Seq(c.copy(members = c.classMembers.flatMap(liftInterface) ++ c.methodMembers))
76+
}
77+
}
78+
5879
/**
5980
* This method is supposed to do the transformation of `object` into
6081
*
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package akka.rk.buh.is.it;
2+
public class Actor {
3+
public class Status {
4+
public Status () { throw new RuntimeException(); }
5+
}
6+
public interface Status$Status extends scala.Serializable {
7+
}
8+
public akka.rk.buh.is.it.Actor.Status$ Status () { throw new RuntimeException(); }
9+
public Actor () { throw new RuntimeException(); }
10+
}

plugin/src/test/resources/input/basic/test.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ package buh.is.it
88
import scala.annotation.varargs
99
import scala.concurrent.duration.FiniteDuration
1010

11+
class Actor {
12+
object Status {
13+
sealed trait Status extends Serializable
14+
}
15+
}
16+
1117
/**
1218
* @tparam A I am a type parameter description
1319
*/

0 commit comments

Comments
 (0)