mirror of https://github.com/sbt/sbt.git
Remove unnecessary F0, F1 and Maybe
`F0`, `F1` and `Maybe` have become useless since Java 8 introduced `Supplier`, `Function` and `Optional` in the default Java 8 standard library. Therefore, they are not necessary anymore. This change is required to change some Zinc's and sbt APIs. They are not widely used, so the changes will be small.
This commit is contained in:
parent
fe7743878f
commit
18a73db57d
|
|
@ -1,9 +0,0 @@
|
|||
/* sbt -- Simple Build Tool
|
||||
* Copyright 2009 Mark Harrah
|
||||
*/
|
||||
package xsbti;
|
||||
|
||||
public interface F0<T>
|
||||
{
|
||||
T apply();
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
package xsbti;
|
||||
|
||||
public interface F1<A1, R>
|
||||
{
|
||||
R apply(A1 a1);
|
||||
}
|
||||
|
|
@ -3,11 +3,12 @@
|
|||
*/
|
||||
package xsbti;
|
||||
|
||||
public interface Logger
|
||||
{
|
||||
void error(F0<String> msg);
|
||||
void warn(F0<String> msg);
|
||||
void info(F0<String> msg);
|
||||
void debug(F0<String> msg);
|
||||
void trace(F0<Throwable> exception);
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Logger {
|
||||
void error(Supplier<String> msg);
|
||||
void warn(Supplier<String> msg);
|
||||
void info(Supplier<String> msg);
|
||||
void debug(Supplier<String> msg);
|
||||
void trace(Supplier<Throwable> exception);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<t> {
|
||||
private Maybe() {}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <s> Maybe<s> nothing() { return (Maybe<s>) Nothing.INSTANCE; }
|
||||
public static <s> Maybe<s> just(final s v) { return new Just<s>(v); }
|
||||
|
||||
public static final class Just<s> extends Maybe<s> {
|
||||
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<Object> {
|
||||
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();
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
|
|
|
|||
Loading…
Reference in New Issue