diff --git a/.travis.yml b/.travis.yml
index 0b421590..d0426bb6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,7 @@
language: scala
scala:
+ - 2.11.0-RC1
- 2.10.3
- - 2.9.3
jdk:
- oraclejdk7
- openjdk7
\ No newline at end of file
diff --git a/misc/src/main/scala/scalariform/gui/ParseTreeModel.scala b/misc/src/main/scala/scalariform/gui/ParseTreeModel.scala
index 5fad7939..c941be3e 100644
--- a/misc/src/main/scala/scalariform/gui/ParseTreeModel.scala
+++ b/misc/src/main/scala/scalariform/gui/ParseTreeModel.scala
@@ -60,7 +60,7 @@ class ParseTreeModel(rootAstNode: AstNode) extends TreeModel {
case class OptionNode(name: String, opt: Option[Any]) extends TreeNode(name) {
- lazy val children = opt map { x ⇒ makeTreeNode(x, "Some") } toList
+ lazy val children = opt.map{ x ⇒ makeTreeNode(x, "Some") }.toList
}
diff --git a/misc/src/main/scala/scalariform/gui/SwingUtils.scala b/misc/src/main/scala/scalariform/gui/SwingUtils.scala
index 37a6d2db..0866b6f9 100644
--- a/misc/src/main/scala/scalariform/gui/SwingUtils.scala
+++ b/misc/src/main/scala/scalariform/gui/SwingUtils.scala
@@ -4,9 +4,7 @@ import javax.swing.event.ListSelectionListener
import javax.swing.event.ListSelectionEvent
object SwingUtils {
-
- implicit def fn2ListSelectionListener(handler: ListSelectionEvent ⇒ Unit): ListSelectionListener = new ListSelectionListener() {
+ implicit class Fn2ListSelectionListener(handler: ListSelectionEvent ⇒ Unit) extends ListSelectionListener {
def valueChanged(e: ListSelectionEvent) = handler(e)
}
-
}
\ No newline at end of file
diff --git a/project/Build.scala b/project/Build.scala
index adef0880..f67a1bb1 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -7,7 +7,7 @@ import com.typesafe.sbt.SbtScalariform
import com.typesafe.sbt.SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
-object ScalariformBuild extends Build {
+object Build extends sbt.Build {
// This is to make sure nobody tries to compile with 1.6 as the target JDK.
// Not clear if this will actually work on 1.8, needs to be tested when that is out.
@@ -27,14 +27,12 @@ object ScalariformBuild extends Build {
version := "0.1.5-SNAPSHOT",
scalaVersion := "2.10.3",
crossScalaVersions := Seq(
- "2.11.0-M8",
- "2.11.0-M7",
- "2.10.0", "2.10.1",
- "2.9.3", "2.9.2", "2.9.1-1", "2.9.1", "2.9.0-1", "2.9.0"
+ "2.11.0-RC1",
+ "2.10.0", "2.10.1"
),
exportJars := true, // Needed for cli oneJar
retrieveManaged := true,
- scalacOptions += "-deprecation",
+ scalacOptions := Seq("-deprecation", "-feature"),
EclipseKeys.withSource := true,
EclipseKeys.eclipseOutput := Some("bin"))
@@ -49,30 +47,24 @@ object ScalariformBuild extends Build {
publishLocal := ())) aggregate (scalariform, cli, misc)
implicit class Regex(sc: StringContext) {
- def r = new util.matching.Regex(sc.parts.mkString, sc.parts.tail.map(_ => "x"): _*)
+ def r = new util.matching.Regex(sc.parts.mkString, sc.parts.tail.map(_ ⇒ "x"): _*)
}
- def getScalaTestDependency(scalaVersion: String) = scalaVersion match {
- case "2.11.0-M8" ⇒ "org.scalatest" %% s"scalatest" % "2.1.RC1" % "test"
- case "2.11.0-M7" ⇒ "org.scalatest" %% s"scalatest" % "2.0.1-SNAP4" % "test"
- case r"2.10.\d+" ⇒ "org.scalatest" % "scalatest_2.10" % "2.0" % "test"
- case "2.9.3" ⇒ "org.scalatest" %% "scalatest" % "1.9.1" % "test"
- case _ ⇒ "org.scalatest" %% "scalatest" % "1.7.2" % "test"
- }
+ val scalaTestDependency = "org.scalatest" %% s"scalatest" % "2.1.0" % "test"
def get2_11Dependencies(scalaVersion: String): List[ModuleID] = scalaVersion match {
- case r"2.11.0-M\d" => List(
- "org.scala-lang.modules" %% "scala-xml" % "1.0.0-RC7",
- "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.0-RC5"
+ case r"2.11.0.*" ⇒ List(
+ "org.scala-lang.modules" %% "scala-xml" % "1.0.0",
+ "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.0"
)
- case _ => Nil
+ case _ ⇒ Nil
}
lazy val scalariform: Project = Project("scalariform", file("scalariform"), settings =
subprojectSettings ++ sbtbuildinfo.Plugin.buildInfoSettings ++ eclipseSettings ++
Seq(
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps) ⇒
- deps ++ get2_11Dependencies(sv) :+ getScalaTestDependency(sv)
+ deps ++ get2_11Dependencies(sv) :+ scalaTestDependency
},
testOptions in Test += Tests.Argument("-oI"),
pomExtra := pomExtraXml,
@@ -97,7 +89,7 @@ object ScalariformBuild extends Build {
mainClass in (Compile, packageBin) := Some("scalariform.commandline.Main"),
artifactName in SbtOneJar.oneJar := { (version: ScalaVersion, module: ModuleID, artifact: Artifact) ⇒ "scalariform.jar" },
publish := (),
- publishLocal := ())) dependsOn (scalariform)
+ publishLocal := ())) dependsOn scalariform
lazy val misc: Project = Project("misc", file("misc"), settings = subprojectSettings ++
Seq(
@@ -134,5 +126,4 @@ object ScalariformBuild extends Build {
https://github.com/daniel-trinh/
-
}
\ No newline at end of file
diff --git a/project/plugins.sbt b/project/plugins.sbt
index fcd57349..6a92c633 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -6,10 +6,10 @@ resolvers += Classpaths.typesafeSnapshots
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0")
-addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.1")
+addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0")
-addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.1")
+addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.2")
-addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.0")
+addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.1")
retrieveManaged := true
\ No newline at end of file
diff --git a/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala b/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala
index 8d6dfb6b..136de28d 100644
--- a/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala
+++ b/scalariform/src/main/scala/scalariform/astselect/AstSelector.scala
@@ -3,7 +3,6 @@ package scalariform.astselect
import scalariform.lexer._
import scalariform.parser._
import scalariform.utils.Range
-import scalariform.utils.Utils._
import scala.util.control.Exception._
import scalariform.ScalaVersions
@@ -58,7 +57,7 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
private val compilationUnitOpt: Option[CompilationUnit] = {
val parser = new ScalaParser(tokens.toArray)
- parser.safeParse(parser.compilationUnitOrScript)
+ parser.safeParse(parser.compilationUnitOrScript())
}
private val allTokens: List[Token] = tokens.flatMap { token ⇒
@@ -183,7 +182,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.asInstanceOf[Class[_ <: AstNode]])
+ case List(node, _*) ⇒ !(nonSelectableAstNodes contains node.getClass)
case Nil ⇒ false
}
diff --git a/scalariform/src/main/scala/scalariform/formatter/CommentFormatter.scala b/scalariform/src/main/scala/scalariform/formatter/CommentFormatter.scala
index ad49d759..7b2df8fa 100644
--- a/scalariform/src/main/scala/scalariform/formatter/CommentFormatter.scala
+++ b/scalariform/src/main/scala/scalariform/formatter/CommentFormatter.scala
@@ -1,7 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.utils._
import scalariform.lexer._
import scalariform.formatter.preferences._
import scala.annotation.tailrec
@@ -45,6 +43,7 @@ trait CommentFormatter { self: HasFormattingPreferences with ScalaFormatter ⇒
val alignBeneathSecondAsterisk = formattingPreferences(PlaceScaladocAsterisksBeneathSecondAsterisk)
val startOnFirstLine = formattingPreferences(MultilineScaladocCommentsStartOnFirstLine)
+ val stopOnLastLine = formattingPreferences(ScaladocCommentsStopOnLastLine)
val beforeStarSpaces = if (alignBeneathSecondAsterisk) " " else " "
val afterStarSpaces = if (startOnFirstLine && !alignBeneathSecondAsterisk) " " else " "
sb.append(start.trim)
@@ -61,8 +60,9 @@ trait CommentFormatter { self: HasFormattingPreferences with ScalaFormatter ⇒
}
firstLine = false
}
- sb.append(newlineSequence).indent(indentLevel).append(beforeStarSpaces).append("*/")
- sb.toString
+ if (stopOnLastLine) sb.append(" */")
+ else sb.append(newlineSequence).indent(indentLevel).append(beforeStarSpaces).append("*/")
+ sb.result()
} else
comment.rawText
diff --git a/scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala b/scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala
index b4f12abd..856a406f 100755
--- a/scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala
+++ b/scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala
@@ -102,7 +102,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
}
private def formatExprElements(exprElements: List[ExprElement])(implicit formatterState: FormatterState): (FormatResult, FormatterState) = {
- if (exprElements flatMap { _.tokens } isEmpty)
+ if (exprElements.flatMap{ _.tokens }.isEmpty)
return (NoFormatResult, formatterState)
var formatResult: FormatResult = NoFormatResult
var currentFormatterState = formatterState
@@ -318,7 +318,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
val alignArgsEnabled = formattingPreferences(AlignArguments) && !formattingPreferences(IndentWithTabs)
var formatResult: FormatResult = NoFormatResult
- var argumentFormatterState = formatterState
+ val argumentFormatterState = formatterState
val ParenArgumentExprs(lparen, contents, rparen) = parenArguments
/* Force a newline for the first argument if this is a set of
diff --git a/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala b/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala
index 8337842d..15b1aca0 100644
--- a/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala
+++ b/scalariform/src/main/scala/scalariform/formatter/ScalaFormatter.scala
@@ -3,9 +3,7 @@ package scalariform.formatter
import scalariform.lexer.Tokens._
import scalariform.lexer._
import scalariform.parser._
-import scalariform.utils.Utils._
import scalariform.utils._
-import scalariform.utils.BooleanLang._
import scalariform.formatter.preferences._
import PartialFunction._
import scalariform.ScalaVersions
@@ -251,7 +249,7 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
}
}
- class StringBuilderExtra(builder: StringBuilder) {
+ implicit class StringBuilderExtra(builder: StringBuilder) {
def indent(indentLevel: Int, baseIndentOption: Option[Int] = None) = {
for {
@@ -265,11 +263,11 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
def write(token: Token, replacementOption: Option[String] = None): Option[TextEdit] = {
val rewriteArrows = formattingPreferences(RewriteArrowSymbols)
- val actualReplacementOption = replacementOption orElse (condOpt(token.tokenType) {
+ val actualReplacementOption = replacementOption orElse condOpt(token.tokenType) {
case ARROW if rewriteArrows ⇒ "⇒"
case LARROW if rewriteArrows ⇒ "←"
case EOF ⇒ ""
- })
+ }
builder.append(actualReplacementOption getOrElse token.rawText)
actualReplacementOption map { replaceEdit(token, _) }
}
@@ -296,7 +294,6 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
}
def currentIndent = {
- val current = currentColumn
val lineStart = builder.length - currentColumn
var pos = lineStart
while (pos < builder.length && builder(pos).isWhitespace)
@@ -315,7 +312,6 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
def atVisibleCharacter = builder.length > 0 && !Character.isWhitespace(lastChar)
}
- implicit def stringBuilder2stringBuilderExtra(builder: StringBuilder): StringBuilderExtra = new StringBuilderExtra(builder)
private def defaultNewlineFormattingInstruction(previousTokenOption: Option[Token], token: Token, nextTokenOption: Option[Token]): IntertokenFormatInstruction = {
val previousTypeOption = previousTokenOption map { _.tokenType }
diff --git a/scalariform/src/main/scala/scalariform/formatter/preferences/IFormattingPreferences.scala b/scalariform/src/main/scala/scalariform/formatter/preferences/IFormattingPreferences.scala
index 6fa5a043..3410f19c 100644
--- a/scalariform/src/main/scala/scalariform/formatter/preferences/IFormattingPreferences.scala
+++ b/scalariform/src/main/scala/scalariform/formatter/preferences/IFormattingPreferences.scala
@@ -14,7 +14,7 @@ trait IFormattingPreferences {
abstract sealed class IndentStyle {
def indent(n: Int): String
- protected def repeat(s: String, n: Int) = 1 to n map { _ ⇒ s } mkString
+ protected def repeat(s: String, n: Int) = (1 to n map { _ ⇒ s }).mkString
}
case object Tabs extends IndentStyle {
diff --git a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala
index 935361e1..e6cc99be 100755
--- a/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala
+++ b/scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala
@@ -65,7 +65,7 @@ object AllPreferences {
PreserveSpaceBeforeArguments, AlignParameters, AlignArguments, DoubleIndentClassDeclaration, FormatXml, IndentPackageBlocks,
AlignSingleLineCaseStatements, AlignSingleLineCaseStatements.MaxArrowIndent, IndentLocalDefs, PreserveDanglingCloseParenthesis,
SpaceInsideParentheses, SpaceInsideBrackets, SpacesWithinPatternBinders, MultilineScaladocCommentsStartOnFirstLine, IndentWithTabs,
- CompactControlReadability, PlaceScaladocAsterisksBeneathSecondAsterisk, SpacesAroundMultiImports)
+ ScaladocCommentsStopOnLastLine, CompactControlReadability, PlaceScaladocAsterisksBeneathSecondAsterisk, SpacesAroundMultiImports)
val preferencesByKey: Map[String, PreferenceDescriptor[_]] = {
var map: Map[String, PreferenceDescriptor[_]] = Map()
@@ -188,6 +188,12 @@ case object MultilineScaladocCommentsStartOnFirstLine extends BooleanPreferenceD
val defaultValue = false
}
+case object ScaladocCommentsStopOnLastLine extends BooleanPreferenceDescriptor {
+ val key = "scaladocCommentsStopOnLastLine"
+ val description = "Place '*/' in last line of Scaladoc comment body (without creating new line)"
+ val defaultValue = false
+}
+
case object IndentWithTabs extends BooleanPreferenceDescriptor {
val key = "indentWithTabs"
val description = "Use a tab character for indentation"
diff --git a/scalariform/src/main/scala/scalariform/lexer/ScalaLexer.scala b/scalariform/src/main/scala/scalariform/lexer/ScalaLexer.scala
index 8bcffdb1..4dfd375e 100644
--- a/scalariform/src/main/scala/scalariform/lexer/ScalaLexer.scala
+++ b/scalariform/src/main/scala/scalariform/lexer/ScalaLexer.scala
@@ -181,7 +181,7 @@ class ScalaLexer(
nextChar()
}
- @deprecated(message = "Use next() instead" /*, since = "0.1.2"*/ )
+ @deprecated("Use next() instead", "0.1.2")
def nextToken(): Token = next()
def next(): Token = {
@@ -263,7 +263,7 @@ object ScalaLexer {
lexer.toList
}
- @deprecated(message = "Use tokenise instead")
+ @deprecated("Use tokenise instead", "0.1.2")
def tokeniseFull(s: String, forgiveErrors: Boolean = false) = ((), tokenise(s, forgiveErrors))
private val BUFFER_SIZE = 16 // sufficient lookahead for "" (15 chars)
diff --git a/scalariform/src/main/scala/scalariform/lexer/Token.scala b/scalariform/src/main/scala/scalariform/lexer/Token.scala
index 365122eb..58533097 100644
--- a/scalariform/src/main/scala/scalariform/lexer/Token.scala
+++ b/scalariform/src/main/scala/scalariform/lexer/Token.scala
@@ -27,13 +27,12 @@ case class Token(tokenType: TokenType, text: String, offset: Int, rawText: Strin
def isNewline = tokenType.isNewline
- @deprecated(message = "Use text instead" /*, since = "0.1.2"*/ )
+ @deprecated("Use text instead", since = "0.1.2")
def getText = text
- @deprecated(message = "Use offset instead" /*, since = "0.1.2"*/ )
+ @deprecated("Use offset instead", since = "0.1.2")
def startIndex = offset
- @deprecated(message = "Use lastCharacterOffset instead" /*, since = "0.1.2"*/ )
+ @deprecated("Use lastCharacterOffset instead", since = "0.1.2")
def stopIndex = lastCharacterOffset
-
-}
\ No newline at end of file
+}
diff --git a/scalariform/src/main/scala/scalariform/lexer/UnicodeEscapeReader.scala b/scalariform/src/main/scala/scalariform/lexer/UnicodeEscapeReader.scala
index be529112..ea0dc7f2 100644
--- a/scalariform/src/main/scala/scalariform/lexer/UnicodeEscapeReader.scala
+++ b/scalariform/src/main/scala/scalariform/lexer/UnicodeEscapeReader.scala
@@ -99,8 +99,7 @@ class UnicodeEscapeReader(val text: String, forgiveErrors: Boolean = false) exte
private def readUnicodeChar(startPos: Int): Char = {
this.unicodeEscapeSequence = consumeUnicodeEscape()
- val decodedChar = decodeUnicodeChar(unicodeEscapeSequence takeRight 4 toList, unicodeEscapeSequence, startPos)
- decodedChar
+ decodeUnicodeChar(unicodeEscapeSequence.takeRight(4).toList, unicodeEscapeSequence, startPos)
}
private def consumeUnicodeEscape(): String = {
@@ -114,7 +113,7 @@ class UnicodeEscapeReader(val text: String, forgiveErrors: Boolean = false) exte
for (n ← 1 to 4)
sb.append(consumeNextCharacter())
- sb.toString
+ sb.toString()
}
private def decodeUnicodeChar(digits: List[Char], unicodeEscapeSequence: String, startPos: Int): Char = {
diff --git a/scalariform/src/main/scala/scalariform/parser/AstNodes.scala b/scalariform/src/main/scala/scalariform/parser/AstNodes.scala
index c62a8c0b..15ec3d6a 100644
--- a/scalariform/src/main/scala/scalariform/parser/AstNodes.scala
+++ b/scalariform/src/main/scala/scalariform/parser/AstNodes.scala
@@ -22,18 +22,30 @@ sealed trait AstNode extends CaseClassReflector {
def isEmpty = tokens.isEmpty
- protected implicit def astNodeToFlattenable(node: AstNode): Flattenable = new Flattenable { val tokens = node.tokens }
- protected implicit def listToFlattenable[T <% Flattenable](list: List[T]): Flattenable = new Flattenable { val tokens = list flatMap { _.tokens } }
- protected implicit def optionToFlattenable[T <% Flattenable](option: Option[T]): Flattenable = new Flattenable { val tokens = option.toList flatMap { _.tokens } }
- protected implicit def pairToFlattenable[T1 <% Flattenable, T2 <% Flattenable](pair: (T1, T2)): Flattenable = new Flattenable { val tokens = pair._1.tokens ::: pair._2.tokens }
- protected implicit def tripleToFlattenable[T1 <% Flattenable, T2 <% Flattenable, T3 <% Flattenable](triple: (T1, T2, T3)): Flattenable = new Flattenable { val tokens = triple._1.tokens ++ triple._2.tokens ++ triple._3.tokens }
- protected implicit def eitherToFlattenable[T1 <% Flattenable, T2 <% Flattenable](either: T1 Either T2): Flattenable = new Flattenable {
- val tokens = either match {
+ //@see https://issues.scala-lang.org/browse/SI-7629
+ private type FlattenableView[A] = A => Flattenable
+ protected implicit class AstNodeToFlattenable(node: AstNode) extends Flattenable { val tokens = node.tokens }
+ protected implicit class ListToFlattenable[T: FlattenableView](list: List[T]) extends Flattenable {
+ val tokens: List[Token] = list flatMap { _.tokens }
+ }
+ protected implicit class OptionToFlattenable[T: FlattenableView](option: Option[T]) extends Flattenable {
+ val tokens: List[Token] = option.toList flatMap { _.tokens }
+ }
+ protected implicit class PairToFlattenable[T1: FlattenableView, T2: FlattenableView](pair: (T1, T2)) extends Flattenable {
+ val tokens: List[Token] = pair._1.tokens ::: pair._2.tokens
+ }
+ protected implicit class TripleToFlattenable[T1: FlattenableView, T2: FlattenableView, T3: FlattenableView](triple: (T1, T2, T3)) extends Flattenable {
+ val tokens: List[Token] = triple._1.tokens ++ triple._2.tokens ++ triple._3.tokens
+ }
+ protected implicit class EitherToFlattenable[T1: FlattenableView, T2: FlattenableView](either: T1 Either T2) extends Flattenable {
+ val tokens: List[Token] = either match {
case Left(f) ⇒ f.tokens
case Right(f) ⇒ f.tokens
}
}
- protected implicit def tokenToFlattenable(token: Token): Flattenable = new Flattenable { val tokens = List(token) }
+ protected implicit class TokenToFlattenable(token: Token) extends Flattenable {
+ val tokens: List[Token] = List(token)
+ }
protected def flatten(flattenables: Flattenable*): List[Token] = flattenables.toList flatMap { _.tokens }
@@ -43,7 +55,7 @@ sealed trait AstNode extends CaseClassReflector {
case a: AstNode ⇒ List(a)
case t: Token ⇒ Nil
case Some(x) ⇒ immediateAstNodes(x)
- case xs @ (_ :: _) ⇒ xs flatMap { immediateAstNodes(_) }
+ case xs @ (_ :: _) ⇒ xs flatMap immediateAstNodes
case Left(x) ⇒ immediateAstNodes(x)
case Right(x) ⇒ immediateAstNodes(x)
case (l, r) ⇒ immediateAstNodes(l) ++ immediateAstNodes(r)
@@ -65,7 +77,7 @@ sealed trait AstNode extends CaseClassReflector {
}
-case class GeneralTokens(val toks: List[Token]) extends AstNode with TypeElement with ExprElement {
+case class GeneralTokens(toks: List[Token]) extends AstNode with TypeElement with ExprElement {
lazy val tokens = flatten(toks)
}
diff --git a/scalariform/src/main/scala/scalariform/parser/InferredSemicolonScalaParser.scala b/scalariform/src/main/scala/scalariform/parser/InferredSemicolonScalaParser.scala
index 7707f71f..853a2de7 100644
--- a/scalariform/src/main/scala/scalariform/parser/InferredSemicolonScalaParser.scala
+++ b/scalariform/src/main/scala/scalariform/parser/InferredSemicolonScalaParser.scala
@@ -2,15 +2,13 @@ package scalariform.parser
import scalariform.lexer.Tokens._
import scalariform.lexer._
-import scalariform.utils.Utils._
-import scala.collection.mutable.ListBuffer
import PartialFunction._
object InferredSemicolonScalaParser {
def findSemicolons(tokens: Array[Token]) = {
val parser = new InferredSemicolonScalaParser(tokens)
- parser.safeParse(parser.compilationUnitOrScript)
+ parser.safeParse(parser.compilationUnitOrScript())
parser.inferredSemicolons
}
@@ -91,7 +89,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
case _ ⇒ accept(SEMI)
}
- private def acceptStatSepOpt() = if (!isStatSeqEnd) acceptStatSep
+ private def acceptStatSepOpt() = if (!isStatSeqEnd) acceptStatSep()
private def isModifier = currentTokenType match {
case ABSTRACT | FINAL | SEALED | PRIVATE |
@@ -372,7 +370,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
}
private def mixinQualifierOpt() {
- if (LBRACKET) inBrackets(ident)
+ if (LBRACKET) inBrackets(ident())
}
private def stableId() = path(thisOK = false, typeOK = false)
@@ -496,7 +494,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
case LBRACE ⇒
inBraces(block())
case LPAREN ⇒ inParens(expr())
- case _ ⇒ expr
+ case _ ⇒ expr()
}
val catchClauseOption =
if (!CATCH)
@@ -846,7 +844,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
case CHARACTER_LITERAL | INTEGER_LITERAL | FLOATING_POINT_LITERAL | STRING_LITERAL | SYMBOL_LITERAL | TRUE | FALSE | NULL ⇒
literal(inPattern = true)
case LPAREN ⇒
- makeParens(noSeq.patterns)
+ makeParens(noSeq.patterns())
case XML_START_OPEN | XML_COMMENT | XML_CDATA | XML_UNPARSED | XML_PROCESSING_INSTRUCTION ⇒
xmlLiteralPattern()
case _ ⇒
@@ -1563,7 +1561,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
private def xmlLiteralPattern() = xml(isPattern = true)
- private var tokensArray: Array[Token] = tokens.toArray
+ private val tokensArray: Array[Token] = tokens.toArray
private var pos = 0
@@ -1588,6 +1586,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
private def lookahead(n: Int): TokenType = this(pos + n).tokenType
+ import scala.language.implicitConversions
private implicit def tokenType2Boolean(tokenType: TokenType): Boolean = currentTokenType == tokenType
private def caseClass = CASE && lookahead(1) == CLASS
@@ -1605,7 +1604,7 @@ class InferredSemicolonScalaParser(tokens: Array[Token]) {
private def isVariableName(name: String): Boolean = {
val first = name(0)
- ((first.isLower && first.isLetter) || first == '_')
+ (first.isLower && first.isLetter) || first == '_'
}
private def isVarPattern(token: Token) = {
diff --git a/scalariform/src/main/scala/scalariform/parser/ScalaParser.scala b/scalariform/src/main/scala/scalariform/parser/ScalaParser.scala
index 036923a1..cb67f9be 100644
--- a/scalariform/src/main/scala/scalariform/parser/ScalaParser.scala
+++ b/scalariform/src/main/scala/scalariform/parser/ScalaParser.scala
@@ -80,7 +80,7 @@ class ScalaParser(tokens: Array[Token]) {
throw new ScalaParserException("Expected token " + tokenType + " but got " + currentToken)
private def acceptStatSep(): Token = currentTokenType match {
- case NEWLINE | NEWLINES ⇒ nextToken
+ case NEWLINE | NEWLINES ⇒ nextToken()
case _ ⇒ accept(SEMI)
}
@@ -404,7 +404,7 @@ class ScalaParser(tokens: Array[Token]) {
}
private def mixinQualifierOpt(): Option[TypeExprElement] =
- if (LBRACKET) Some(TypeExprElement(typeElementFlatten3(inBrackets(ident)))) else None
+ if (LBRACKET) Some(TypeExprElement(typeElementFlatten3(inBrackets(ident())))) else None
private def stableId(): List[Token] = path(thisOK = false, typeOK = false)
@@ -545,7 +545,7 @@ class ScalaParser(tokens: Array[Token]) {
val (lbrace, block_, rbrace) = inBraces(block())
makeExpr(BlockExpr(lbrace, Right(block_), rbrace))
case LPAREN ⇒ makeExpr(inParens(expr()))
- case _ ⇒ expr
+ case _ ⇒ expr()
}
val catchClauseOption: Option[CatchClause] =
if (!CATCH)
@@ -1651,7 +1651,7 @@ class ScalaParser(tokens: Array[Token]) {
private def templateStatSeq(): StatSeq = {
val statAndStatSeps = ListBuffer[(Option[Stat], Option[Token])]()
- var selfReferenceOpt = if (isExprIntro) {
+ val selfReferenceOpt = if (isExprIntro) {
val expr_ = expr(InTemplate)
if (ARROW) {
val arrowToken = nextToken()
@@ -1937,7 +1937,7 @@ class ScalaParser(tokens: Array[Token]) {
private def xmlLiteralPattern() = xml(isPattern = true)
- private var tokensArray: Array[Token] = tokens.toArray
+ private val tokensArray: Array[Token] = tokens.toArray
private var pos = 0
@@ -1962,6 +1962,7 @@ class ScalaParser(tokens: Array[Token]) {
private def lookahead(n: Int): TokenType = this(pos + n).tokenType
+ import scala.language.implicitConversions
private implicit def tokenType2Boolean(tokenType: TokenType): Boolean = currentTokenType == tokenType
private def caseClass = CASE && lookahead(1) == CLASS
@@ -1978,7 +1979,7 @@ class ScalaParser(tokens: Array[Token]) {
private def isVariableName(name: String): Boolean = {
val first = name(0)
- ((first.isLower && first.isLetter) || first == '_')
+ (first.isLower && first.isLetter) || first == '_'
}
private def isVarPattern(token: Token) = {
@@ -2031,13 +2032,15 @@ object ScalaParser {
*/
def parse(text: String, scalaVersion: String = ScalaVersions.DEFAULT_VERSION): Option[AstNode] = {
val parser = new ScalaParser(ScalaLexer.tokenise(text, scalaVersion = scalaVersion).toArray)
- parser.safeParse(parser.compilationUnitOrScript)
+ parser.safeParse(parser.compilationUnitOrScript())
}
trait ExprElementFlattenable { def elements: List[ExprElement] }
+ //@see https://issues.scala-lang.org/browse/SI-7629
+ private type ExprFlattenableView[A] = A ⇒ ExprElementFlattenable
case class ExprElements(elements: List[ExprElement]) extends ExprElementFlattenable
- def exprElementFlatten[T <% ExprElementFlattenable]: (T ⇒ List[ExprElement]) = t ⇒ { exprElementFlatten2(t) }
- def exprElementFlatten2[T <% ExprElementFlattenable](t: T): List[ExprElement] = groupGeneralTokens(t.elements)
+ def exprElementFlatten[T: ExprFlattenableView]: (T ⇒ List[ExprElement]) = t ⇒ { exprElementFlatten2(t) }
+ def exprElementFlatten2[T: ExprFlattenableView](t: T): List[ExprElement] = groupGeneralTokens(t.elements)
def groupGeneralTokens(xs: List[ExprElement]): List[ExprElement] = {
val eq = (x: ExprElement, y: ExprElement) ⇒ (x, y) match {
case (GeneralTokens(_), GeneralTokens(_)) ⇒ true
@@ -2059,44 +2062,53 @@ object ScalaParser {
}
}
- implicit def tokenToExprFlattenable(token: Token): ExprElementFlattenable = GeneralTokens(List(token))
- implicit def listOfTokenToExprFlattenable(tokens: List[Token]): ExprElementFlattenable = GeneralTokens(tokens)
- implicit def exprToExprFlattenable(expr: Expr): ExprElementFlattenable = expr.contents
- implicit def exprElementToExprFlattenable(exprElement: ExprElement): ExprElementFlattenable = ExprElements(List(exprElement))
- implicit def ordinaryPairToExprFlattenable[A <% ExprElementFlattenable, B <% ExprElementFlattenable](pair: (A, B)): ExprElementFlattenable =
- ExprElements(pair._1.elements ::: pair._2.elements)
- implicit def tripleToExprFlattenable[A <% ExprElementFlattenable, B <% ExprElementFlattenable, C <% ExprElementFlattenable](triple: (A, B, C)): ExprElementFlattenable =
- ExprElements(triple._1.elements ::: triple._2.elements ::: triple._3.elements)
- implicit def eitherToExprFlattenable[A <% ExprElementFlattenable, B <% ExprElementFlattenable](either: Either[A, B]): ExprElementFlattenable = ExprElements(either match {
- case Left(x) ⇒ x.elements
- case Right(x) ⇒ x.elements
- })
- implicit def optionToExprFlattenable[T <% ExprElementFlattenable](option: Option[T]): ExprElementFlattenable = option.toList
- implicit def listToExprFlattenable[T <% ExprElementFlattenable](list: List[T]): ExprElementFlattenable = ExprElements(list flatMap { _.elements })
- implicit def vectorToExprFlattenable[T <% ExprElementFlattenable](vector: Vector[T]): ExprElementFlattenable = ExprElements(vector.toList flatMap { _.elements })
+ implicit class TokenToExprFlattenable(token: Token) extends ExprElementToExprFlattenable(GeneralTokens(List(token)))
+ implicit class ListOfTokenToExprFlattenable(tokens: List[Token]) extends ExprElementToExprFlattenable(GeneralTokens(tokens))
+ implicit class ExprToExprFlattenable(expr: Expr) extends ListToExprFlattenable(expr.contents)
+ implicit class ExprElementToExprFlattenable(exprElement: ExprElement) extends ExprElements(List(exprElement))
+ implicit class OrdinaryPairToExprFlattenable[A, B](pair: (A, B))
+ (implicit e1: ExprFlattenableView[A], e2: ExprFlattenableView[B])
+ extends ExprElements(e1(pair._1).elements ::: e2(pair._2).elements)
+ implicit class TripleToExprFlattenable[A, B, C](triple: (A, B, C))
+ (implicit e1: ExprFlattenableView[A], e2: ExprFlattenableView[B], e3: ExprFlattenableView[C])
+ extends ExprElements(e1(triple._1).elements ::: e2(triple._2).elements ::: e3(triple._3).elements)
+ implicit class EitherToExprFlattenable[A, B](either: Either[A, B])
+ (implicit e1: ExprFlattenableView[A], e2: ExprFlattenableView[B])
+ extends ExprElements(either match {
+ case Left(x) ⇒ e1(x).elements
+ case Right(x) ⇒ e2(x).elements
+ })
+ implicit class OptionToExprFlattenable[T: ExprFlattenableView](option: Option[T]) extends ListToExprFlattenable(option.toList)
+ implicit class ListToExprFlattenable[T: ExprFlattenableView](list: List[T]) extends ExprElements(list flatMap { _.elements })
+ implicit class VectorToExprFlattenable[T: ExprFlattenableView](vector: Vector[T]) extends ExprElements(vector.toList flatMap { _.elements })
def makeExpr(flattenables: ExprElementFlattenable*): Expr =
Expr(flattenables.toList flatMap { _.elements })
trait TypeElementFlattenable { def elements: List[TypeElement] }
- case class TypeElements(val elements: List[TypeElement]) extends TypeElementFlattenable
- def typeElementFlatten[T <% TypeElementFlattenable]: (T ⇒ List[TypeElement]) = _.elements
- def typeElementFlatten2[T <% TypeElementFlattenable](t: T): List[TypeElement] = t.elements
+ case class TypeElements(elements: List[TypeElement]) extends TypeElementFlattenable
+ //@see https://issues.scala-lang.org/browse/SI-7629
+ private type TypeFlattenableView[A] = A ⇒ TypeElementFlattenable
+ def typeElementFlatten[T: TypeFlattenableView]: (T ⇒ List[TypeElement]) = _.elements
+ def typeElementFlatten2[T: TypeFlattenableView](t: T): List[TypeElement] = t.elements
def typeElementFlatten3(flattenables: TypeElementFlattenable*): List[TypeElement] = flattenables.toList flatMap { _.elements }
- implicit def tokenToTypeFlattenable(token: Token): TypeElementFlattenable = GeneralTokens(List(token))
- implicit def listOfTokenToTypeFlattenable(tokens: List[Token]): TypeElementFlattenable = GeneralTokens(tokens)
- implicit def typeElementToTypeFlattenable(typeElement: TypeElement): TypeElementFlattenable = TypeElements(List(typeElement))
- implicit def eitherToTypeFlattenable[A <% TypeElementFlattenable, B <% TypeElementFlattenable](either: Either[A, B]): TypeElementFlattenable = TypeElements(either match {
- case Left(x) ⇒ x.elements
- case Right(x) ⇒ x.elements
- })
- implicit def pairToTypeFlattenable[A <% TypeElementFlattenable, B <% TypeElementFlattenable](pair: (A, B)): TypeElementFlattenable =
- TypeElements(pair._1.elements ::: pair._2.elements)
- implicit def tripleToTypeFlattenable[A <% TypeElementFlattenable, B <% TypeElementFlattenable, C <% TypeElementFlattenable](triple: (A, B, C)): TypeElementFlattenable =
- TypeElements(triple._1.elements ::: triple._2.elements ::: triple._3.elements)
- implicit def optionToTypeFlattenable[T <% TypeElementFlattenable](option: Option[T]): TypeElementFlattenable = option.toList
- implicit def listToTypeFlattenable[T <% TypeElementFlattenable](list: List[T]): TypeElementFlattenable = TypeElements(list flatMap { _.elements })
-
+ implicit class TokenToTypeFlattenable(token: Token) extends TypeElementToTypeFlattenable(GeneralTokens(List(token)))
+ implicit class ListOfTokenToTypeFlattenable(tokens: List[Token]) extends TypeElementToTypeFlattenable(GeneralTokens(tokens))
+ implicit class TypeElementToTypeFlattenable(typeElement: TypeElement) extends TypeElements(List(typeElement))
+ implicit class EitherToTypeFlattenable[A, B](either: Either[A, B])
+ (implicit e1: TypeFlattenableView[A], e2: TypeFlattenableView[B])
+ extends TypeElements(either match {
+ case Left(x) ⇒ e1(x).elements
+ case Right(x) ⇒ e2(x).elements
+ })
+ implicit class PairToTypeFlattenable[A, B](pair: (A, B))
+ (implicit e1: TypeFlattenableView[A], e2: TypeFlattenableView[B])
+ extends TypeElements(e1(pair._1).elements ::: e2(pair._2).elements)
+ implicit class TripleToTypeFlattenable[A, B, C](triple: (A, B, C))
+ (implicit e1: TypeFlattenableView[A], e2: TypeFlattenableView[B], e3: TypeFlattenableView[C])
+ extends TypeElements(e1(triple._1).elements ::: e2(triple._2).elements ::: e3(triple._3).elements)
+ implicit class OptionToTypeFlattenable[T: TypeFlattenableView](option: Option[T]) extends ListToTypeFlattenable(option.toList)
+ implicit class ListToTypeFlattenable[T: TypeFlattenableView](list: List[T]) extends TypeElements(list flatMap { _.elements })
}
// Not AST nodes, used as an intermediate structures during parsing:
@@ -2106,4 +2118,3 @@ case class TemplateOpt(templateInheritanceSectionOpt: Option[TemplateInheritance
case class PrePackageBlock(name: CallExpr, newlineOpt: Option[Token], lbrace: Token, topStats: StatSeq, rbrace: Token) {
def complete(packageToken: Token) = PackageBlock(packageToken, name, newlineOpt, lbrace, topStats, rbrace)
}
-
diff --git a/scalariform/src/main/scala/scalariform/utils/BooleanLang.scala b/scalariform/src/main/scala/scalariform/utils/BooleanLang.scala
index f028d952..d3ab18dc 100644
--- a/scalariform/src/main/scala/scalariform/utils/BooleanLang.scala
+++ b/scalariform/src/main/scala/scalariform/utils/BooleanLang.scala
@@ -4,11 +4,8 @@ object BooleanLang {
def not(b: Boolean) = !b
- class PimpedBoolean(b1: Boolean) {
+ implicit class PimpedBoolean(b1: Boolean) {
def and(b2: Boolean) = b1 && b2
def or(b2: Boolean) = b1 || b2
}
-
- implicit def boolean2PimpedBoolean(b: Boolean): PimpedBoolean = new PimpedBoolean(b)
-
}
diff --git a/scalariform/src/main/scala/scalariform/utils/Utils.scala b/scalariform/src/main/scala/scalariform/utils/Utils.scala
index 4f796857..6e43ff6c 100644
--- a/scalariform/src/main/scala/scalariform/utils/Utils.scala
+++ b/scalariform/src/main/scala/scalariform/utils/Utils.scala
@@ -8,19 +8,13 @@ object Utils {
def when[T](b: Boolean)(x: ⇒ T): Option[T] = if (b) Some(x) else None
- def asInstanceOf[T](o: Any) = if (o.isInstanceOf[T]) Some(o.asInstanceOf[T]) else None
-
def checkNotNull[T](item: T): T = { require(item != null); item }
- implicit def boolean2ImpliesWrapper(b: Boolean): ImpliesWrapper = new ImpliesWrapper(b)
-
- class ImpliesWrapper(b: Boolean) {
+ implicit class ImpliesWrapper(b: Boolean) {
def implies(b2: ⇒ Boolean) = if (!b) true else b2
}
- implicit def string2PimpedString(s: String) = new PimpedString(s)
-
- class PimpedString(s: String) {
+ implicit class PimpedString(s: String) {
def toIntOpt: Option[Int] = try Some(s.toInt) catch { case _: NumberFormatException ⇒ None }
}
@@ -45,22 +39,12 @@ object Utils {
}
}
- import scala.reflect.Manifest
- implicit def any2optionable(x: AnyRef) = new {
- def matchInstance[B](implicit m: Manifest[B]): Option[B] =
- if (Manifest.singleType(x) <:< m)
- Some(x.asInstanceOf[B])
- else
- None
- }
-
def groupBy[A](eq: (A, A) ⇒ Boolean, lst: List[A]): List[List[A]] =
lst match {
case Nil ⇒ Nil
- case (x :: xs) ⇒ {
+ case (x :: xs) ⇒
val (ys, zs) = xs span { eq(x, _) }
(x :: ys) :: groupBy(eq, zs)
- }
}
// Swing ---------------------
@@ -71,12 +55,12 @@ object Utils {
import javax.swing.tree._
def expandAll(tree: JTree) {
- val root = tree.getModel().getRoot()
+ val root = tree.getModel.getRoot
expandAll(tree, new TreePath(root))
}
private def expandAll(tree: JTree, parent: TreePath) {
- val node = parent.getLastPathComponent()
+ val node = parent.getLastPathComponent
val model = tree.getModel
val children = 0 until model.getChildCount(node) map { model.getChild(node, _) }
for (child ← children) {
@@ -145,4 +129,3 @@ object Utils {
text.take(range.offset) + replacement + text.drop(range.offset + range.length)
}
-
diff --git a/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala b/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala
index bd8a2d4a..886fd1ce 100644
--- a/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala
+++ b/scalariform/src/test/scala/scalariform/astselect/AstSelectorTest.scala
@@ -1,12 +1,12 @@
package scalariform.astselect
import org.scalatest._
-import org.scalatest.matchers._
+import org.scalatest.Matchers
import scalariform.utils.Range
import scalariform.ScalaVersions
// format: OFF
-class AstSelectorTest extends FlatSpec with ShouldMatchers {
+class AstSelectorTest extends FlatSpec with Matchers {
// Legend:
//
@@ -319,8 +319,8 @@ class AstSelectorTest extends FlatSpec with ShouldMatchers {
}
}
- implicit def stringToTestString(source: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION): TestString = new TestString(source, scalaVersion)
- class TestString(source: String, scalaVersion: String) {
+ implicit class StringToTestString(source: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION) extends TestString(source, scalaVersion)
+ class TestString(source: String, scalaVersion: String) {
def ~(initialSelectionDiagram: String) = IntermediateTest(source, initialSelectionDiagram, scalaVersion)
}
diff --git a/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala
index b680a590..4f2cbaab 100644
--- a/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/AbstractFormatterTest.scala
@@ -1,23 +1,19 @@
package scalariform.formatter
-import scalariform.parser._
import scalariform.lexer._
import scalariform.formatter.preferences._
-import scala.util.parsing.input._
-import scala.util.parsing.combinator._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
-import org.scalatest.TestFailedException
-import org.scalatest.TestPendingException
+import org.scalatest.Matchers
+import org.scalatest.exceptions.{TestFailedException, TestPendingException}
import scalariform.ScalaVersions
-abstract class AbstractFormatterTest extends FlatSpec with ShouldMatchers with SpecificFormatter {
+abstract class AbstractFormatterTest extends FlatSpec with Matchers with SpecificFormatter {
def prettyPrint(s: String): String =
//s.replaceAll("\n", "↵\n").replaceAll("\t", "↦" ).replaceAll(" ", "▵")
s.replaceAll("\n", "¶\n").replaceAll("\t", "↦") //.replaceAll(" ", "▲")
- implicit def string2FormatTest(s: String)(implicit formattingPreferences: IFormattingPreferences = FormattingPreferences(), scalaVersion: String = ScalaVersions.DEFAULT_VERSION): FormatTest =
+ implicit class String2FormatTest(s: String)(implicit formattingPreferences: IFormattingPreferences = FormattingPreferences(), scalaVersion: String = ScalaVersions.DEFAULT_VERSION) extends
FormatTest(s.stripMargin, formattingPreferences, scalaVersion)
def testFailedException(message: String) = new TestFailedException(message = Some(message), cause = None, failedCodeStackDepth = 2)
diff --git a/scalariform/src/test/scala/scalariform/formatter/BlockExprFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/BlockExprFormatterTest.scala
index f3527907..6a18804a 100644
--- a/scalariform/src/test/scala/scalariform/formatter/BlockExprFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/BlockExprFormatterTest.scala
@@ -1,8 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
-
// format: OFF
class BlockExprFormatterTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala
index efa45510..cfa85487 100644
--- a/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/CaseClausesFormatterTest.scala
@@ -1,7 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala
index a0838b02..4c788477 100644
--- a/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/CommentFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
@@ -133,6 +132,37 @@ class CommentFormatterTest extends AbstractFormatterTest {
|"""
}
+ {
+ implicit val formattingPreferences = FormattingPreferences
+ .setPreference(MultilineScaladocCommentsStartOnFirstLine, true)
+ .setPreference(ScaladocCommentsStopOnLastLine, true)
+
+ """/** This method applies f to each
+ | * element of the given list.
+ | */""" ==>
+ """/** This method applies f to each
+ | * element of the given list. */
+ |"""
+
+ """/** Foo
+ |Bar
+ |*Baz */""" ==>
+ """/** Foo
+ | * Bar
+ | * Baz */
+ |"""
+
+ """/** Foo
+ |*/""" ==>
+ """/** Foo */
+ |"""
+
+ """/**
+ |*/""" ==>
+ """/** */
+ |"""
+ }
+
{
implicit val formattingPreferences = FormattingPreferences.setPreference(PlaceScaladocAsterisksBeneathSecondAsterisk, true)
diff --git a/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala b/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala
index a6405026..ec1fdb1c 100644
--- a/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/CompactControlReadabilityTest.scala
@@ -1,9 +1,6 @@
package scalariform.formatter
-import preferences.FormattingPreferences._
import scalariform.formatter.preferences._
-import scalariform.parser._
-import scalariform.formatter._
// format: OFF
class CompactControlReadabilityTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala
index c9a20f5a..5cb8e6a3 100644
--- a/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/DefOrDclFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/ForExprFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/ForExprFormatterTest.scala
index 44092fdd..761a4a6c 100644
--- a/scalariform/src/test/scala/scalariform/formatter/ForExprFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/ForExprFormatterTest.scala
@@ -1,8 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
-
// format: OFF
class ForExprFormatterTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala b/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala
index a8430e47..04b91691 100644
--- a/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/FormatterDirectiveParserTest.scala
@@ -1,11 +1,11 @@
package scalariform.formatter
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
+import org.scalatest.Matchers
import FormatterDirectiveParser.getDirectives
// format: +preserveSpaceBeforeArguments
-class FormatterDirectiveParserTest extends FlatSpec with ShouldMatchers {
+class FormatterDirectiveParserTest extends FlatSpec with Matchers {
it should "parse formatter ON/OFF instructions" in {
"format: ON " ==> ToggleFormatting(true)
@@ -25,7 +25,7 @@ class FormatterDirectiveParserTest extends FlatSpec with ShouldMatchers {
"blahformat: -rewriteArrowSymbols, +spaceBeforeColon\nblah" ==> (ToggleOption(false, "rewriteArrowSymbols"), ToggleOption(true, "spaceBeforeColon"))
}
- implicit def string2FormatTest(s: String): FormatTest = FormatTest(s.stripMargin)
+ implicit class String2FormatTest(s: String) extends FormatTest(s.stripMargin)
case class FormatTest(source: String) {
def ==>(expectedDirectives: FormatterDirective*) {
diff --git a/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala
index cc376716..14da5f3f 100644
--- a/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/ImportFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences.{SpacesAroundMultiImports, FormattingPreferences}
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala b/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala
index fcfa2cbe..acb049d3 100644
--- a/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/IndentWithTabsTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala
index 885b5eaa..0199a001 100644
--- a/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/MiscExpressionFormatterTest.scala
@@ -1,7 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala
index ae340c07..91541572 100644
--- a/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/PackageFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala b/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala
index e8e07402..5f9b7130 100644
--- a/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/RewriteArrowsTest.scala
@@ -1,7 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala
index b261e84e..b43a6929 100644
--- a/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/ScriptFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
// format: OFF
class ScriptFormatterTest extends AbstractFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/StringInterpolationFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/StringInterpolationFormatterTest.scala
index 9e88c80c..1994631d 100644
--- a/scalariform/src/test/scala/scalariform/formatter/StringInterpolationFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/StringInterpolationFormatterTest.scala
@@ -1,9 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
-import scalariform.formatter.preferences._
-
// format: OFF
class StringInterpolationFormatterTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala
index 22b3c69f..2c8e737c 100644
--- a/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/TemplateFormatterTest.scala
@@ -1,7 +1,6 @@
package scalariform.formatter
import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/formatter/TryExprFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/TryExprFormatterTest.scala
index 5ba9736f..dff3df10 100644
--- a/scalariform/src/test/scala/scalariform/formatter/TryExprFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/TryExprFormatterTest.scala
@@ -1,8 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
-
// format: OFF
class TryExprFormatterTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/WhileExprFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/WhileExprFormatterTest.scala
index d2fc13e3..6fa290ea 100644
--- a/scalariform/src/test/scala/scalariform/formatter/WhileExprFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/WhileExprFormatterTest.scala
@@ -1,8 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
-
// format: OFF
class WhileExprFormatterTest extends AbstractExpressionFormatterTest {
diff --git a/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala b/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala
index 7bcee88d..5dacfb0b 100644
--- a/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala
+++ b/scalariform/src/test/scala/scalariform/formatter/XmlExpressionFormatterTest.scala
@@ -1,7 +1,5 @@
package scalariform.formatter
-import scalariform.parser._
-import scalariform.formatter._
import scalariform.formatter.preferences._
// format: OFF
diff --git a/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala b/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala
index 6455dced..62b1ff3d 100644
--- a/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala
+++ b/scalariform/src/test/scala/scalariform/lexer/NewlineInferencerTest.scala
@@ -3,18 +3,15 @@ package scalariform.lexer
import scalariform._
import scalariform.lexer.Tokens._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
-import org.scalatest.TestFailedException
-import org.scalatest.TestPendingException
-import java.io._
+import org.scalatest.Matchers
/**
* Test full tokeniser, including newline inferencing.
*/
-class NewlineInferencerTest extends FlatSpec with ShouldMatchers {
+class NewlineInferencerTest extends FlatSpec with Matchers {
- implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) =
- new TestString(s, forgiveErrors, scalaVersion);
+ implicit class String2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT)
+ extends TestString(s, forgiveErrors, scalaVersion)
// See issue #60
"""
@@ -41,12 +38,8 @@ class NewlineInferencerTest extends FlatSpec with ShouldMatchers {
val actualTokenTypes = actualTokens.map(_.tokenType)
require(actualTokenTypes.last == EOF, "Last token must be EOF, but was " + actualTokens.last.tokenType)
require(actualTokenTypes.count(_ == EOF) == 1, "There must only be one EOF token")
- val reconstitutedSource = actualTokens.init.map(_.rawText).mkString
require(actualTokenTypes.init == expectedTokens, "Tokens do not match. Expected " + expectedTokens + ", but was " + actualTokenTypes.init)
}
}
-
}
-
}
-
diff --git a/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala b/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala
index 5fef04ac..ccbd8357 100644
--- a/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala
+++ b/scalariform/src/test/scala/scalariform/lexer/RedundantSemicolonDetectorTest.scala
@@ -1,30 +1,28 @@
package scalariform.lexer
import scalariform._
-import scalariform.lexer.Tokens._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
-import org.scalatest.TestFailedException
-import org.scalatest.TestPendingException
+import org.scalatest.Matchers
import scalariform.utils.Utils._
-class RedundantSemicolonDetectorTest extends FlatSpec with ShouldMatchers {
+class RedundantSemicolonDetectorTest extends FlatSpec with Matchers {
- implicit def stringToCheckable(s: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION) =
- new { def check() = checkSemis(s, scalaVersion) }; // Expected redundant semicolons are indicated with <;>
+ implicit class StringToCheckable(s: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION) {
+ def check() = checkSemis(s, scalaVersion)
+ }
"""
class A {
def foo = 42<;>
def bar = 123; def baz = 1234
}<;>
- """.check();
+ """.check()
"""
{
println("Foo")<;>
}
- """.check();
+ """.check()
"""
class A {
@@ -36,10 +34,10 @@ class RedundantSemicolonDetectorTest extends FlatSpec with ShouldMatchers {
""".check()
{
- implicit val scalaVersion = "2.10.0";
+ implicit val scalaVersion = "2.10.0"
"""
s"my name is ${person.name<;>}"
- """.check
+ """.check()
}
private def checkSemis(encodedSource: String, scalaVersion: String) {
diff --git a/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala b/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala
index cca99d4d..549f983e 100644
--- a/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala
+++ b/scalariform/src/test/scala/scalariform/lexer/ScalaLexerTest.scala
@@ -3,45 +3,42 @@ package scalariform.lexer
import scalariform._
import scalariform.lexer.Tokens._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
-import org.scalatest.TestFailedException
-import org.scalatest.TestPendingException
-import java.io._
+import org.scalatest.Matchers
-class ScalaLexerTest extends FlatSpec with ShouldMatchers {
+class ScalaLexerTest extends FlatSpec with Matchers {
- implicit def string2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) =
- new TestString(s, forgiveErrors, scalaVersion)
+ implicit class String2TestString(s: String)(implicit forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT)
+ extends TestString(s, forgiveErrors, scalaVersion)
"" producesTokens ()
- "println" producesTokens (VARID)
+ "println" producesTokens VARID
- "lazy" producesTokens (LAZY)
+ "lazy" producesTokens LAZY
"println;println" producesTokens (VARID, SEMI, VARID)
- "foo_+" producesTokens (VARID)
+ "foo_+" producesTokens VARID
- "++" producesTokens (VARID)
+ "++" producesTokens VARID
- "*=" producesTokens (VARID)
+ "*=" producesTokens VARID
- "/" producesTokens (VARID)
+ "/" producesTokens VARID
"foo/bar" producesTokens (VARID, VARID, VARID)
- "*/" producesTokens (VARID)
+ "*/" producesTokens VARID
- "*/+" producesTokens (VARID)
+ "*/+" producesTokens VARID
"foo bar baz" producesTokens (VARID, WS, VARID, WS, VARID)
- " " producesTokens (WS)
+ " " producesTokens WS
- "// comment" producesTokens (LINE_COMMENT)
+ "// comment" producesTokens LINE_COMMENT
- "//" producesTokens (LINE_COMMENT)
+ "//" producesTokens LINE_COMMENT
"foo// comment" producesTokens (VARID, LINE_COMMENT)
@@ -52,61 +49,61 @@ class ScalaLexerTest extends FlatSpec with ShouldMatchers {
"foo/* comment */bar" producesTokens (VARID, MULTILINE_COMMENT, VARID)
- "/* bar /* baz */ var */" producesTokens (MULTILINE_COMMENT)
+ "/* bar /* baz */ var */" producesTokens MULTILINE_COMMENT
- "/**/" producesTokens (MULTILINE_COMMENT)
+ "/**/" producesTokens MULTILINE_COMMENT
- "`yield`" producesTokens (VARID)
+ "`yield`" producesTokens VARID
- """"foobar"""" producesTokens (STRING_LITERAL)
+ """"foobar"""" producesTokens STRING_LITERAL
- "\"\"\"f\"o\"o\"\"\"" producesTokens (STRING_LITERAL)
+ "\"\"\"f\"o\"o\"\"\"" producesTokens STRING_LITERAL
- """"\""""" producesTokens (STRING_LITERAL)
+ """"\""""" producesTokens STRING_LITERAL
- "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" producesTokens (STRING_LITERAL)
+ "\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"" producesTokens STRING_LITERAL
"foo.bar.baz" producesTokens (VARID, DOT, VARID, DOT, VARID)
- ".1234" producesTokens (FLOATING_POINT_LITERAL)
- ".1234e2" producesTokens (FLOATING_POINT_LITERAL)
- ".1234e+2" producesTokens (FLOATING_POINT_LITERAL)
- ".1e-2" producesTokens (FLOATING_POINT_LITERAL)
- ".1e+2345f" producesTokens (FLOATING_POINT_LITERAL)
- ".1e+2345d" producesTokens (FLOATING_POINT_LITERAL)
-
- "100" producesTokens (INTEGER_LITERAL)
- "1" producesTokens (INTEGER_LITERAL)
- "1L" producesTokens (INTEGER_LITERAL)
- "0" producesTokens (INTEGER_LITERAL)
- "0L" producesTokens (INTEGER_LITERAL)
- "0x2345" producesTokens (INTEGER_LITERAL)
- "0x" producesTokens (INTEGER_LITERAL)
- "0x32413L" producesTokens (INTEGER_LITERAL)
+ ".1234" producesTokens FLOATING_POINT_LITERAL
+ ".1234e2" producesTokens FLOATING_POINT_LITERAL
+ ".1234e+2" producesTokens FLOATING_POINT_LITERAL
+ ".1e-2" producesTokens FLOATING_POINT_LITERAL
+ ".1e+2345f" producesTokens FLOATING_POINT_LITERAL
+ ".1e+2345d" producesTokens FLOATING_POINT_LITERAL
+
+ "100" producesTokens INTEGER_LITERAL
+ "1" producesTokens INTEGER_LITERAL
+ "1L" producesTokens INTEGER_LITERAL
+ "0" producesTokens INTEGER_LITERAL
+ "0L" producesTokens INTEGER_LITERAL
+ "0x2345" producesTokens INTEGER_LITERAL
+ "0x" producesTokens INTEGER_LITERAL
+ "0x32413L" producesTokens INTEGER_LITERAL
"1Lfoo" producesTokens (INTEGER_LITERAL, VARID)
"0x1Lfoo" producesTokens (INTEGER_LITERAL, VARID)
- "0.1234" producesTokens (FLOATING_POINT_LITERAL)
- "0.1234e2" producesTokens (FLOATING_POINT_LITERAL)
- "0.1234e+2" producesTokens (FLOATING_POINT_LITERAL)
- "0.1e-2" producesTokens (FLOATING_POINT_LITERAL)
- "0.1e+2345f" producesTokens (FLOATING_POINT_LITERAL)
- "0.1e+2345d" producesTokens (FLOATING_POINT_LITERAL)
+ "0.1234" producesTokens FLOATING_POINT_LITERAL
+ "0.1234e2" producesTokens FLOATING_POINT_LITERAL
+ "0.1234e+2" producesTokens FLOATING_POINT_LITERAL
+ "0.1e-2" producesTokens FLOATING_POINT_LITERAL
+ "0.1e+2345f" producesTokens FLOATING_POINT_LITERAL
+ "0.1e+2345d" producesTokens FLOATING_POINT_LITERAL
- "10e2" producesTokens (FLOATING_POINT_LITERAL)
- "10e+2" producesTokens (FLOATING_POINT_LITERAL)
- "10e-2" producesTokens (FLOATING_POINT_LITERAL)
- "10e+2345f" producesTokens (FLOATING_POINT_LITERAL)
- "10e+2345d" producesTokens (FLOATING_POINT_LITERAL)
+ "10e2" producesTokens FLOATING_POINT_LITERAL
+ "10e+2" producesTokens FLOATING_POINT_LITERAL
+ "10e-2" producesTokens FLOATING_POINT_LITERAL
+ "10e+2345f" producesTokens FLOATING_POINT_LITERAL
+ "10e+2345d" producesTokens FLOATING_POINT_LITERAL
"22.`yield`" producesTokens (INTEGER_LITERAL, DOT, VARID)
"42.toString" producesTokens (INTEGER_LITERAL, DOT, VARID)
{
implicit val scalaVersion = ScalaVersions.Scala_2_9
- "5.f" producesTokens (FLOATING_POINT_LITERAL)
- "5.d" producesTokens (FLOATING_POINT_LITERAL)
- "5." producesTokens (FLOATING_POINT_LITERAL)
+ "5.f" producesTokens FLOATING_POINT_LITERAL
+ "5.d" producesTokens FLOATING_POINT_LITERAL
+ "5." producesTokens FLOATING_POINT_LITERAL
}
{
@@ -138,22 +135,22 @@ class ScalaLexerTest extends FlatSpec with ShouldMatchers {
}
- "'f'" producesTokens (CHARACTER_LITERAL)
- """'\n'""" producesTokens (CHARACTER_LITERAL)
- """'\025'""" producesTokens (CHARACTER_LITERAL)
+ "'f'" producesTokens CHARACTER_LITERAL
+ """'\n'""" producesTokens CHARACTER_LITERAL
+ """'\025'""" producesTokens CHARACTER_LITERAL
- "'symbol" producesTokens (SYMBOL_LITERAL)
- "'yield" producesTokens (SYMBOL_LITERAL)
+ "'symbol" producesTokens SYMBOL_LITERAL
+ "'yield" producesTokens SYMBOL_LITERAL
"private val tokenTextBuffer = new StringBuilder" producesTokens (PRIVATE, WS, VAL, WS, VARID, WS, EQUALS, WS, NEW, WS, VARID)
"""println("bob")
println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VARID, LPAREN, STRING_LITERAL, RPAREN)
- "\\u0061" producesTokens (VARID)
- "\\uuuuuuuuuuuuuuuuuuuuuuuuu0061" producesTokens (VARID)
- "\"\\u0061\"" producesTokens (STRING_LITERAL)
- "\"\\u000a\"" producesTokens (STRING_LITERAL)
+ "\\u0061" producesTokens VARID
+ "\\uuuuuuuuuuuuuuuuuuuuuuuuu0061" producesTokens VARID
+ "\"\\u0061\"" producesTokens STRING_LITERAL
+ "\"\\u000a\"" producesTokens STRING_LITERAL
"" producesTokens (XML_START_OPEN, XML_NAME, XML_WHITESPACE, XML_EMPTY_CLOSE)
"" producesTokens (XML_START_OPEN, XML_NAME, XML_TAG_CLOSE, XML_END_OPEN, XML_NAME, XML_TAG_CLOSE)
@@ -192,19 +189,19 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR
"" producesTokens (XML_START_OPEN, XML_NAME, XML_TAG_CLOSE, XML_COMMENT, XML_END_OPEN, XML_NAME, XML_TAG_CLOSE)
- "Hello, world!]]>" producesTokens (XML_CDATA)
+ "Hello, world!]]>" producesTokens XML_CDATA
"3 + + 4" producesTokens (INTEGER_LITERAL, WS, PLUS, WS, XML_COMMENT, WS, PLUS, WS, INTEGER_LITERAL)
"{{ = }}" producesTokens (XML_START_OPEN, XML_NAME, XML_TAG_CLOSE, XML_PCDATA, XML_END_OPEN, XML_NAME, XML_TAG_CLOSE)
- "0X1234" producesTokens (INTEGER_LITERAL)
+ "0X1234" producesTokens INTEGER_LITERAL
- """&<<>""^%@$!#""" producesTokens (XML_UNPARSED)
+ """&<<>""^%@$!#""" producesTokens XML_UNPARSED
"""3 + &<<>""^%@$!# + 3""" producesTokens (INTEGER_LITERAL, WS, PLUS, WS, XML_UNPARSED, WS, PLUS, WS,
INTEGER_LITERAL)
- """""" producesTokens (XML_PROCESSING_INSTRUCTION)
+ """""" producesTokens XML_PROCESSING_INSTRUCTION
"""
@@ -218,9 +215,9 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR
"for(<-Nil)Nil" producesTokens (FOR, LPAREN, XML_START_OPEN, XML_NAME, XML_EMPTY_CLOSE, LARROW, VARID, RPAREN, VARID)
- "\"\\u001A\"" producesTokens (STRING_LITERAL)
+ "\"\\u001A\"" producesTokens STRING_LITERAL
- "\"\"\"\\u001A\"\"\"" producesTokens (STRING_LITERAL)
+ "\"\"\"\\u001A\"\"\"" producesTokens STRING_LITERAL
"foo+\\u0061+bar" producesTokens (VARID, PLUS, VARID, PLUS, VARID)
@@ -230,22 +227,21 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR
"-5 max(2)" producesTokens (MINUS, INTEGER_LITERAL, WS, VARID, LPAREN, INTEGER_LITERAL, RPAREN)
"Lexer" should "throw a lexer exception" in {
- evaluating { ScalaLexer.rawTokenise("\"\"\"") } should produce[ScalaLexerException]
- evaluating { ScalaLexer.rawTokenise("") } should produce[ScalaLexerException]
- evaluating { ScalaLexer.rawTokenise("") } should produce[ScalaLexerException]
+ an[ScalaLexerException] should be thrownBy { ScalaLexer.rawTokenise("\"\"\"") }
+ an[ScalaLexerException] should be thrownBy { ScalaLexer.rawTokenise("") }
+ an[ScalaLexerException] should be thrownBy { ScalaLexer.rawTokenise("") }
}
{
implicit val forgiveErrors = true
- "\"\"\"" producesTokens (STRING_LITERAL)
- "'" producesTokens (CHARACTER_LITERAL)
- "\"unclosed" producesTokens (STRING_LITERAL)
- "\\ufoob" producesTokens (WS)
- "`unclosed" producesTokens (VARID)
- "" producesTokens (XML_PROCESSING_INSTRUCTION)
- "" producesTokens (XML_UNPARSED)
-
+ "\"\"\"" producesTokens STRING_LITERAL
+ "'" producesTokens CHARACTER_LITERAL
+ "\"unclosed" producesTokens STRING_LITERAL
+ "\\ufoob" producesTokens WS
+ "`unclosed" producesTokens VARID
+ "" producesTokens XML_PROCESSING_INSTRUCTION
+ "" producesTokens XML_UNPARSED
}
class TestString(s: String, forgiveErrors: Boolean = false, scalaVersion: ScalaVersion = ScalaVersions.DEFAULT) {
@@ -265,7 +261,5 @@ println("foo")""" producesTokens (VARID, LPAREN, STRING_LITERAL, RPAREN, WS, VAR
require(s == reconstitutedSource, "tokens do not partition text correctly: " + s + " vs " + reconstitutedSource)
}
}
-
}
-
}
diff --git a/scalariform/src/test/scala/scalariform/parser/ParserTest.scala b/scalariform/src/test/scala/scalariform/parser/ParserTest.scala
index 4a2063da..71dde793 100644
--- a/scalariform/src/test/scala/scalariform/parser/ParserTest.scala
+++ b/scalariform/src/test/scala/scalariform/parser/ParserTest.scala
@@ -1,24 +1,23 @@
package scalariform.parser
import scalariform.lexer._
-import scalariform.parser._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
+import org.scalatest.Matchers
// format: +preserveSpaceBeforeArguments
-class ParserTest extends FlatSpec with ShouldMatchers {
+class ParserTest extends FlatSpec with Matchers {
"Parser" should "throw a parse exception" in {
- evaluating { parseExpression("for {x <- b if }") } should produce[ScalaParserException]
+ an[ScalaParserException] should be thrownBy { parseExpression("for {x <- b if }") }
}
"Parser" should "throw a parse exception for empty match " in {
- evaluating { parseExpression("a match { }") } should produce[ScalaParserException]
+ an[ScalaParserException] should be thrownBy { parseExpression("a match { }") }
}
"Parser" should "produce a parse exception on a trailing close brace" in {
- evaluating { parseCompilationUnit("class A{}}") } should produce[ScalaParserException]
+ an[ScalaParserException] should be thrownBy { parseCompilationUnit("class A{}}") }
}
"Parser" should "not throw an exception" in {
@@ -38,11 +37,11 @@ class ParserTest extends FlatSpec with ShouldMatchers {
}
"Parser" should "throw a parse exception in bad package blocks" in {
- evaluating { parseCompilationUnit("package a {} package b {}") } should produce[ScalaParserException]
+ an[ScalaParserException] should be thrownBy { parseCompilationUnit("package a {} package b {}") }
}
private def parser(s: String) = new ScalaParser(ScalaLexer.tokenise(s).toArray)
- private def parseExpression(s: String) = parser(s).expr
- private def parseCompilationUnit(s: String) = parser(s).compilationUnit
+ private def parseExpression(s: String) = parser(s).expr()
+ private def parseCompilationUnit(s: String) = parser(s).compilationUnit()
}
diff --git a/scalariform/src/test/scala/scalariform/parser/ScalaParserTest.scala b/scalariform/src/test/scala/scalariform/parser/ScalaParserTest.scala
index cae004a5..ce71c24d 100644
--- a/scalariform/src/test/scala/scalariform/parser/ScalaParserTest.scala
+++ b/scalariform/src/test/scala/scalariform/parser/ScalaParserTest.scala
@@ -1,13 +1,12 @@
package scalariform.parser
import scalariform.lexer._
-import scalariform.parser._
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
+import org.scalatest.Matchers
// format: +preserveSpaceBeforeArguments
-class ScalaParserTest extends FlatSpec with ShouldMatchers {
+class ScalaParserTest extends FlatSpec with Matchers {
"Parser" should "not throw exception" in {
// parseExpression("class X")
@@ -18,7 +17,6 @@ class ScalaParserTest extends FlatSpec with ShouldMatchers {
class C(@annotation(foo = {1 + 2}) n: Int)
"""
}
-
}
private def parseExpression(s: String) = {
@@ -26,5 +24,4 @@ class C(@annotation(foo = {1 + 2}) n: Int)
val scalaParser = new ScalaParser(tokens.toArray)
scalaParser.compilationUnit()
}
-
}
diff --git a/scalariform/src/test/scala/scalariform/utils/TextEditTest.scala b/scalariform/src/test/scala/scalariform/utils/TextEditTest.scala
index f5b0ee9f..f03d4220 100644
--- a/scalariform/src/test/scala/scalariform/utils/TextEditTest.scala
+++ b/scalariform/src/test/scala/scalariform/utils/TextEditTest.scala
@@ -1,10 +1,10 @@
package scalariform.utils
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
+import org.scalatest.Matchers
// format: +preserveSpaceBeforeArguments
-class TextEditTest extends FlatSpec with ShouldMatchers {
+class TextEditTest extends FlatSpec with Matchers {
import TextEditProcessor.runEdits
diff --git a/scalariform/src/test/scala/scalariform/utils/TrimmedTest.scala b/scalariform/src/test/scala/scalariform/utils/TrimmedTest.scala
index cfae758b..f23981c2 100644
--- a/scalariform/src/test/scala/scalariform/utils/TrimmedTest.scala
+++ b/scalariform/src/test/scala/scalariform/utils/TrimmedTest.scala
@@ -1,10 +1,10 @@
package scalariform.utils
import org.scalatest.FlatSpec
-import org.scalatest.matchers.ShouldMatchers
+import org.scalatest.Matchers
// format: +preserveSpaceBeforeArguments
-class TrimmedTest extends FlatSpec with ShouldMatchers {
+class TrimmedTest extends FlatSpec with Matchers {
it should "just work" in {