mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[scripts] KTNB-1391, KTNB-819, KTIJ-37776 Choose KtBlockExpression as a container for top-level script declarations
We had all top-level refactoring-generated declarations inserted into KtScript element. However, the contract is that all declarations should be inserted into its child, KtBlockExpression. Merge-request: IJ-MR-193891 Merged-by: Ilya Muradyan <Ilya.Muradyan@jetbrains.com> (cherry picked from commit f4a388dc736bd8bb4396520124b27f34999aab8c) IJ-MR-194486 GitOrigin-RevId: 53cf4675dcdd6401f53b8903b05d21218348c6ff
This commit is contained in:
committed by
intellij-monorepo-bot
parent
744725eade
commit
8792825de4
+11
-1
@@ -86,6 +86,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.psi.psiUtil.siblings
|
||||
import org.jetbrains.kotlin.psi.unpackFunctionLiteral
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.Collections
|
||||
import kotlin.math.min
|
||||
|
||||
@@ -412,7 +413,16 @@ fun PsiElement.getExtractionContainers(strict: Boolean = true, includeAll: Boole
|
||||
|
||||
return when (enclosingDeclaration) {
|
||||
is KtFile -> Collections.singletonList(enclosingDeclaration)
|
||||
is KtScript -> Collections.singletonList(enclosingDeclaration)
|
||||
is KtScript -> {
|
||||
/**
|
||||
* [KtScript] element is essentially a class, so it should always have
|
||||
* a single child, which is a [KtBlockExpression]. Inserting an element as an immediate child
|
||||
* of the [KtScript] element is a mistake.
|
||||
*/
|
||||
Collections.singletonList(
|
||||
enclosingDeclaration.children.firstIsInstanceOrNull<KtBlockExpression>() ?: enclosingDeclaration
|
||||
)
|
||||
}
|
||||
is KtClassBody -> getAllExtractionContainers(strict).filterIsInstance<KtClassBody>()
|
||||
else -> {
|
||||
val targetContainer = when (enclosingDeclaration) {
|
||||
|
||||
Reference in New Issue
Block a user