Skip to content
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: scala
scala:
- 2.11.0-RC1
- 2.10.3
- 2.9.3
jdk:
- oraclejdk7
- openjdk7
2 changes: 1 addition & 1 deletion misc/src/main/scala/scalariform/gui/ParseTreeModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
4 changes: 1 addition & 3 deletions misc/src/main/scala/scalariform/gui/SwingUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}
33 changes: 12 additions & 21 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"))

Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -134,5 +126,4 @@ object ScalariformBuild extends Build {
<url>https://github.com/daniel-trinh/</url>
</developer>
</developers>

}
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ⇒
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package scalariform.formatter

import scalariform.parser._
import scalariform.utils._
import scalariform.lexer._
import scalariform.formatter.preferences._
import scala.annotation.tailrec
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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, _) }
}
Expand All @@ -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)
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions scalariform/src/main/scala/scalariform/lexer/ScalaLexer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 "</xml:unparsed>" (15 chars)
Expand Down
9 changes: 4 additions & 5 deletions scalariform/src/main/scala/scalariform/lexer/Token.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
32 changes: 22 additions & 10 deletions scalariform/src/main/scala/scalariform/parser/AstNodes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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)
Expand All @@ -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)
}

Expand Down
Loading