Skip to content

Commit

Permalink
FormatTokens: move getBraces from TreeOps
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Aug 16, 2024
1 parent ad82f55 commit 1eec787
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ class FormatTokens(leftTok2tok: Map[TokenHash, Int])(val arr: Array[FormatToken]
def isEnclosedInMatching(tree: Tree): Boolean =
isEnclosedInMatching(tree.tokens, tree)

@inline
def getBracesIfEnclosed(tree: Tree): Option[(FormatToken, FormatToken)] =
getDelimsIfEnclosed(tree).filter(_._1.left.is[Token.LeftBrace])

@inline
def isEnclosedInBraces(tree: Tree): Boolean = getDelimsIfEnclosed(tree)
.exists(_._1.left.is[Token.LeftBrace])

@inline
private def areMatchingParens(close: Token)(open: => Token): Boolean = close
.is[Token.RightParen] && areMatching(close)(open)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class RedundantBraces(implicit val ftoks: FormatTokens)
// Leave this alone for now.
// In future there should be an option to surround such expressions with parens instead of braces
if (isSeqMulti(t.values)) okToRemoveBlockWithinApply(b)
else (t.pos.start != b.pos.start) && SingleArgInBraces.inBraces(t)
else (t.pos.start != b.pos.start) && ftoks.isEnclosedInBraces(t)

case d: Defn.Def =>
def disqualifiedByUnit = !settings.includeUnitMethods &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,9 @@ object TreeOps {
case _ => None
}
@inline
def inBraces(tree: Tree)(implicit ftoks: FormatTokens): Boolean =
getBraces(tree).isDefined
@inline
def getBraces(tree: Tree)(implicit
private def getBraces(tree: Tree)(implicit
ftoks: FormatTokens,
): Option[(FormatToken, FormatToken)] = ftoks.getDelimsIfEnclosed(tree)
.filter(_._1.left.is[LeftBrace])
): Option[(FormatToken, FormatToken)] = ftoks.getBracesIfEnclosed(tree)

def orBlock(tree: Tree)(implicit
ftoks: FormatTokens,
Expand Down

0 comments on commit 1eec787

Please sign in to comment.