mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] KTIJ-36447 Fix handling nested binary expression
GitOrigin-RevId: bdf722a2bd6f916ba7e6b80004aac0890dc9397c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
302b47d737
commit
bc27a192f2
+7
-8
@@ -4,12 +4,12 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.modcommand.PsiUpdateModCommandAction
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
|
||||
internal object NoReturnValueFactory {
|
||||
val noReturnValue =
|
||||
@@ -65,8 +65,9 @@ internal object NoReturnValueFactory {
|
||||
factory.createExpression("{$baseExpressionText}")
|
||||
}
|
||||
else -> {
|
||||
LOG.error("Unknown parent class: ${parent?.javaClass?.name}. The result expression could be incorrect.")
|
||||
factory.createExpression("{$baseExpressionText}")
|
||||
throw KotlinExceptionWithAttachments("Unknown parent class: ${parent?.javaClass?.name}.")
|
||||
.withPsiAttachment("element.kt", element)
|
||||
.withPsiAttachment("file.kt", element.containingFile)
|
||||
}
|
||||
}
|
||||
return newExpression
|
||||
@@ -74,14 +75,12 @@ internal object NoReturnValueFactory {
|
||||
|
||||
private fun findParentOrOuterMostParentheses(element: KtElement): PsiElement? {
|
||||
var parent: PsiElement? = element.parent
|
||||
while (parent is KtParenthesizedExpression) {
|
||||
while (parent is KtParenthesizedExpression || parent is KtBinaryExpression) {
|
||||
val parentOfParent = parent.parent
|
||||
if (parentOfParent !is KtParenthesizedExpression) break
|
||||
if (parentOfParent !is KtParenthesizedExpression && parentOfParent !is KtBinaryExpression) break
|
||||
parent = parentOfParent
|
||||
}
|
||||
return parent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val LOG = Logger.getInstance(NoReturnValueFactory::class.java)
|
||||
}
|
||||
+5
@@ -8034,6 +8034,11 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
runTest("../../../idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/ignoredWithAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedBinaryExpressions.kt")
|
||||
public void testNestedBinaryExpressions() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/nestedBinaryExpressions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parentheses.kt")
|
||||
public void testParentheses() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/explicitlyIgnoreReturnValue/parentheses.kt");
|
||||
|
||||
+5
@@ -9787,6 +9787,11 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
|
||||
runTest("testData/quickfix/explicitlyIgnoreReturnValue/ignoredWithAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedBinaryExpressions.kt")
|
||||
public void testNestedBinaryExpressions() throws Exception {
|
||||
runTest("testData/quickfix/explicitlyIgnoreReturnValue/nestedBinaryExpressions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parentheses.kt")
|
||||
public void testParentheses() throws Exception {
|
||||
runTest("testData/quickfix/explicitlyIgnoreReturnValue/parentheses.kt");
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Explicitly ignore return value" "true"
|
||||
// LANGUAGE_VERSION: 2.2
|
||||
// COMPILER_ARGUMENTS: -Xreturn-value-checker=full
|
||||
fun someFunction() {
|
||||
someFunctionValue() ?: (someFunctionValue() ?: <caret>someFunctionValue() ?: error("failure"))
|
||||
}
|
||||
fun someFunctionValue(): Int? = 1
|
||||
|
||||
// IGNORE_K1
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Explicitly ignore return value" "true"
|
||||
// LANGUAGE_VERSION: 2.2
|
||||
// COMPILER_ARGUMENTS: -Xreturn-value-checker=full
|
||||
fun someFunction() {
|
||||
val _ = someFunctionValue() ?: (someFunctionValue() ?: <caret>someFunctionValue() ?: error("failure"))
|
||||
}
|
||||
fun someFunctionValue(): Int? = 1
|
||||
|
||||
// IGNORE_K1
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.NoReturnValueFactory$UnderscoreValueFix
|
||||
Reference in New Issue
Block a user