mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 15:15:45 +07:00
remove illegal dependency kotlin.code-insight.k2 -> kotlin.core because turned out kotlin.core is k1-specific
followup to jetbrains.team/p/ij/reviews/125638 (part of KTIJ-28926 K2: Create Function From Usage Fix) GitOrigin-RevId: a2bdeeffea16b9ca049ee397f95069b4f88c6e4b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
13d0cf5f60
commit
165bbb3559
@@ -8,6 +8,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/system" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/docs/plugin-graph/dist" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/docs/dist-visualizer/dist" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/native" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
+30
-30
@@ -211,42 +211,42 @@ fun <T : KtDeclaration> insertMembersAfter(
|
||||
)
|
||||
}
|
||||
|
||||
if (otherMembers.isNotEmpty()) {
|
||||
val psiFactory = KtPsiFactory(project)
|
||||
val tailComments = classOrObject.allChildren.toList()
|
||||
.takeLastWhile { it is PsiComment || it is PsiWhiteSpace }
|
||||
.map { commentOrSpace ->
|
||||
if (commentOrSpace is PsiWhiteSpace) {
|
||||
psiFactory.createWhiteSpace(commentOrSpace.text)
|
||||
} else {
|
||||
commentOrSpace.copy().also { commentOrSpace.delete() }
|
||||
}
|
||||
if (otherMembers.isNotEmpty()) {
|
||||
val psiFactory = KtPsiFactory(project)
|
||||
val tailComments = classOrObject.allChildren.toList()
|
||||
.takeLastWhile { it is PsiComment || it is PsiWhiteSpace }
|
||||
.map { commentOrSpace ->
|
||||
if (commentOrSpace is PsiWhiteSpace) {
|
||||
psiFactory.createWhiteSpace(commentOrSpace.text)
|
||||
} else {
|
||||
commentOrSpace.copy().also { commentOrSpace.delete() }
|
||||
}
|
||||
val body = classOrObject.getOrCreateBody()
|
||||
val lBrace = body.lBrace
|
||||
if (lBrace != null) {
|
||||
tailComments.reversed().map { body.addAfter(it, lBrace) }
|
||||
}
|
||||
val body = classOrObject.getOrCreateBody()
|
||||
val lBrace = body.lBrace
|
||||
if (lBrace != null) {
|
||||
tailComments.reversed().map { body.addAfter(it, lBrace) }
|
||||
}
|
||||
|
||||
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return emptyList()
|
||||
otherMembers.mapTo(insertedMembers) {
|
||||
afterAnchor = getAnchor(it) ?: afterAnchor
|
||||
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return emptyList()
|
||||
otherMembers.mapTo(insertedMembers) {
|
||||
afterAnchor = getAnchor(it) ?: afterAnchor
|
||||
|
||||
if (classOrObject is KtClass && classOrObject.isEnum()) {
|
||||
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
|
||||
val bound = (enumEntries.lastOrNull() ?: classOrObject.allChildren.firstOrNull { element ->
|
||||
element.node.elementType == KtTokens.SEMICOLON
|
||||
})
|
||||
if (it !is KtEnumEntry) {
|
||||
if (bound != null && afterAnchor.startOffset <= bound.startOffset) {
|
||||
afterAnchor = bound
|
||||
}
|
||||
} else if (bound == null && body.declarations.isNotEmpty()) {
|
||||
afterAnchor = body.lBrace!!
|
||||
} else if (bound != null && afterAnchor.startOffset > bound.startOffset) {
|
||||
afterAnchor = bound.prevSibling!!
|
||||
if (classOrObject is KtClass && classOrObject.isEnum()) {
|
||||
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
|
||||
val bound = (enumEntries.lastOrNull() ?: classOrObject.allChildren.firstOrNull { element ->
|
||||
element.node.elementType == KtTokens.SEMICOLON
|
||||
})
|
||||
if (it !is KtEnumEntry) {
|
||||
if (bound != null && afterAnchor.startOffset <= bound.startOffset) {
|
||||
afterAnchor = bound
|
||||
}
|
||||
} else if (bound == null && body.declarations.isNotEmpty()) {
|
||||
afterAnchor = body.lBrace!!
|
||||
} else if (bound != null && afterAnchor.startOffset > bound.startOffset) {
|
||||
afterAnchor = bound.prevSibling!!
|
||||
}
|
||||
}
|
||||
|
||||
it.removeModifier(KtTokens.EXTERNAL_KEYWORD)
|
||||
|
||||
+8
-7
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package org.jetbrains.kotlin.idea.core
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import org.jetbrains.kotlin.idea.base.codeInsight.ShortenReferencesFacility
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
@@ -21,18 +22,18 @@ fun <T : KtDeclaration> insertMembersAfterAndReformat(
|
||||
val insertedMembersElementPointers = insertMembersAfter(editor, classOrObject, members, anchor, getAnchor)
|
||||
val firstElement = insertedMembersElementPointers.firstOrNull() ?: return@runWriteAction emptyList()
|
||||
|
||||
fun insertedMembersElements() = insertedMembersElementPointers.mapNotNull { it.element }
|
||||
|
||||
// TODO make shorten references work in both K1 and K2
|
||||
if (!org.jetbrains.kotlin.idea.base.plugin.KotlinPluginModeProvider.Companion.isK2Mode()) {
|
||||
ShortenReferences.DEFAULT.process(insertedMembersElements())
|
||||
for (pointer in insertedMembersElementPointers) {
|
||||
val element = pointer.element
|
||||
if (element != null) {
|
||||
ShortenReferencesFacility.getInstance().shorten(element)
|
||||
}
|
||||
}
|
||||
if (editor != null) {
|
||||
firstElement.element?.let { moveCaretIntoGeneratedElement(editor, it) }
|
||||
}
|
||||
|
||||
insertedMembersElementPointers.onEach { it.element?.let { element -> codeStyleManager.reformat(element) } }
|
||||
insertedMembersElements()
|
||||
insertedMembersElementPointers.mapNotNull { it.element }
|
||||
}
|
||||
}
|
||||
|
||||
+24
-25
@@ -9,7 +9,6 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.isAncestor
|
||||
import org.jetbrains.kotlin.idea.base.psi.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.base.psi.replaced
|
||||
import org.jetbrains.kotlin.idea.core.insertMembersAfterAndReformat
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -22,10 +21,10 @@ object CreateFromUsageUtil {
|
||||
// TODO: Simplify and use formatter as much as possible
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <D : KtNamedDeclaration> placeDeclarationInContainer(
|
||||
declaration: D,
|
||||
container: PsiElement,
|
||||
anchor: PsiElement,
|
||||
fileToEdit: KtFile = container.containingFile as KtFile
|
||||
declaration: D,
|
||||
container: PsiElement,
|
||||
anchor: PsiElement,
|
||||
fileToEdit: KtFile = container.containingFile as KtFile
|
||||
): D {
|
||||
val psiFactory = KtPsiFactory(container.project)
|
||||
val newLine = psiFactory.createNewLine()
|
||||
@@ -47,8 +46,8 @@ object CreateFromUsageUtil {
|
||||
|
||||
val neighborType = neighbor?.node?.elementType
|
||||
val lineBreaksNeeded = when {
|
||||
neighborType == KtTokens.LBRACE || neighborType == KtTokens.RBRACE -> 1
|
||||
neighbor is KtDeclaration && (neighbor !is KtProperty || decl !is KtProperty) -> 2
|
||||
neighborType == KtTokens.LBRACE || neighborType == KtTokens.RBRACE -> 1
|
||||
neighbor is KtDeclaration && (neighbor !is KtProperty || decl !is KtProperty) -> 2
|
||||
else -> 1
|
||||
}
|
||||
|
||||
@@ -58,14 +57,14 @@ object CreateFromUsageUtil {
|
||||
val actualContainer = (container as? KtClassOrObject)?.getOrCreateBody() ?: container
|
||||
|
||||
fun addDeclarationToClassOrObject(
|
||||
classOrObject: KtClassOrObject,
|
||||
declaration: KtNamedDeclaration
|
||||
classOrObject: KtClassOrObject,
|
||||
declaration: KtNamedDeclaration
|
||||
): KtNamedDeclaration {
|
||||
val classBody = classOrObject.getOrCreateBody()
|
||||
return if (declaration is KtNamedFunction) {
|
||||
val neighbor = PsiTreeUtil.skipSiblingsBackward(
|
||||
classBody.rBrace ?: classBody.lastChild!!,
|
||||
PsiWhiteSpace::class.java
|
||||
classBody.rBrace ?: classBody.lastChild!!,
|
||||
PsiWhiteSpace::class.java
|
||||
)
|
||||
classBody.addAfter(declaration, neighbor) as KtNamedDeclaration
|
||||
} else classBody.addAfter(declaration, classBody.lBrace!!) as KtNamedDeclaration
|
||||
@@ -83,10 +82,10 @@ object CreateFromUsageUtil {
|
||||
|
||||
val declarationInPlace = when {
|
||||
declaration is KtPrimaryConstructor -> {
|
||||
(container as KtClass).createPrimaryConstructorIfAbsent().replaced(declaration)
|
||||
(container as KtClass).createPrimaryConstructorIfAbsent().replaced(declaration)
|
||||
}
|
||||
|
||||
declaration is KtProperty && container !is KtBlockExpression -> {
|
||||
declaration is KtProperty && container !is KtBlockExpression -> {
|
||||
val sibling = actualContainer.getChildOfType<KtProperty>() ?: when (actualContainer) {
|
||||
is KtClassBody -> actualContainer.declarations.firstOrNull() ?: actualContainer.rBrace
|
||||
is KtFile -> actualContainer.declarations.first()
|
||||
@@ -127,7 +126,7 @@ object CreateFromUsageUtil {
|
||||
sibling = container.body?.lBrace
|
||||
}
|
||||
|
||||
insertMembersAfterAndReformat(null, container, declaration, sibling)
|
||||
org.jetbrains.kotlin.idea.core.insertMembersAfterAndReformat(null, container, declaration, sibling)
|
||||
}
|
||||
else -> throw KotlinExceptionWithAttachments("Invalid containing element: ${container::class.java}")
|
||||
.withPsiAttachment("container", container)
|
||||
@@ -148,7 +147,7 @@ object CreateFromUsageUtil {
|
||||
}
|
||||
val semicolon = prevEnumEntry.allChildren.firstOrNull { it.node?.elementType == KtTokens.SEMICOLON }
|
||||
if (semicolon != null) {
|
||||
(semicolon.prevSibling as? PsiWhiteSpace)?.text?.let {
|
||||
(semicolon.prevSibling as? PsiWhiteSpace)?.text?.let {
|
||||
declarationInPlace.add(psiFactory.createWhiteSpace(it))
|
||||
}
|
||||
declarationInPlace.add(psiFactory.createSemicolon())
|
||||
@@ -183,11 +182,11 @@ object CreateFromUsageUtil {
|
||||
}
|
||||
|
||||
fun computeDefaultVisibilityAsString(
|
||||
containingElement: PsiElement,
|
||||
isAbstract: Boolean,
|
||||
isExtension: Boolean,
|
||||
isConstructor: Boolean,
|
||||
originalElement: PsiElement
|
||||
containingElement: PsiElement,
|
||||
isAbstract: Boolean,
|
||||
isExtension: Boolean,
|
||||
isConstructor: Boolean,
|
||||
originalElement: PsiElement
|
||||
): String {
|
||||
val modifier = if (isAbstract) null
|
||||
else if (containingElement is KtClassOrObject
|
||||
@@ -202,12 +201,12 @@ object CreateFromUsageUtil {
|
||||
}
|
||||
|
||||
private val modifierToKotlinToken: Map<JvmModifier, KtModifierKeywordToken> = mapOf(
|
||||
JvmModifier.PRIVATE to KtTokens.PRIVATE_KEYWORD,
|
||||
JvmModifier.PACKAGE_LOCAL to KtTokens.INTERNAL_KEYWORD,
|
||||
JvmModifier.PROTECTED to KtTokens.PROTECTED_KEYWORD,
|
||||
JvmModifier.PUBLIC to KtTokens.PUBLIC_KEYWORD
|
||||
JvmModifier.PRIVATE to KtTokens.PRIVATE_KEYWORD,
|
||||
JvmModifier.PACKAGE_LOCAL to KtTokens.INTERNAL_KEYWORD,
|
||||
JvmModifier.PROTECTED to KtTokens.PROTECTED_KEYWORD,
|
||||
JvmModifier.PUBLIC to KtTokens.PUBLIC_KEYWORD
|
||||
)
|
||||
fun modifierToString(modifier: JvmModifier?):String {
|
||||
return modifierToKotlinToken[modifier]?.let { if (it == KtTokens.PUBLIC_KEYWORD) "" else it.value } ?:""
|
||||
return modifierToKotlinToken[modifier]?.let { if (it == KtTokens.PUBLIC_KEYWORD) "" else it.value } ?: ""
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,6 @@
|
||||
<orderEntry type="module" module-name="kotlin.refactorings.common" />
|
||||
<orderEntry type="module" module-name="kotlin.base.analysis" />
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.utils" />
|
||||
<orderEntry type="module" module-name="kotlin.core" />
|
||||
<orderEntry type="library" name="kotlinc.high-level-api-fir" level="project" />
|
||||
<orderEntry type="module" module-name="kotlin.formatter.minimal" />
|
||||
</component>
|
||||
|
||||
+1
@@ -21,5 +21,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.editor" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
|
||||
<orderEntry type="module" module-name="intellij.java.psi" />
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.impl-base" />
|
||||
</component>
|
||||
</module>
|
||||
+1
@@ -38,5 +38,6 @@
|
||||
<orderEntry type="module" module-name="intellij.java.psi" />
|
||||
<orderEntry type="module" module-name="kotlin.base.analysis-api.utils" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.impl-base" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -56,5 +56,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ml.impl" />
|
||||
<orderEntry type="module" module-name="kotlin.base.plugin" />
|
||||
<orderEntry type="module" module-name="kotlin.highlighting.k1" />
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.impl-base" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -37,5 +37,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.editor" />
|
||||
<orderEntry type="module" module-name="intellij.java.impl" />
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.impl-base" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user