Skip to content
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
20 changes: 13 additions & 7 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
version = 2.4.2
edition = 2019-10
version = 3.10.7
runner.dialect = Scala212Source3
maxColumn = 100
project.git = true

# http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings = JavaDoc

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
docstrings.style = Asterisk
docstrings.wrap = no

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
Expand All @@ -19,6 +17,14 @@ align.openParenCallSite = false
align.openParenDefnSite = false

# For better code clarity
danglingParentheses = true
danglingParentheses.preset = true

trailingCommas = preserve

rewrite.scala3.convertToNewSyntax = true
runner.dialectOverride {
allowSignificantIndentation = false
allowAsForImportRename = false
allowStarWildcardImport = false
allowPostfixStarVarargSplices = false
}
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ lazy val treeExample = (project in (file("examples") / "bt"))
})
.settings(relaxOldScala)

def relaxOldScala: Seq[Setting[_]] = Seq(
def relaxOldScala: Seq[Setting[?]] = Seq(
scalacOptions := {
val old = scalacOptions.value
CrossVersion.partialVersion(scalaVersion.value) match {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/LowPriorityCollectionTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sbinary
import scala.collection.Factory

trait LowPriorityCollectionTypes extends Generic {
def canBuildFormat[CC[X] <: Iterable[X], T](
implicit bin: Format[T],
def canBuildFormat[CC[X] <: Iterable[X], T](implicit
bin: Format[T],
cbf: Factory[T, CC[T]]
): Format[CC[T]] =
new LengthEncoded[CC[T], T] {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13-/LowPriorityCollectionTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package sbinary
import scala.collection.generic.CanBuildFrom

trait LowPriorityCollectionTypes extends Generic {
def canBuildFormat[CC[X] <: Traversable[X], T](
implicit bin: Format[T],
def canBuildFormat[CC[X] <: Traversable[X], T](implicit
bin: Format[T],
cbf: CanBuildFrom[Nothing, T, CC[T]]
): Format[CC[T]] =
new LengthEncoded[CC[T], T] {
Expand Down
52 changes: 26 additions & 26 deletions core/src/main/scala/javaprotocol.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sbinary;
import Operations._;

trait StandardPrimitives extends CoreProtocol {
private def readUnsigned(in: Input) = in.readByte.toInt & 0xFF
private def readUnsigned(in: Input) = in.readByte.toInt & 0xff

implicit object BooleanFormat extends Format[Boolean] {
def reads(in: Input) = in.readByte != 0
Expand All @@ -13,16 +13,16 @@ trait StandardPrimitives extends CoreProtocol {
implicit object CharFormat extends Format[Char] {
def reads(in: Input) = ((readUnsigned(in) << 8) + readUnsigned(in)).toChar;
def writes(out: Output, t: Char) = {
out.writeByte(((t >>> 8) & 0xFF).toByte);
out.writeByte(((t >>> 0) & 0xFF).toByte);
out.writeByte(((t >>> 8) & 0xff).toByte);
out.writeByte(((t >>> 0) & 0xff).toByte);
}
}

implicit object ShortFormat extends Format[Short] {
def reads(in: Input) = ((readUnsigned(in) << 8) + readUnsigned(in)).toShort

def writes(out: Output, t: Short) = {
out.writeByte(((t >>> 8) & 0xFF).toByte);
out.writeByte(((t >>> 8) & 0xff).toByte);
out.writeByte(t.toByte);
}
}
Expand All @@ -37,10 +37,10 @@ trait StandardPrimitives extends CoreProtocol {
}

def writes(out: Output, t: Int): Unit = {
out.writeByte(((t >>> 24) & 0xFF).toByte);
out.writeByte(((t >>> 16) & 0xFF).toByte);
out.writeByte(((t >>> 8) & 0xFF).toByte);
out.writeByte(((t >>> 0) & 0xFF).toByte);
out.writeByte(((t >>> 24) & 0xff).toByte);
out.writeByte(((t >>> 16) & 0xff).toByte);
out.writeByte(((t >>> 8) & 0xff).toByte);
out.writeByte(((t >>> 0) & 0xff).toByte);
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ trait StandardPrimitives extends CoreProtocol {
}

trait JavaUTF extends CoreProtocol {
private[this] def readUnsignedByte(in: Input): Int = in.readByte.toInt & 0xFF
private[this] def readUnsignedByte(in: Input): Int = in.readByte.toInt & 0xff
private[this] def readUnsignedShort(in: Input): Int =
(readUnsignedByte(in) << 8) + readUnsignedByte(in)

Expand Down Expand Up @@ -116,7 +116,7 @@ trait JavaUTF extends CoreProtocol {
}

while (count < utflen) {
c = bbuffer(count).toInt & 0xFF
c = bbuffer(count).toInt & 0xff
cbuffer(charCount) = ((c >> 4) match {
case 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 => {
count += 1;
Expand All @@ -127,17 +127,17 @@ trait JavaUTF extends CoreProtocol {
if (count > utflen) partial;

char2 = bbuffer(count - 1)
if ((char2 & 0xC0) != 0x80) malformed(count);
(((c & 0x1F) << 6) | (char2 & 0x3F));
if ((char2 & 0xc0) != 0x80) malformed(count);
(((c & 0x1f) << 6) | (char2 & 0x3f));
}
case 14 => {
count += 3;
char2 = bbuffer(count - 2);
char3 = bbuffer(count - 1);
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
if (((char2 & 0xc0) != 0x80) || ((char3 & 0xc0) != 0x80))
malformed(count - 1);

((c & 0x0F).toInt << 12) | ((char2 & 0x3F).toInt << 6) | ((char3 & 0x3F).toInt << 0);
((c & 0x0f).toInt << 12) | ((char2 & 0x3f).toInt << 6) | ((char3 & 0x3f).toInt << 0);
}
case _ => malformed(count);
}).toChar
Expand All @@ -155,8 +155,8 @@ trait JavaUTF extends CoreProtocol {

while (i < value.length) {
utflen += (
if ((c >= 0x0001) && (c <= 0x007F)) 1
else if (c > 0x07FF) 3
if ((c >= 0x0001) && (c <= 0x007f)) 1
else if (c > 0x07ff) 3
else 2
)
i += 1;
Expand All @@ -172,26 +172,26 @@ trait JavaUTF extends CoreProtocol {
count += 1;
}

append((utflen >>> 8) & 0xFF)
append(utflen & 0xFF)
append((utflen >>> 8) & 0xff)
append(utflen & 0xff)

i = 0;
while ((i < value.length) && ((c >= 0x0001) && (c <= 0x007F))) {
while ((i < value.length) && ((c >= 0x0001) && (c <= 0x007f))) {
bbuffer(count) = c.toByte;
count += 1;
i += 1;
}

while (i < value.length) {
if ((c >= 0x0001) && (c <= 0x007F)) {
if ((c >= 0x0001) && (c <= 0x007f)) {
append(c);
} else if (c > 0x07FF) {
append(0xE0 | ((c >> 12) & 0x0F));
append(0x80 | ((c >> 6) & 0x3F));
append(0x80 | ((c >> 0) & 0x3F));
} else if (c > 0x07ff) {
append(0xe0 | ((c >> 12) & 0x0f));
append(0x80 | ((c >> 6) & 0x3f));
append(0x80 | ((c >> 0) & 0x3f));
} else {
append(0xC0 | ((c >> 6) & 0x1F));
append(0x80 | ((c >> 0) & 0x3F));
append(0xc0 | ((c >> 6) & 0x1f));
append(0x80 | ((c >> 0) & 0x3f));
}

i += 1;
Expand Down
33 changes: 13 additions & 20 deletions core/src/test/scala/binaryTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ object Equal {
}
}

implicit def eqTuple3[S, T, U](
implicit
implicit def eqTuple3[S, T, U](implicit
eqS: Equal[S],
eqT: Equal[T],
eqU: Equal[U]
Expand Down Expand Up @@ -78,8 +77,7 @@ import Equal._;
object CompatTests extends Properties("CompatTests") {
import java.io._;

def compatFor[T](name: String, readJ: DataInput => T, writeJ: (DataOutput, T) => Unit)(
implicit
def compatFor[T](name: String, readJ: DataInput => T, writeJ: (DataOutput, T) => Unit)(implicit
fmt: Format[T],
arb: Arbitrary[T]
) = {
Expand Down Expand Up @@ -130,40 +128,35 @@ object LazyIOTests extends Properties("LazyIO") {
}

object FormatTests extends Properties("Formats") {
def validFormat[T](
implicit
def validFormat[T](implicit
bin: Format[T],
arb: Arbitrary[T],
equal: Equal[T]
) =
forAll(
(x: T) =>
try {
equal(x, fromByteArray[T](toByteArray(x)))
} catch {
case (e: Throwable) => e.printStackTrace; false
}
forAll((x: T) =>
try {
equal(x, fromByteArray[T](toByteArray(x)))
} catch {
case (e: Throwable) => e.printStackTrace; false
}
)

def formatSpec[T](name: String)(
implicit
def formatSpec[T](name: String)(implicit
bin: Format[T],
arb: Arbitrary[T],
equal: Equal[T]
) = { property(name) = validFormat[T] }

implicit def arbitrarySortedMap[K, V](
implicit
implicit def arbitrarySortedMap[K, V](implicit
ord: Ordering[K],
arbK: Arbitrary[K],
arbV: Arbitrary[V]
): Arbitrary[immutable.SortedMap[K, V]] = {
Arbitrary(arbitrary[List[(K, V)]].map(x => immutable.TreeMap(x: _*)))
}

//implicit def arbitrarySet[T](implicit arb : Arbitrary[T]) : Arbitrary[immutable.Set[T]] = Arbitrary(arbitrary[List[T]].map((x : List[T]) => immutable.Set(x :_*)));
implicit def arbitraryArray[T](
implicit
// implicit def arbitrarySet[T](implicit arb : Arbitrary[T]) : Arbitrary[immutable.Set[T]] = Arbitrary(arbitrary[List[T]].map((x : List[T]) => immutable.Set(x :_*)));
implicit def arbitraryArray[T](implicit
arb: Arbitrary[T],
mf: scala.reflect.Manifest[T]
): Arbitrary[Array[T]] =
Expand Down
13 changes: 9 additions & 4 deletions project/Fmpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import Keys._

object Fmpp {

/*** Templating **/
/**
* * Templating *
*/
lazy val fmpp = TaskKey[Seq[File]]("fmpp")
lazy val fmppOptions = SettingKey[Seq[String]]("fmpp-options")
lazy val FmppConfig = config("fmpp") hide
Expand All @@ -13,11 +15,13 @@ object Fmpp {
libraryDependencies += "net.sourceforge.fmpp" % "fmpp" % "0.9.16" % FmppConfig,
ivyConfigurations += FmppConfig,
fmppOptions := "--ignore-temporary-files" :: Nil,
FmppConfig / fullClasspath := update.value select configurationFilter(FmppConfig.name) map Attributed.blank
FmppConfig / fullClasspath := update.value select configurationFilter(
FmppConfig.name
) map Attributed.blank
)

import sbt.io.Path._
def fmppConfig(c: Configuration): Seq[Setting[_]] =
def fmppConfig(c: Configuration): Seq[Setting[?]] =
inConfig(c)(
Seq(
sourceGenerators += fmpp,
Expand All @@ -35,7 +39,8 @@ object Fmpp {
val args = fmppOptions.value
val s = streams.value
IO.delete(output)
val arguments = "-U" +: "all" +: "-S" +: srcRoot.getAbsolutePath +: "-O" +: output.getAbsolutePath +: (args ++ sources.getPaths)
val arguments =
"-U" +: "all" +: "-S" +: srcRoot.getAbsolutePath +: "-O" +: output.getAbsolutePath +: (args ++ sources.getPaths)
r.run("fmpp.tools.CommandLine", cp.files, arguments, s.log) // .foreach(sys.error)
(output ** "*.scala").get
}
Expand Down
12 changes: 6 additions & 6 deletions project/HouseRulesPlugins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ object HouseRulesPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

override def buildSettings: Seq[Def.Setting[_]] = baseBuildSettings
override def projectSettings: Seq[Def.Setting[_]] = baseSettings
override def buildSettings: Seq[Def.Setting[?]] = baseBuildSettings
override def projectSettings: Seq[Def.Setting[?]] = baseSettings

lazy val baseBuildSettings: Seq[Def.Setting[_]] = Seq()
lazy val baseBuildSettings: Seq[Def.Setting[?]] = Seq()

lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
lazy val baseSettings: Seq[Def.Setting[?]] = Seq(
scalacOptions ++= Seq("-encoding", "utf8"),
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlint"),
scalacOptions += "-language:higherKinds",
Expand All @@ -31,8 +31,8 @@ object HouseRulesPlugin extends AutoPlugin {
scalacOptions += "-Ywarn-numeric-widen",
scalacOptions += "-Ywarn-value-discard",
scalacOptions ++= "-Ywarn-unused-import".ifScala(v => 11 <= v && v <= 12).value.toList
) ++ Seq(Compile, Test).flatMap(
c => c / console / scalacOptions --= Seq("-Ywarn-unused-import", "-Xlint")
) ++ Seq(Compile, Test).flatMap(c =>
c / console / scalacOptions --= Seq("-Ywarn-unused-import", "-Xlint")
)

private def scalaPartV = Def setting (CrossVersion partialVersion scalaVersion.value)
Expand Down
Loading