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

src/main/scala-2.11/com/typesafe/genjavadoc/Comments.scala

Lines changed: 1 addition & 1 deletion
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

src/main/scala-2.12/com/typesafe/genjavadoc/Comments.scala

Lines changed: 1 addition & 1 deletion
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()

src/main/scala-2.13/com/typesafe/genjavadoc/Comments.scala

Lines changed: 1 addition & 1 deletion
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()

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

Lines changed: 2 additions & 7 deletions
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

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

Lines changed: 4 additions & 3 deletions
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})" ::
Lines changed: 14 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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+
}
File renamed without changes.
File renamed without changes.
Lines changed: 11 additions & 0 deletions
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+
}

0 commit comments

Comments
 (0)