Skip to content

Commit cb5459b

Browse files
ndyole
authored andcommitted
Don't suggest adding replaceWith in DeprecationLevel.HIDDEN (JetBrains#1094)
#KT-17917 Fixed
1 parent 8d6d228 commit cb5459b

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

idea/src/org/jetbrains/kotlin/idea/intentions/DeprecatedCallableAddReplaceWithIntention.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
3737
import org.jetbrains.kotlin.resolve.DescriptorUtils
3838
import org.jetbrains.kotlin.resolve.ImportPath
3939
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
40+
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
4041
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
4142
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
4243
import org.jetbrains.kotlin.types.typeUtil.isUnit
@@ -118,9 +119,18 @@ class DeprecatedCallableAddReplaceWithIntention : SelfTargetingRangeIntention<Kt
118119
val descriptorFqName = DescriptorUtils.getFqName(descriptor).toSafe()
119120
if (descriptorFqName != KotlinBuiltIns.FQ_NAMES.deprecated) continue
120121

121-
val replaceWithArguments = resolvedCall.valueArguments.entries
122-
.single { it.key.name.asString() == "replaceWith"/*TODO: kotlin.deprecated::replaceWith.name*/ }.value
123-
return if (replaceWithArguments.arguments.isEmpty()) entry else null
122+
val args = resolvedCall.valueArguments.mapKeys { it.key.name.asString() }
123+
val replaceWithArguments = args["replaceWith"] /*TODO: kotlin.deprecated::replaceWith.name*/
124+
val level = args["level"]
125+
126+
if (replaceWithArguments?.arguments?.isNotEmpty() ?: false) return null
127+
128+
if (level != null && level.arguments.isNotEmpty()) {
129+
val levelDescriptor = level.arguments[0].getArgumentExpression().getResolvedCall(bindingContext)?.candidateDescriptor
130+
if (levelDescriptor?.name?.asString() == "HIDDEN") return null
131+
}
132+
133+
return entry
124134
}
125135
return null
126136
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// IS_APPLICABLE: false
2+
3+
<caret>@Deprecated("Use the other version", level=DeprecationLevel.HIDDEN)
4+
fun foo(a: Int) { foo(a) }
5+
6+
fun foo(a: Int, b: Int = 0) { ... }

idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7802,6 +7802,12 @@ public void testDeclarationInside() throws Exception {
78027802
doTest(fileName);
78037803
}
78047804

7805+
@TestMetadata("DeprecationLevelHidden.kt")
7806+
public void testDeprecationLevelHidden() throws Exception {
7807+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/DeprecationLevelHidden.kt");
7808+
doTest(fileName);
7809+
}
7810+
78057811
@TestMetadata("ExceptionInPropertyDestructuringEntry.kt")
78067812
public void testExceptionInPropertyDestructuringEntry() throws Exception {
78077813
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/ExceptionInPropertyDestructuringEntry.kt");

0 commit comments

Comments
 (0)