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

Workaround non-null parent requirement of StubBase #513

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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)

- Workaround non-null parent requirement of StubBase (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,18 @@ 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)) {
KotlinPlaceHolderStubImpl(stub, KtStubElementTypes.VALUE_PARAMETER_LIST)) {
override fun getParameters(): List<KtParameter> {
return accessor.valueParameters
}
Expand Down