7
7
8
8
package sbt .internal .util
9
9
10
- import scala .language .experimental .macros
11
-
12
10
sealed trait SourcePosition
13
11
14
12
sealed trait FilePosition extends SourcePosition {
@@ -28,47 +26,4 @@ final case class RangePosition(path: String, range: LineRange) extends FilePosit
28
26
def startLine = range.start
29
27
}
30
28
31
- object SourcePosition {
32
-
33
- /** Creates a SourcePosition by using the enclosing position of the invocation of this method.
34
- * @return SourcePosition
35
- */
36
- def fromEnclosing (): SourcePosition = macro SourcePositionMacro .fromEnclosingImpl
37
-
38
- }
39
-
40
- import scala .annotation .tailrec
41
- import scala .reflect .macros .blackbox
42
- import scala .reflect .internal .util .UndefinedPosition
43
-
44
- final class SourcePositionMacro (val c : blackbox.Context ) {
45
- import c .universe .{ NoPosition => _ , _ }
46
-
47
- def fromEnclosingImpl (): Expr [SourcePosition ] = {
48
- val pos = c.enclosingPosition
49
- if (! pos.isInstanceOf [UndefinedPosition ] && pos.line >= 0 && pos.source != null ) {
50
- val f = pos.source.file
51
- val name = constant[String ](ownerSource(f.path, f.name))
52
- val line = constant[Int ](pos.line)
53
- reify { LinePosition (name.splice, line.splice) }
54
- } else
55
- reify { NoPosition }
56
- }
57
-
58
- private [this ] def ownerSource (path : String , name : String ): String = {
59
- @ tailrec def inEmptyPackage (s : Symbol ): Boolean =
60
- s != NoSymbol && (
61
- s.owner == c.mirror.EmptyPackage
62
- || s.owner == c.mirror.EmptyPackageClass
63
- || inEmptyPackage(s.owner)
64
- )
65
-
66
- c.internal.enclosingOwner match {
67
- case ec if ! ec.isStatic => name
68
- case ec if inEmptyPackage(ec) => path
69
- case ec => s " ( ${ec.fullName}) $name"
70
- }
71
- }
72
-
73
- private [this ] def constant [T : WeakTypeTag ](t : T ): Expr [T ] = c.Expr [T ](Literal (Constant (t)))
74
- }
29
+ object SourcePosition extends SourcePositionImpl
0 commit comments