From 2f2596c133e61533856111de3b14186fa4f6b5a7 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Sun, 2 Dec 2012 03:17:20 -0500 Subject: [PATCH] record source name or full path for settings/tasks depending on whether the enclosing package is the empty package --- main/settings/TaskMacro.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main/settings/TaskMacro.scala b/main/settings/TaskMacro.scala index 8c5468248..dd7d3a5f3 100644 --- a/main/settings/TaskMacro.scala +++ b/main/settings/TaskMacro.scala @@ -149,13 +149,27 @@ object TaskMacro import c.universe._ val pos = c.enclosingPosition if(pos.isDefined && pos.line >= 0 && pos.source != null) { - val name = constant[String](c, pos.source.file.name) + val f = pos.source.file + val name = constant[String](c, settingSource(c, f.path, f.name)) val line = constant[Int](c, pos.line) reify { sbt.LinePosition(name.splice, line.splice) } } else reify{ sbt.NoPosition } } + private[this] def settingSource(c: Context, path: String, name: String): String = + { + val ec = c.enclosingClass.symbol + def inEmptyPackage(s: c.Symbol): Boolean = + s != c.universe.NoSymbol && (s.owner == c.mirror.EmptyPackage || s.owner == c.mirror.EmptyPackageClass || inEmptyPackage(s.owner)) + if(!ec.isStatic) + name + else if(inEmptyPackage(ec)) + path + else + s"(${ec.fullName}) $name" + } + private[this] def constant[T: c.TypeTag](c: Context, t: T): c.Expr[T] = { import c.universe._ c.Expr[T](Literal(Constant(t)))