mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
[kotlin] k2 change signature: hide ERROR from empty type presentation
^KTIJ-29074 fixed GitOrigin-RevId: a0ccdee851f445cddfad57e9d27180d38dc4e6c7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
276414e3e4
commit
536cb20e0d
@@ -53,5 +53,6 @@
|
||||
<orderEntry type="module" module-name="kotlin.code-insight.utils" />
|
||||
<orderEntry type="module" module-name="kotlin.fir.frontend-independent" />
|
||||
<orderEntry type="module" module-name="kotlin.searching.base" />
|
||||
<orderEntry type="library" name="kotlinc.high-level-api-impl-base" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -53,7 +53,7 @@ class KotlinMethodDescriptor(private val callable: KtNamedDeclaration) :
|
||||
}.firstOrNull() ?: "receiver"
|
||||
|
||||
KotlinParameterInfo(
|
||||
0, KotlinTypeInfo(ktType.render(position = Variance.INVARIANT), callable), receiverName,
|
||||
0, KotlinTypeInfo(ktType, callable), receiverName,
|
||||
KotlinValVar.None, null, false, null, callable
|
||||
)
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class KotlinMethodDescriptor(private val callable: KtNamedDeclaration) :
|
||||
(callable as? KtCallableDeclaration)
|
||||
?.valueParameters?.forEach { p ->
|
||||
val parameterInfo = KotlinParameterInfo(
|
||||
params.size, KotlinTypeInfo(p.getReturnKtType().render(position = Variance.INVARIANT), callable),
|
||||
params.size, KotlinTypeInfo(p.getReturnKtType(), callable),
|
||||
p.name ?: "",
|
||||
p.valOrVarKeyword.toValVar(),
|
||||
p.defaultValue, p.defaultValue != null, p.defaultValue, callable
|
||||
|
||||
@@ -12,15 +12,33 @@ import org.jetbrains.kotlin.analysis.api.components.buildSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.components.buildTypeParameterType
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisFromWriteAction
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.allowAnalysisOnEdt
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.KtTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.impl.KtTypeRendererForSource
|
||||
import org.jetbrains.kotlin.analysis.api.renderer.types.renderers.KtTypeErrorTypeRenderer
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtDefinitelyNotNullType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtFunctionalType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtSubstitutor
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.analysis.api.types.KtTypeErrorType
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
data class KotlinTypeInfo(var text: String?, val context: KtElement)
|
||||
data class KotlinTypeInfo(var text: String?, val context: KtElement) {
|
||||
constructor(ktType: KtType, context: KtElement): this(analyze(context) { ktType.render(errorIgnoringRenderer, Variance.INVARIANT) }, context)
|
||||
}
|
||||
|
||||
private val errorIgnoringRenderer: KtTypeRenderer = KtTypeRendererForSource.WITH_QUALIFIED_NAMES.with {
|
||||
typeErrorTypeRenderer = object : KtTypeErrorTypeRenderer {
|
||||
context(KtAnalysisSession, KtTypeRenderer)
|
||||
override fun renderType(type: KtTypeErrorType, printer: PrettyPrinter) {
|
||||
type.tryRenderAsNonErrorType()?.let {
|
||||
printer.append(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(KtAllowAnalysisFromWriteAction::class, KtAllowAnalysisOnEdt::class)
|
||||
internal fun KtPsiFactory.createType(
|
||||
|
||||
@@ -166,7 +166,7 @@ object ChangeSignatureFixFactory {
|
||||
val argumentExpression = currentArgument.getArgumentExpression()
|
||||
val ktType = getKtType(argumentExpression) ?: return null
|
||||
return KotlinParameterInfo(
|
||||
originalType = KotlinTypeInfo(ktType.render(position = Variance.IN_VARIANCE), callElement),
|
||||
originalType = KotlinTypeInfo(ktType, callElement),
|
||||
name = getNewArgumentName(currentArgument, validator),
|
||||
originalIndex = -1,
|
||||
valOrVar = defaultValOrVar(ktCallableDeclaration),
|
||||
|
||||
@@ -85,7 +85,7 @@ internal class KotlinChangeSignatureDialog(
|
||||
val psiFactory = KtPsiFactory(myDefaultValueContext.project)
|
||||
|
||||
val contentElement = psiFactory.createTypeCodeFragment(resultParameterInfo.typeText, typeContext).getContentElement()
|
||||
val presentableText = if (contentElement != null) {
|
||||
val presentableText = if (resultParameterInfo.typeText.isNotEmpty() && contentElement != null) {
|
||||
analyzeInModalWindow(contentElement, KotlinBundle.message("fix.change.signature.prepare")) {
|
||||
contentElement.getKtType().getPresentableText()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user