From bcaa635a4ede3ec8dfc834384489c114e8a5960d Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 19 Jun 2020 01:27:53 +0300 Subject: [PATCH] Fix parameter info presentation with regard to DeprecatedSinceKotlin --- .../jetbrains/kotlin/builtins/KotlinBuiltIns.java | 2 ++ .../KotlinFunctionParameterInfoHandler.kt | 12 ++++++++---- .../functionCall/deprecatedSinceKotlinApplicable.kt | 11 +++++++++++ .../deprecatedSinceKotlinNotApplicable.kt | 11 +++++++++++ .../parameterInfo/ParameterInfoTestGenerated.java | 10 ++++++++++ 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinApplicable.kt create mode 100644 idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinNotApplicable.kt diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index fcebea1394f..6c23b406ffc 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -1117,6 +1117,8 @@ public abstract class KotlinBuiltIns { return classFqNameEquals(descriptor, FQ_NAMES.cloneable); } + // This function only checks presence of Deprecated annotation at declaration-site, it doesn't take into account @DeprecatedSinceKotlin + // To check that a referenced descriptor is actually deprecated at call-site, use DeprecationResolver public static boolean isDeprecated(@NotNull DeclarationDescriptor declarationDescriptor) { if (declarationDescriptor.getOriginal().getAnnotations().hasAnnotation(FQ_NAMES.deprecated)) return true; diff --git a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt index afed54f747b..d9a93ca3a5f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/parameterInfo/KotlinFunctionParameterInfoHandler.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.core.OptionalParametersHelper import org.jetbrains.kotlin.idea.core.resolveCandidates import org.jetbrains.kotlin.idea.resolve.ResolutionFacade +import org.jetbrains.kotlin.idea.resolve.frontendService import org.jetbrains.kotlin.idea.util.ShadowedDeclarationsFilter import org.jetbrains.kotlin.lexer.KtSingleValueToken import org.jetbrains.kotlin.lexer.KtTokens @@ -51,6 +52,7 @@ import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall +import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.types.KotlinType @@ -278,9 +280,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase? = null, var isResolvedToDescriptor: Boolean = false, - var isGreyArgumentIndex: Int = -1 + var isGreyArgumentIndex: Int = -1, + var isDeprecatedAtCallSite: Boolean = false ) private fun resolveCallInfo( @@ -417,6 +418,8 @@ abstract class KotlinParameterInfoWithCallHandlerBase().getDeprecations(resultingDescriptor).isNotEmpty() + with(info) { this.call = call this.resolvedCall = resolvedCall @@ -425,6 +428,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase1) +} +/* +Text: (x: Int), Disabled: false, Strikeout: true, Green: true +*/ \ No newline at end of file diff --git a/idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinNotApplicable.kt b/idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinNotApplicable.kt new file mode 100644 index 00000000000..4b10ec1c81e --- /dev/null +++ b/idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinNotApplicable.kt @@ -0,0 +1,11 @@ +@Suppress("DEPRECATED_SINCE_KOTLIN_OUTSIDE_KOTLIN_SUBPACKAGE") +@Deprecated("") +@DeprecatedSinceKotlin(warningSince = "1.9") +fun f(x: Int) {} + +fun d(x: Int) { + f(1) +} +/* +Text: (x: Int), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java index b1ee7d23ac3..be267a7693b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java @@ -121,6 +121,16 @@ public class ParameterInfoTestGenerated extends AbstractParameterInfoTest { runTest("idea/testData/parameterInfo/functionCall/Deprecated.kt"); } + @TestMetadata("deprecatedSinceKotlinApplicable.kt") + public void testDeprecatedSinceKotlinApplicable() throws Exception { + runTest("idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinApplicable.kt"); + } + + @TestMetadata("deprecatedSinceKotlinNotApplicable.kt") + public void testDeprecatedSinceKotlinNotApplicable() throws Exception { + runTest("idea/testData/parameterInfo/functionCall/deprecatedSinceKotlinNotApplicable.kt"); + } + @TestMetadata("ExtensionOnCapturedScopeChange.kt") public void testExtensionOnCapturedScopeChange() throws Exception { runTest("idea/testData/parameterInfo/functionCall/ExtensionOnCapturedScopeChange.kt");