aboutsummaryrefslogblamecommitdiff
path: root/src/dotty/tools/dotc/util/SourcePosition.scala
blob: 3c84f18535c5623b6a4c15624b468af2c5a08e18 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14













                                                                    

                                                 


                                                    


                                                                      
 
package dotty.tools.dotc.util

import Positions.{Position, NoPosition}

/** A source position is comprised of a position in a source file */
case class SourcePosition(source: SourceFile, pos: Position) {
  def point: Int = pos.point
  def start: Int = pos.start
  def end: Int = pos.end
  def exists = pos.exists

  def lineContents: String = source.lineContents(point)
  def line: Int = source.offsetToLine(point)
  def column: Int = source.column(point)

  override def toString = s"${source.file}:$line"
}

/** A sentinel for a non-existing source position */
object NoSourcePosition extends SourcePosition(NoSource, NoPosition) {
  override def toString = "?"
}