diff --git a/internal/util-interface/src/main/java/xsbti/F0.java b/internal/util-interface/src/main/java/xsbti/F0.java deleted file mode 100644 index b0091b186..000000000 --- a/internal/util-interface/src/main/java/xsbti/F0.java +++ /dev/null @@ -1,9 +0,0 @@ -/* sbt -- Simple Build Tool - * Copyright 2009 Mark Harrah - */ -package xsbti; - -public interface F0 -{ - T apply(); -} diff --git a/internal/util-interface/src/main/java/xsbti/F1.java b/internal/util-interface/src/main/java/xsbti/F1.java deleted file mode 100644 index 8797e9196..000000000 --- a/internal/util-interface/src/main/java/xsbti/F1.java +++ /dev/null @@ -1,6 +0,0 @@ -package xsbti; - -public interface F1 -{ - R apply(A1 a1); -} diff --git a/internal/util-interface/src/main/java/xsbti/Logger.java b/internal/util-interface/src/main/java/xsbti/Logger.java index 60dfab7b5..1e9539fe7 100644 --- a/internal/util-interface/src/main/java/xsbti/Logger.java +++ b/internal/util-interface/src/main/java/xsbti/Logger.java @@ -3,11 +3,12 @@ */ package xsbti; -public interface Logger -{ - void error(F0 msg); - void warn(F0 msg); - void info(F0 msg); - void debug(F0 msg); - void trace(F0 exception); +import java.util.function.Supplier; + +public interface Logger { + void error(Supplier msg); + void warn(Supplier msg); + void info(Supplier msg); + void debug(Supplier msg); + void trace(Supplier exception); } diff --git a/internal/util-interface/src/main/java/xsbti/Maybe.java b/internal/util-interface/src/main/java/xsbti/Maybe.java deleted file mode 100644 index 0c5ea23b8..000000000 --- a/internal/util-interface/src/main/java/xsbti/Maybe.java +++ /dev/null @@ -1,48 +0,0 @@ -/* sbt -- Simple Build Tool - * Copyright 2008, 2009, 2010 Mark Harrah - */ -package xsbti; - -/** Intended as a lightweight carrier for scala.Option. */ -public abstract class Maybe { - private Maybe() {} - - @SuppressWarnings("unchecked") - public static Maybe nothing() { return (Maybe) Nothing.INSTANCE; } - public static Maybe just(final s v) { return new Just(v); } - - public static final class Just extends Maybe { - private final s v; - - public Just(final s v) { this.v = v; } - - public s value() { return v; } - - public boolean isDefined() { return true; } - public s get() { return v; } - public int hashCode() { return 17 + (v == null ? 0 : v.hashCode()); } - public String toString() { return "Maybe.just(" + v + ")"; } - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof Just)) return false; - final Just that = (Just) o; - return v == null ? that.v == null : v.equals(that.v); - } - } - - public static final class Nothing extends Maybe { - public static final Nothing INSTANCE = new Nothing(); - private Nothing() { } - - public boolean isDefined() { return false; } - public Object get() { throw new UnsupportedOperationException("nothing.get"); } - - public int hashCode() { return 1; } - public String toString() { return "Maybe.nothing()"; } - public boolean equals(Object o) { return this == o || o != null && o instanceof Nothing; } - } - - public final boolean isEmpty() { return !isDefined(); } - public abstract boolean isDefined(); - public abstract t get(); -} diff --git a/internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala b/internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala index 328ba8bc7..63e4213cb 100644 --- a/internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala +++ b/internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala @@ -1,22 +1,29 @@ package sbt.util -import xsbti.{ Maybe, F0, F1, T2, Position, Problem, Severity } +import xsbti.{ Position, Problem, Severity, T2 } import java.io.File import java.util.Optional +import java.util.function.Supplier object InterfaceUtil { - def f0[A](a: => A): F0[A] = new ConcreteF0[A](a) - def f1[A1, R](f: A1 => R): F1[A1, R] = new ConcreteF1(f) + def toSupplier[A](a: => A): Supplier[A] = new Supplier[A] { + override def get: A = a + } + + import java.util.function.{ Function => JavaFunction } + def toJavaFunction[A1, R](f: A1 => R): JavaFunction[A1, R] = new JavaFunction[A1, R] { + override def apply(t: A1): R = f(t) + } + def t2[A1, A2](x: (A1, A2)): T2[A1, A2] = new ConcreteT2(x._1, x._2) - def m2o[A](m: Maybe[A]): Option[A] = - if (m.isDefined) Some(m.get) - else None + def toOption[A](m: Optional[A]): Option[A] = + if (m.isPresent) Some(m.get) else None - def o2m[A](o: Option[A]): Maybe[A] = + def toOptional[A](o: Option[A]): Optional[A] = o match { - case Some(v) => Maybe.just(v) - case None => Maybe.nothing() + case Some(v) => Optional.of(v) + case None => Optional.empty() } def jo2o[A](o: Optional[A]): Option[A] = @@ -36,14 +43,6 @@ object InterfaceUtil { def problem(cat: String, pos: Position, msg: String, sev: Severity): Problem = new ConcreteProblem(cat, pos, msg, sev) - private final class ConcreteF0[A](a: => A) extends F0[A] { - def apply: A = a - } - - private final class ConcreteF1[A1, R](f: A1 => R) extends F1[A1, R] { - def apply(a1: A1): R = f(a1) - } - private final class ConcreteT2[A1, A2](a1: A1, a2: A2) extends T2[A1, A2] { val get1: A1 = a1 val get2: A2 = a2 diff --git a/internal/util-logging/src/main/scala/sbt/util/Logger.scala b/internal/util-logging/src/main/scala/sbt/util/Logger.scala index fd5b34a60..abcad3428 100644 --- a/internal/util-logging/src/main/scala/sbt/util/Logger.scala +++ b/internal/util-logging/src/main/scala/sbt/util/Logger.scala @@ -3,13 +3,14 @@ */ package sbt.util -import xsbti.{ Logger => xLogger, F0 } -import xsbti.{ Maybe, Position, Problem, Severity } +import xsbti.{ Logger => xLogger } +import xsbti.{ Position, Problem, Severity } + import sys.process.ProcessLogger import sbt.internal.util.{ BufferedLogger, FullLogger } - import java.io.File import java.util.Optional +import java.util.function.Supplier /** * This is intended to be the simplest logging interface for use by code that wants to log. @@ -32,12 +33,12 @@ abstract class Logger extends xLogger { def success(message: => String): Unit def log(level: Level.Value, message: => String): Unit - def debug(msg: F0[String]): Unit = log(Level.Debug, msg) - def warn(msg: F0[String]): Unit = log(Level.Warn, msg) - def info(msg: F0[String]): Unit = log(Level.Info, msg) - def error(msg: F0[String]): Unit = log(Level.Error, msg) - def trace(msg: F0[Throwable]): Unit = trace(msg.apply) - def log(level: Level.Value, msg: F0[String]): Unit = log(level, msg.apply) + def debug(msg: Supplier[String]): Unit = log(Level.Debug, msg) + def warn(msg: Supplier[String]): Unit = log(Level.Warn, msg) + def info(msg: Supplier[String]): Unit = log(Level.Info, msg) + def error(msg: Supplier[String]): Unit = log(Level.Error, msg) + def trace(msg: Supplier[Throwable]): Unit = trace(msg.get()) + def log(level: Level.Value, msg: Supplier[String]): Unit = log(level, msg.get) } object Logger { @@ -67,17 +68,18 @@ object Logger { case _ => wrapXLogger(lg) } private[this] def wrapXLogger(lg: xLogger): Logger = new Logger { - override def debug(msg: F0[String]): Unit = lg.debug(msg) - override def warn(msg: F0[String]): Unit = lg.warn(msg) - override def info(msg: F0[String]): Unit = lg.info(msg) - override def error(msg: F0[String]): Unit = lg.error(msg) - override def trace(msg: F0[Throwable]): Unit = lg.trace(msg) - override def log(level: Level.Value, msg: F0[String]): Unit = lg.log(level, msg) - def trace(t: => Throwable): Unit = trace(f0(t)) - def success(s: => String): Unit = info(f0(s)) + import InterfaceUtil.toSupplier + override def debug(msg: Supplier[String]): Unit = lg.debug(msg) + override def warn(msg: Supplier[String]): Unit = lg.warn(msg) + override def info(msg: Supplier[String]): Unit = lg.info(msg) + override def error(msg: Supplier[String]): Unit = lg.error(msg) + override def trace(msg: Supplier[Throwable]): Unit = lg.trace(msg) + override def log(level: Level.Value, msg: Supplier[String]): Unit = lg.log(level, msg) + def trace(t: => Throwable): Unit = trace(toSupplier(t)) + def success(s: => String): Unit = info(toSupplier(s)) def log(level: Level.Value, msg: => String): Unit = { - val fmsg = f0(msg) + val fmsg = toSupplier(msg) level match { case Level.Debug => lg.debug(fmsg) case Level.Info => lg.info(fmsg) @@ -86,9 +88,7 @@ object Logger { } } } - def f0[A](a: => A): F0[A] = InterfaceUtil.f0[A](a) - def m2o[A](m: Maybe[A]): Option[A] = InterfaceUtil.m2o(m) - def o2m[A](o: Option[A]): Maybe[A] = InterfaceUtil.o2m(o) + def jo2o[A](o: Optional[A]): Option[A] = InterfaceUtil.jo2o(o) def o2jo[A](o: Option[A]): Optional[A] = InterfaceUtil.o2jo(o) def position(line0: Option[Integer], content: String, offset0: Option[Integer], pointer0: Option[Integer],