mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] k2: enable i18n batch mode
^KTIJ-29932 fixed GitOrigin-RevId: f7358d98e504b4137d34a31fc838ebf10b431ae9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
241d69d7dd
commit
7f21671ba2
+2
-2
@@ -186,7 +186,7 @@ class K1ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
return selector as KtNameReferenceExpression
|
||||
}
|
||||
|
||||
override fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean {
|
||||
return newExpression.getPossiblyQualifiedCallExpression()?.canMoveLambdaOutsideParentheses() == true
|
||||
override fun canMoveLambdaOutsideParentheses(callExpression: KtCallExpression?): Boolean {
|
||||
return callExpression?.canMoveLambdaOutsideParentheses() == true
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.plugin.references.SimpleNameReferenceExtension
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
|
||||
import org.jetbrains.kotlin.resolve.DataClassResolver
|
||||
import org.jetbrains.kotlin.resolve.references.ReferenceAccess
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
@@ -256,10 +257,10 @@ abstract class KtReferenceMutateServiceBase : KtReferenceMutateService {
|
||||
private fun convertOperatorToFunctionCall(opExpression: KtOperationExpression): Pair<KtExpression, KtSimpleNameExpression> =
|
||||
OperatorToFunctionConverter.convert(opExpression)
|
||||
|
||||
protected abstract fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean
|
||||
abstract fun canMoveLambdaOutsideParentheses(callExpression: KtCallExpression?): Boolean
|
||||
|
||||
protected fun replaceWithImplicitInvokeInvocation(newExpression: KtDotQualifiedExpression): KtExpression? {
|
||||
val canMoveLambda = canMoveLambdaOutsideParentheses(newExpression)
|
||||
val canMoveLambda = canMoveLambdaOutsideParentheses(newExpression.getPossiblyQualifiedCallExpression())
|
||||
return OperatorToFunctionConverter.replaceExplicitInvokeCallWithImplicit(newExpression)?.let { newQualifiedExpression ->
|
||||
newQualifiedExpression.getPossiblyQualifiedCallExpression()
|
||||
?.takeIf { canMoveLambda }
|
||||
|
||||
+2
-3
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementOrCallableRef
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isTopLevelKtOrJavaMember
|
||||
@@ -253,8 +252,8 @@ internal class K2ReferenceMutateService : KtReferenceMutateServiceBase() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun canMoveLambdaOutsideParentheses(newExpression: KtDotQualifiedExpression): Boolean {
|
||||
return newExpression.getPossiblyQualifiedCallExpression()?.canMoveLambdaOutsideParentheses() == true
|
||||
override fun canMoveLambdaOutsideParentheses(callExpression: KtCallExpression?): Boolean {
|
||||
return callExpression?.canMoveLambdaOutsideParentheses() == true
|
||||
}
|
||||
|
||||
}
|
||||
+4
-7
@@ -9,6 +9,7 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
@@ -31,9 +32,6 @@ abstract class KotlinUastBaseCodeGenerationPlugin : UastCodeGenerationPlugin {
|
||||
override val language: Language
|
||||
get() = KotlinLanguage.INSTANCE
|
||||
|
||||
override fun getElementFactory(project: Project): UastElementFactory =
|
||||
KotlinUastElementFactory(project)
|
||||
|
||||
override fun <T : UElement> replace(oldElement: UElement, newElement: T, elementType: Class<T>): T? {
|
||||
val oldPsi = oldElement.toSourcePsiFakeAware().singleOrNull() ?: return null
|
||||
val newPsi = newElement.sourcePsi?.let {
|
||||
@@ -144,7 +142,7 @@ abstract class KotlinUastBaseCodeGenerationPlugin : UastCodeGenerationPlugin {
|
||||
|
||||
private fun hasBraces(oldPsi: KtBlockExpression): Boolean = oldPsi.lBrace != null && oldPsi.rBrace != null
|
||||
|
||||
open class KotlinUastElementFactory(project: Project) : UastElementFactory {
|
||||
abstract class KotlinUastElementFactory(project: Project) : UastElementFactory {
|
||||
private val contextlessPsiFactory = KtPsiFactory(project)
|
||||
|
||||
private fun psiFactory(context: PsiElement?): KtPsiFactory {
|
||||
@@ -177,9 +175,8 @@ open class KotlinUastElementFactory(project: Project) : UastElementFactory {
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun moveLambdaOutsideParenthesis(methodCall: KtCallExpression) {
|
||||
TODO("Not implemented")
|
||||
}
|
||||
@OptIn(KtAllowAnalysisOnEdt::class)
|
||||
protected abstract fun moveLambdaOutsideParenthesis(methodCall: KtCallExpression)
|
||||
|
||||
override fun createQualifiedReference(qualifiedName: String, context: PsiElement?): UQualifiedReferenceExpression? {
|
||||
return psiFactory(context).createExpression(qualifiedName).let {
|
||||
|
||||
+24
@@ -676,6 +676,30 @@ abstract class AbstractKotlinUastGenerationTest : KotlinLightCodeInsightFixtureT
|
||||
""".trimIndent(), psiFile.text)
|
||||
}
|
||||
|
||||
fun `test moving lambda from parenthesis`() {
|
||||
myFixture.configureByText("myFile.kt", """
|
||||
fun a(p: (Int) -> Unit) {}
|
||||
""".trimIndent())
|
||||
|
||||
|
||||
val lambdaExpression = uastElementFactory.createLambdaExpression(
|
||||
emptyList(),
|
||||
uastElementFactory.createNullLiteral(null),
|
||||
null
|
||||
) ?: kfail("Cannot create lambda")
|
||||
|
||||
val callExpression = uastElementFactory.createCallExpression(
|
||||
null,
|
||||
"a",
|
||||
listOf(lambdaExpression),
|
||||
null,
|
||||
UastCallKind.METHOD_CALL,
|
||||
myFixture.file
|
||||
) ?: kfail("Cannot create method call")
|
||||
|
||||
TestCase.assertEquals("""a{ null }""", callExpression.sourcePsi?.text)
|
||||
}
|
||||
|
||||
protected fun createTypeFromText(s: String, newClass: PsiElement?): PsiType {
|
||||
return JavaPsiFacade.getElementFactory(myFixture.project).createTypeFromText(s, newClass)
|
||||
}
|
||||
|
||||
+1
-13
@@ -1,17 +1,13 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiType
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.uast.generate.UastElementFactory
|
||||
import org.jetbrains.uast.kotlin.generate.KotlinUastBaseCodeGenerationPlugin
|
||||
import org.jetbrains.uast.kotlin.generate.KotlinUastElementFactory
|
||||
import org.jetbrains.uast.kotlin.internal.analyzeForUast
|
||||
|
||||
open class FirKotlinUastCodeGenerationPlugin : KotlinUastBaseCodeGenerationPlugin() {
|
||||
abstract class FirKotlinUastCodeGenerationPlugin : KotlinUastBaseCodeGenerationPlugin() {
|
||||
@OptIn(KtAllowAnalysisOnEdt::class)
|
||||
override fun shortenReference(sourcePsi: KtElement): PsiElement {
|
||||
val ktFile = sourcePsi.containingKtFile
|
||||
@@ -22,12 +18,4 @@ open class FirKotlinUastCodeGenerationPlugin : KotlinUastBaseCodeGenerationPlugi
|
||||
//todo apply shortening
|
||||
return sourcePsi
|
||||
}
|
||||
|
||||
override fun getElementFactory(project: Project): UastElementFactory {
|
||||
return object : KotlinUastElementFactory(project) {
|
||||
override fun PsiType?.suggestName(context: PsiElement?): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,6 @@
|
||||
<orderEntry type="module" module-name="kotlin.gradle.gradle" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="kotlin.test-framework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="kotlin.base.util" />
|
||||
<orderEntry type="module" module-name="kotlin.refactorings.common" />
|
||||
</component>
|
||||
</module>
|
||||
+26
@@ -1,12 +1,38 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.uast.kotlin
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.api.KtAllowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.idea.refactoring.moveFunctionLiteralOutsideParentheses
|
||||
import org.jetbrains.kotlin.idea.refactoring.rename.KtReferenceMutateServiceBase
|
||||
import org.jetbrains.kotlin.idea.references.KtReferenceMutateService
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.uast.UElement
|
||||
import org.jetbrains.uast.generate.UastCommentSaver
|
||||
import org.jetbrains.uast.generate.UastElementFactory
|
||||
import org.jetbrains.uast.kotlin.generate.KotlinUastElementFactory
|
||||
import org.jetbrains.uast.kotlin.generate.createUastCommentSaver
|
||||
|
||||
|
||||
class IdeaFirKotlinUastCodeGenerationPlugin : FirKotlinUastCodeGenerationPlugin(){
|
||||
@OptIn(KtAllowAnalysisOnEdt::class)
|
||||
override fun getElementFactory(project: Project): UastElementFactory {
|
||||
return object : KotlinUastElementFactory(project) {
|
||||
override fun moveLambdaOutsideParenthesis(methodCall: KtCallExpression) {
|
||||
val mutateService =
|
||||
ApplicationManager.getApplication().getService(KtReferenceMutateService::class.java) as KtReferenceMutateServiceBase
|
||||
|
||||
allowAnalysisOnEdt {
|
||||
if (mutateService.canMoveLambdaOutsideParentheses(methodCall)) {
|
||||
methodCall.moveFunctionLiteralOutsideParentheses()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun grabComments(firstResultUElement: UElement, lastResultUElement: UElement): UastCommentSaver? {
|
||||
return createUastCommentSaver(firstResultUElement, lastResultUElement)
|
||||
}
|
||||
|
||||
-24
@@ -568,28 +568,4 @@ class KotlinUastGenerationTest : AbstractKotlinUastGenerationTest() {
|
||||
USimpleNameReferenceExpression (identifier = a)
|
||||
""".trimIndent(), lambda.putIntoVarInitializer().asRecursiveLogString().trim())
|
||||
}
|
||||
|
||||
fun `test moving lambda from parenthesis`() {
|
||||
myFixture.configureByText("myFile.kt", """
|
||||
fun a(p: (Int) -> Unit) {}
|
||||
""".trimIndent())
|
||||
|
||||
|
||||
val lambdaExpression = uastElementFactory.createLambdaExpression(
|
||||
emptyList(),
|
||||
uastElementFactory.createNullLiteral(null),
|
||||
null
|
||||
) ?: kfail("Cannot create lambda")
|
||||
|
||||
val callExpression = uastElementFactory.createCallExpression(
|
||||
null,
|
||||
"a",
|
||||
listOf(lambdaExpression),
|
||||
null,
|
||||
UastCallKind.METHOD_CALL,
|
||||
myFixture.file
|
||||
) ?: kfail("Cannot create method call")
|
||||
|
||||
TestCase.assertEquals("""a{ null }""", callExpression.sourcePsi?.text)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user