apply formatting

This commit is contained in:
Eugene Yokota 2019-04-20 23:23:13 -04:00
parent 2ac7501c7c
commit 98ec0075f4
9 changed files with 105 additions and 67 deletions

View File

@ -7,20 +7,26 @@ import java.io.IOException
object ErrorHandling {
def translate[T](msg: => String)(f: => T) =
try { f } catch {
try {
f
} catch {
case e: IOException => throw new TranslatedIOException(msg + e.toString, e)
case e: Exception => throw new TranslatedException(msg + e.toString, e)
}
def wideConvert[T](f: => T): Either[Throwable, T] =
try { Right(f) } catch {
try {
Right(f)
} catch {
case ex @ (_: Exception | _: StackOverflowError) => Left(ex)
case err @ (_: ThreadDeath | _: VirtualMachineError) => throw err
case x: Throwable => Left(x)
}
def convert[T](f: => T): Either[Exception, T] =
try { Right(f) } catch { case e: Exception => Left(e) }
try {
Right(f)
} catch { case e: Exception => Left(e) }
def reducedToString(e: Throwable): String =
if (e.getClass == classOf[RuntimeException]) {

View File

@ -50,7 +50,11 @@ class BufferedAppender private[BufferedAppender] (name: String, delegate: Append
def record() = synchronized { recording = true }
def buffer[T](f: => T): T = {
record()
try { f } finally { stopQuietly() }
try {
f
} finally {
stopQuietly()
}
}
def bufferQuietly[T](f: => T): T = {
record()
@ -60,7 +64,11 @@ class BufferedAppender private[BufferedAppender] (name: String, delegate: Append
result
} catch { case e: Throwable => stopQuietly(); throw e }
}
def stopQuietly() = synchronized { try { stopBuffer() } catch { case _: Exception => () } }
def stopQuietly() = synchronized {
try {
stopBuffer()
} catch { case _: Exception => () }
}
/**
* Flushes the buffer to the delegate logger. This method calls logAll on the delegate
@ -99,7 +107,11 @@ class BufferedLogger(delegate: AbstractLogger) extends BasicLogger {
def record() = synchronized { recording = true }
def buffer[T](f: => T): T = {
record()
try { f } finally { stopQuietly() }
try {
f
} finally {
stopQuietly()
}
}
def bufferQuietly[T](f: => T): T = {
record()
@ -109,7 +121,11 @@ class BufferedLogger(delegate: AbstractLogger) extends BasicLogger {
result
} catch { case e: Throwable => stopQuietly(); throw e }
}
def stopQuietly() = synchronized { try { stop() } catch { case _: Exception => () } }
def stopQuietly() = synchronized {
try {
stop()
} catch { case _: Exception => () }
}
/**
* Flushes the buffer to the delegate logger. This method calls logAll on the delegate

View File

@ -438,7 +438,8 @@ class ConsoleAppender private[ConsoleAppender] (
out.lockObject.synchronized {
message.linesIterator.foreach { line =>
val builder = new java.lang.StringBuilder(
labelColor.length + label.length + messageColor.length + line.length + reset.length * 3 + 3)
labelColor.length + label.length + messageColor.length + line.length + reset.length * 3 + 3
)
def fmted(a: String, b: String) = builder.append(reset).append(a).append(b).append(reset)
builder.append(reset).append('[')
fmted(labelColor, label)
@ -468,7 +469,8 @@ class ConsoleAppender private[ConsoleAppender] (
s"$ScrollUp$DeleteLine$msg${CursorLeft1000}" + (
if (scrollNum <= 1) ""
else scrollUp(scrollNum - 1)
))
)
)
out.flush()
} else {
out.println(msg)

View File

@ -28,8 +28,10 @@ class ManagedLogger(
private val SuccessEventTag = scala.reflect.runtime.universe.typeTag[SuccessEvent]
// send special event for success since it's not a real log level
override def success(message: => String): Unit = {
infoEvent[SuccessEvent](SuccessEvent(message))(implicitly[JsonFormat[SuccessEvent]],
SuccessEventTag)
infoEvent[SuccessEvent](SuccessEvent(message))(
implicitly[JsonFormat[SuccessEvent]],
SuccessEventTag
)
}
def registerStringCodec[A: ShowLines: TypeTag]: Unit = {

View File

@ -46,19 +46,21 @@ object InterfaceUtil {
sourcePath0: Option[String],
sourceFile0: Option[File]
): Position =
position(line0,
content,
offset0,
pointer0,
pointerSpace0,
sourcePath0,
sourceFile0,
None,
None,
None,
None,
None,
None)
position(
line0,
content,
offset0,
pointer0,
pointerSpace0,
sourcePath0,
sourceFile0,
None,
None,
None,
None,
None,
None
)
def position(
line0: Option[Integer],
@ -75,29 +77,33 @@ object InterfaceUtil {
endLine0: Option[Integer],
endColumn0: Option[Integer]
): Position =
new ConcretePosition(line0,
content,
offset0,
pointer0,
pointerSpace0,
sourcePath0,
sourceFile0,
startOffset0,
endOffset0,
startLine0,
startColumn0,
endLine0,
endColumn0)
new ConcretePosition(
line0,
content,
offset0,
pointer0,
pointerSpace0,
sourcePath0,
sourceFile0,
startOffset0,
endOffset0,
startLine0,
startColumn0,
endLine0,
endColumn0
)
@deprecated("Use the overload of this method with more arguments", "1.2.2")
def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem =
problem(cat, pos, msg, sev, None)
def problem(cat: String,
pos: Position,
msg: String,
sev: Severity,
rendered: Option[String]): Problem =
def problem(
cat: String,
pos: Position,
msg: String,
sev: Severity,
rendered: Option[String]
): Problem =
new ConcreteProblem(cat, pos, msg, sev, rendered)
private final class ConcreteT2[A1, A2](a1: A1, a2: A2) extends T2[A1, A2] {

View File

@ -15,7 +15,9 @@ class ScriptRunner {
def processStatement(handler: StatementHandler, statement: Statement): Unit = {
val state = states(handler).asInstanceOf[handler.State]
val nextState =
try { Right(handler(statement.command, statement.arguments, state)) } catch {
try {
Right(handler(statement.command, statement.arguments, state))
} catch {
case e: Exception => Left(e)
}
nextState match {
@ -42,7 +44,9 @@ class ScriptRunner {
statements foreach (Function.tupled(processStatement))
} finally {
for (handler <- handlers; state <- states.get(handler)) {
try { handler.finish(state.asInstanceOf[handler.State]) } catch { case e: Exception => () }
try {
handler.finish(state.asInstanceOf[handler.State])
} catch { case e: Exception => () }
}
}
}

View File

@ -75,21 +75,22 @@ final class ScriptedTests(
val g = groupDir.getName
val n = nme.getName
val str = s"$g / $n"
() =>
{
println("Running " + str)
testResources.readWriteResourceDirectory(g, n) { testDirectory =>
val disabled = new File(testDirectory, "disabled").isFile
if (disabled) {
log.info("D " + str + " [DISABLED]")
None
} else {
try { scriptedTest(str, testDirectory, prescripted, log); None } catch {
case _: TestException | _: PendingTestSuccessException => Some(str)
}
() => {
println("Running " + str)
testResources.readWriteResourceDirectory(g, n) { testDirectory =>
val disabled = new File(testDirectory, "disabled").isFile
if (disabled) {
log.info("D " + str + " [DISABLED]")
None
} else {
try {
scriptedTest(str, testDirectory, prescripted, log); None
} catch {
case _: TestException | _: PendingTestSuccessException => Some(str)
}
}
}
}
}
}
@ -149,7 +150,9 @@ final class ScriptedTests(
case e: Exception =>
testFailed()
if (!pending) throw e
} finally { buffered.clearBuffer() }
} finally {
buffered.clearBuffer()
}
}
}

View File

@ -60,7 +60,7 @@ object Cache {
val result = default(key)
update(result)
result
}
}
def debug[I](label: String, cache: SingletonCache[I]): SingletonCache[I] =
new SingletonCache[I] {

View File

@ -137,16 +137,15 @@ object FileFunction {
): Set[File] => Set[File] = {
lazy val inCache = Difference.inputs(storeFactory.make("in-cache"), inStyle)
lazy val outCache = Difference.outputs(storeFactory.make("out-cache"), outStyle)
inputs =>
{
inCache(inputs) { inReport =>
outCache { outReport =>
if (inReport.modified.isEmpty && outReport.modified.isEmpty)
outReport.checked
else
action(inReport, outReport)
}
inputs => {
inCache(inputs) { inReport =>
outCache { outReport =>
if (inReport.modified.isEmpty && outReport.modified.isEmpty)
outReport.checked
else
action(inReport, outReport)
}
}
}
}
}