[uast] UastElementFactory.createReturnExpression: fix incorrect name

GitOrigin-RevId: 0a855337810fc979607b26b54acd1c89342757a0
This commit is contained in:
Tagir Valeev
2022-12-08 16:55:31 +01:00
committed by intellij-monorepo-bot
parent d242e3fdbc
commit 5c3372c82d
5 changed files with 13 additions and 13 deletions

View File

@@ -343,10 +343,10 @@ class KotlinUastElementFactory(project: Project) : UastElementFactory {
@Deprecated("use version with context parameter")
fun createReturnExpresion(expression: UExpression?, inLambda: Boolean): UReturnExpression {
logger<KotlinUastElementFactory>().error("Please switch caller to the version with a context parameter")
return createReturnExpresion(expression, inLambda, null)
return createReturnExpression(expression, inLambda, null)
}
override fun createReturnExpresion(expression: UExpression?, inLambda: Boolean, context: PsiElement?): UReturnExpression {
override fun createReturnExpression(expression: UExpression?, inLambda: Boolean, context: PsiElement?): UReturnExpression {
val label = if (inLambda && context != null) getParentLambdaLabelName(context)?.let { "@$it" } ?: "" else ""
val returnExpression = psiFactory(context).createExpression("return$label 1") as KtReturnExpression
val sourcePsi = expression?.sourcePsi

View File

@@ -120,7 +120,7 @@ class KotlinUastGenerationTest : KotlinLightCodeInsightFixtureTestCase() {
val expression = psiFactory.createExpression("a + b").toUElementOfType<UExpression>()
?: kfail("Cannot find plugin")
val returnExpression = uastElementFactory.createReturnExpresion(expression, false, dummyContextFile())
val returnExpression = uastElementFactory.createReturnExpression(expression, false, dummyContextFile())
TestCase.assertEquals("a + b", returnExpression.returnExpression?.asRenderString())
TestCase.assertEquals("return a + b", returnExpression.sourcePsi?.text)
}
@@ -682,7 +682,7 @@ class KotlinUastGenerationTest : KotlinLightCodeInsightFixtureTestCase() {
UastBinaryOperator.GREATER,
uLambdaExpression.sourcePsi
)!!,
createReturnExpresion(
createReturnExpression(
createStringLiteralExpression("exit", uLambdaExpression.sourcePsi), true,
uLambdaExpression.sourcePsi
),
@@ -776,7 +776,7 @@ class KotlinUastGenerationTest : KotlinLightCodeInsightFixtureTestCase() {
uLambdaExpression.sourcePsi
)!!,
oldBlockExpression,
createReturnExpresion(
createReturnExpression(
createStringLiteralExpression("exit", uLambdaExpression.sourcePsi), true,
uLambdaExpression.sourcePsi
),
@@ -893,7 +893,7 @@ class KotlinUastGenerationTest : KotlinLightCodeInsightFixtureTestCase() {
val localVariable = uastElementFactory.createLocalVariable("a", null, uastElementFactory.createNullLiteral(context), true, context)
val declarationExpression =
uastElementFactory.createDeclarationExpression(listOf(localVariable), context)
val returnExpression = uastElementFactory.createReturnExpresion(
val returnExpression = uastElementFactory.createReturnExpression(
uastElementFactory.createSimpleReference(localVariable, context), false, context
)
val block = uastElementFactory.createBlockExpression(listOf(declarationExpression, returnExpression), context)

View File

@@ -133,9 +133,9 @@ interface UastElementFactory {
fun createParenthesizedExpression(expression: UExpression,
context: PsiElement?): UParenthesizedExpression?
fun createReturnExpresion(expression: UExpression?,
inLambda: Boolean = false,
context: PsiElement?): UReturnExpression?
fun createReturnExpression(expression: UExpression?,
inLambda: Boolean = false,
context: PsiElement?): UReturnExpression?
fun createLocalVariable(suggestedName: String?,
type: PsiType?,

View File

@@ -327,9 +327,9 @@ class JavaUastElementFactory(private val project: Project) : UastElementFactory
return JavaUDeclarationsExpression(null, declarations)
}
override fun createReturnExpresion(expression: UExpression?,
inLambda: Boolean,
context: PsiElement?): UReturnExpression? {
override fun createReturnExpression(expression: UExpression?,
inLambda: Boolean,
context: PsiElement?): UReturnExpression? {
val returnStatement = psiFactory.createStatementFromText("return ;", null) as? PsiReturnStatement ?: return null
expression?.sourcePsi?.node?.let { (returnStatement as CompositeElement).addChild(it, returnStatement.lastChild.node) }

View File

@@ -88,7 +88,7 @@ class JavaUastGenerationTest : AbstractJavaUastLightTest() {
val expression = psiFactory.createExpressionFromText("a + b", null).toUElementOfType<UExpression>()
?: fail("Cannot find plugin")
val returnExpression = uastElementFactory.createReturnExpresion(expression, false, null) ?: fail("cannot create return expression")
val returnExpression = uastElementFactory.createReturnExpression(expression, false, null) ?: fail("cannot create return expression")
TestCase.assertEquals("return a + b;", returnExpression.sourcePsi?.text)
}