Skip to content

Commit

Permalink
Use inExpression in a nullsafe way (#417)
Browse files Browse the repository at this point in the history
Summary:
peekLast is a JDK method using platform types for the return value.

Pull Request resolved: #417

Reviewed By: strulovich

Differential Revision: D49260503

Pulled By: hick209

fbshipit-source-id: 3a113bebbe32b180ebaf30e1718bcaf7e69ca52b
  • Loading branch information
nreid260 authored and facebook-github-bot committed Sep 15, 2023
1 parent 2be7c7e commit 9c06ac1
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1673,7 +1673,8 @@ class KotlinInputAstVisitor(
prefix = "(",
postfix = ")",
breakAfterPrefix = false,
breakBeforePostfix = false)
breakBeforePostfix = false,
)
builder.forcedBreak()
}

Expand Down Expand Up @@ -2425,7 +2426,7 @@ class KotlinInputAstVisitor(
* @throws FormattingError
*/
override fun visitElement(element: PsiElement) {
inExpression.addLast(element is KtExpression || inExpression.peekLast())
inExpression.addLast(element is KtExpression || inExpression.last())
val previous = builder.depth()
try {
super.visitElement(element)
Expand Down Expand Up @@ -2493,10 +2494,6 @@ class KotlinInputAstVisitor(
markForPartialFormat()
}

private fun inExpression(): Boolean {
return inExpression.peekLast()
}

/**
* markForPartialFormat is used to delineate the smallest areas of code that must be formatted
* together.
Expand All @@ -2505,7 +2502,7 @@ class KotlinInputAstVisitor(
* covered by an area marked by this method.
*/
private fun markForPartialFormat() {
if (!inExpression()) {
if (!inExpression.last()) {
builder.markForPartialFormat()
}
}
Expand Down

0 comments on commit 9c06ac1

Please sign in to comment.