diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt index 337ad188be9..a0c75027069 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinInlayParameterHintsProvider.kt @@ -24,6 +24,7 @@ import com.intellij.lang.Language import com.intellij.lang.java.JavaLanguage import com.intellij.psi.PsiElement import com.intellij.psi.codeStyle.CodeStyleSettingsManager +import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze @@ -40,12 +41,9 @@ import org.jetbrains.kotlin.renderer.RenderingFormat import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull +import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -/** - * @author Yuli Fiterman - */ - //hack to separate type presentation from param info presentation private const val TYPE_INFO_PREFIX = "@TYPE@" private val typeRenderer = DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions { @@ -140,7 +138,7 @@ private enum class HintType(desc: String, enabled: Boolean) { } private fun KtExpression.isUnclearExpression() = when(this) { - is KtConstantExpression, is KtThisExpression, is KtBinaryExpression -> true + is KtConstantExpression, is KtThisExpression, is KtBinaryExpression, is KtStringTemplateExpression -> true is KtPrefixExpression -> baseExpression is KtConstantExpression && (operationToken == KtTokens.PLUS || operationToken == KtTokens.MINUS) else -> false } @@ -214,7 +212,10 @@ class KotlinInlayParameterHintsProvider : InlayParameterHintsProvider { val resolvedCall = elem.getResolvedCall(ctx) val resolvedCallee = resolvedCall?.candidateDescriptor if (resolvedCallee is FunctionDescriptor) { - val fqName = resolvedCallee.fqNameOrNull()?.asString() ?: return null + val fqName = if (resolvedCallee is ConstructorDescriptor) + resolvedCallee.containingDeclaration.fqNameSafe.asString() + else + (resolvedCallee.fqNameOrNull()?.asString() ?: return null) val paramNames = resolvedCall.valueArguments .mapNotNull { (valueParameterDescriptor, resolvedValueArgument) -> if (resolvedValueArgument !is DefaultValueArgument) valueParameterDescriptor.name else null diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayParameterHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayParameterHintsTest.kt new file mode 100644 index 00000000000..c577ccbf7a4 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayParameterHintsTest.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.parameterInfo + +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor + +class InlayParameterHintsTest : KotlinLightCodeInsightFixtureTestCase() { + override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE + + fun check(text: String) { + myFixture.configureByText("A.kt", text) + myFixture.testInlays() + } + + fun `test insert literal arguments`() { + check(""" + fun test(file: File) { + val testNow = System.currentTimeMillis() > 34000 + val times = 1 + val pi = 4.0f + val title = "Testing..." + val ch = 'q'; + + configure(true, 555, 3.141f, "Huge Title", 'c', null) + configure(testNow, shouldIgnoreRoots(), fourteen, pi, title, c, file) + } + + fun configure(testNow: Boolean, times: Int, pii: Float, title: String, terminate: Char, file: File) { + System.out.println() + System.out.println() + }""") + } + + fun `test do not show for Exceptions`() { + check(""" + fun test() { + val t = IllegalStateException("crime"); + }""") + } +}