Skip to content

Commit

Permalink
TreeOps: add isEmptyTree and function body
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Mar 3, 2024
1 parent 07c61a2 commit bbefde2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -920,16 +920,6 @@ class FormatOps(
maxPrecedence
}

def isEmptyFunctionBody(tree: Tree): Boolean =
tree match {
case function: Term.FunctionTerm =>
function.body match {
case b: Term.Block => b.stats.isEmpty
case _ => false
}
case _ => false
}

def functionExpire(function: Term.FunctionTerm): (T, ExpiresOn) = {
def dropWS(rtoks: Seq[T]): Seq[T] =
rtoks.dropWhile(_.is[T.Whitespace])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,7 @@ class Router(formatOps: FormatOps) {
case c: Case => c.cond.isDefined
case _ => false
}
val bodyIsEmpty = body match {
case t: Term.Block => t.stats.isEmpty
case t => t.tokens.isEmpty
}
val bodyIsEmpty = isEmptyTree(body)
def baseSplit = Split(Space, 0)
def nlSplit(ft: FormatToken)(cost: Int)(implicit l: FileLine) =
Split(NewlineT(isDouble = ft.hasBlankLine && bodyIsEmpty), cost)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,16 @@ object TreeOps {
def isInterpolate(tree: Tree): Boolean =
isTreeOrBlockParent(tree)(_.isAny[Term.Interpolate, Pat.Interpolate])

def isEmptyTree(tree: Tree): Boolean =
tree match {
case t: Term.Block => t.stats.isEmpty
case t => t.tokens.isEmpty
}

def isEmptyFunctionBody(tree: Tree): Boolean =
tree match {
case t: Term.FunctionTerm => isEmptyTree(t.body)
case _ => false
}

}

0 comments on commit bbefde2

Please sign in to comment.