Skip to content

Commit ac24c81

Browse files
authored
Merge pull request #117 from lightbend/nestedInterfaces
Avoid nested interfaces in classes with the same name
2 parents c20e9e5 + 507bbff commit ac24c81

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
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)) {
20+
for (c flatten(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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ 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(
73+
name = s"${nestedInterface.name}$$${nestedInterface.name}",
74+
static = false
75+
)
76+
)
77+
case _ =>
78+
Seq(c.copy(members = c.classMembers.flatMap(liftInterface) ++ c.methodMembers))
79+
}
80+
}
81+
5882
/**
5983
* This method is supposed to do the transformation of `object` into
6084
*
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package akka.rk.buh.is.it;
2+
public class Status$ {
3+
/**
4+
* Static reference to the singleton instance of this Scala object.
5+
*/
6+
public static final Status$ MODULE$ = null;
7+
public Status$ () { throw new RuntimeException(); }
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package akka.rk.buh.is.it;
2+
public interface Status$Status extends scala.Serializable {
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package akka.rk.buh.is.it;
2+
public class Status {
3+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ package buh.is.it
44
import scala.annotation.varargs
55
import scala.concurrent.duration.FiniteDuration
66

7+
object Status {
8+
sealed trait Status extends Serializable
9+
}
10+
711
/**
812
* @tparam A I am a type parameter description
913
*/

0 commit comments

Comments
 (0)