Skip to content

Commit 52b8fdb

Browse files
authored
Merge pull request #274 from lrytz/t220
use point positions in comment index
2 parents bd654c7 + 4c9d2f4 commit 52b8fdb

File tree

14 files changed

+46
-39
lines changed

14 files changed

+46
-39
lines changed

Diff for: src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ trait Comments extends BaseComments { this: TransformCake =>
3838
def foundStarComment(start: Int, end: Int) = try {
3939
val str = docBuffer.toString
4040
val pos = new RangePosition(unit.source, start, start, end)
41-
comments += pos -> Comment(pos, str)
41+
comments += pos.point -> Comment(pos, str)
4242
true
4343
} finally {
4444
docBuffer = null

Diff for: src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait Comments extends BaseComments { this: TransformCake =>
1313
override def newScanner = new parser.ScaladocUnitScanner(unit, Nil) {
1414
override def registerDocComment(str: String, pos: Position) = {
1515
super.registerDocComment(str, pos)
16-
comments += pos -> Comment(pos, str)
16+
comments += pos.point -> Comment(pos, str)
1717
}
1818
}
1919
}.parse()

Diff for: src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ trait Comments extends BaseComments { this: TransformCake =>
1313
override def newScanner = new parser.ScaladocUnitScanner(unit, Nil) {
1414
override def registerDocComment(str: String, pos: Position) = {
1515
super.registerDocComment(str, pos)
16-
comments += pos -> Comment(pos, str)
16+
comments += pos.point -> Comment(pos, str)
1717
}
1818
}
1919
}.parse()

Diff for: src/main/scala/com/typesafe/genjavadoc/BaseComments.scala

+2-7
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ trait BaseComments { this: TransformCake =>
7171
}
7272
}
7373

74-
implicit val positionOrdering: Ordering[Position] = new Ordering[Position] {
75-
def compare(a: Position, b: Position) =
76-
if (a.end < b.start) -1
77-
else if (a.start > b.end) 1
78-
else 0
79-
}
80-
var comments = TreeMap[Position, Comment]()
74+
implicit val positionOrdering: Ordering[Position] = Ordering.by(_.point)
75+
var comments = TreeMap[Int, Comment]()
8176

8277
// This is overriden in the Scala Version Specific Comments.scala
8378
protected def parseComments(): Unit

Diff for: src/main/scala/com/typesafe/genjavadoc/BasicTransform.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.typesafe.genjavadoc
22

33
import scala.reflect.internal.Flags
4+
import scala.reflect.internal.util.Position
45

56
trait BasicTransform { this: TransformCake =>
67
import global._
@@ -36,7 +37,7 @@ trait BasicTransform { this: TransformCake =>
3637
try code finally keep = old
3738
}
3839

39-
private var pos: Position = rangePos(unit.source, 0, 0, 0)
40+
private var pos: Position = Position.offset(unit.source, 0)
4041

4142
private var templateMaxPos: Position = pos
4243
private var prevTemplateMaxPos: Position = pos
@@ -50,8 +51,8 @@ trait BasicTransform { this: TransformCake =>
5051
val ret = if (tp.isDefined) {
5152
val old = pos
5253
pos = max(tp, prevTemplateMaxPos)
53-
if (old.precedes(pos)) {
54-
(positions.from(old) intersect positions.to(pos)).toSeq.map(comments).filter(Scaladoc).lastOption match {
54+
if (old <= pos) {
55+
(positions.from(old.point) intersect positions.to(pos.point)).toSeq.map(comments).filter(Scaladoc).lastOption match {
5556
case Some(c) => c.text // :+ s"// found in '${between(old, pos)}'"
5657
case None =>
5758
// s"// empty '${between(old, pos)}' (${pos.lineContent}:${pos.column})" ::

Diff for: src/test/resources/expected_output/basic/Foo$.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* A simple class
3+
*/
4+
public class Foo$ {
5+
/**
6+
* Static reference to the singleton instance of this Scala object.
7+
*/
8+
public static final Foo$ MODULE$ = null;
9+
public Foo$ () { throw new RuntimeException(); }
10+
/**
11+
* @return something something
12+
*/
13+
public java.lang.String bar () { throw new RuntimeException(); }
14+
}

Diff for: src/test/resources/expected_output/basic/Foo.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* A simple class
3+
*/
4+
public class Foo {
5+
/**
6+
* @return something something
7+
*/
8+
static public java.lang.String bar () { throw new RuntimeException(); }
9+
}

Diff for: src/test/resources/input/basic/root.scala

+11
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
class AtTheRoot
2+
3+
/**
4+
* A simple class
5+
*/
6+
object Foo {
7+
8+
/**
9+
* @return something something
10+
*/
11+
def bar: String = ""
12+
}

Diff for: src/test/scala/com/typesafe/genjavadoc/RangePosSpec.scala

-18
This file was deleted.

Diff for: src/test/scala/com/typesafe/genjavadoc/SignatureSpec.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SignatureSpec {
6060
val scalac = new GenJavadocCompiler(Seq(
6161
s"genjavadoc:out=$docPath",
6262
"genjavadoc:suppressSynthetic=false"
63-
), rangepos = false)
63+
))
6464

6565
val javaSources = expectedClasses.map{cls =>
6666
docPath + "/" + cls.replace(".", "/") + ".java"

Diff for: src/test/scala/com/typesafe/genjavadoc/util/CompilerSpec.scala

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ trait CompilerSpec {
2020
/** Extra plugin arguments. */
2121
def extraSettings: Seq[String] = Seq.empty
2222

23-
/** whether to enable -Yrangepos */
24-
def rangepos: Boolean = false
25-
2623
@Test def compileSourcesAndGenerateExpectedOutput(): Unit = {
2724
val doc = IO.tempDir("java")
2825
val docPath = doc.getAbsolutePath
2926
val defaultSettings = Seq(s"out=$docPath", "suppressSynthetic=false")
3027
val scalac = new GenJavadocCompiler((defaultSettings ++ extraSettings).map{ kv =>
3128
s"genjavadoc:$kv"
32-
}, rangepos)
29+
})
3330

3431
scalac.compile(sources)
3532
assertFalse("Scala compiler reported errors", scalac.reporter.hasErrors)

Diff for: src/test/scala/com/typesafe/genjavadoc/util/GenJavaDocCompiler.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import scala.tools.nsc.{Global, Settings}
99
/** An instance of the Scala compiler with the genjavadoc plugin enabled
1010
* @param pluginOptions additional parameters to pass to the compiler
1111
*/
12-
class GenJavadocCompiler(pluginOptions: Seq[String], rangepos: Boolean) {
12+
class GenJavadocCompiler(pluginOptions: Seq[String]) {
1313

1414
private val settings = new Settings
1515

16-
settings.Yrangepos.value = rangepos
17-
1816
val reporter = new ConsoleReporter(settings)
1917
private val global = new Global(settings, reporter) {
2018
override protected def loadRoughPluginsList() =

0 commit comments

Comments
 (0)