Skip to content

Commit

Permalink
Backport changes from several previous PRs
Browse files Browse the repository at this point in the history
This commit introduces changes to Scala 2.10 sources from the following
PRs:

* #225
* #216
* #206
* #221

It also removes a stub for 2.8 compatibility in `DelegatingReporter`.
Support for Scala 2.8 compatibility is not already maintained it.
  • Loading branch information
jvican committed Feb 21, 2017
1 parent 7f602a4 commit 5d46c1b
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 223 deletions.
18 changes: 12 additions & 6 deletions internal/compiler-bridge/src-2.10/main/scala/xsbt/API.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010, 2011 Mark Harrah
*/

package xsbt

import scala.tools.nsc.Phase
Expand All @@ -11,7 +12,7 @@ object API {
val name = "xsbt-api"
}

final class API(val global: CallbackGlobal) extends Compat {
final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers {
import global._

def newPhase(prev: Phase) = new ApiPhase(prev)
Expand Down Expand Up @@ -39,12 +40,12 @@ final class API(val global: CallbackGlobal) extends Compat {
if (global.callback.nameHashing) {
val extractUsedNames = new ExtractUsedNames[global.type](global)
val allUsedNames = extractUsedNames.extract(unit)
def showUsedNames(className: String, names: Set[String]): String =
def showUsedNames(className: String, names: Iterable[String]): String =
s"$className:\n\t${names.mkString(", ")}"
debuglog("The " + sourceFile + " contains the following used names:\n" +
allUsedNames.map((showUsedNames _).tupled).mkString("\n"))
allUsedNames foreach {
case (className: String, names: Set[String]) =>
case (className: String, names: Iterable[String]) =>
names foreach { (name: String) => callback.usedName(className, name) }
}
}
Expand Down Expand Up @@ -73,9 +74,14 @@ final class API(val global: CallbackGlobal) extends Compat {
case _ =>
}
}
def isTopLevel(sym: Symbol): Boolean =
(sym ne null) && (sym != NoSymbol) && !sym.isImplClass && !sym.isNestedClass && sym.isStatic &&
!sym.hasFlag(Flags.SYNTHETIC) && !sym.hasFlag(Flags.JAVA)
def isTopLevel(sym: Symbol): Boolean = {
!ignoredSymbol(sym) &&
sym.isStatic &&
!sym.isImplClass &&
!sym.hasFlag(Flags.SYNTHETIC) &&
!sym.hasFlag(Flags.JAVA) &&
!sym.isNestedClass
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class Analyzer(val global: CallbackGlobal) extends LocateClassFile {
// Dependency phase has ran. For example, the implementation classes for traits.
val isLocalClass = localToNonLocalClass.isLocal(sym).getOrElse(true)
if (!isLocalClass) {
val srcClassName = className(sym)
val srcClassName = classNameAsString(sym)
val binaryClassName = flatclassName(sym, '.', separatorRequired)
callback.generatedNonLocalClass(sourceFile, classFile, binaryClassName, srcClassName)
} else {
Expand Down
14 changes: 11 additions & 3 deletions internal/compiler-bridge/src-2.10/main/scala/xsbt/ClassName.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ trait ClassName {
/**
* Create a (source) name for a class symbol `s`.
*/
protected def className(s: Symbol): String = pickledName(s)
protected def className(s: Symbol): Name = pickledName(s)

/**
* Create a String (source) name for a class symbol `s`.
*/
protected def classNameAsString(s: Symbol): String = pickledNameAsString(s)

/**
* Create a (source) name for the class symbol `s` with a prefix determined by the class symbol `in`.
Expand All @@ -35,8 +40,11 @@ trait ClassName {
in.fullName + "." + s.name
}

private def pickledName(s: Symbol): String =
atPhase(currentRun.picklerPhase) { s.fullName }
private def pickledName(s: Symbol): Name =
atPhase(currentRun.picklerPhase.next) { s.fullNameAsName('.') }

private def pickledNameAsString(s: Symbol): String =
atPhase(currentRun.picklerPhase.next) { s.fullName }

protected def isTopLevelModule(sym: Symbol): Boolean =
atPhase(currentRun.picklerPhase.next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,11 @@ private final class DelegatingReporter(warnFatal: Boolean, noWarn: Boolean, priv
val sourceFile = src.file.file
val line = pos.line
val lineContent = pos.lineContent.stripLineEnd
val offset = getOffset(pos)
val offset = pos.point
val pointer = offset - src.lineToOffset(src.offsetToLine(offset))
val pointerSpace = ((lineContent: Seq[Char]).take(pointer).map { case '\t' => '\t'; case x => ' ' }).mkString
position(Option(sourcePath), Option(sourceFile), Option(line), lineContent, Option(offset), Option(pointer), Option(pointerSpace))
}
private[this] def getOffset(pos: Position): Int =
{
// for compatibility with 2.8
implicit def withPoint(p: Position): WithPoint = new WithPoint(pos)
final class WithPoint(val p: Position) { def point = p.offset.get }
pos.point
}
private[this] def position(sourcePath0: Option[String], sourceFile0: Option[File], line0: Option[Int], lineContent0: String, offset0: Option[Int], pointer0: Option[Int], pointerSpace0: Option[String]) =
new PositionImpl(sourcePath0, sourceFile0, line0, lineContent0, offset0, pointer0, pointerSpace0)

Expand Down
Loading

0 comments on commit 5d46c1b

Please sign in to comment.