Skip to content

Commit

Permalink
Reformat zinc with scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jvican committed May 3, 2017
1 parent b55f23c commit b893f80
Show file tree
Hide file tree
Showing 135 changed files with 5,774 additions and 3,615 deletions.
406 changes: 221 additions & 185 deletions build.sbt

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions internal/compiler-bridge/src/main/scala/xsbt/API.scala
Expand Up @@ -22,14 +22,13 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers {
class ApiPhase(prev: Phase) extends GlobalPhase(prev) {
override def description = "Extracts the public API from source files."
def name = API.name
override def run(): Unit =
{
val start = System.currentTimeMillis
super.run()
callback.apiPhaseCompleted()
val stop = System.currentTimeMillis
debuglog("API phase took : " + ((stop - start) / 1000.0) + " s")
}
override def run(): Unit = {
val start = System.currentTimeMillis
super.run()
callback.apiPhaseCompleted()
val stop = System.currentTimeMillis
debuglog("API phase took : " + ((stop - start) / 1000.0) + " s")
}

def apply(unit: global.CompilationUnit): Unit = processUnit(unit)

Expand All @@ -52,7 +51,8 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers {
}
}

private final class TopLevelHandler(extractApi: ExtractAPI[global.type]) extends TopLevelTraverser {
private final class TopLevelHandler(extractApi: ExtractAPI[global.type])
extends TopLevelTraverser {
def allNonLocalClasses: Set[ClassLike] = {
extractApi.allExtractedNonLocalClasses
}
Expand All @@ -73,11 +73,11 @@ final class API(val global: CallbackGlobal) extends Compat with GlobalHelpers {
}
def isTopLevel(sym: Symbol): Boolean = {
!ignoredSymbol(sym) &&
sym.isStatic &&
!sym.isImplClass &&
!sym.hasFlag(Flags.SYNTHETIC) &&
!sym.hasFlag(Flags.JAVA) &&
!sym.isNestedClass
sym.isStatic &&
!sym.isImplClass &&
!sym.hasFlag(Flags.SYNTHETIC) &&
!sym.hasFlag(Flags.JAVA) &&
!sym.isNestedClass
}
}

Expand Down
8 changes: 6 additions & 2 deletions internal/compiler-bridge/src/main/scala/xsbt/Analyzer.scala
Expand Up @@ -17,7 +17,8 @@ final class Analyzer(val global: CallbackGlobal) extends LocateClassFile {

def newPhase(prev: Phase): Phase = new AnalyzerPhase(prev)
private class AnalyzerPhase(prev: Phase) extends GlobalPhase(prev) {
override def description = "Finds concrete instances of provided superclasses, and application entry points."
override def description =
"Finds concrete instances of provided superclasses, and application entry points."
def name = Analyzer.name
def apply(unit: CompilationUnit): Unit = {
if (!unit.isJava) {
Expand All @@ -38,7 +39,10 @@ final class Analyzer(val global: CallbackGlobal) extends LocateClassFile {
if (!isLocalClass) {
val srcClassName = classNameAsString(sym)
val binaryClassName = flatclassName(sym, '.', separatorRequired)
callback.generatedNonLocalClass(sourceFile, classFile, binaryClassName, srcClassName)
callback.generatedNonLocalClass(sourceFile,
classFile,
binaryClassName,
srcClassName)
} else {
callback.generatedLocalClass(sourceFile, classFile)
}
Expand Down
17 changes: 9 additions & 8 deletions internal/compiler-bridge/src/main/scala/xsbt/ClassName.scala
Expand Up @@ -38,14 +38,15 @@ trait ClassName extends Compat {
* If `s` represents a package object `pkg3`, then the returned name will be `pkg1.pkg2.pkg3.package`.
* If `s` represents a class `Foo` nested in package object `pkg3` then the returned name is `pkg1.pkg2.pk3.Foo`.
*/
protected def classNameAsSeenIn(in: Symbol, s: Symbol): String = enteringPhase(currentRun.picklerPhase.next) {
if (in.isRoot || in.isRootPackage || in == NoSymbol || in.isEffectiveRoot)
s.simpleName.toString
else if (in.isPackageObjectOrClass)
in.owner.fullName + "." + s.name
else
in.fullName + "." + s.name
}
protected def classNameAsSeenIn(in: Symbol, s: Symbol): String =
enteringPhase(currentRun.picklerPhase.next) {
if (in.isRoot || in.isRootPackage || in == NoSymbol || in.isEffectiveRoot)
s.simpleName.toString
else if (in.isPackageObjectOrClass)
in.owner.fullName + "." + s.name
else
in.fullName + "." + s.name
}

private def pickledName(s: Symbol): Name =
enteringPhase(currentRun.picklerPhase.next) { s.fullNameAsName('.') }
Expand Down
7 changes: 6 additions & 1 deletion internal/compiler-bridge/src/main/scala/xsbt/Command.scala
Expand Up @@ -11,6 +11,7 @@ import scala.tools.nsc.{ CompilerCommand, Settings }
import Compat._

object Command {

/**
* Construct a CompilerCommand using reflection, to be compatible with Scalac before and after
* <a href="https://lampsvn.epfl.ch/trac/scala/changeset/21274">r21274</a>
Expand All @@ -21,7 +22,11 @@ object Command {
constr(classOf[List[_]], classOf[Settings]).newInstance(arguments, settings)
} catch {
case _: NoSuchMethodException =>
constr(classOf[List[_]], classOf[Settings], classOf[(_) => _], classOf[Boolean]).newInstance(arguments, settings, (s: String) => throw new RuntimeException(s), false.asInstanceOf[AnyRef])
constr(classOf[List[_]], classOf[Settings], classOf[(_) => _], classOf[Boolean])
.newInstance(arguments,
settings,
(s: String) => throw new RuntimeException(s),
false.asInstanceOf[AnyRef])
}
}

Expand Down
133 changes: 88 additions & 45 deletions internal/compiler-bridge/src/main/scala/xsbt/CompilerInterface.scala
Expand Up @@ -16,10 +16,20 @@ import Log.debug
import java.io.File

final class CompilerInterface {
def newCompiler(options: Array[String], output: Output, initialLog: Logger, initialDelegate: Reporter, resident: Boolean): CachedCompiler =
def newCompiler(options: Array[String],
output: Output,
initialLog: Logger,
initialDelegate: Reporter,
resident: Boolean): CachedCompiler =
new CachedCompiler0(options, output, new WeakLog(initialLog, initialDelegate), resident)

def run(sources: Array[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, progress: CompileProgress, cached: CachedCompiler): Unit =
def run(sources: Array[File],
changes: DependencyChanges,
callback: AnalysisCallback,
log: Logger,
delegate: Reporter,
progress: CompileProgress,
cached: CachedCompiler): Unit =
cached.run(sources, changes, callback, log, delegate, progress)
}
// for compatibility with Scala versions without Global.registerTopLevelSym (2.8.1 and earlier)
Expand All @@ -29,7 +39,11 @@ sealed trait GlobalCompat { self: Global =>
def informUnitStarting(phase: Phase, unit: CompilationUnit): Unit = ()
}
}
sealed abstract class CallbackGlobal(settings: Settings, reporter: reporters.Reporter, output: Output) extends Global(settings, reporter) with GlobalCompat {
sealed abstract class CallbackGlobal(settings: Settings,
reporter: reporters.Reporter,
output: Output)
extends Global(settings, reporter)
with GlobalCompat {
def callback: AnalysisCallback
def findClass(name: String): Option[(AbstractFile, Boolean)]
lazy val outputDirs: Iterable[File] = {
Expand Down Expand Up @@ -57,9 +71,13 @@ sealed abstract class CallbackGlobal(settings: Settings, reporter: reporters.Rep
*/
private[xsbt] val localToNonLocalClass = new LocalToNonLocalClass[this.type](this)
}
class InterfaceCompileFailed(val arguments: Array[String], val problems: Array[Problem], override val toString: String) extends xsbti.CompileFailed
class InterfaceCompileFailed(val arguments: Array[String],
val problems: Array[Problem],
override val toString: String)
extends xsbti.CompileFailed

class InterfaceCompileCancelled(val arguments: Array[String], override val toString: String) extends xsbti.CompileCancelled
class InterfaceCompileCancelled(val arguments: Array[String], override val toString: String)
extends xsbti.CompileCancelled

private final class WeakLog(private[this] var log: Logger, private[this] var delegate: Reporter) {
def apply(message: String): Unit = {
Expand All @@ -74,12 +92,18 @@ private final class WeakLog(private[this] var log: Logger, private[this] var del
}
}

private final class CachedCompiler0(args: Array[String], output: Output, initialLog: WeakLog, resident: Boolean) extends CachedCompiler with CachedCompilerCompat {
private final class CachedCompiler0(args: Array[String],
output: Output,
initialLog: WeakLog,
resident: Boolean)
extends CachedCompiler
with CachedCompilerCompat {
val settings = new Settings(s => initialLog(s))
output match {
case multi: MultipleOutput =>
for (out <- multi.outputGroups)
settings.outputDirs.add(out.sourceDirectory.getAbsolutePath, out.outputDirectory.getAbsolutePath)
settings.outputDirs
.add(out.sourceDirectory.getAbsolutePath, out.outputDirectory.getAbsolutePath)
case single: SingleOutput =>
settings.outputDirs.setSingleOutput(single.outputDirectory.getAbsolutePath)
}
Expand All @@ -91,27 +115,46 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
dreporter.printSummary()
handleErrors(dreporter, initialLog.logger)
}
} finally
initialLog.clear()
} finally initialLog.clear()

def noErrors(dreporter: DelegatingReporter) = !dreporter.hasErrors && command.ok

def commandArguments(sources: Array[File]): Array[String] =
(command.settings.recreateArgs ++ sources.map(_.getAbsolutePath)).toArray[String]

def run(sources: Array[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, delegate: Reporter, progress: CompileProgress): Unit = synchronized {
debug(log, "Running cached compiler " + hashCode.toLong.toHexString + ", interfacing (CompilerInterface) with Scala compiler " + scala.tools.nsc.Properties.versionString)
def run(sources: Array[File],
changes: DependencyChanges,
callback: AnalysisCallback,
log: Logger,
delegate: Reporter,
progress: CompileProgress): Unit = synchronized {
debug(
log,
"Running cached compiler " + hashCode.toLong.toHexString + ", interfacing (CompilerInterface) with Scala compiler " + scala.tools.nsc.Properties.versionString
)
val dreporter = DelegatingReporter(settings, delegate)
try { run(sources.toList, changes, callback, log, dreporter, progress) }
finally { dreporter.dropDelegate() }
try { run(sources.toList, changes, callback, log, dreporter, progress) } finally {
dreporter.dropDelegate()
}
}
private[this] def run(sources: List[File], changes: DependencyChanges, callback: AnalysisCallback, log: Logger, dreporter: DelegatingReporter, compileProgress: CompileProgress): Unit = {
private[this] def run(sources: List[File],
changes: DependencyChanges,
callback: AnalysisCallback,
log: Logger,
dreporter: DelegatingReporter,
compileProgress: CompileProgress): Unit = {
if (command.shouldStopWithInfo) {
dreporter.info(null, command.getInfoMessage(compiler), true)
throw new InterfaceCompileFailed(args, Array(), "Compiler option supplied that disabled actual compilation.")
throw new InterfaceCompileFailed(
args,
Array(),
"Compiler option supplied that disabled actual compilation.")
}
if (noErrors(dreporter)) {
debug(log, args.mkString("Calling Scala compiler with arguments (CompilerInterface):\n\t", "\n\t", ""))
debug(log,
args.mkString("Calling Scala compiler with arguments (CompilerInterface):\n\t",
"\n\t",
""))
compiler.set(callback, dreporter)
val run = new compiler.Run with compiler.RunCompat {
override def informUnitStarting(phase: Phase, unit: compiler.CompilationUnit): Unit = {
Expand All @@ -125,7 +168,9 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
val sortedSourceFiles = sources.map(_.getAbsolutePath).sortWith(_ < _)
run compile sortedSourceFiles
processUnreportedWarnings(run)
dreporter.problems foreach { p => callback.problem(p.category, p.position, p.message, p.severity, true) }
dreporter.problems foreach { p =>
callback.problem(p.category, p.position, p.message, p.severity, true)
}
}
dreporter.printSummary()
if (!noErrors(dreporter)) handleErrors(dreporter, log)
Expand All @@ -134,25 +179,25 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
// all of them (because we cancelled the compilation)
if (dreporter.cancelled) handleCompilationCancellation(dreporter, log)
}
def handleErrors(dreporter: DelegatingReporter, log: Logger): Nothing =
{
debug(log, "Compilation failed (CompilerInterface)")
throw new InterfaceCompileFailed(args, dreporter.problems, "Compilation failed")
}
def handleErrors(dreporter: DelegatingReporter, log: Logger): Nothing = {
debug(log, "Compilation failed (CompilerInterface)")
throw new InterfaceCompileFailed(args, dreporter.problems, "Compilation failed")
}
def handleCompilationCancellation(dreporter: DelegatingReporter, log: Logger): Nothing = {
assert(dreporter.cancelled, "We should get here only if when compilation got cancelled")
debug(log, "Compilation cancelled (CompilerInterface)")
throw new InterfaceCompileCancelled(args, "Compilation has been cancelled")
}
def processUnreportedWarnings(run: compiler.Run): Unit = {
// allConditionalWarnings and the ConditionalWarning class are only in 2.10+
final class CondWarnCompat(val what: String, val warnings: mutable.ListBuffer[(compiler.Position, String)])
final class CondWarnCompat(val what: String,
val warnings: mutable.ListBuffer[(compiler.Position, String)])
implicit def compat(run: AnyRef): Compat = new Compat
final class Compat { def allConditionalWarnings = List[CondWarnCompat]() }

val warnings = run.allConditionalWarnings
if (warnings.nonEmpty)
compiler.logUnreportedWarnings(warnings.map(cw => ("" /*cw.what*/ , cw.warnings.toList)))
compiler.logUnreportedWarnings(warnings.map(cw => ("" /*cw.what*/, cw.warnings.toList)))
}

val compiler: Compiler = newCompiler
Expand Down Expand Up @@ -207,28 +252,27 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
def name = phaseName
}

override lazy val phaseDescriptors =
{
phasesSet += sbtAnalyzer
if (callback.enabled()) {
phasesSet += sbtDependency
phasesSet += apiExtractor
}
superComputePhaseDescriptors
override lazy val phaseDescriptors = {
phasesSet += sbtAnalyzer
if (callback.enabled()) {
phasesSet += sbtDependency
phasesSet += apiExtractor
}
superComputePhaseDescriptors
}
private[this] def superComputePhaseDescriptors() = this.computePhaseDescriptors
private[this] def superDropRun(): Unit =
try { superCall("dropRun"); () } catch { case e: NoSuchMethodException => () } // dropRun not in 2.8.1
private[this] def superCall(methodName: String): AnyRef =
{
val meth = classOf[Global].getDeclaredMethod(methodName)
meth.setAccessible(true)
meth.invoke(this)
}
private[this] def superCall(methodName: String): AnyRef = {
val meth = classOf[Global].getDeclaredMethod(methodName)
meth.setAccessible(true)
meth.invoke(this)
}
def logUnreportedWarnings(seq: Seq[(String, List[(Position, String)])]): Unit = // Scala 2.10.x and later
{
val drep = reporter.asInstanceOf[DelegatingReporter]
for ((what, warnings) <- seq; (pos, msg) <- warnings) yield callback.problem(what, drep.convert(pos), msg, Severity.Warn, false)
for ((what, warnings) <- seq; (pos, msg) <- warnings)
yield callback.problem(what, drep.convert(pos), msg, Severity.Warn, false)
()
}

Expand All @@ -245,12 +289,11 @@ private final class CachedCompiler0(args: Array[String], output: Output, initial
def findClass(name: String): Option[(AbstractFile, Boolean)] =
getOutputClass(name).map(f => (f, true)) orElse findOnClassPath(name).map(f => (f, false))

def getOutputClass(name: String): Option[AbstractFile] =
{
// This could be improved if a hint where to look is given.
val className = name.replace('.', '/') + ".class"
outputDirs map (new File(_, className)) find (_.exists) map (AbstractFile.getFile(_))
}
def getOutputClass(name: String): Option[AbstractFile] = {
// This could be improved if a hint where to look is given.
val className = name.replace('.', '/') + ".class"
outputDirs map (new File(_, className)) find (_.exists) map (AbstractFile.getFile(_))
}

def findOnClassPath(name: String): Option[AbstractFile] =
classPath.findClass(name).flatMap(_.binary.asInstanceOf[Option[AbstractFile]])
Expand Down
24 changes: 18 additions & 6 deletions internal/compiler-bridge/src/main/scala/xsbt/ConsoleFactory.scala
Expand Up @@ -10,10 +10,22 @@ package xsbt
import xsbti.Logger

class ConsoleFactory extends xsbti.ConsoleFactory {
def createConsole(args: Array[String], bootClasspathString: String,
classpathString: String, initialCommands: String, cleanupCommands: String,
loader: ClassLoader, bindNames: Array[String], bindValues: Array[AnyRef],
log: Logger): xsbti.ConsoleInterface =
new ConsoleInterface(args, bootClasspathString, classpathString,
initialCommands, cleanupCommands, loader, bindNames, bindValues, log)
def createConsole(args: Array[String],
bootClasspathString: String,
classpathString: String,
initialCommands: String,
cleanupCommands: String,
loader: ClassLoader,
bindNames: Array[String],
bindValues: Array[AnyRef],
log: Logger): xsbti.ConsoleInterface =
new ConsoleInterface(args,
bootClasspathString,
classpathString,
initialCommands,
cleanupCommands,
loader,
bindNames,
bindValues,
log)
}

0 comments on commit b893f80

Please sign in to comment.