Skip to content

Commit 4f0e413

Browse files
authored
Remote private classes and methods from output (#159)
Since they are not included in the javadoc anyway, and private classes inside traits (which are converted to private classes inside interfaces) are problematic.
1 parent 602b2fc commit 4f0e413

File tree

27 files changed

+83
-117
lines changed

27 files changed

+83
-117
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ trait AST { this: TransformCake ⇒
1111
trait Templ {
1212
def name: String
1313
def sig: String
14+
def access: String
1415
}
1516

1617
case class ClassInfo(
@@ -90,7 +91,7 @@ trait AST { this: TransformCake ⇒
9091
}
9192
}
9293

93-
case class MethodInfo(pattern: String String, ret: String, name: String, comment: Seq[String]) extends Templ {
94+
case class MethodInfo(access: String, pattern: String String, ret: String, name: String, comment: Seq[String]) extends Templ {
9495
def sig = pattern(s"$ret $name")
9596
}
9697
object MethodInfo {
@@ -136,7 +137,7 @@ trait AST { this: TransformCake ⇒
136137
case Some(deprec) => deprec.appendToComment(commentWithParams)
137138
case _ => commentWithParams
138139
}
139-
MethodInfo(pattern, ret, name, commentWithParamsAndDeprec)
140+
MethodInfo(acc, pattern, ret, name, commentWithParamsAndDeprec)
140141
}
141142

142143
/**

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 flattenObjects(classes.flatMap(liftInnerClassesWithSameName))) {
20+
for (c flattenObjects(classes.flatMap(liftInnerClassesWithSameName).flatMap(withoutPrivates))) {
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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ trait Output { this: TransformCake ⇒
5656
}
5757

5858
/**
59-
* Lift nested interfaces and classees with the same name as their parent class to the parent
59+
* Private methods and classes are not visible in the javadoc,
60+
* so they can be removed wholesale.
61+
*/
62+
def withoutPrivates(c: ClassInfo): Option[ClassInfo] = {
63+
def templWithoutPrivates(t: Templ): Option[Templ] = {
64+
if (t.access.contains("private")) None
65+
else t match {
66+
case c: ClassInfo =>
67+
Some(c.copy(members = c.members.flatMap(templWithoutPrivates)))
68+
case other =>
69+
Some(other)
70+
}
71+
}
72+
73+
if (c.access.contains("private")) None
74+
else Some(c.copy(members = c.members.flatMap(templWithoutPrivates)))
75+
}
76+
77+
/**
78+
* Lift nested interfaces with the same name as their parent class to the parent
6079
* level, as Java does not allow this, mangling their name accordingly
6180
*
6281
* Also applied recursively to members
@@ -131,7 +150,7 @@ trait Output { this: TransformCake ⇒
131150
private def mangleModule(obj: ClassInfo, addMODULE: Boolean, pruneClasses: Boolean): ClassInfo = {
132151
val moduleInstance =
133152
if (addMODULE || (obj.module && obj.static))
134-
Some(MethodInfo(x x, "public static final", s"${obj.name}$$ MODULE$$ = null;",
153+
Some(MethodInfo("public", x x, "public static final", s"${obj.name}$$ MODULE$$ = null;",
135154
Seq("/**", " * Static reference to the singleton instance of this Scala object.", " */")))
136155
else None
137156

plugin/src/test/resources/expected_output/basic/akka/actor/Identify.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
public final class Identify implements scala.Product, scala.Serializable {
33
static public akka.actor.Identify apply (Object messageId) { throw new RuntimeException(); }
44
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(); }
65
public Object messageId () { throw new RuntimeException(); }
76
// not preceding
87
public Identify (Object messageId) { throw new RuntimeException(); }
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package akka.actor.event;
2+
public interface ManagedActorClassification {
3+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package akka.actor.typed;
22
public abstract class DispatcherSelector extends akka.actor.typed.Props {
3-
static private java.lang.Object readResolve () { throw new RuntimeException(); }
43
public DispatcherSelector () { throw new RuntimeException(); }
54
}

plugin/src/test/resources/expected_output/basic/akka/rk/buh/is/it/A.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,6 @@ static public class EE$ {
125125
*/
126126
public void method () { throw new RuntimeException(); }
127127
}
128-
/**
129-
* object A.NoComment
130-
*/
131-
static private class NoComment$ {
132-
/**
133-
* Static reference to the singleton instance of this Scala object.
134-
*/
135-
public static final NoComment$ MODULE$ = null;
136-
public NoComment$ () { throw new RuntimeException(); }
137-
}
138128
/**
139129
* def IAmStatic: Int
140130
* @return (undocumented)

plugin/src/test/resources/expected_output/basic/akka/rk/buh/is/it/CompressionProtocol.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ static public class Events$ {
88
public final class HeavyHitterDetected implements akka.rk.buh.is.it.CompressionProtocol.Events.Event, scala.Product, scala.Serializable {
99
static public akka.rk.buh.is.it.CompressionProtocol.Events.HeavyHitterDetected apply (Object key, int id, long count) { throw new RuntimeException(); }
1010
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(); }
11-
static private java.lang.Object readResolve () { throw new RuntimeException(); }
1211
public Object key () { throw new RuntimeException(); }
1312
public int id () { throw new RuntimeException(); }
1413
public long count () { throw new RuntimeException(); }

plugin/src/test/resources/expected_output/basic/akka/rk/buh/is/it/EWMA$.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ public class EWMA$ implements scala.Serializable {
66
*/
77
public static final EWMA$ MODULE$ = null;
88
public EWMA$ () { throw new RuntimeException(); }
9-
/**
10-
* math.log(2)
11-
* @return (undocumented)
12-
*/
13-
private double LogOf2 () { throw new RuntimeException(); }
149
/**
1510
* Calculate the alpha (decay factor) used in {@link akka.cluster.EWMA}
1611
* from specified half-life and interval between observations.

plugin/src/test/resources/expected_output/basic/akka/rk/buh/is/it/EWMA.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@
1919
* <p>
2020
*/
2121
public final class EWMA implements scala.Product, scala.Serializable {
22-
/**
23-
* math.log(2)
24-
* @return (undocumented)
25-
*/
26-
static private double LogOf2 () { throw new RuntimeException(); }
2722
// not preceding
2823
static public akka.rk.buh.is.it.EWMA apply (double value, double alpha) { throw new RuntimeException(); }
2924
static public scala.Option<scala.Tuple2<java.lang.Object, java.lang.Object>> unapply (akka.rk.buh.is.it.EWMA x$0) { throw new RuntimeException(); }
30-
static private java.lang.Object readResolve () { throw new RuntimeException(); }
3125
public double value () { throw new RuntimeException(); }
3226
public double alpha () { throw new RuntimeException(); }
3327
// not preceding

0 commit comments

Comments
 (0)