Skip to content

Commit

Permalink
Merge pull request #272 from Sciss/sciss_work
Browse files Browse the repository at this point in the history
add support for Scala 2.13.0-M5
  • Loading branch information
godenji authored Feb 8, 2019
2 parents 78c655f + 339a5e5 commit d722d18
Show file tree
Hide file tree
Showing 43 changed files with 189 additions and 145 deletions.
11 changes: 6 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++
sonatypeProfileName := organization.value,
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq(
"2.12.4",
"2.13.0-M5",
"2.12.8",
"2.11.12",
"2.10.7"
),
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq(
case Some((2, major)) if major >= 12 => Seq(
"-Xlint:-unused,_", "-Ywarn-unused:imports",
"-language:postfixOps", "-language:implicitConversions",
"-deprecation", "-feature"
Expand Down Expand Up @@ -76,8 +77,8 @@ def subprojectSettings(projectName: String) = commonSettings ++ Seq(
def scala2_11Dependencies = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, major)) if major >= 11 => Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
"org.scala-lang.modules" %% "scala-xml" % "1.1.1",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1"
)
case _ => Nil
}
Expand All @@ -89,7 +90,7 @@ lazy val scalariform = (project
settings(publishSettings("scalariform"))
settings(
libraryDependencies ++= scala2_11Dependencies.value,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.6-SNAP6" % Test,
// sbt doesn't automatically load the content of the MANIFST.MF file, therefore
// we have to do it here by ourselves. Furthermore, the version format in the
// MANIFEST.MF is `version.qualifier`, which means that we have to replace
Expand Down
11 changes: 6 additions & 5 deletions cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package scalariform.commandline

import java.io.File
import java.util.{ ArrayList, Collection }
import scala.collection.JavaConverters._
import java.util

import org.apache.commons.io._
import org.apache.commons.io.filefilter._

import scala.collection.JavaConverters._

object ScalaFileWalker extends DirectoryWalker(TrueFileFilter.INSTANCE, FileFilterUtils.suffixFileFilter(".scala"), -1) {

def findScalaFiles(path: String): List[File] = findScalaFiles(new File(path))

def findScalaFiles(path: File): List[File] = {
val results = new ArrayList[File]
val results = new util.ArrayList[File]
walk(path, results)
results.asScala.toList
}

override protected def handleFile(file: File, depth: Int, results: Collection[_]) {
val castResults = results.asInstanceOf[Collection[File]]
override protected def handleFile(file: File, depth: Int, results: util.Collection[_]): Unit = {
val castResults = results.asInstanceOf[util.Collection[File]]
castResults.add(file)
}

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.0.4
sbt.version=1.2.8
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")
2 changes: 1 addition & 1 deletion scalariform/src/main/scala/scalariform/ScalaVersions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ case class ScalaVersion(major: Int, minor: Int, extra: String = "") extends Orde

def compare(that: ScalaVersion): Int = Ordering[(Int, Int)].compare(this.majorMinor, that.majorMinor)

override def toString: String = major + "." + minor + "." + extra
override def toString: String = major.toString + "." + minor + "." + extra

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
*/
private def expandToEnclosingAst(node: AstNode, initialSelection: Range, enclosingNodes: List[AstNode]): Option[Range] = {

val nodeRange = adjustedNodeRange(node).getOrElse { return None }
val nodeRange = adjustedNodeRange(node) match {
case Some(r) => r
case None => return None
}

if (!nodeRange.contains(initialSelection)) { return None }

Expand Down Expand Up @@ -183,7 +186,7 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
nodeStack match {
case List(_: BlockExpr, _: MatchExpr, _*) false
case List(_: BlockExpr, _: ProcFunBody, _*) false
case List(node, _*) !(nonSelectableAstNodes contains node.getClass)
case node :: _ !(nonSelectableAstNodes contains node.getClass)
case Nil false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ trait CaseClauseFormatter { self: HasFormattingPreferences with ExprFormatter wi
statSeq.firstTokenOption.isDefined && newlineBefore(statSeq) ||
containsNewline(statSeq) && !singleExpr

def unindent(x: Map[Token, IntertokenFormatInstruction]) = x.map {
def unindent(x: Map[Token, IntertokenFormatInstruction]): Map[Token, IntertokenFormatInstruction] = x.map {
case (k, EnsureNewlineAndIndent(indentLevel, relativeTo)) =>
k -> EnsureNewlineAndIndent(indentLevel - 1, relativeTo)
case z => z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ abstract class ScalaFormatter
object ScalaFormatter {

// format: OFF
val ENSURE_SPACE_AFTER = Set(
val ENSURE_SPACE_AFTER: Set[TokenType] = Set(
ABSTRACT, CASE, CATCH, CLASS, DEF,
DO, ELSE, EXTENDS, FINAL,
FINALLY, FOR, FORSOME, IF, IMPLICIT,
Expand All @@ -566,7 +566,7 @@ object ScalaFormatter {
/* USCORE, */ COLON, EQUALS, ARROW, LARROW, SUBTYPE, VIEWBOUND, SUPERTYPE, /* HASH, AT */
LBRACE, SEMI)

val ENSURE_SPACE_BEFORE = Set(
val ENSURE_SPACE_BEFORE: Set[TokenType] = Set(
ABSTRACT, CASE, CATCH, CLASS, DEF,
/* DO, */ ELSE, EXTENDS, FINAL,
FINALLY, /* FOR, */ FORSOME, /* IF, */ IMPLICIT,
Expand All @@ -589,7 +589,7 @@ object ScalaFormatter {
@throws(classOf[ScalaParserException])
def formatAsEdits(source: String, formattingPreferences: IFormattingPreferences = FormattingPreferences(), lineDelimiter: Option[String] = None,
initialIndentLevel: Int = 0, scalaVersion: String = ScalaVersions.DEFAULT_VERSION): List[TextEdit] = {
val specificFormatter = new SpecificFormatter {
val specificFormatter: SpecificFormatter = new SpecificFormatter {

type Result = CompilationUnit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ case class IntegerPreference(min: Int, max: Int) extends PreferenceType[Int] {
try {
val n = Integer.parseInt(s)
if (n < min)
Left(n + " is below minimum of " + min)
Left(n.toString + " is below minimum of " + min)
else if (n > max)
Left(n + " is above maximum of " + max)
Left(n.toString + " is above maximum of " + max)
else
Right(n)
} catch {
Expand Down
11 changes: 7 additions & 4 deletions scalariform/src/main/scala/scalariform/lexer/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ object Tokens {
val XML_UNPARSED = TokenType("XML_UNPARSED", isXml = true)
val XML_PROCESSING_INSTRUCTION = TokenType("XML_PROCESSING_INSTRUCTION", isXml = true)

val KEYWORDS = Set(
val KEYWORDS: Set[TokenType] = Set(
ABSTRACT, CASE, CATCH, CLASS, DEF,
DO, ELSE, EXTENDS, FINAL,
FINALLY, FOR, FORSOME, IF, IMPLICIT,
Expand All @@ -109,10 +109,13 @@ object Tokens {
VAL, VAR, WHILE, WITH, YIELD
)

val COMMENTS = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT)
val COMMENTS: Set[TokenType] = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT)

val IDS = Set(VARID, PLUS, MINUS, STAR, PIPE, TILDE, EXCLAMATION)
val IDS: Set[TokenType] = Set(VARID, PLUS, MINUS, STAR, PIPE, TILDE, EXCLAMATION)

val LITERALS = Set(CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL, STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL)
val LITERALS: Set[TokenType] = Set(
CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL,
STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL
)

}
4 changes: 3 additions & 1 deletion scalariform/src/main/scala/scalariform/parser/AstNodes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ sealed trait AstNode extends Product {
case Right(f) f.tokens
}
}
protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable { val tokens = List(token) }
protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable {
val tokens: List[Token] = List(token)
}

protected def flatten(flattenables: Flattenable*): List[Token] = flattenables.toList flatMap { _.tokens }

Expand Down
8 changes: 4 additions & 4 deletions scalariform/src/main/scala/scalariform/utils/Range.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package scalariform.utils

case class Range(offset: Int, length: Int) {

def contains(other: Range) = other.offset >= offset && other.offset + other.length <= offset + length
def contains(other: Range): Boolean = other.offset >= offset && other.offset + other.length <= offset + length

def strictlyContains(other: Range) = (this contains other) && this.length > other.length
def strictlyContains(other: Range): Boolean = (this contains other) && this.length > other.length

/**
* @return the smallest range that contains both this and other
*/
def mergeWith(other: Range) = {
def mergeWith(other: Range): Range = {
val List(earliest, latest) = List(this, other) sortBy (_.offset)
Range(earliest.offset, latest.offset - earliest.offset + latest.length)
}

def intersects(other: Range) =
def intersects(other: Range): Boolean =
!(other.offset >= offset + length || other.offset + other.length - 1 < offset)

def expandLeft(n: Int): Range = Range(offset - n, length + n)
Expand Down
4 changes: 2 additions & 2 deletions scalariform/src/main/scala/scalariform/utils/TextEdits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ case class TextEdit(position: Int, length: Int, replacement: String) {

require(length >= 0)

override lazy val toString = {
override lazy val toString: String = {
val replacementDisplay = replacement.replace("\n", """\n""").replace("\r", """\r""")
getClass.getSimpleName + "(position = " + position + ", length = " + length + ", replacement = '" + replacementDisplay + "')"
}

def shift(n: Int) = copy(position = position + n)
def shift(n: Int): TextEdit = copy(position = position + n)

}

Expand Down
2 changes: 1 addition & 1 deletion scalariform/src/main/scala/scalariform/utils/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import scala.collection.mutable.ListBuffer

object Utils {

implicit def string2PimpedString(s: String) = new PimpedString(s)
implicit def string2PimpedString(s: String): PimpedString = new PimpedString(s)

class PimpedString(s: String) {
def toIntOpt: Option[Int] = try Some(s.toInt) catch { case _: NumberFormatException None }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class AstSelectorTest extends FlatSpec with Matchers {
*/

{
implicit val scalaVersion = "2.10.0"
implicit val scalaVersion: String = "2.10.0"

""" s"my name is ?{person.name}." """.replace('?', '$') ~
""" $$$$$$ " """ ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ abstract class AbstractExpressionFormatterTest extends AbstractFormatterTest {

type Result = Expr

def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState())
def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState())

def parse(parser: ScalaParser) = parser.expr()
def parse(parser: ScalaParser): Result = parser.expr()

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi

require(formattingPreferences != null)

def ==>(expectedRaw: String) {
def ==>(expectedRaw: String): Unit =
it should ("format >>>" + prettyPrint(source) + "<<< as >>>" + prettyPrint(expectedRaw) + "<<< with preferences " + formattingPreferences + " in version " + scalaVersion) in {
val expected = expectedRaw.stripMargin
val actual = format(source, scalaVersion = scalaVersion)(formattingPreferences)
Expand All @@ -45,15 +45,14 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi
throw testFailedException("Idempotency token inconsistency:\n ---- One ---- \n" + afterTokens2 + "\n ---- Twice ---- \n" + afterTokens2 + "\n")
}
}
}

def =/=>(expected: String): Because = {
//println("Warning -- skipped test:\n" + source)
new Because(expected)
}

class Because(expected: String) {
def because(reason: String) = {
def because(reason: String): Unit = {
//println("because " + reason)
it should ("format >>>" + prettyPrint(source) + "<<< as >>>" + prettyPrint(expected) + "<<<, but did not because " + reason) in {
throw new TestPendingException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
|}"""

{
implicit val formattingPreferences = FormattingPreferences.setPreference(
implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(
SingleCasePatternOnNewline, false
)
"""a match { case a => b; c;
Expand Down Expand Up @@ -187,7 +187,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
|}"""

{
implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)

"""a match {
| case b(c @ ~()) =>
Expand All @@ -201,7 +202,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {

{

implicit val formattingPreferences = FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true)

"""a match {
|case x => 1
Expand Down Expand Up @@ -285,7 +287,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
|}"""

{
implicit val formattingPreferences =
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true).setPreference(RewriteArrowSymbols, true)

"""a match {
Expand All @@ -300,7 +302,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {

{

implicit val formattingPreferences =
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 5)
Expand Down Expand Up @@ -354,7 +356,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
|}"""

{
implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)

"""(a: @switch) match {
|case elem@Multi(values@_*) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class CommentFormatterTest extends AbstractFormatterTest {

type Result = CompilationUnit

def parse(parser: ScalaParser) = parser.scriptBody()
def parse(parser: ScalaParser): Result = parser.scriptBody()

def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState())
def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState())

override val debug = false

Expand Down Expand Up @@ -142,7 +142,8 @@ class CommentFormatterTest extends AbstractFormatterTest {
| */ """

{
implicit val formattingPreferences = FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)

"""/** This method applies f to each
| * element of the given list.
Expand Down Expand Up @@ -175,7 +176,8 @@ class CommentFormatterTest extends AbstractFormatterTest {
}

{
implicit val formattingPreferences = FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)

"""/** This method applies f to each
| * element of the given list.
Expand Down Expand Up @@ -211,7 +213,7 @@ class CommentFormatterTest extends AbstractFormatterTest {
}

{
implicit val formattingPreferences = FormattingPreferences
implicit val formattingPreferences: FormattingPreferences = FormattingPreferences
.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
"""/** This method applies f to each
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import scalariform.formatter.preferences._
// format: OFF
class CompactControlReadabilityTest extends AbstractExpressionFormatterTest {

implicit val formattingPreferences = FormattingPreferences.setPreference(CompactControlReadability, true)
implicit val formattingPreferences: FormattingPreferences =
FormattingPreferences.setPreference(CompactControlReadability, true)

"""if(a){
|foo
Expand Down
Loading

0 comments on commit d722d18

Please sign in to comment.