Replace procedure syntax by explicit Unit annotation

This commit is contained in:
Pierre DAL-PRA 2015-08-03 23:13:59 +02:00
parent d1e719b07c
commit 404c5e8fc6
18 changed files with 89 additions and 90 deletions

View File

@ -40,7 +40,7 @@ object Cache extends CacheImplicits {
println(label + ".read: " + v) println(label + ".read: " + v)
v v
} }
def write(to: Out, v: Internal) { def write(to: Out, v: Internal): Unit = {
println(label + ".write: " + v) println(label + ".write: " + v)
c.write(to, v) c.write(to, v)
} }
@ -119,7 +119,7 @@ trait BasicCacheImplicits {
if (left <= 0) acc.reverse else next(left - 1, t.read(from) :: acc) if (left <= 0) acc.reverse else next(left - 1, t.read(from) :: acc)
next(size, Nil) next(size, Nil)
} }
def write(to: Out, vs: Internal) { def write(to: Out, vs: Internal): Unit = {
val size = vs.length val size = vs.length
IntFormat.writes(to, size) IntFormat.writes(to, size)
for (v <- vs) t.write(to, v) for (v <- vs) t.write(to, v)
@ -165,7 +165,7 @@ trait HListCacheImplicits {
val t = tail.read(from) val t = tail.read(from)
(h, t) (h, t)
} }
def write(to: Out, j: Internal) { def write(to: Out, j: Internal): Unit = {
head.write(to, j._1) head.write(to, j._1)
tail.write(to, j._2) tail.write(to, j._2)
} }
@ -185,7 +185,7 @@ trait HListCacheImplicits {
val t = tail.reads(from) val t = tail.reads(from)
HCons(h, t) HCons(h, t)
} }
def writes(to: Out, hc: H :+: T) { def writes(to: Out, hc: H :+: T): Unit = {
head.writes(to, hc.head) head.writes(to, hc.head)
tail.writes(to, hc.tail) tail.writes(to, hc.tail)
} }
@ -205,8 +205,8 @@ trait UnionImplicits {
val value = cache.read(in) val value = cache.read(in)
new Found[cache.Internal](cache, clazz, value, index) new Found[cache.Internal](cache, clazz, value, index)
} }
def write(to: Out, i: Internal) { def write(to: Out, i: Internal): Unit = {
def write0[I](f: Found[I]) { def write0[I](f: Found[I]): Unit = {
ByteFormat.writes(to, f.index.toByte) ByteFormat.writes(to, f.index.toByte)
f.cache.write(to, f.value) f.cache.write(to, f.value)
} }

View File

@ -13,22 +13,22 @@ class TestCallback(override val nameHashing: Boolean = false) extends AnalysisCa
val usedNames = scala.collection.mutable.Map.empty[File, Set[String]].withDefaultValue(Set.empty) val usedNames = scala.collection.mutable.Map.empty[File, Set[String]].withDefaultValue(Set.empty)
val apis: scala.collection.mutable.Map[File, SourceAPI] = scala.collection.mutable.Map.empty val apis: scala.collection.mutable.Map[File, SourceAPI] = scala.collection.mutable.Map.empty
def sourceDependency(dependsOn: File, source: File, inherited: Boolean) { def sourceDependency(dependsOn: File, source: File, inherited: Boolean): Unit = {
val context = if(inherited) DependencyByInheritance else DependencyByMemberRef val context = if(inherited) DependencyByInheritance else DependencyByMemberRef
sourceDependency(dependsOn, source, context) sourceDependency(dependsOn, source, context)
} }
def sourceDependency(dependsOn: File, source: File, context: DependencyContext) { sourceDependencies += ((dependsOn, source, context)) } def sourceDependency(dependsOn: File, source: File, context: DependencyContext): Unit = { sourceDependencies += ((dependsOn, source, context)) }
def binaryDependency(binary: File, name: String, source: File, inherited: Boolean) { def binaryDependency(binary: File, name: String, source: File, inherited: Boolean): Unit = {
val context = if(inherited) DependencyByInheritance else DependencyByMemberRef val context = if(inherited) DependencyByInheritance else DependencyByMemberRef
binaryDependency(binary, name, source, context) binaryDependency(binary, name, source, context)
} }
def binaryDependency(binary: File, name: String, source: File, context: DependencyContext) { binaryDependencies += ((binary, name, source, context)) } def binaryDependency(binary: File, name: String, source: File, context: DependencyContext): Unit = { binaryDependencies += ((binary, name, source, context)) }
def generatedClass(source: File, module: File, name: String) { products += ((source, module, name)) } def generatedClass(source: File, module: File, name: String): Unit = { products += ((source, module, name)) }
def usedName(source: File, name: String) { usedNames(source) += name } def usedName(source: File, name: String): Unit = { usedNames(source) += name }
def api(source: File, sourceAPI: SourceAPI): Unit = { def api(source: File, sourceAPI: SourceAPI): Unit = {
assert(!apis.contains(source), s"The `api` method should be called once per source file: $source") assert(!apis.contains(source), s"The `api` method should be called once per source file: $source")
apis(source) = sourceAPI apis(source) = sourceAPI
} }
def problem(category: String, pos: xsbti.Position, message: String, severity: xsbti.Severity, reported: Boolean) {} def problem(category: String, pos: xsbti.Position, message: String, severity: xsbti.Severity, reported: Boolean): Unit = ()
} }

