Skip to content

Commit

Permalink
Reformat with AlignSingleLineCaseStatements(true)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Jan 21, 2011
1 parent 0c60045 commit 6fc91f2
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 97 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -218,7 +218,7 @@ Is reformatted as::
alignSingleLineCaseStatements.maxArrowIndent alignSingleLineCaseStatements.maxArrowIndent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Default: ``25`` Default: ``40``


When using alignSingleLineCaseStatements == true, this is a limit on When using alignSingleLineCaseStatements == true, this is a limit on
the number of spaces that can be inserted before an arrow to align it the number of spaces that can be inserted before an arrow to align it
Expand Down
2 changes: 1 addition & 1 deletion docs/source/README.rst
Expand Up @@ -218,7 +218,7 @@ Is reformatted as::
alignSingleLineCaseStatements.maxArrowIndent alignSingleLineCaseStatements.maxArrowIndent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Default: ``25`` Default: ``40``


When using alignSingleLineCaseStatements == true, this is a limit on When using alignSingleLineCaseStatements == true, this is a limit on
the number of spaces that can be inserted before an arrow to align it the number of spaces that can be inserted before an arrow to align it
Expand Down
4 changes: 2 additions & 2 deletions gui/src/main/scala/scalariform/gui/ParseTreeModel.scala
Expand Up @@ -41,7 +41,7 @@ class ParseTreeModel(rootAstNode: AstNode) extends TreeModel {
val fields = astNode.getFields val fields = astNode.getFields
lazy val children = fields flatMap { lazy val children = fields flatMap {
case (_, None) | (_, Nil) None case (_, None) | (_, Nil) None
case (fieldName, value) Some(makeTreeNode(value.asInstanceOf[AnyRef], fieldName)) case (fieldName, value) Some(makeTreeNode(value.asInstanceOf[AnyRef], fieldName))
} }
override def toString = { override def toString = {
val typeName = astNode.getClass.getSimpleName val typeName = astNode.getClass.getSimpleName
Expand All @@ -64,7 +64,7 @@ class ParseTreeModel(rootAstNode: AstNode) extends TreeModel {


case class EitherNode(name: String, either: Either[_ <: AnyRef, _ <: AnyRef]) extends TreeNode(name) { case class EitherNode(name: String, either: Either[_ <: AnyRef, _ <: AnyRef]) extends TreeNode(name) {
lazy val children = either match { lazy val children = either match {
case Left(obj) List(makeTreeNode(obj)) case Left(obj) List(makeTreeNode(obj))
case Right(obj) List(makeTreeNode(obj)) case Right(obj) List(makeTreeNode(obj))
} }


Expand Down
2 changes: 1 addition & 1 deletion project/build/Project.scala
Expand Up @@ -5,7 +5,7 @@ class Project(info: ProjectInfo) extends ParentProject(info) {


trait FormatterOptions /* extends ScalariformPlugin */ { trait FormatterOptions /* extends ScalariformPlugin */ {


/* override */ def scalariformOptions = Seq(VerboseScalariform, RewriteArrowSymbols(true), AlignParameters(true)) /* override */ def scalariformOptions = Seq(VerboseScalariform, RewriteArrowSymbols(true), AlignParameters(true), AlignSingleLineCaseStatements(true))


} }


Expand Down
6 changes: 3 additions & 3 deletions scalariform/src/main/scala/scalariform/commandline/Main.scala
Expand Up @@ -152,9 +152,9 @@ object Main {
for (file files) { for (file files) {
val formatResult = checkSource(Source.fromFile(file, encoding)) val formatResult = checkSource(Source.fromFile(file, encoding))
val resultString = formatResult match { val resultString = formatResult match {
case FormattedCorrectly "OK" case FormattedCorrectly "OK"
case NotFormattedCorrectly "FAILED" case NotFormattedCorrectly "FAILED"
case DidNotParse "ERROR" case DidNotParse "ERROR"
} }
val padding = " " * (6 - resultString.length) val padding = " " * (6 - resultString.length)
log("[" + resultString + "]" + padding + " " + file) log("[" + resultString + "]" + padding + " " + file)
Expand Down Expand Up @@ -231,7 +231,7 @@ object Main {
for { for {
key sortedPreferences key sortedPreferences
preference = AllPreferences.preferencesByKey(key) preference = AllPreferences.preferencesByKey(key)
IntegerPreference(min, max) <- Some(preference.preferenceType) IntegerPreference(min, max) Some(preference.preferenceType)
} { } {
val optionText = " -" + key + "=[" + min + "-" + max + "]" val optionText = " -" + key + "=[" + min + "-" + max + "]"
val filler = " " * (descriptionColumn - optionText.length) val filler = " " * (descriptionColumn - optionText.length)
Expand Down
Expand Up @@ -43,7 +43,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
if (formattingPreferences(CompactStringConcatenation)) { if (formattingPreferences(CompactStringConcatenation)) {
val infixPlus = element match { val infixPlus = element match {
case InfixExprElement(Token(PLUS, _, _, _)) true case InfixExprElement(Token(PLUS, _, _, _)) true
case _ false case _ false
} }
val stringConcatenation = (previousElement, nextElementOption) match { val stringConcatenation = (previousElement, nextElementOption) match {
case (GeneralTokens(tokens), _) if tokens.last.tokenType == STRING_LITERAL true case (GeneralTokens(tokens), _) if tokens.last.tokenType == STRING_LITERAL true
Expand Down Expand Up @@ -95,26 +95,26 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
} }


private def format(exprElement: ExprElement)(implicit formatterState: FormatterState): FormatResult = exprElement match { private def format(exprElement: ExprElement)(implicit formatterState: FormatterState): FormatResult = exprElement match {
case ifExpr: IfExpr format(ifExpr) case ifExpr: IfExpr format(ifExpr)
case whileExpr: WhileExpr format(whileExpr) case whileExpr: WhileExpr format(whileExpr)
case doExpr: DoExpr format(doExpr) case doExpr: DoExpr format(doExpr)
case blockExpr: BlockExpr format(blockExpr, indent = true) case blockExpr: BlockExpr format(blockExpr, indent = true)
case forExpr: ForExpr format(forExpr) case forExpr: ForExpr format(forExpr)
case tryExpr: TryExpr format(tryExpr) case tryExpr: TryExpr format(tryExpr)
case template: Template format(template) case template: Template format(template)
case statSeq: StatSeq format(statSeq) // TODO: revisit case statSeq: StatSeq format(statSeq) // TODO: revisit
case argumentExprs: ArgumentExprs format(argumentExprs) case argumentExprs: ArgumentExprs format(argumentExprs)
case anonymousFunction: AnonymousFunction format(anonymousFunction) case anonymousFunction: AnonymousFunction format(anonymousFunction)
case GeneralTokens(_) NoFormatResult case GeneralTokens(_) NoFormatResult
case PrefixExprElement(_) NoFormatResult case PrefixExprElement(_) NoFormatResult
case InfixExprElement(_) NoFormatResult case InfixExprElement(_) NoFormatResult
case PostfixExprElement(_) NoFormatResult case PostfixExprElement(_) NoFormatResult
case annotation: Annotation format(annotation) case annotation: Annotation format(annotation)
case typeExprElement: TypeExprElement format(typeExprElement.contents) case typeExprElement: TypeExprElement format(typeExprElement.contents)
case expr: Expr format(expr.contents) case expr: Expr format(expr.contents)
case xmlExpr: XmlExpr format(xmlExpr) case xmlExpr: XmlExpr format(xmlExpr)
case parenExpr: ParenExpr format(parenExpr) case parenExpr: ParenExpr format(parenExpr)
case _ NoFormatResult case _ NoFormatResult
} }


def format(anonymousFunction: AnonymousFunction)(implicit formatterState: FormatterState): FormatResult = { // <-- Also formatted specially in BlockExpr def format(anonymousFunction: AnonymousFunction)(implicit formatterState: FormatterState): FormatResult = { // <-- Also formatted specially in BlockExpr
Expand All @@ -132,7 +132,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
} }


def format(argumentExprs: ArgumentExprs)(implicit formatterState: FormatterState): FormatResult = argumentExprs match { def format(argumentExprs: ArgumentExprs)(implicit formatterState: FormatterState): FormatResult = argumentExprs match {
case BlockArgumentExprs(contents) format(contents) case BlockArgumentExprs(contents) format(contents)
case ParenArgumentExprs(lparen, contents, rparen) format(GeneralTokens(List(lparen)) :: contents) case ParenArgumentExprs(lparen, contents, rparen) format(GeneralTokens(List(lparen)) :: contents)
} }


Expand Down Expand Up @@ -337,9 +337,9 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi


private def format(enumerator: Enumerator)(implicit formatterState: FormatterState): FormatResult = { private def format(enumerator: Enumerator)(implicit formatterState: FormatterState): FormatResult = {
enumerator match { enumerator match {
case expr@Expr(_) format(expr) case expr@Expr(_) format(expr)
case generator@Generator(_, _, _, _, _) format(generator) case generator@Generator(_, _, _, _, _) format(generator)
case guard@Guard(_, _) format(guard: Guard) case guard@Guard(_, _) format(guard: Guard)
} }
} }


Expand Down Expand Up @@ -520,11 +520,11 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi


private def format(stat: Stat)(implicit formatterState: FormatterState): FormatResult = private def format(stat: Stat)(implicit formatterState: FormatterState): FormatResult =
stat match { stat match {
case expr: Expr format(expr) case expr: Expr format(expr)
case fullDefOrDcl: FullDefOrDcl format(fullDefOrDcl) case fullDefOrDcl: FullDefOrDcl format(fullDefOrDcl)
case import_ : ImportClause format(import_) case import_ : ImportClause format(import_)
case packageBlock: PackageBlock format(packageBlock) case packageBlock: PackageBlock format(packageBlock)
case _ NoFormatResult // TODO case _ NoFormatResult // TODO
} }


def format(packageBlock: PackageBlock)(implicit formatterState: FormatterState): FormatResult = { def format(packageBlock: PackageBlock)(implicit formatterState: FormatterState): FormatResult = {
Expand Down Expand Up @@ -559,7 +559,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
formatResult = formatResult.before(annotation.firstToken, preAnnotationFormattingInstruction) formatResult = formatResult.before(annotation.firstToken, preAnnotationFormattingInstruction)
if (nextOption.isEmpty) { if (nextOption.isEmpty) {
val firstPostAnnotationToken = modifiers match { val firstPostAnnotationToken = modifiers match {
case Nil defOrDcl.firstToken case Nil defOrDcl.firstToken
case (modifier :: rest) modifier.firstToken case (modifier :: rest) modifier.firstToken
} }
formatResult = formatResult.before(firstPostAnnotationToken, preAnnotationFormattingInstruction) formatResult = formatResult.before(firstPostAnnotationToken, preAnnotationFormattingInstruction)
Expand All @@ -570,11 +570,11 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
} }


private def format(defOrDcl: DefOrDcl)(implicit formatterState: FormatterState): FormatResult = defOrDcl match { private def format(defOrDcl: DefOrDcl)(implicit formatterState: FormatterState): FormatResult = defOrDcl match {
case patDefOrDcl: PatDefOrDcl format(patDefOrDcl) case patDefOrDcl: PatDefOrDcl format(patDefOrDcl)
case typeDefOrDcl: TypeDefOrDcl format(typeDefOrDcl) case typeDefOrDcl: TypeDefOrDcl format(typeDefOrDcl)
case funDefOrDcl: FunDefOrDcl format(funDefOrDcl) case funDefOrDcl: FunDefOrDcl format(funDefOrDcl)
case tmplDef: TmplDef format(tmplDef) case tmplDef: TmplDef format(tmplDef)
case _ NoFormatResult // TODO case _ NoFormatResult // TODO
} }


private def format(patDefOrDcl: PatDefOrDcl)(implicit formatterState: FormatterState): FormatResult = { private def format(patDefOrDcl: PatDefOrDcl)(implicit formatterState: FormatterState): FormatResult = {
Expand Down Expand Up @@ -699,7 +699,7 @@ trait ExprFormatter { self: HasFormattingPreferences with AnnotationFormatter wi
} }


private def format(importExpr: ImportExpr)(implicit formatterState: FormatterState): FormatResult = importExpr match { private def format(importExpr: ImportExpr)(implicit formatterState: FormatterState): FormatResult = importExpr match {
case expr@Expr(_) format(expr) case expr@Expr(_) format(expr)
case blockImportExpr@BlockImportExpr(_, _) format(blockImportExpr) case blockImportExpr@BlockImportExpr(_, _) format(blockImportExpr)
} }


Expand Down
Expand Up @@ -116,7 +116,7 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
for ((previousOption, line) Utils.pairWithPrevious(lines)) { for ((previousOption, line) Utils.pairWithPrevious(lines)) {
line match { line match {
case StarLine(fromStar) sb.append(newlineSequence).indent(indentLevel).append(" ").append(fromStar) case StarLine(fromStar) sb.append(newlineSequence).indent(indentLevel).append(" ").append(fromStar)
case _ sb.append(line) case _ sb.append(line)
} }
} }
sb.toString sb.toString
Expand Down Expand Up @@ -194,7 +194,7 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
val newlineCount = token.getText.count(_ == '\n') val newlineCount = token.getText.count(_ == '\n')
val newlinesToWrite = previousOpt match { val newlinesToWrite = previousOpt match {
case Some(SingleLineComment(_)) math.min(1, newlineCount) case Some(SingleLineComment(_)) math.min(1, newlineCount)
case _ math.min(2, newlineCount) case _ math.min(2, newlineCount)
} }
for (i 1 to newlinesToWrite) for (i 1 to newlinesToWrite)
builder.newline() builder.newline()
Expand Down Expand Up @@ -250,9 +250,9 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
def write(token: Token, replacementOption: Option[String] = None): Option[TextEdit] = { def write(token: Token, replacementOption: Option[String] = None): Option[TextEdit] = {
val rewriteArrows = formattingPreferences(RewriteArrowSymbols) val rewriteArrows = formattingPreferences(RewriteArrowSymbols)
val actualReplacementOption = replacementOption orElse (condOpt(token.getType) { val actualReplacementOption = replacementOption orElse (condOpt(token.getType) {
case ARROW if rewriteArrows "" case ARROW if rewriteArrows ""
case LARROW if rewriteArrows "" case LARROW if rewriteArrows ""
case EOF "" case EOF ""
}) })
builder.append(actualReplacementOption getOrElse token.getText) builder.append(actualReplacementOption getOrElse token.getText)
actualReplacementOption map { replaceEdit(token, _) } actualReplacementOption map { replaceEdit(token, _) }
Expand Down Expand Up @@ -368,14 +368,14 @@ abstract class ScalaFormatter extends HasFormattingPreferences with TypeFormatte
return CompactEnsuringGap return CompactEnsuringGap
type1 match { type1 match {
case ARROW if type2 != RPAREN return CompactEnsuringGap // TODO: Redundant? no test fails. case ARROW if type2 != RPAREN return CompactEnsuringGap // TODO: Redundant? no test fails.
case COMMA return CompactEnsuringGap case COMMA return CompactEnsuringGap
case _ case _
} }
type2 match { type2 match {
case IF if type1 != LPAREN return CompactEnsuringGap case IF if type1 != LPAREN return CompactEnsuringGap
case ARROW if type1 != LPAREN return CompactEnsuringGap case ARROW if type1 != LPAREN return CompactEnsuringGap
case AT if IDS contains type2 return CompactEnsuringGap case AT if IDS contains type2 return CompactEnsuringGap
case _ case _
} }
Compact Compact
} }
Expand Down
Expand Up @@ -39,13 +39,13 @@ trait TypeFormatter { self: HasFormattingPreferences with AnnotationFormatter wi


private def format(typeElement: TypeElement)(implicit formatterState: FormatterState): FormatResult = { private def format(typeElement: TypeElement)(implicit formatterState: FormatterState): FormatResult = {
typeElement match { typeElement match {
case type_ @Type(_) format(type_) case type_ @Type(_) format(type_)
case refinement@Refinement(_, _, _) format(refinement) case refinement@Refinement(_, _, _) format(refinement)
case annotation@Annotation(_, _, _, _) format(annotation) case annotation@Annotation(_, _, _, _) format(annotation)
case TypeParamClause(contents) format(contents) case TypeParamClause(contents) format(contents)
case VarianceTypeElement(id) NoFormatResult case VarianceTypeElement(id) NoFormatResult
case VarargsTypeElement(star) NoFormatResult case VarargsTypeElement(star) NoFormatResult
case _ NoFormatResult case _ NoFormatResult
} }
} }


Expand Down
Expand Up @@ -21,10 +21,10 @@ trait XmlFormatter { self: HasFormattingPreferences with ExprFormatter with Scal


def format(xmlContent: XmlContents)(implicit formatterState: FormatterState): FormatResult = { def format(xmlContent: XmlContents)(implicit formatterState: FormatterState): FormatResult = {
xmlContent match { xmlContent match {
case expr@Expr(_) format(expr) case expr@Expr(_) format(expr)
case xmlNonEmpty@XmlNonEmptyElement(_, _, _) format(xmlNonEmpty) case xmlNonEmpty@XmlNonEmptyElement(_, _, _) format(xmlNonEmpty)
case xmlEmpty@XmlEmptyElement(_, _, _, _, _) format(xmlEmpty) case xmlEmpty@XmlEmptyElement(_, _, _, _, _) format(xmlEmpty)
case _ NoFormatResult // TODO case _ NoFormatResult // TODO
} }
} }


Expand Down
Expand Up @@ -11,9 +11,9 @@ sealed trait PreferenceType[T] {
case object BooleanPreference extends PreferenceType[Boolean] { case object BooleanPreference extends PreferenceType[Boolean] {
def parseValue(s: String) = def parseValue(s: String) =
s.toLowerCase match { s.toLowerCase match {
case "true" Right(true) case "true" Right(true)
case "false" Right(false) case "false" Right(false)
case _ Left("Could not parse as boolean value: " + s) case _ Left("Could not parse as boolean value: " + s)
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion scalariform/src/main/scala/scalariform/lexer/Lexer.scala
Expand Up @@ -62,7 +62,7 @@ abstract class Lexer(reader: UnicodeEscapeReader) extends TokenTests {
val virtualChar = chQueue.dequeue() val virtualChar = chQueue.dequeue()
tokenTextBuffer.append(virtualChar) tokenTextBuffer.append(virtualChar)
val delta = unicodeEscapesQueue.dequeue() match { val delta = unicodeEscapesQueue.dequeue() match {
case None 1 case None 1
case Some(s) s.length case Some(s) s.length
} }
actualTokenTextLength += delta actualTokenTextLength += delta
Expand Down
Expand Up @@ -102,7 +102,7 @@ class NewlineInferencer(private val delegate: Iterator[(HiddenTokens, Token)]) {


private def followingTokenIsClassOrObject: Boolean = private def followingTokenIsClassOrObject: Boolean =
buffer.headOption match { buffer.headOption match {
case None false case None false
case Some((_, followingToken)) followingToken.getType == CLASS || followingToken.getType == OBJECT case Some((_, followingToken)) followingToken.getType == CLASS || followingToken.getType == OBJECT
} }


Expand Down
Expand Up @@ -60,7 +60,7 @@ trait ScalaOnlyLexer extends Lexer {
(ch(1): @switch) match { (ch(1): @switch) match {
case '/' getSingleLineComment() case '/' getSingleLineComment()
case '*' getMultilineComment() case '*' getMultilineComment()
case _ nextChar(); getOperatorRest() case _ nextChar(); getOperatorRest()
} }
case '0' case '0'
if (ch(1) == 'x' || ch(1) == 'X') if (ch(1) == 'x' || ch(1) == 'X')
Expand Down Expand Up @@ -242,7 +242,7 @@ trait ScalaOnlyLexer extends Lexer {
case '/' case '/'
(ch(1): @switch) match { (ch(1): @switch) match {
case '/' | '*' finishNamed() case '/' | '*' finishNamed()
case _ nextChar(); getOperatorRest() case _ nextChar(); getOperatorRest()
} }
case _ case _
if (isSpecial(ch)) { nextChar(); getOperatorRest() } else finishNamed() if (isSpecial(ch)) { nextChar(); getOperatorRest() } else finishNamed()
Expand Down Expand Up @@ -367,11 +367,11 @@ trait ScalaOnlyLexer extends Lexer {
def restOfUncertainToken() = { def restOfUncertainToken() = {
def isEfd = ch match { def isEfd = ch match {
case 'e' | 'E' | 'f' | 'F' | 'd' | 'D' true case 'e' | 'E' | 'f' | 'F' | 'd' | 'D' true
case _ false case _ false
} }
def isL = ch match { def isL = ch match {
case 'l' | 'L' true case 'l' | 'L' true
case _ false case _ false
} }


if (isEfd) if (isEfd)
Expand Down
Expand Up @@ -30,7 +30,7 @@ class WhitespaceAndCommentsGrouper(private val delegate: ScalaLexer) extends Ite


private def isHiddenToken(token: Token) = token.getType match { private def isHiddenToken(token: Token) = token.getType match {
case WS | LINE_COMMENT | MULTILINE_COMMENT true case WS | LINE_COMMENT | MULTILINE_COMMENT true
case _ false case _ false
} }


private def makeHiddenToken(token: Token) = token.getType match { private def makeHiddenToken(token: Token) = token.getType match {
Expand Down
Expand Up @@ -26,7 +26,7 @@ trait AstNode extends CaseClassReflector {
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 pairToFlattenable[T1 <% Flattenable, T2 <% Flattenable](pair: (T1, T2)): Flattenable = new Flattenable { val tokens = pair._1.tokens ::: pair._2.tokens }
protected implicit def eitherToFlattenable[T1 <% Flattenable, T2 <% Flattenable](either: T1 Either T2): Flattenable = new Flattenable { protected implicit def eitherToFlattenable[T1 <% Flattenable, T2 <% Flattenable](either: T1 Either T2): Flattenable = new Flattenable {
val tokens = either match { val tokens = either match {
case Left(f) f.tokens case Left(f) f.tokens
case Right(f) f.tokens case Right(f) f.tokens
} }
} }
Expand Down

0 comments on commit 6fc91f2

Please sign in to comment.