Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatTokens: move getBraces from TreeOps #4161

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading