Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Remove unnecessary F0, F1 and Maybe #84

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions internal/util-interface/src/main/java/xsbti/F0.java

This file was deleted.

6 changes: 0 additions & 6 deletions internal/util-interface/src/main/java/xsbti/F1.java

This file was deleted.

15 changes: 8 additions & 7 deletions internal/util-interface/src/main/java/xsbti/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
48 changes: 0 additions & 48 deletions internal/util-interface/src/main/java/xsbti/Maybe.java

This file was deleted.

33 changes: 16 additions & 17 deletions internal/util-logging/src/main/scala/sbt/util/InterfaceUtil.scala
Original file line number Diff line number Diff line change
@@ -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] =
Expand All @@ -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
Expand Down
42 changes: 21 additions & 21 deletions internal/util-logging/src/main/scala/sbt/util/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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],
Expand Down