Skip to content

Commit

Permalink
Workaround non-null parent requirement of StubBase (#513)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #513

Reviewed By: davidtorosyan

Differential Revision: D61870580

Pulled By: hick209

fbshipit-source-id: 046a133a61355fd3a16dd9c92bb803e5b791f60e
  • Loading branch information
jsjeon authored and facebook-github-bot committed Aug 30, 2024
1 parent 9154b36 commit 9dcd261
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

### Fixed
- Comments respecting max line width (https://github.com/facebook/ktfmt/pull/511)
- Exception while parsing property accessor on Kotlin 2.0.20-Beta2+ (https://github.com/facebook/ktfmt/pull/513)


## [0.52]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.util.Optional
import org.jetbrains.kotlin.com.intellij.psi.PsiComment
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.com.intellij.psi.stubs.PsiFileStubImpl
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtAnnotatedExpression
Expand Down Expand Up @@ -1415,15 +1416,17 @@ class KotlinInputAstVisitor(
return 0
}

// Bug in Kotlin 1.9.10: KtProperyAccessor is the direct parent of the left and right paren
// Bug in Kotlin 1.9.10: KtPropertyAccessor is the direct parent of the left and right paren
// elements. Also parameterList is always null for getters. As a workaround, we create our own
// fake KtParameterList.
// TODO: won't need this after https://youtrack.jetbrains.com/issue/KT-70922
private fun getParameterListWithBugFixes(accessor: KtPropertyAccessor): KtParameterList? {
if (accessor.bodyExpression == null && accessor.bodyBlockExpression == null) return null

val stub = accessor.stub ?: PsiFileStubImpl(accessor.containingFile)

return object :
KtParameterList(
KotlinPlaceHolderStubImpl(accessor.stub, KtStubElementTypes.VALUE_PARAMETER_LIST)) {
KtParameterList(KotlinPlaceHolderStubImpl(stub, KtStubElementTypes.VALUE_PARAMETER_LIST)) {
override fun getParameters(): List<KtParameter> {
return accessor.valueParameters
}
Expand Down

0 comments on commit 9dcd261

Please sign in to comment.