Skip to content

Commit b5db671

Browse files
authored
Merge pull request #137 from SethTisue/assuage-seths-ocd
it's Javadoc and Scaladoc (not JavaDoc and ScalaDoc)
2 parents 1b4129a + b4aafd5 commit b5db671

File tree

8 files changed

+50
-50
lines changed

8 files changed

+50
-50
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# GenJavaDoc
1+
# GenJavadoc
22

33
[![Build Status](https://travis-ci.org/lightbend/genjavadoc.svg?branch=master)](https://travis-ci.org/lightbend/genjavadoc)
44

5-
This project’s goal is the creation of real JavaDoc for Scala projects. While ScalaDoc—the native API documentation format of Scala—has several benefits over JavaDoc, Java programmers are very much used to having access to API documentation in a syntax matching their programming language of choice. Another motivating factor may be that javadoc-JARs are supported within IDE, e.g. showing tooltip help texts.
5+
This project’s goal is the creation of real Javadoc for Scala projects. While Scaladoc—the native API documentation format of Scala—has several benefits over Javadoc, Java programmers are very much used to having access to API documentation in a syntax matching their programming language of choice. Another motivating factor may be that javadoc-JARs are supported within IDE, e.g. showing tooltip help texts.
66

77
## How to Use It
88

9-
GenJavaDoc is a Scala compiler plugin which emits structurally equivalent Java code for all Scala sources of a project, keeping the ScalaDoc comments (with a few format adaptions). Integration into an SBT build is quite simple:
9+
GenJavadoc is a Scala compiler plugin which emits structurally equivalent Java code for all Scala sources of a project, keeping the Scaladoc comments (with a few format adaptions). Integration into an SBT build is quite simple:
1010

1111
~~~ scala
12-
lazy val JavaDoc = config("genjavadoc") extend Compile
12+
lazy val Javadoc = config("genjavadoc") extend Compile
1313

14-
lazy val javadocSettings = inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
14+
lazy val javadocSettings = inConfig(Javadoc)(Defaults.configSettings) ++ Seq(
1515
addCompilerPlugin("com.typesafe.genjavadoc" %% "genjavadoc-plugin" % "0.11" cross CrossVersion.full),
1616
scalacOptions += s"-P:genjavadoc:out=${target.value}/java",
17-
packageDoc in Compile := (packageDoc in JavaDoc).value,
18-
sources in JavaDoc :=
17+
packageDoc in Compile := (packageDoc in Javadoc).value,
18+
sources in Javadoc :=
1919
(target.value / "java" ** "*.java").get ++
2020
(sources in Compile).value.filter(_.getName.endsWith(".java")),
21-
javacOptions in JavaDoc := Seq(),
22-
artifactName in packageDoc in JavaDoc := ((sv, mod, art) =>
21+
javacOptions in Javadoc := Seq(),
22+
artifactName in packageDoc in Javadoc := ((sv, mod, art) =>
2323
"" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar")
2424
)
2525
~~~
@@ -29,16 +29,16 @@ project. One way to do this is to place the following line in your
2929
`build.sbt` file:
3030

3131
~~~ scala
32-
lazy val root = project.in(file(".")).configs(JavaDoc).settings(javadocSettings: _*)
32+
lazy val root = project.in(file(".")).configs(Javadoc).settings(javadocSettings: _*)
3333
~~~
3434

3535
Adding `javadocSettings` to a `Project` this way will replace the
36-
packaging of the API docs to use the JavaDoc instead of the ScalaDoc
37-
(i.e. the `XY-javadoc.jar` will then contain JavaDoc). The ScalaDoc
36+
packaging of the API docs to use the Javadoc instead of the Scaladoc
37+
(i.e. the `XY-javadoc.jar` will then contain Javadoc). The Scaladoc
3838
can still be generated using the normal `doc` task, whereas the
39-
JavaDoc can now be generated using `genjavadoc:doc`.
39+
Javadoc can now be generated using `genjavadoc:doc`.
4040

41-
GenJavaDoc can also be integrated into a Maven build (inspired by [this answer on StackOverflow](http://stackoverflow.com/questions/12301620/how-to-generate-an-aggregated-scaladoc-for-a-maven-site/16288487#16288487)):
41+
GenJavadoc can also be integrated into a Maven build (inspired by [this answer on StackOverflow](http://stackoverflow.com/questions/12301620/how-to-generate-an-aggregated-scaladoc-for-a-maven-site/16288487#16288487)):
4242

4343
~~~ xml
4444
<profile>
@@ -103,9 +103,9 @@ GenJavaDoc can also be integrated into a Maven build (inspired by [this answer o
103103
</profile>
104104
~~~
105105

106-
### Translation of ScalaDoc comments
106+
### Translation of Scaladoc comments
107107

108-
Comments found within the Scala sources are transferred to the corresponding Java sources including some modifications. These are necessary since ScalaDoc supports different mark-up elements than JavaDoc. The modifications are:
108+
Comments found within the Scala sources are transferred to the corresponding Java sources including some modifications. These are necessary since Scaladoc supports different mark-up elements than Javadoc. The modifications are:
109109

110110
* `{{{ ... }}}` is translated to `<pre><code> ... </code></pre>`, where within the pre-formatted text the following are represented by their HTML entities: `@`, `<`, `>`
111111
* typographic quotes (double as well as single) are translated to `&rdquo;` and friends
@@ -116,30 +116,30 @@ Comments found within the Scala sources are transferred to the corresponding Jav
116116

117117
### Additional transformations
118118

119-
Some additional transformations are applied in order to make the generated JavaDoc more useful:
119+
Some additional transformations are applied in order to make the generated Javadoc more useful:
120120

121-
* if a Scala method or class was marked `@scala.annotation.deprecated` an equivalent JavaDoc `@deprecated` comment line will be inserted to the resulting JavaDoc comment.
121+
* if a Scala method or class was marked `@scala.annotation.deprecated` an equivalent Javadoc `@deprecated` comment line will be inserted to the resulting Javadoc comment.
122122

123123
## How it Works
124124

125-
ScalaDoc generation is done by a special variant of the Scala compiler, which can in principle emit different output, but the syntax parsed by the ScalaDoc code is the Scala one: the compiler phases which adapt the AST to be more Java-like (to emit JVM byte-code in the end) are not run. On the other hand source comments cannot easily be associated with method signatures parsed from class files, and generating corresponding Java code to be fed into the `javadoc` tool is also no small task.
125+
Scaladoc generation is done by a special variant of the Scala compiler, which can in principle emit different output, but the syntax parsed by the Scaladoc code is the Scala one: the compiler phases which adapt the AST to be more Java-like (to emit JVM byte-code in the end) are not run. On the other hand source comments cannot easily be associated with method signatures parsed from class files, and generating corresponding Java code to be fed into the `javadoc` tool is also no small task.
126126

127-
The approach taken here is to use the Scala compiler’s support as far as possible and then generate mostly valid Java code corresponding to the AST—but only the class and method structur without implementations. Since the JavaDoc shall contain generic type information, and shall also not be confused by artifacts of Scala’s encoding of traits and other things, the AST must be inspected before the “erasure” phase; due to Java’s flat method parameter lists the other bound on where to hook into the transformation is that it should be after the “uncurry” phase (which transforms `def f(x: Int)(s: String)` into `def f(x: int, s: String)`). Luckily there is a gap between those two phases which is just wide enough to squeeze some code in.
127+
The approach taken here is to use the Scala compiler’s support as far as possible and then generate mostly valid Java code corresponding to the AST—but only the class and method structur without implementations. Since the Javadoc shall contain generic type information, and shall also not be confused by artifacts of Scala’s encoding of traits and other things, the AST must be inspected before the “erasure” phase; due to Java’s flat method parameter lists the other bound on where to hook into the transformation is that it should be after the “uncurry” phase (which transforms `def f(x: Int)(s: String)` into `def f(x: int, s: String)`). Luckily there is a gap between those two phases which is just wide enough to squeeze some code in.
128128

129129
One drawback of this choice is that the flattening of classes and companion objects or the mixing-in of method implementations from traits into derived classes happens much later in the transformation pipeline, meaning that the compiler plugin has to do that transformation itself; for this it has the advantage that it does not need to be 100% Scala-correct since the goal is just to document method signatures, not to implement all the intricacies of access widening and so on.
130130

131131
## Known Limitations
132132

133-
* Many ScalaDoc tags and features are simply not supported by the javadoc tool and genjavadoc does not reimplement them:
133+
* Many Scaladoc tags and features are simply not supported by the javadoc tool and genjavadoc does not reimplement them:
134134

135-
* `@note`, `@example`, `@group` etc. do not work and are errors in JavaDoc 8, so they cannot be used
135+
* `@note`, `@example`, `@group` etc. do not work and are errors in Javadoc 8, so they cannot be used
136136
* links to methods that use the overload disambiguation syntax will not work
137137

138-
* Classes and objects nested inside nested objects are emitted by Scalac in such a form that there is no valid Java syntax to produce the same binary names. This is due to differences in name mangling (where javac inserts more dollar signs than scalac does). This means that while JavaDoc is generated for these (in order to guarantee that JavaDoc will find all the types it needs) the precise names are neither correct nor usable in practice.
138+
* Classes and objects nested inside nested objects are emitted by Scalac in such a form that there is no valid Java syntax to produce the same binary names. This is due to differences in name mangling (where javac inserts more dollar signs than scalac does). This means that while Javadoc is generated for these (in order to guarantee that Javadoc will find all the types it needs) the precise names are neither correct nor usable in practice.
139139

140140
## Reporting Bugs
141141

142-
If you find errors in the generation process or have suggestions on how to improve the quality of the emitted JavaDoc contents, please report issues on this GitHub repo’s issue tracker.
142+
If you find errors in the generation process or have suggestions on how to improve the quality of the emitted Javadoc contents, please report issues on this GitHub repo’s issue tracker.
143143

144144
## License
145145

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<plugin>
2-
<name>GenJavaDoc</name>
3-
<classname>com.typesafe.genjavadoc.GenJavaDocPlugin</classname>
2+
<name>GenJavadoc</name>
3+
<classname>com.typesafe.genjavadoc.GenJavadocPlugin</classname>
44
</plugin>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ trait BaseComments { this: TransformCake ⇒
8888

8989
def between(p1: Position, p2: Position) = unit.source.content.slice(p1.start, p2.start).filterNot(_ == '\n').mkString
9090

91-
object ScalaDoc extends (Comment Boolean) {
91+
object Scaladoc extends (Comment Boolean) {
9292
def apply(c: Comment): Boolean = c.text.head.startsWith("/**")
9393
}
9494

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ trait BasicTransform { this: TransformCake ⇒
5151
val old = pos
5252
pos = max(tp, prevTemplateMaxPos)
5353
if (old.precedes(pos)) {
54-
(positions.from(old) intersect positions.to(pos)).toSeq.map(comments).filter(ScalaDoc).lastOption match {
54+
(positions.from(old) intersect positions.to(pos)).toSeq.map(comments).filter(Scaladoc).lastOption match {
5555
case Some(c) c.text // :+ s"// found in '${between(old, pos)}'"
5656
case None
5757
// s"// empty '${between(old, pos)}' (${pos.lineContent}:${pos.column})" ::

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import nsc.transform.Transform
88
import java.io.File
99
import java.util.Properties
1010

11-
object GenJavaDocPlugin {
11+
object GenJavadocPlugin {
1212

1313
val javaKeywords = Set("abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
1414
"default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if",
@@ -23,8 +23,8 @@ object GenJavaDocPlugin {
2323
val defaultFilteredStrings = stringToFilter(defaultFilterString)
2424
}
2525

26-
class GenJavaDocPlugin(val global: Global) extends Plugin {
27-
import GenJavaDocPlugin._
26+
class GenJavadocPlugin(val global: Global) extends Plugin {
27+
import GenJavadocPlugin._
2828

2929
val name = "genjavadoc"
3030
val description = ""
@@ -51,31 +51,31 @@ class GenJavaDocPlugin(val global: Global) extends Plugin {
5151

5252
import global._
5353

54-
type GT = GenJavaDocPlugin.this.global.type
54+
type GT = GenJavadocPlugin.this.global.type
5555

56-
override val global: GT = GenJavaDocPlugin.this.global
56+
override val global: GT = GenJavadocPlugin.this.global
5757

5858
val isPreFields =
5959
nsc.Properties.versionNumberString.startsWith("2.11.")
6060
override val runsAfter = List(if(isPreFields) "uncurry" else "fields")
61-
val phaseName = "GenJavaDoc"
61+
val phaseName = "GenJavadoc"
6262

63-
def newTransformer(unit: CompilationUnit) = new GenJavaDocTransformer(unit)
63+
def newTransformer(unit: CompilationUnit) = new GenJavadocTransformer(unit)
6464

65-
class GenJavaDocTransformer(val unit: CompilationUnit) extends Transformer with TransformCake {
65+
class GenJavadocTransformer(val unit: CompilationUnit) extends Transformer with TransformCake {
6666

6767
override lazy val global: GT = MyComponent.this.global
68-
override val outputBase: File = GenJavaDocPlugin.this.outputBase
69-
override val suppressSynthetic: Boolean = GenJavaDocPlugin.this.suppressSynthetic
70-
override val fabricateParams: Boolean = GenJavaDocPlugin.this.fabricateParams
71-
override val strictVisibility: Boolean = GenJavaDocPlugin.this.strictVisibility
68+
override val outputBase: File = GenJavadocPlugin.this.outputBase
69+
override val suppressSynthetic: Boolean = GenJavadocPlugin.this.suppressSynthetic
70+
override val fabricateParams: Boolean = GenJavadocPlugin.this.fabricateParams
71+
override val strictVisibility: Boolean = GenJavadocPlugin.this.strictVisibility
7272

7373
override def superTransformUnit(unit: CompilationUnit) = super.transformUnit(unit)
7474
override def superTransform(tree: Tree) = super.transform(tree)
7575
override def transform(tree: Tree) = newTransform(tree)
7676
override def transformUnit(unit: CompilationUnit) = newTransformUnit(unit)
77-
override def javaKeywords = GenJavaDocPlugin.javaKeywords
78-
override def filteredStrings = GenJavaDocPlugin.this.filteredStrings
77+
override def javaKeywords = GenJavadocPlugin.javaKeywords
78+
override def filteredStrings = GenJavadocPlugin.this.filteredStrings
7979
}
8080
}
8181
}

plugin/src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import java.lang.reflect.Modifier
88
import util._
99

1010
object SignatureSpec {
11-
// this should match up against the definition in GenJavaDocPlugin
11+
// this should match up against the definition in GenJavadocPlugin
1212
val javaKeywords = Set("abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
1313
"default", "do", "double", "else", "enum", "extends", "final", "finally", "float", "for", "goto", "if",
1414
"implements", "import", "instanceof", "int", "interface", "long", "native", "new", "package", "private",
1515
"protected", "public", "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this",
1616
"throw", "throws", "transient", "try", "void", "volatile", "while")
1717

18-
// this should match up against the definition in GenJavaDocPlugin
18+
// this should match up against the definition in GenJavadocPlugin
1919
// with the addition of "$lzycompute", which is special
2020
val defaultFilteredStrings = Set("$$", "$lzycompute")
2121

@@ -54,7 +54,7 @@ class SignatureSpec extends WordSpec with Matchers {
5454
val doc = IO.tempDir("java")
5555
val docPath = doc.getAbsolutePath
5656

57-
val scalac = new GenJavaDocCompiler(Seq(
57+
val scalac = new GenJavadocCompiler(Seq(
5858
s"genjavadoc:out=$docPath",
5959
"genjavadoc:suppressSynthetic=false"
6060
))
@@ -74,7 +74,7 @@ class SignatureSpec extends WordSpec with Matchers {
7474

7575
/*
7676
* This translation is necessary for the evil hack that allows things
77-
* nested in nested objects to be accepted by JavaDoc: while the emitted
77+
* nested in nested objects to be accepted by Javadoc: while the emitted
7878
* Java code compiles, the name mangling of javac and scalac differs for
7979
* such nestings, which means that it is impossible to express the Scalac
8080
* generated byte-code in valid Java source. To make things compile

plugin/src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ trait CompilerSpec { self: WordSpec with Matchers =>
2727
extraSettings.mkString(",")
2828
}
2929

30-
("GenJavaDoc with " + configInfo) must {
30+
("GenJavadoc with " + configInfo) must {
3131
val doc = IO.tempDir("java")
3232
val docPath = doc.getAbsolutePath
3333
val defaultSettings = Seq(s"out=$docPath", "suppressSynthetic=false")
34-
val scalac = new GenJavaDocCompiler((defaultSettings ++ extraSettings).map{ kv =>
34+
val scalac = new GenJavadocCompiler((defaultSettings ++ extraSettings).map{ kv =>
3535
s"genjavadoc:$kv"
3636
})
3737

plugin/src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import scala.tools.nsc.{Global, Settings}
99
/** An instance of the Scala compiler with the genjavadoc plugin enabled
1010
* @param params additional parameters to pass to the compiler
1111
*/
12-
class GenJavaDocCompiler(params: Seq[String]) {
12+
class GenJavadocCompiler(params: Seq[String]) {
1313

1414
private val settings = new Settings
1515
val reporter = new ConsoleReporter(settings)
1616
private val global = new Global(settings, reporter) {
1717
override protected def loadRoughPluginsList() =
18-
new GenJavaDocPlugin(this) :: super.loadRoughPluginsList()
18+
new GenJavadocPlugin(this) :: super.loadRoughPluginsList()
1919
}
2020

2121
val target = IO.tempDir("scala-classes")

0 commit comments

Comments
 (0)