mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] SpecifyOverrideExplicitlyFix: fix false negative with object declaration
^KTIJ-26891 GitOrigin-RevId: 8691331d6b01d4b66fb337631e997995dbaf200b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dbcbef97aa
commit
208c3e8d2b
+10
-5
@@ -4,8 +4,7 @@ package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import org.jetbrains.kotlin.analysis.api.calls.successfulVariableAccessCall
|
||||
import org.jetbrains.kotlin.analysis.api.calls.symbol
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KtFirDiagnostic
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KtCallableReturnTypeFilter
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.impl.KtDeclarationRendererForSource
|
||||
@@ -13,6 +12,7 @@ import org.jetbrains.kotlin.analysis.api.renderer.declarations.modifiers.rendere
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.callables.KtValueParameterSymbolRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtConstructorSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
|
||||
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
|
||||
@@ -41,9 +41,7 @@ internal object SpecifyOverrideExplicitlyFixFactory {
|
||||
|
||||
for (specifier in ktClass.superTypeListEntries) {
|
||||
if (specifier is KtDelegatedSuperTypeEntry) {
|
||||
val delegateExpression = specifier.delegateExpression as? KtNameReferenceExpression
|
||||
val resolvedCall = delegateExpression?.resolveCall()?.successfulVariableAccessCall()
|
||||
val delegateTargetSymbol = resolvedCall?.partiallyAppliedSymbol?.symbol ?: return@ModCommandBased emptyList()
|
||||
val delegateTargetSymbol = specifier.getSymbol() ?: return@ModCommandBased emptyList()
|
||||
|
||||
if (delegateTargetSymbol is KtValueParameterSymbol &&
|
||||
delegateTargetSymbol.getContainingSymbol().let {
|
||||
@@ -85,6 +83,13 @@ internal object SpecifyOverrideExplicitlyFixFactory {
|
||||
listOf(SpecifyOverrideExplicitlyFix(ktClass, elementContext))
|
||||
}
|
||||
|
||||
context(KtAnalysisSession)
|
||||
private fun KtDelegatedSuperTypeEntry.getSymbol(): KtNamedSymbol? {
|
||||
val nameReferenceExpression = delegateExpression as? KtNameReferenceExpression ?: return null
|
||||
val declaration = nameReferenceExpression.reference?.resolve() as? KtDeclaration ?: return null
|
||||
return declaration.getSymbol() as? KtNamedSymbol
|
||||
}
|
||||
|
||||
private val renderer = KtDeclarationRendererForSource.WITH_SHORT_NAMES.with {
|
||||
returnTypeFilter = KtCallableReturnTypeFilter.ALWAYS
|
||||
valueParameterRenderer = KtValueParameterSymbolRenderer.TYPE_ONLY
|
||||
|
||||
+5
@@ -5374,6 +5374,11 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
runTest("../../../idea/tests/testData/quickfix/specifyOverrideExplicitly/notPossible.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectDeclaration.kt")
|
||||
public void testObjectDeclaration() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/specifyOverrideExplicitly/objectDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("outer.kt")
|
||||
public void testOuter() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/specifyOverrideExplicitly/outer.kt");
|
||||
|
||||
+5
@@ -14145,6 +14145,11 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest {
|
||||
runTest("testData/quickfix/specifyOverrideExplicitly/notPossible.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectDeclaration.kt")
|
||||
public void testObjectDeclaration() throws Exception {
|
||||
runTest("testData/quickfix/specifyOverrideExplicitly/objectDeclaration.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("outer.kt")
|
||||
public void testOuter() throws Exception {
|
||||
runTest("testData/quickfix/specifyOverrideExplicitly/outer.kt");
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Specify override for 'foo(): Unit' explicitly" "true"
|
||||
interface A {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
open class B : A {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
object Obj : A {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
class<caret> Derived : B(), A by Obj
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SpecifyOverrideExplicitlyFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SpecifyOverrideExplicitlyFixFactory$SpecifyOverrideExplicitlyFix
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Specify override for 'foo(): Unit' explicitly" "true"
|
||||
interface A {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
open class B : A {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
object Obj : A {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
class<caret> Derived : B(), A by Obj {
|
||||
override fun foo() {
|
||||
Obj.foo()
|
||||
}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.SpecifyOverrideExplicitlyFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SpecifyOverrideExplicitlyFixFactory$SpecifyOverrideExplicitlyFix
|
||||
Reference in New Issue
Block a user