diff --git a/src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala b/src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala index 784ac94..2667d1f 100644 --- a/src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala +++ b/src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala @@ -38,7 +38,7 @@ trait Comments extends BaseComments { this: TransformCake => def foundStarComment(start: Int, end: Int) = try { val str = docBuffer.toString val pos = new RangePosition(unit.source, start, start, end) - comments += pos -> Comment(pos, str) + comments += pos.point -> Comment(pos, str) true } finally { docBuffer = null diff --git a/src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala b/src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala index 98e6921..0aa35b4 100644 --- a/src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala +++ b/src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala @@ -13,7 +13,7 @@ trait Comments extends BaseComments { this: TransformCake => override def newScanner = new parser.ScaladocUnitScanner(unit, Nil) { override def registerDocComment(str: String, pos: Position) = { super.registerDocComment(str, pos) - comments += pos -> Comment(pos, str) + comments += pos.point -> Comment(pos, str) } } }.parse() diff --git a/src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala b/src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala index 5257c4b..75f4d1c 100644 --- a/src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala +++ b/src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala @@ -13,7 +13,7 @@ trait Comments extends BaseComments { this: TransformCake => override def newScanner = new parser.ScaladocUnitScanner(unit, Nil) { override def registerDocComment(str: String, pos: Position) = { super.registerDocComment(str, pos) - comments += pos -> Comment(pos, str) + comments += pos.point -> Comment(pos, str) } } }.parse() diff --git a/src/main/scala/com/typesafe/genjavadoc/BaseComments.scala b/src/main/scala/com/typesafe/genjavadoc/BaseComments.scala index 65313d8..56eb3fe 100644 --- a/src/main/scala/com/typesafe/genjavadoc/BaseComments.scala +++ b/src/main/scala/com/typesafe/genjavadoc/BaseComments.scala @@ -71,13 +71,8 @@ trait BaseComments { this: TransformCake => } } - implicit val positionOrdering: Ordering[Position] = new Ordering[Position] { - def compare(a: Position, b: Position) = - if (a.end < b.start) -1 - else if (a.start > b.end) 1 - else 0 - } - var comments = TreeMap[Position, Comment]() + implicit val positionOrdering: Ordering[Position] = Ordering.by(_.point) + var comments = TreeMap[Int, Comment]() // This is overriden in the Scala Version Specific Comments.scala protected def parseComments(): Unit diff --git a/src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala b/src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala index 8d80fd3..ad491b0 100644 --- a/src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala +++ b/src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala @@ -1,6 +1,7 @@ package com.typesafe.genjavadoc import scala.reflect.internal.Flags +import scala.reflect.internal.util.Position trait BasicTransform { this: TransformCake => import global._ @@ -36,7 +37,7 @@ trait BasicTransform { this: TransformCake => try code finally keep = old } - private var pos: Position = rangePos(unit.source, 0, 0, 0) + private var pos: Position = Position.offset(unit.source, 0) private var templateMaxPos: Position = pos private var prevTemplateMaxPos: Position = pos @@ -50,8 +51,8 @@ trait BasicTransform { this: TransformCake => val ret = if (tp.isDefined) { val old = pos pos = max(tp, prevTemplateMaxPos) - if (old.precedes(pos)) { - (positions.from(old) intersect positions.to(pos)).toSeq.map(comments).filter(Scaladoc).lastOption match { + if (old <= pos) { + (positions.from(old.point) intersect positions.to(pos.point)).toSeq.map(comments).filter(Scaladoc).lastOption match { case Some(c) => c.text // :+ s"// found in '${between(old, pos)}'" case None => // s"// empty '${between(old, pos)}' (${pos.lineContent}:${pos.column})" :: diff --git a/src/test/resources/expected_output/basic/Foo$.java b/src/test/resources/expected_output/basic/Foo$.java new file mode 100644 index 0000000..02f542f --- /dev/null +++ b/src/test/resources/expected_output/basic/Foo$.java @@ -0,0 +1,14 @@ +/** + * A simple class + */ +public class Foo$ { + /** + * Static reference to the singleton instance of this Scala object. + */ + public static final Foo$ MODULE$ = null; + public Foo$ () { throw new RuntimeException(); } + /** + * @return something something + */ + public java.lang.String bar () { throw new RuntimeException(); } +} diff --git a/src/test/resources/expected_output/basic/Foo.java b/src/test/resources/expected_output/basic/Foo.java new file mode 100644 index 0000000..aa111de --- /dev/null +++ b/src/test/resources/expected_output/basic/Foo.java @@ -0,0 +1,9 @@ +/** + * A simple class + */ +public class Foo { + /** + * @return something something + */ + static public java.lang.String bar () { throw new RuntimeException(); } +} diff --git a/src/test/resources/expected_output/rangepos/akka/cluster/ClusterRouterGroupSettings.java b/src/test/resources/expected_output/basic/akka/cluster/ClusterRouterGroupSettings.java similarity index 100% rename from src/test/resources/expected_output/rangepos/akka/cluster/ClusterRouterGroupSettings.java rename to src/test/resources/expected_output/basic/akka/cluster/ClusterRouterGroupSettings.java diff --git a/src/test/resources/input/rangepos/akka/cluster/ClusterRouterGroupSettings.scala b/src/test/resources/input/basic/akka/cluster/ClusterRouterGroupSettings.scala similarity index 100% rename from src/test/resources/input/rangepos/akka/cluster/ClusterRouterGroupSettings.scala rename to src/test/resources/input/basic/akka/cluster/ClusterRouterGroupSettings.scala diff --git a/src/test/resources/input/basic/root.scala b/src/test/resources/input/basic/root.scala index 0311e0f..f6a106b 100644 --- a/src/test/resources/input/basic/root.scala +++ b/src/test/resources/input/basic/root.scala @@ -1 +1,12 @@ class AtTheRoot + +/** + * A simple class + */ +object Foo { + + /** + * @return something something + */ + def bar: String = "" +} diff --git a/src/test/scala/com/typesafe/genjavadoc/RangePosSpec.scala b/src/test/scala/com/typesafe/genjavadoc/RangePosSpec.scala deleted file mode 100644 index 37143b0..0000000 --- a/src/test/scala/com/typesafe/genjavadoc/RangePosSpec.scala +++ /dev/null @@ -1,18 +0,0 @@ -package com.typesafe.genjavadoc - -import java.io.File - -import com.typesafe.genjavadoc.util.CompilerSpec - -class RangePosSpec extends CompilerSpec { - /** Sources to compile. */ - override def sources: Seq[String] = Seq( - new File("src/test/resources/input/rangepos/akka/cluster/ClusterRouterGroupSettings.scala").getAbsolutePath - ) - - override def rangepos = true - - /** Root directory that contains expected Java output. */ - override def expectedPath: String = - new File("src/test/resources/expected_output/rangepos").getAbsolutePath -} diff --git a/src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala b/src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala index cadb4ab..16e362d 100644 --- a/src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala +++ b/src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala @@ -60,7 +60,7 @@ class SignatureSpec { val scalac = new GenJavadocCompiler(Seq( s"genjavadoc:out=$docPath", "genjavadoc:suppressSynthetic=false" - ), rangepos = false) + )) val javaSources = expectedClasses.map{cls => docPath + "/" + cls.replace(".", "/") + ".java" diff --git a/src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala b/src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala index 2d7fc59..2e5d201 100644 --- a/src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala +++ b/src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala @@ -20,16 +20,13 @@ trait CompilerSpec { /** Extra plugin arguments. */ def extraSettings: Seq[String] = Seq.empty - /** whether to enable -Yrangepos */ - def rangepos: Boolean = false - @Test def compileSourcesAndGenerateExpectedOutput(): Unit = { val doc = IO.tempDir("java") val docPath = doc.getAbsolutePath val defaultSettings = Seq(s"out=$docPath", "suppressSynthetic=false") val scalac = new GenJavadocCompiler((defaultSettings ++ extraSettings).map{ kv => s"genjavadoc:$kv" - }, rangepos) + }) scalac.compile(sources) assertFalse("Scala compiler reported errors", scalac.reporter.hasErrors) diff --git a/src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala b/src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala index 9c767ee..80c0ea1 100644 --- a/src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala +++ b/src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala @@ -9,12 +9,10 @@ import scala.tools.nsc.{Global, Settings} /** An instance of the Scala compiler with the genjavadoc plugin enabled * @param pluginOptions additional parameters to pass to the compiler */ -class GenJavadocCompiler(pluginOptions: Seq[String], rangepos: Boolean) { +class GenJavadocCompiler(pluginOptions: Seq[String]) { private val settings = new Settings - settings.Yrangepos.value = rangepos - val reporter = new ConsoleReporter(settings) private val global = new Global(settings, reporter) { override protected def loadRoughPluginsList() =