Skip to content

Commit 339a5e5

Browse files
committed
add support for Scala 2.13.0-M5
- add to cross-versions - update dependencies as necessary - some code clean up (explicit return types in public methods, no procedure syntax, return types for implicit values)
1 parent 5cda34e commit 339a5e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+189
-145
lines changed

build.sbt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++
1010
sonatypeProfileName := organization.value,
1111
scalaVersion := crossScalaVersions.value.head,
1212
crossScalaVersions := Seq(
13-
"2.12.4",
13+
"2.13.0-M5",
14+
"2.12.8",
1415
"2.11.12",
1516
"2.10.7"
1617
),
1718
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
18-
case Some((2, 12)) => Seq(
19+
case Some((2, major)) if major >= 12 => Seq(
1920
"-Xlint:-unused,_", "-Ywarn-unused:imports",
2021
"-language:postfixOps", "-language:implicitConversions",
2122
"-deprecation", "-feature"
@@ -76,8 +77,8 @@ def subprojectSettings(projectName: String) = commonSettings ++ Seq(
7677
def scala2_11Dependencies = Def.setting {
7778
CrossVersion.partialVersion(scalaVersion.value) match {
7879
case Some((2, major)) if major >= 11 => Seq(
79-
"org.scala-lang.modules" %% "scala-xml" % "1.0.6",
80-
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.6"
80+
"org.scala-lang.modules" %% "scala-xml" % "1.1.1",
81+
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1"
8182
)
8283
case _ => Nil
8384
}
@@ -89,7 +90,7 @@ lazy val scalariform = (project
8990
settings(publishSettings("scalariform"))
9091
settings(
9192
libraryDependencies ++= scala2_11Dependencies.value,
92-
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.4" % "test",
93+
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.6-SNAP6" % Test,
9394
// sbt doesn't automatically load the content of the MANIFST.MF file, therefore
9495
// we have to do it here by ourselves. Furthermore, the version format in the
9596
// MANIFEST.MF is `version.qualifier`, which means that we have to replace

cli/src/main/scala/scalariform/commandline/ScalaFileWalker.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package scalariform.commandline
22

33
import java.io.File
4-
import java.util.{ ArrayList, Collection }
5-
import scala.collection.JavaConverters._
4+
import java.util
65

76
import org.apache.commons.io._
87
import org.apache.commons.io.filefilter._
98

9+
import scala.collection.JavaConverters._
10+
1011
object ScalaFileWalker extends DirectoryWalker(TrueFileFilter.INSTANCE, FileFilterUtils.suffixFileFilter(".scala"), -1) {
1112

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

1415
def findScalaFiles(path: File): List[File] = {
15-
val results = new ArrayList[File]
16+
val results = new util.ArrayList[File]
1617
walk(path, results)
1718
results.asScala.toList
1819
}
1920

20-
override protected def handleFile(file: File, depth: Int, results: Collection[_]) {
21-
val castResults = results.asInstanceOf[Collection[File]]
21+
override protected def handleFile(file: File, depth: Int, results: util.Collection[_]): Unit = {
22+
val castResults = results.asInstanceOf[util.Collection[File]]
2223
castResults.add(file)
2324
}
2425

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.0.4
1+
sbt.version=1.2.8

project/plugins.sbt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.2")
2-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
3-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
2+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
3+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
44
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.0")
5-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
6-
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18")
5+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
6+
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.3.0")

scalariform/src/main/scala/scalariform/ScalaVersions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ case class ScalaVersion(major: Int, minor: Int, extra: String = "") extends Orde
2929

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

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

3434
}
3535

scalariform/src/main/scala/scalariform/astselect/AstSelector.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
147147
*/
148148
private def expandToEnclosingAst(node: AstNode, initialSelection: Range, enclosingNodes: List[AstNode]): Option[Range] = {
149149

150-
val nodeRange = adjustedNodeRange(node).getOrElse { return None }
150+
val nodeRange = adjustedNodeRange(node) match {
151+
case Some(r) => r
152+
case None => return None
153+
}
151154

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

@@ -183,7 +186,7 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
183186
nodeStack match {
184187
case List(_: BlockExpr, _: MatchExpr, _*) false
185188
case List(_: BlockExpr, _: ProcFunBody, _*) false
186-
case List(node, _*) !(nonSelectableAstNodes contains node.getClass)
189+
case node :: _ !(nonSelectableAstNodes contains node.getClass)
187190
case Nil false
188191
}
189192

scalariform/src/main/scala/scalariform/formatter/CaseClauseFormatter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ trait CaseClauseFormatter { self: HasFormattingPreferences with ExprFormatter wi
125125
statSeq.firstTokenOption.isDefined && newlineBefore(statSeq) ||
126126
containsNewline(statSeq) && !singleExpr
127127

128-
def unindent(x: Map[Token, IntertokenFormatInstruction]) = x.map {
128+
def unindent(x: Map[Token, IntertokenFormatInstruction]): Map[Token, IntertokenFormatInstruction] = x.map {
129129
case (k, EnsureNewlineAndIndent(indentLevel, relativeTo)) =>
130130
k -> EnsureNewlineAndIndent(indentLevel - 1, relativeTo)
131131
case z => z

scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ abstract class ScalaFormatter
554554
object ScalaFormatter {
555555

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

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

594594
type Result = CompilationUnit
595595

scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ case class IntegerPreference(min: Int, max: Int) extends PreferenceType[Int] {
5050
try {
5151
val n = Integer.parseInt(s)
5252
if (n < min)
53-
Left(n + " is below minimum of " + min)
53+
Left(n.toString + " is below minimum of " + min)
5454
else if (n > max)
55-
Left(n + " is above maximum of " + max)
55+
Left(n.toString + " is above maximum of " + max)
5656
else
5757
Right(n)
5858
} catch {

scalariform/src/main/scala/scalariform/lexer/Tokens.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ object Tokens {
9898
val XML_UNPARSED = TokenType("XML_UNPARSED", isXml = true)
9999
val XML_PROCESSING_INSTRUCTION = TokenType("XML_PROCESSING_INSTRUCTION", isXml = true)
100100

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

112-
val COMMENTS = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT)
112+
val COMMENTS: Set[TokenType] = Set(LINE_COMMENT, MULTILINE_COMMENT, XML_COMMENT)
113113

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

116-
val LITERALS = Set(CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL, STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL)
116+
val LITERALS: Set[TokenType] = Set(
117+
CHARACTER_LITERAL, INTEGER_LITERAL, FLOATING_POINT_LITERAL, STRING_LITERAL,
118+
STRING_PART, SYMBOL_LITERAL, TRUE, FALSE, NULL
119+
)
117120

118121
}

scalariform/src/main/scala/scalariform/parser/AstNodes.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ sealed trait AstNode extends Product {
3232
case Right(f) f.tokens
3333
}
3434
}
35-
protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable { val tokens = List(token) }
35+
protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable {
36+
val tokens: List[Token] = List(token)
37+
}
3638

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

scalariform/src/main/scala/scalariform/utils/Range.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package scalariform.utils
22

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

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

7-
def strictlyContains(other: Range) = (this contains other) && this.length > other.length
7+
def strictlyContains(other: Range): Boolean = (this contains other) && this.length > other.length
88

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

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

2020
def expandLeft(n: Int): Range = Range(offset - n, length + n)

scalariform/src/main/scala/scalariform/utils/TextEdits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ case class TextEdit(position: Int, length: Int, replacement: String) {
1414

1515
require(length >= 0)
1616

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

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

2424
}
2525

scalariform/src/main/scala/scalariform/utils/Utils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.collection.mutable.ListBuffer
77

88
object Utils {
99

10-
implicit def string2PimpedString(s: String) = new PimpedString(s)
10+
implicit def string2PimpedString(s: String): PimpedString = new PimpedString(s)
1111

1212
class PimpedString(s: String) {
1313
def toIntOpt: Option[Int] = try Some(s.toInt) catch { case _: NumberFormatException None }

scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class AstSelectorTest extends FlatSpec with Matchers {
282282
*/
283283

284284
{
285-
implicit val scalaVersion = "2.10.0"
285+
implicit val scalaVersion: String = "2.10.0"
286286

287287
""" s"my name is ?{person.name}." """.replace('?', '$') ~
288288
""" $$$$$$ " """ ~

scalariform/src/test/scala/scalariform/formatter/AbstractExpressionFormatterTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ abstract class AbstractExpressionFormatterTest extends AbstractFormatterTest {
66

77
type Result = Expr
88

9-
def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState())
9+
def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState())
1010

11-
def parse(parser: ScalaParser) = parser.expr()
11+
def parse(parser: ScalaParser): Result = parser.expr()
1212

1313
}

scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class AbstractFormatterTest extends FlatSpec with Matchers with Specifi
2323

2424
require(formattingPreferences != null)
2525

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

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

5554
class Because(expected: String) {
56-
def because(reason: String) = {
55+
def because(reason: String): Unit = {
5756
//println("because " + reason)
5857
it should ("format >>>" + prettyPrint(source) + "<<< as >>>" + prettyPrint(expected) + "<<<, but did not because " + reason) in {
5958
throw new TestPendingException

scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
8585
|}"""
8686

8787
{
88-
implicit val formattingPreferences = FormattingPreferences.setPreference(
88+
implicit val formattingPreferences: FormattingPreferences = FormattingPreferences.setPreference(
8989
SingleCasePatternOnNewline, false
9090
)
9191
"""a match { case a => b; c;
@@ -187,7 +187,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
187187
|}"""
188188

189189
{
190-
implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
190+
implicit val formattingPreferences: FormattingPreferences =
191+
FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
191192

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

202203
{
203204

204-
implicit val formattingPreferences = FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true)
205+
implicit val formattingPreferences: FormattingPreferences =
206+
FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true)
205207

206208
"""a match {
207209
|case x => 1
@@ -285,7 +287,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
285287
|}"""
286288

287289
{
288-
implicit val formattingPreferences =
290+
implicit val formattingPreferences: FormattingPreferences =
289291
FormattingPreferences.setPreference(AlignSingleLineCaseStatements, true).setPreference(RewriteArrowSymbols, true)
290292

291293
"""a match {
@@ -300,7 +302,7 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
300302

301303
{
302304

303-
implicit val formattingPreferences =
305+
implicit val formattingPreferences: FormattingPreferences =
304306
FormattingPreferences
305307
.setPreference(AlignSingleLineCaseStatements, true)
306308
.setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 5)
@@ -354,7 +356,8 @@ class CaseClausesFormatterTest extends AbstractExpressionFormatterTest {
354356
|}"""
355357

356358
{
357-
implicit val formattingPreferences = FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
359+
implicit val formattingPreferences: FormattingPreferences =
360+
FormattingPreferences.setPreference(SpacesWithinPatternBinders, false)
358361

359362
"""(a: @switch) match {
360363
|case elem@Multi(values@_*) =>

scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class CommentFormatterTest extends AbstractFormatterTest {
88

99
type Result = CompilationUnit
1010

11-
def parse(parser: ScalaParser) = parser.scriptBody()
11+
def parse(parser: ScalaParser): Result = parser.scriptBody()
1212

13-
def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState())
13+
def format(formatter: ScalaFormatter, result: Result): FormatResult = formatter.format(result)(FormatterState())
1414

1515
override val debug = false
1616

@@ -142,7 +142,8 @@ class CommentFormatterTest extends AbstractFormatterTest {
142142
| */ """
143143

144144
{
145-
implicit val formattingPreferences = FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
145+
implicit val formattingPreferences: FormattingPreferences =
146+
FormattingPreferences.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
146147

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

177178
{
178-
implicit val formattingPreferences = FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
179+
implicit val formattingPreferences: FormattingPreferences =
180+
FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
179181

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

213215
{
214-
implicit val formattingPreferences = FormattingPreferences
216+
implicit val formattingPreferences: FormattingPreferences = FormattingPreferences
215217
.setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
216218
.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
217219
"""/** This method applies f to each

scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import scalariform.formatter.preferences._
55
// format: OFF
66
class CompactControlReadabilityTest extends AbstractExpressionFormatterTest {
77

8-
implicit val formattingPreferences = FormattingPreferences.setPreference(CompactControlReadability, true)
8+
implicit val formattingPreferences: FormattingPreferences =
9+
FormattingPreferences.setPreference(CompactControlReadability, true)
910

1011
"""if(a){
1112
|foo

0 commit comments

Comments
 (0)