mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] provide renderer aware of real java names in override/implement dialogs
^KTIJ-37396 fixed (cherry picked from commit d0bf23dc1dfeaf1716433e495b1d6899bdc30858) IJ-CR-192831 GitOrigin-RevId: d3f06e96a0d00732bdecc9ef7bbed3af78471fea
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bd98ab211c
commit
190fb56dde
@@ -4,9 +4,13 @@ package org.jetbrains.kotlin.idea.util
|
||||
import com.intellij.psi.impl.compiled.ClsParameterImpl
|
||||
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
|
||||
import org.jetbrains.kotlin.analysis.api.KaSession
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.KaDeclarationRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.declarations.renderers.KaDeclarationNameRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.signatures.KaVariableSignature
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaSymbolModality
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KaValueParameterSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaNamedSymbol
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
|
||||
@@ -47,6 +51,29 @@ val KaValueParameterSymbol.realName: Name?
|
||||
return realJavaName
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a renderer that uses names from attached sources for value parameters based on cls java parameter names and delegates to the initial renderer otherwise
|
||||
*
|
||||
* @see KaVariableSignature.realName
|
||||
* @see KaValueParameterSymbol.hasSynthesizedName
|
||||
*/
|
||||
@OptIn(KaExperimentalApi::class)
|
||||
fun createRealNameRenderer(renderer: KaDeclarationNameRenderer): KaDeclarationNameRenderer = object : KaDeclarationNameRenderer {
|
||||
override fun renderName(
|
||||
analysisSession: KaSession,
|
||||
name: Name,
|
||||
symbol: KaNamedSymbol?,
|
||||
declarationRenderer: KaDeclarationRenderer,
|
||||
printer: PrettyPrinter
|
||||
) {
|
||||
if (symbol is KaValueParameterSymbol && symbol.hasSynthesizedName) {
|
||||
printer.append((with(analysisSession) { symbol.realName } ?: name).asString())
|
||||
} else {
|
||||
renderer.renderName(analysisSession, name, symbol, declarationRenderer, printer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A real name for the parameter represented by the given signature.
|
||||
*
|
||||
|
||||
@@ -44,6 +44,7 @@ jvm_library(
|
||||
"//plugins/kotlin/code-insight/impl-base:kotlin-codeInsight-shared",
|
||||
"//plugins/kotlin/base/analysis",
|
||||
"@lib//:kotlinc-analysis-api-impl-base",
|
||||
"//plugins/kotlin/base/code-insight",
|
||||
]
|
||||
)
|
||||
### auto-generated section `build intellij.kotlin.codeInsight.overrideImplement` end
|
||||
+1
@@ -47,5 +47,6 @@
|
||||
<orderEntry type="module" module-name="intellij.kotlin.codeInsight.shared" />
|
||||
<orderEntry type="module" module-name="intellij.kotlin.base.analysis" />
|
||||
<orderEntry type="library" name="kotlinc.analysis-api-impl-base" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.kotlin.base.codeInsight" />
|
||||
</component>
|
||||
</module>
|
||||
+4
@@ -66,6 +66,7 @@ import org.jetbrains.kotlin.idea.core.TemplateKind
|
||||
import org.jetbrains.kotlin.idea.core.getFunctionBodyTextFromTemplate
|
||||
import org.jetbrains.kotlin.idea.j2k.IdeaDocCommentConverter
|
||||
import org.jetbrains.kotlin.idea.kdoc.KDocElementFactory
|
||||
import org.jetbrains.kotlin.idea.util.createRealNameRenderer
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
@@ -325,6 +326,9 @@ private fun createRenderer(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nameRenderer = createRealNameRenderer(nameRenderer)
|
||||
|
||||
if (mode == MemberGenerateMode.OVERRIDE) {
|
||||
annotationRenderer = annotationRenderer.with {
|
||||
annotationFilter = KaRendererAnnotationsFilter { annotation, _ -> keepAnnotation(annotation, containingKtFile) }
|
||||
|
||||
+3
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.base.analysis.api.utils.invokeShortening
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.core.insertMembersAfter
|
||||
import org.jetbrains.kotlin.idea.core.moveCaretIntoGeneratedElement
|
||||
import org.jetbrains.kotlin.idea.util.createRealNameRenderer
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClassBody
|
||||
@@ -401,6 +402,8 @@ abstract class KtGenerateMembersHandler(
|
||||
}
|
||||
|
||||
propertyAccessorsRenderer = KaPropertyAccessorsRenderer.NONE
|
||||
|
||||
nameRenderer = createRealNameRenderer(nameRenderer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
public class L : MyList() {
|
||||
<caret>
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// FIR_IDENTICAL
|
||||
public class L : MyList() {
|
||||
override fun add(index: Int, element: Any?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public abstract class MyList {
|
||||
public abstract void add(int index, Object element);
|
||||
}
|
||||
+5
-1
@@ -16,7 +16,7 @@ abstract class OverrideImplementWithLibTest<T : ClassMember> : AbstractOverrideI
|
||||
val mockSourcesBase = IDEA_TEST_DATA_DIR.resolve("codeInsight/overrideImplement/withLib")
|
||||
val mockSource = mockSourcesBase.resolve(getTestName(true) + "Src")
|
||||
|
||||
mockLibraryFacility = MockLibraryFacility(mockSource, attachSources = false)
|
||||
mockLibraryFacility = MockLibraryFacility(mockSource, attachSources = name.contains("Cls"))
|
||||
mockLibraryFacility.setUp(module)
|
||||
}
|
||||
|
||||
@@ -34,4 +34,8 @@ abstract class OverrideImplementWithLibTest<T : ClassMember> : AbstractOverrideI
|
||||
fun testGenericSubstituted() {
|
||||
doOverrideFileTest()
|
||||
}
|
||||
|
||||
fun testJavaClsParameterNames() {
|
||||
doOverrideFileTest()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user