Skip to content

Commit 36732d7

Browse files
joderskyretronym
authored andcommitted
Javadoc: make parsing of java comments optional
1 parent ad67700 commit 36732d7

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

src/scaladoc/scala/tools/nsc/doc/ScaladocGlobal.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ trait ScaladocGlobalTrait extends Global {
1313

1414
override val useOffsetPositions = false
1515
override def newUnitParser(unit: CompilationUnit) = new syntaxAnalyzer.ScaladocUnitParser(unit, Nil)
16-
override def newJavaUnitParser(unit: CompilationUnit) = new syntaxAnalyzer.ScaladocJavaUnitParser(unit)
16+
override def newJavaUnitParser(unit: CompilationUnit) = if (createJavadoc) {
17+
new syntaxAnalyzer.ScaladocJavaUnitParser(unit)
18+
} else {
19+
super.newJavaUnitParser(unit)
20+
}
1721

1822
override lazy val syntaxAnalyzer = new ScaladocSyntaxAnalyzer[outer.type](outer) {
1923
val runsAfter = List[String]()
@@ -41,7 +45,7 @@ class ScaladocGlobal(settings: doc.Settings, reporter: Reporter) extends Global(
4145
phasesSet += analyzer.typerFactory
4246
}
4347
override def forScaladoc = true
44-
override def createJavadoc = true
48+
override def createJavadoc = if (settings.docNoJavaComments.value) false else true
4549

4650
override lazy val analyzer = new {
4751
val global: ScaladocGlobal.this.type = ScaladocGlobal.this

src/scaladoc/scala/tools/nsc/doc/Settings.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ class Settings(error: String => Unit, val printMsg: String => Unit = println(_))
213213
"Group similar functions together (based on the @group annotation)"
214214
)
215215

216+
val docNoJavaComments = BooleanSetting (
217+
"-no-java-comments",
218+
"Prevents parsing and inclusion of comments from java sources."
219+
)
220+
216221
// For improved help output.
217222
def scaladocSpecific = Set[Settings#Setting](
218223
docformat, doctitle, docfooter, docversion, docUncompilable, docsourceurl, docgenerator, docRootContent, useStupidTypes,
@@ -222,7 +227,7 @@ class Settings(error: String => Unit, val printMsg: String => Unit = println(_))
222227
docImplicits, docImplicitsDebug, docImplicitsShowAll, docImplicitsHide, docImplicitsSoundShadowing,
223228
docDiagramsMaxNormalClasses, docDiagramsMaxImplicitClasses,
224229
docNoPrefixes, docNoLinkWarnings, docRawOutput, docSkipPackages,
225-
docExpandAllTypes, docGroups
230+
docExpandAllTypes, docGroups, docNoJavaComments
226231
)
227232
val isScaladocSpecific: String => Boolean = scaladocSpecific map (_.name)
228233

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package scala.tools.partest
2+
3+
import scala.tools.nsc.doc.Universe
4+
5+
/** A class for testing scaladoc model generation on java sources. */
6+
abstract class ScaladocJavaModelTest extends ScaladocModelTest {
7+
8+
// overridden to pass explicit files to newDocFactory.makeUniverse (rather than code strings)
9+
// since the .java file extension is required
10+
override def model: Option[Universe] = {
11+
val path = resourcePath + "/" + resourceFile
12+
newDocFactory.makeUniverse(Left(List(path)))
13+
}
14+
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Done.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import scala.tools.nsc.doc.Universe
2+
import scala.tools.nsc.doc.model._
3+
import scala.tools.partest.ScaladocJavaModelTest
4+
5+
object Test extends ScaladocJavaModelTest {
6+
7+
override def resourceFile = "SI-4826.java"
8+
override def scaladocSettings = "-no-java-comments"
9+
10+
def testModel(rootPackage: Package) = {
11+
import access._
12+
13+
val base = rootPackage._package("test")._package("scaladoc")
14+
val clazz = base._class("JavaComments")
15+
val method = clazz._method("answer")
16+
17+
assert(clazz.comment == None)
18+
assert(method.comment == None)
19+
}
20+
}

test/scaladoc/run/SI-4826.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
import scala.tools.nsc.doc.Universe
22
import scala.tools.nsc.doc.model._
3-
import scala.tools.partest.ScaladocModelTest
3+
import scala.tools.partest.ScaladocJavaModelTest
44

5-
object Test extends ScaladocModelTest {
5+
object Test extends ScaladocJavaModelTest {
66

77
override def resourceFile = "SI-4826.java"
8-
9-
// overridden to pass explicit files to newDocFactory.makeUniverse (rather than code strings)
10-
// since the .java file extension is required
11-
override def model: Option[Universe] = {
12-
val path = resourcePath + "/" + resourceFile
13-
newDocFactory.makeUniverse(Left(List(path)))
14-
}
15-
16-
// no need for special settings
178
override def scaladocSettings = ""
189

1910
def testModel(rootPackage: Package) = {

0 commit comments

Comments
 (0)