use java.util.Optional in Position

This commit is contained in:
Eugene Yokota 2017-01-25 20:42:15 -05:00
parent c985d9cdc0
commit f76e3aa2bb
12 changed files with 137 additions and 19 deletions

View File

@ -3,16 +3,19 @@
*/
package xsbti;
import java.io.File;
import java.util.Optional;
public interface Position
{
Maybe<Integer> line();
Optional<Integer> line();
String lineContent();
Maybe<Integer> offset();
Optional<Integer> offset();
// pointer to the column position of the error/warning
Maybe<Integer> pointer();
Maybe<String> pointerSpace();
Optional<Integer> pointer();
Optional<String> pointerSpace();
Maybe<String> sourcePath();
Maybe<java.io.File> sourceFile();
}
Optional<String> sourcePath();
Optional<File> sourceFile();
}

View File

@ -1,5 +1,5 @@
/**
* This code is generated using sbt-datatype.
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY

View File

@ -1,5 +1,5 @@
/**
* This code is generated using sbt-datatype.
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY

View File

@ -1,5 +1,5 @@
/**
* This code is generated using sbt-datatype.
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY

View File

@ -1,5 +1,5 @@
/**
* This code is generated using sbt-datatype.
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY

View File

@ -1,5 +1,5 @@
/**
* This code is generated using sbt-datatype.
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
// DO NOT EDIT MANUALLY

View File

@ -0,0 +1,19 @@
package sbt.internal.util
@target(Java)
@codecPackage("sbt.internal.util.codec")
@fullCodec("JsonProtocol")
enum Severity
{
Info, Warn, Error
}
type Position {
line: Int
lineContent: String!
offset: Int
pointer: Int
pointerSpace: String
sourcePath: String
sourceFile: java.io.File
}

View File

@ -0,0 +1,49 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
package sbt.internal.util.codec
import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder }
import xsbti.Position
import java.util.Optional
trait PositionFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val PositionFormat: JsonFormat[Position] = new JsonFormat[Position] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Position = {
jsOpt match {
case Some(js) =>
unbuilder.beginObject(js)
val line0 = unbuilder.readField[Optional[java.lang.Integer]]("line")
val lineContent0 = unbuilder.readField[String]("lineContent")
val offset0 = unbuilder.readField[Optional[java.lang.Integer]]("offset")
val pointer0 = unbuilder.readField[Optional[java.lang.Integer]]("pointer")
val pointerSpace0 = unbuilder.readField[Optional[String]]("pointerSpace")
val sourcePath0 = unbuilder.readField[Optional[String]]("sourcePath")
val sourceFile0 = unbuilder.readField[Optional[java.io.File]]("sourceFile")
unbuilder.endObject()
new Position() {
override val line = line0
override val lineContent = lineContent0
override val offset = offset0
override val pointer = pointer0
override val pointerSpace = pointerSpace0
override val sourcePath = sourcePath0
override val sourceFile = sourceFile0
}
case None =>
deserializationError("Expected JsObject but found None")
}
}
override def write[J](obj: Position, builder: Builder[J]): Unit = {
builder.beginObject()
builder.addField("line", obj.line)
builder.addField("lineContent", obj.lineContent)
builder.addField("offset", obj.offset)
builder.addField("pointer", obj.pointer)
builder.addField("pointerSpace", obj.pointerSpace)
builder.addField("sourcePath", obj.sourcePath)
builder.addField("sourceFile", obj.sourceFile)
builder.endObject()
}
}
}

View File

@ -0,0 +1,33 @@
/**
* This code is generated using [[http://www.scala-sbt.org/contraband/ sbt-contraband]].
*/
package sbt.internal.util.codec
import _root_.sjsonnew.{ deserializationError, Builder, JsonFormat, Unbuilder }
import xsbti.Severity;
trait SeverityFormats { self: sjsonnew.BasicJsonProtocol =>
implicit lazy val SeverityFormat: JsonFormat[Severity] = new JsonFormat[Severity] {
override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): Severity = {
jsOpt match {
case Some(js) =>
unbuilder.readString(js) match {
case "Info" => Severity.Info
case "Warn" => Severity.Warn
case "Error" => Severity.Error
}
case None =>
deserializationError("Expected JsString but found None")
}
}
override def write[J](obj: Severity, builder: Builder[J]): Unit = {
val str = obj match {
case Severity.Info => "Info"
case Severity.Warn => "Warn"
case Severity.Error => "Error"
}
builder.writeString(str)
}
}
}

View File

@ -2,6 +2,7 @@ package sbt.util
import xsbti.{ Maybe, F0, F1, T2, Position, Problem, Severity }
import java.io.File
import java.util.Optional
object InterfaceUtil {
def f0[A](a: => A): F0[A] = new ConcreteF0[A](a)
@ -18,6 +19,16 @@ object InterfaceUtil {
case None => Maybe.nothing()
}
def jo2o[A](o: Optional[A]): Option[A] =
if (o.isPresent) Some(o.get)
else None
def o2jo[A](o: Option[A]): Optional[A] =
o match {
case Some(v) => Optional.ofNullable(v)
case None => Optional.empty[A]()
}
def position(line0: Option[Integer], content: String, offset0: Option[Integer], pointer0: Option[Integer],
pointerSpace0: Option[String], sourcePath0: Option[String], sourceFile0: Option[File]): Position =
new ConcretePosition(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0)
@ -61,13 +72,13 @@ object InterfaceUtil {
sourcePath0: Option[String],
sourceFile0: Option[File]
) extends Position {
val line = o2m(line0)
val line = o2jo(line0)
val lineContent = content
val offset = o2m(offset0)
val pointer = o2m(pointer0)
val pointerSpace = o2m(pointerSpace0)
val sourcePath = o2m(sourcePath0)
val sourceFile = o2m(sourceFile0)
val offset = o2jo(offset0)
val pointer = o2jo(pointer0)
val pointerSpace = o2jo(pointerSpace0)
val sourcePath = o2jo(sourcePath0)
val sourceFile = o2jo(sourceFile0)
}
private final class ConcreteProblem(

View File

@ -9,6 +9,7 @@ import sys.process.ProcessLogger
import sbt.internal.util.{ BufferedLogger, FullLogger }
import java.io.File
import java.util.Optional
/**
* This is intended to be the simplest logging interface for use by code that wants to log.
@ -88,6 +89,8 @@ 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],
pointerSpace0: Option[String], sourcePath0: Option[String], sourceFile0: Option[File]): Position =
InterfaceUtil.position(line0, content, offset0, pointer0, pointerSpace0, sourcePath0, sourceFile0)

View File

@ -1 +1 @@
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0-M3")
addSbtPlugin("org.scala-sbt" % "sbt-contraband" % "0.3.0-M4")