View File

@ -190,7 +190,7 @@ final class ContextUtil[C <: Context](val ctx: C) {
// Workaround copied from scala/async:can be removed once https://github.com/scala/scala/pull/3179 is merged. // Workaround copied from scala/async:can be removed once https://github.com/scala/scala/pull/3179 is merged.
private[this] class ChangeOwnerAndModuleClassTraverser(oldowner: global.Symbol, newowner: global.Symbol) extends global.ChangeOwnerTraverser(oldowner, newowner) { private[this] class ChangeOwnerAndModuleClassTraverser(oldowner: global.Symbol, newowner: global.Symbol) extends global.ChangeOwnerTraverser(oldowner, newowner) {
override def traverse(tree: global.Tree) { override def traverse(tree: global.Tree): Unit = {
tree match { tree match {
case _: global.DefTree => change(tree.symbol.moduleClass) case _: global.DefTree => change(tree.symbol.moduleClass)
case _ => case _ =>

View File

@ -21,18 +21,18 @@ object Dag {
val finished = (new java.util.LinkedHashSet[T]).asScala val finished = (new java.util.LinkedHashSet[T]).asScala
def visitAll(nodes: Iterable[T]) = nodes foreach visit def visitAll(nodes: Iterable[T]) = nodes foreach visit
def visit(node: T) { def visit(node: T): Unit = {
if (!discovered(node)) { if (!discovered(node)) {
discovered(node) = true; discovered(node) = true;
try { visitAll(dependencies(node)); } catch { case c: Cyclic => throw node :: c } try { visitAll(dependencies(node)); } catch { case c: Cyclic => throw node :: c }
finished += node; finished += node
} else if (!finished(node)) } else if (!finished(node))
throw new Cyclic(node) throw new Cyclic(node)
} }
visitAll(nodes); visitAll(nodes)
finished.toList; finished.toList
} }
// doesn't check for cycles // doesn't check for cycles
def topologicalSortUnchecked[T](node: T)(dependencies: T => Iterable[T]): List[T] = topologicalSortUnchecked(node :: Nil)(dependencies) def topologicalSortUnchecked[T](node: T)(dependencies: T => Iterable[T]): List[T] = topologicalSortUnchecked(node :: Nil)(dependencies)
@ -43,11 +43,11 @@ object Dag {
var finished: List[T] = Nil var finished: List[T] = Nil
def visitAll(nodes: Iterable[T]) = nodes foreach visit def visitAll(nodes: Iterable[T]) = nodes foreach visit
def visit(node: T) { def visit(node: T): Unit = {
if (!discovered(node)) { if (!discovered(node)) {
discovered(node) = true; discovered(node) = true
visitAll(dependencies(node)) visitAll(dependencies(node))
finished ::= node; finished ::= node
} }
} }

View File

@ -111,7 +111,7 @@ abstract class EvaluateSettings[Scope] {
final def isNew: Boolean = synchronized { state == New } final def isNew: Boolean = synchronized { state == New }
final def isCalling: Boolean = synchronized { state == Calling } final def isCalling: Boolean = synchronized { state == Calling }
final def registerIfNew(): Unit = synchronized { if (state == New) register() } final def registerIfNew(): Unit = synchronized { if (state == New) register() }
private[this] def register() { private[this] def register(): Unit = {
assert(state == New, "Already registered and: " + toString) assert(state == New, "Already registered and: " + toString)
val deps = dependsOn val deps = dependsOn
blockedOn = deps.size - deps.count(_.doneOrBlock(this)) blockedOn = deps.size - deps.count(_.doneOrBlock(this))
@ -133,12 +133,12 @@ abstract class EvaluateSettings[Scope] {
if (blockedOn == 0) schedule() if (blockedOn == 0) schedule()
} }
final def evaluate(): Unit = synchronized { evaluate0() } final def evaluate(): Unit = synchronized { evaluate0() }
protected final def makeCall(source: BindNode[_, T], target: INode[T]) { protected final def makeCall(source: BindNode[_, T], target: INode[T]): Unit = {
assert(state == Ready, "Invalid state for call to makeCall: " + toString) assert(state == Ready, "Invalid state for call to makeCall: " + toString)
state = Calling state = Calling
target.call(source) target.call(source)
} }
protected final def setValue(v: T) { protected final def setValue(v: T): Unit = {
assert(state != Evaluated, "Already evaluated (trying to set value to " + v + "): " + toString) assert(state != Evaluated, "Already evaluated (trying to set value to " + v + "): " + toString)
if (v == null) sys.error("Setting value cannot be null: " + keyString) if (v == null) sys.error("Setting value cannot be null: " + keyString)
value = v value = v

View File

@ -20,7 +20,7 @@ object Param {
type T = s type T = s
def in = a def in = a
private var r: B[T] = _ private var r: B[T] = _
def ret(b: B[T]) { r = b } def ret(b: B[T]): Unit = { r = b }
def ret: B[T] = r def ret: B[T] = r
} }
p(v) p(v)

View File

@ -354,7 +354,7 @@ trait Init[Scope] {
// set of defined scoped keys, used to ensure a derived setting is only added if all dependencies are present // set of defined scoped keys, used to ensure a derived setting is only added if all dependencies are present
val defined = new mutable.HashSet[ScopedKey[_]] val defined = new mutable.HashSet[ScopedKey[_]]
def addDefs(ss: Seq[Setting[_]]) { for (s <- ss) defined += s.key } def addDefs(ss: Seq[Setting[_]]): Unit = { for (s <- ss) defined += s.key }
addDefs(defs) addDefs(defs)
// true iff the scoped key is in `defined`, taking delegation into account // true iff the scoped key is in `defined`, taking delegation into account

View File

@ -104,7 +104,7 @@ object JLineCompletion {
!(common.isEmpty && display.isEmpty) !(common.isEmpty && display.isEmpty)
} }
def appendCompletion(common: String, reader: ConsoleReader) { def appendCompletion(common: String, reader: ConsoleReader): Unit = {
reader.getCursorBuffer.write(common) reader.getCursorBuffer.write(common)
reader.redrawLine() reader.redrawLine()
} }
@ -113,16 +113,16 @@ object JLineCompletion {
* `display` is assumed to be the exact strings requested to be displayed. * `display` is assumed to be the exact strings requested to be displayed.
* In particular, duplicates should have been removed already. * In particular, duplicates should have been removed already.
*/ */
def showCompletions(display: Seq[String], reader: ConsoleReader) { def showCompletions(display: Seq[String], reader: ConsoleReader): Unit = {
printCompletions(display, reader) printCompletions(display, reader)
reader.drawLine() reader.drawLine()
} }
def printCompletions(cs: Seq[String], reader: ConsoleReader) { def printCompletions(cs: Seq[String], reader: ConsoleReader): Unit = {
val print = shouldPrint(cs, reader) val print = shouldPrint(cs, reader)
reader.println() reader.println()
if (print) printLinesAndColumns(cs, reader) if (print) printLinesAndColumns(cs, reader)
} }
def printLinesAndColumns(cs: Seq[String], reader: ConsoleReader) { def printLinesAndColumns(cs: Seq[String], reader: ConsoleReader): Unit = {
val (lines, columns) = cs partition hasNewline val (lines, columns) = cs partition hasNewline
for (line <- lines) { for (line <- lines) {
reader.print(line) reader.print(line)

View File

@ -185,7 +185,7 @@ object Parser extends ParserMain {
def mkFailure(error: => String, definitive: Boolean = false): Failure = new Failure(error :: Nil, definitive) def mkFailure(error: => String, definitive: Boolean = false): Failure = new Failure(error :: Nil, definitive)
@deprecated("This method is deprecated and will be removed in the next major version. Use the parser directly to check for invalid completions.", since = "0.13.2") @deprecated("This method is deprecated and will be removed in the next major version. Use the parser directly to check for invalid completions.", since = "0.13.2")
def checkMatches(a: Parser[_], completions: Seq[String]) { def checkMatches(a: Parser[_], completions: Seq[String]): Unit = {
val bad = completions.filter(apply(a)(_).resultEmpty.isFailure) val bad = completions.filter(apply(a)(_).resultEmpty.isFailure)
if (bad.nonEmpty) sys.error("Invalid example completions: " + bad.mkString("'", "', '", "'")) if (bad.nonEmpty) sys.error("Invalid example completions: " + bad.mkString("'", "', '", "'"))
} }

View File

@ -15,7 +15,7 @@ object JLineTest {
} }
val parsers = Map("1" -> one, "2" -> two, "3" -> three, "4" -> four, "5" -> five) val parsers = Map("1" -> one, "2" -> two, "3" -> three, "4" -> four, "5" -> five)
def main(args: Array[String]) { def main(args: Array[String]): Unit = {
import jline.TerminalFactory import jline.TerminalFactory
import jline.console.ConsoleReader import jline.console.ConsoleReader
val reader = new ConsoleReader() val reader = new ConsoleReader()
@ -23,7 +23,7 @@ object JLineTest {
val parser = parsers(args(0)) val parser = parsers(args(0))
JLineCompletion.installCustomCompletor(reader, parser) JLineCompletion.installCustomCompletor(reader, parser)
def loop() { def loop(): Unit = {
val line = reader.readLine("> ") val line = reader.readLine("> ")
if (line ne null) { if (line ne null) {
println("Result: " + apply(parser)(line).resultEmpty) println("Result: " + apply(parser)(line).resultEmpty)
@ -130,7 +130,7 @@ object ParserExample {
println(apply(t)("test w").resultEmpty) println(apply(t)("test w").resultEmpty)
println(apply(t)("test was were").resultEmpty) println(apply(t)("test was were").resultEmpty)
def run(n: Int) { def run(n: Int): Unit = {
val a = 'a'.id val a = 'a'.id
val aq = a.? val aq = a.?
val aqn = repeat(aq, min = n, max = n) val aqn = repeat(aq, min = n, max = n)
@ -140,7 +140,7 @@ object ParserExample {
def r = apply(ann)("a" * (n * 2)).resultEmpty def r = apply(ann)("a" * (n * 2)).resultEmpty
println(r.isValid) println(r.isValid)
} }
def run2(n: Int) { def run2(n: Int): Unit = {
val ab = "ab".?.* val ab = "ab".?.*
val r = apply(ab)("a" * n).resultEmpty val r = apply(ab)("a" * n).resultEmpty
println(r) println(r)

View File

@ -81,7 +81,7 @@ object ConsoleLogger {
nextESC(s, 0, sb) nextESC(s, 0, sb)
sb.toString sb.toString
} }
private[this] def nextESC(s: String, start: Int, sb: java.lang.StringBuilder) { private[this] def nextESC(s: String, start: Int, sb: java.lang.StringBuilder): Unit = {
val escIndex = s.indexOf(ESC, start) val escIndex = s.indexOf(ESC, start)
if (escIndex < 0) if (escIndex < 0)
sb.append(s, start, s.length) sb.append(s, start, s.length)
@ -167,7 +167,7 @@ class ConsoleLogger private[ConsoleLogger] (val out: ConsoleOut, override val an
} }
def successLabelColor = GREEN def successLabelColor = GREEN
def successMessageColor = RESET def successMessageColor = RESET
override def success(message: => String) { override def success(message: => String): Unit = {
if (successEnabled) if (successEnabled)
log(successLabelColor, Level.SuccessLabel, successMessageColor, message) log(successLabelColor, Level.SuccessLabel, successMessageColor, message)
} }
@ -180,13 +180,13 @@ class ConsoleLogger private[ConsoleLogger] (val out: ConsoleOut, override val an
for (msg <- suppressedMessage(new SuppressedTraceContext(traceLevel, ansiCodesSupported && useColor))) for (msg <- suppressedMessage(new SuppressedTraceContext(traceLevel, ansiCodesSupported && useColor)))
printLabeledLine(labelColor(Level.Error), "trace", messageColor(Level.Error), msg) printLabeledLine(labelColor(Level.Error), "trace", messageColor(Level.Error), msg)
} }
def log(level: Level.Value, message: => String) { def log(level: Level.Value, message: => String): Unit = {
if (atLevel(level)) if (atLevel(level))
log(labelColor(level), level.toString, messageColor(level), message) log(labelColor(level), level.toString, messageColor(level), message)
} }
private def reset(): Unit = setColor(RESET) private def reset(): Unit = setColor(RESET)
private def setColor(color: String) { private def setColor(color: String): Unit = {
if (ansiCodesSupported && useColor) if (ansiCodesSupported && useColor)
out.lockObject.synchronized { out.print(color) } out.lockObject.synchronized { out.print(color) }
} }
@ -210,6 +210,6 @@ class ConsoleLogger private[ConsoleLogger] (val out: ConsoleOut, override val an
} }
def logAll(events: Seq[LogEvent]) = out.lockObject.synchronized { events.foreach(log) } def logAll(events: Seq[LogEvent]) = out.lockObject.synchronized { events.foreach(log) }
def control(event: ControlEvent.Value, message: => String) { log(labelColor(Level.Info), Level.Info.toString, BLUE, message) } def control(event: ControlEvent.Value, message: => String): Unit = log(labelColor(Level.Info), Level.Info.toString, BLUE, message)
} }
final class SuppressedTraceContext(val traceLevel: Int, val useColor: Boolean) final class SuppressedTraceContext(val traceLevel: Int, val useColor: Boolean)

View File

@ -9,23 +9,23 @@ package sbt
*/ */
class FilterLogger(delegate: AbstractLogger) extends BasicLogger { class FilterLogger(delegate: AbstractLogger) extends BasicLogger {
override lazy val ansiCodesSupported = delegate.ansiCodesSupported override lazy val ansiCodesSupported = delegate.ansiCodesSupported
def trace(t: => Throwable) { def trace(t: => Throwable): Unit = {
if (traceEnabled) if (traceEnabled)
delegate.trace(t) delegate.trace(t)
} }
override def setSuccessEnabled(flag: Boolean) { delegate.setSuccessEnabled(flag) } override def setSuccessEnabled(flag: Boolean): Unit = delegate.setSuccessEnabled(flag)
override def successEnabled = delegate.successEnabled override def successEnabled = delegate.successEnabled
override def setTrace(level: Int) { delegate.setTrace(level) } override def setTrace(level: Int): Unit = delegate.setTrace(level)
override def getTrace = delegate.getTrace override def getTrace = delegate.getTrace
def log(level: Level.Value, message: => String) { def log(level: Level.Value, message: => String): Unit = {
if (atLevel(level)) if (atLevel(level))
delegate.log(level, message) delegate.log(level, message)
} }
def success(message: => String) { def success(message: => String): Unit = {
if (successEnabled) if (successEnabled)
delegate.success(message) delegate.success(message)
} }
def control(event: ControlEvent.Value, message: => String) { def control(event: ControlEvent.Value, message: => String): Unit = {
if (atLevel(Level.Info)) if (atLevel(Level.Info))
delegate.control(event, message) delegate.control(event, message)
} }

View File

@ -6,11 +6,11 @@ package sbt
/** Promotes the simple Logger interface to the full AbstractLogger interface. */ /** Promotes the simple Logger interface to the full AbstractLogger interface. */
class FullLogger(delegate: Logger) extends BasicLogger { class FullLogger(delegate: Logger) extends BasicLogger {
override val ansiCodesSupported: Boolean = delegate.ansiCodesSupported override val ansiCodesSupported: Boolean = delegate.ansiCodesSupported
def trace(t: => Throwable) { def trace(t: => Throwable): Unit = {
if (traceEnabled) if (traceEnabled)
delegate.trace(t) delegate.trace(t)
} }
def log(level: Level.Value, message: => String) { def log(level: Level.Value, message: => String): Unit = {
if (atLevel(level)) if (atLevel(level))
delegate.log(level, message) delegate.log(level, message)
} }

View File

@ -34,7 +34,7 @@ class LoggerWriter(delegate: Logger, unbufferedLevel: Option[Level.Value], nl: S
process() process()
} }
private[this] def process() { private[this] def process(): Unit = {
val i = buffer.indexOf(nl) val i = buffer.indexOf(nl)
if (i >= 0) { if (i >= 0) {
log(buffer.substring(0, i)) log(buffer.substring(0, i))

View File

@ -11,24 +11,24 @@ class MultiLogger(delegates: List[AbstractLogger]) extends BasicLogger {
private[this] lazy val allSupportCodes = delegates forall supported private[this] lazy val allSupportCodes = delegates forall supported
private[this] def supported = (_: AbstractLogger).ansiCodesSupported private[this] def supported = (_: AbstractLogger).ansiCodesSupported
override def setLevel(newLevel: Level.Value) { override def setLevel(newLevel: Level.Value): Unit = {
super.setLevel(newLevel) super.setLevel(newLevel)
dispatch(new SetLevel(newLevel)) dispatch(new SetLevel(newLevel))
} }
override def setTrace(level: Int) { override def setTrace(level: Int): Unit = {
super.setTrace(level) super.setTrace(level)
dispatch(new SetTrace(level)) dispatch(new SetTrace(level))
} }
override def setSuccessEnabled(flag: Boolean) { override def setSuccessEnabled(flag: Boolean): Unit = {
super.setSuccessEnabled(flag) super.setSuccessEnabled(flag)
dispatch(new SetSuccess(flag)) dispatch(new SetSuccess(flag))
} }
def trace(t: => Throwable) { dispatch(new Trace(t)) } def trace(t: => Throwable): Unit = dispatch(new Trace(t))
def log(level: Level.Value, message: => String) { dispatch(new Log(level, message)) } def log(level: Level.Value, message: => String): Unit = dispatch(new Log(level, message))
def success(message: => String) { dispatch(new Success(message)) } def success(message: => String): Unit = dispatch(new Success(message))
def logAll(events: Seq[LogEvent]) { delegates.foreach(_.logAll(events)) } def logAll(events: Seq[LogEvent]): Unit = delegates.foreach(_.logAll(events))
def control(event: ControlEvent.Value, message: => String) { delegates.foreach(_.control(event, message)) } def control(event: ControlEvent.Value, message: => String): Unit = delegates.foreach(_.control(event, message))
private[this] def dispatch(event: LogEvent) { private[this] def dispatch(event: LogEvent): Unit = {
val plainEvent = if (allSupportCodes) event else removeEscapes(event) val plainEvent = if (allSupportCodes) event else removeEscapes(event)
for (d <- delegates) for (d <- delegates)
if (d.ansiCodesSupported) if (d.ansiCodesSupported)

View File

@ -40,7 +40,7 @@ object LogWriterTest extends Properties("Log Writer") {
* represented as separately written segments (ToLog instances). ToLog.`byCharacter` * represented as separately written segments (ToLog instances). ToLog.`byCharacter`
* indicates whether to write the segment by character (true) or all at once (false) * indicates whether to write the segment by character (true) or all at once (false)
*/ */
def logLines(writer: Writer, lines: List[List[ToLog]], newLine: String) { def logLines(writer: Writer, lines: List[List[ToLog]], newLine: String): Unit = {
for (line <- lines; section <- line) { for (line <- lines; section <- line) {
val content = section.content val content = section.content
val normalized = Escape.newline(content, newLine) val normalized = Escape.newline(content, newLine)
@ -141,10 +141,10 @@ final class RecordingLogger extends BasicLogger {
def getEvents = events.reverse def getEvents = events.reverse
override def ansiCodesSupported = true override def ansiCodesSupported = true
def trace(t: => Throwable) { events ::= new Trace(t) } def trace(t: => Throwable): Unit = { events ::= new Trace(t) }
def log(level: Level.Value, message: => String) { events ::= new Log(level, message) } def log(level: Level.Value, message: => String): Unit = { events ::= new Log(level, message) }
def success(message: => String) { events ::= new Success(message) } def success(message: => String): Unit = { events ::= new Success(message) }
def logAll(es: Seq[LogEvent]) { events :::= es.toList } def logAll(es: Seq[LogEvent]): Unit = { events :::= es.toList }
def control(event: ControlEvent.Value, message: => String) { events ::= new ControlEvent(event, message) } def control(event: ControlEvent.Value, message: => String): Unit = { events ::= new ControlEvent(event, message) }
} }

View File

@ -58,8 +58,8 @@ object BasicIO {
processLinesFully(processLine)(reader.readLine) processLinesFully(processLine)(reader.readLine)
reader.close() reader.close()
} }
def processLinesFully(processLine: String => Unit)(readLine: () => String) { def processLinesFully(processLine: String => Unit)(readLine: () => String): Unit = {
def readFully() { def readFully(): Unit = {
val line = readLine() val line = readLine()
if (line != null) { if (line != null) {
processLine(line) processLine(line)
@ -68,7 +68,7 @@ object BasicIO {
} }
readFully() readFully()
} }
def connectToIn(o: OutputStream) { transferFully(Uncloseable protect System.in, o) } def connectToIn(o: OutputStream): Unit = transferFully(Uncloseable protect System.in, o)
def input(connect: Boolean): OutputStream => Unit = if (connect) connectToIn else closeOut def input(connect: Boolean): OutputStream => Unit = if (connect) connectToIn else closeOut
def standard(connectInput: Boolean): ProcessIO = standard(input(connectInput), inheritInput(connectInput)) def standard(connectInput: Boolean): ProcessIO = standard(input(connectInput), inheritInput(connectInput))
def standard(in: OutputStream => Unit, inheritIn: JProcessBuilder => Boolean): ProcessIO = new ProcessIO(in, toStdOut, toStdErr, inheritIn) def standard(in: OutputStream => Unit, inheritIn: JProcessBuilder => Boolean): ProcessIO = new ProcessIO(in, toStdOut, toStdErr, inheritIn)
@ -87,10 +87,10 @@ object BasicIO {
buffer.append(Newline) buffer.append(Newline)
} }
private[this] def transferFullyImpl(in: InputStream, out: OutputStream) { private[this] def transferFullyImpl(in: InputStream, out: OutputStream): Unit = {
val continueCount = 1 //if(in.isInstanceOf[PipedInputStream]) 1 else 0 val continueCount = 1 //if(in.isInstanceOf[PipedInputStream]) 1 else 0
val buffer = new Array[Byte](BufferSize) val buffer = new Array[Byte](BufferSize)
def read() { def read(): Unit = {
val byteCount = in.read(buffer) val byteCount = in.read(buffer)
if (byteCount >= continueCount) { if (byteCount >= continueCount) {
out.write(buffer, 0, byteCount) out.write(buffer, 0, byteCount)
@ -189,7 +189,7 @@ private abstract class BasicProcess extends Process {
} }
private abstract class CompoundProcess extends BasicProcess { private abstract class CompoundProcess extends BasicProcess {
def destroy() { destroyer() } def destroy(): Unit = destroyer()
def exitValue() = getExitValue().getOrElse(sys.error("No exit code: process destroyed.")) def exitValue() = getExitValue().getOrElse(sys.error("No exit code: process destroyed."))
def start() = getExitValue def start() = getExitValue
@ -294,7 +294,7 @@ private class PipedProcesses(a: ProcessBuilder, b: ProcessBuilder, defaultIO: Pr
} }
} }
private class PipeSource(currentSource: SyncVar[Option[InputStream]], pipe: PipedOutputStream, label: => String) extends Thread { private class PipeSource(currentSource: SyncVar[Option[InputStream]], pipe: PipedOutputStream, label: => String) extends Thread {
final override def run() { final override def run(): Unit = {
currentSource.get match { currentSource.get match {
case Some(source) => case Some(source) =>
try { BasicIO.transferFully(source, pipe) } try { BasicIO.transferFully(source, pipe) }
@ -311,7 +311,7 @@ private class PipeSource(currentSource: SyncVar[Option[InputStream]], pipe: Pipe
} }
} }
private class PipeSink(pipe: PipedInputStream, currentSink: SyncVar[Option[OutputStream]], label: => String) extends Thread { private class PipeSink(pipe: PipedInputStream, currentSink: SyncVar[Option[OutputStream]], label: => String) extends Thread {
final override def run() { final override def run(): Unit = {
currentSink.get match { currentSink.get match {
case Some(sink) => case Some(sink) =>
try { BasicIO.transferFully(pipe, sink) } try { BasicIO.transferFully(pipe, sink) }
@ -338,7 +338,7 @@ private[sbt] class DummyProcessBuilder(override val toString: String, exitValue:
private class DummyProcess(action: => Int) extends Process { private class DummyProcess(action: => Int) extends Process {
private[this] val exitCode = Future(action) private[this] val exitCode = Future(action)
override def exitValue() = exitCode() override def exitValue() = exitCode()
override def destroy() {} override def destroy(): Unit = ()
} }
/** Represents a simple command without any redirection or combination. */ /** Represents a simple command without any redirection or combination. */
private[sbt] class SimpleProcessBuilder(p: JProcessBuilder) extends AbstractProcessBuilder { private[sbt] class SimpleProcessBuilder(p: JProcessBuilder) extends AbstractProcessBuilder {
@ -410,12 +410,12 @@ private final class ThreadProcess(thread: Thread, success: SyncVar[Boolean]) ext
thread.join() thread.join()
if (success.get) 0 else 1 if (success.get) 0 else 1
} }
override def destroy() { thread.interrupt() } override def destroy(): Unit = thread.interrupt()
} }
object Uncloseable { object Uncloseable {
def apply(in: InputStream): InputStream = new FilterInputStream(in) { override def close() {} } def apply(in: InputStream): InputStream = new FilterInputStream(in) { override def close(): Unit = () }
def apply(out: OutputStream): OutputStream = new FilterOutputStream(out) { override def close() {} } def apply(out: OutputStream): OutputStream = new FilterOutputStream(out) { override def close(): Unit = () }
def protect(in: InputStream): InputStream = if (in eq System.in) Uncloseable(in) else in def protect(in: InputStream): InputStream = if (in eq System.in) Uncloseable(in) else in
def protect(out: OutputStream): OutputStream = if ((out eq System.out) || (out eq System.err)) Uncloseable(out) else out def protect(out: OutputStream): OutputStream = if ((out eq System.out) || (out eq System.err)) Uncloseable(out) else out
} }

View File

@ -3,12 +3,12 @@ package sbt
import java.io.{ File, FileNotFoundException, IOException } import java.io.{ File, FileNotFoundException, IOException }
object exit { object exit {
def main(args: Array[String]) { def main(args: Array[String]): Unit = {
System.exit(java.lang.Integer.parseInt(args(0))) System.exit(java.lang.Integer.parseInt(args(0)))
} }
} }
object cat { object cat {
def main(args: Array[String]) { def main(args: Array[String]): Unit = {
try { try {
if (args.length == 0) if (args.length == 0)
IO.transfer(System.in, System.out) IO.transfer(System.in, System.out)
@ -41,7 +41,6 @@ object cat {
} }
} }
object echo { object echo {
def main(args: Array[String]) { def main(args: Array[String]): Unit =
System.out.println(args.mkString(" ")) System.out.println(args.mkString(" "))
}
} }