Don't suggest adding replaceWith in DeprecationLevel.HIDDEN (#1094)

#KT-17917 Fixed
This commit is contained in:
nd
2017-05-24 15:06:51 +02:00
committed by Dmitry Jemerov
parent 8d6d228bb8
commit cb5459b7d7
3 changed files with 25 additions and 3 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
import org.jetbrains.kotlin.resolve.calls.model.isReallySuccess
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.types.typeUtil.isUnit
@@ -118,9 +119,18 @@ class DeprecatedCallableAddReplaceWithIntention : SelfTargetingRangeIntention<Kt
val descriptorFqName = DescriptorUtils.getFqName(descriptor).toSafe()
if (descriptorFqName != KotlinBuiltIns.FQ_NAMES.deprecated) continue
val replaceWithArguments = resolvedCall.valueArguments.entries
.single { it.key.name.asString() == "replaceWith"/*TODO: kotlin.deprecated::replaceWith.name*/ }.value
return if (replaceWithArguments.arguments.isEmpty()) entry else null
val args = resolvedCall.valueArguments.mapKeys { it.key.name.asString() }
val replaceWithArguments = args["replaceWith"] /*TODO: kotlin.deprecated::replaceWith.name*/
val level = args["level"]
if (replaceWithArguments?.arguments?.isNotEmpty() ?: false) return null
if (level != null && level.arguments.isNotEmpty()) {
val levelDescriptor = level.arguments[0].getArgumentExpression().getResolvedCall(bindingContext)?.candidateDescriptor
if (levelDescriptor?.name?.asString() == "HIDDEN") return null
}
return entry
}
return null
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
<caret>@Deprecated("Use the other version", level=DeprecationLevel.HIDDEN)
fun foo(a: Int) { foo(a) }
fun foo(a: Int, b: Int = 0) { ... }
@@ -7802,6 +7802,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("DeprecationLevelHidden.kt")
public void testDeprecationLevelHidden() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/DeprecationLevelHidden.kt");
doTest(fileName);
}
@TestMetadata("ExceptionInPropertyDestructuringEntry.kt")
public void testExceptionInPropertyDestructuringEntry() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/ExceptionInPropertyDestructuringEntry.kt");