Don't suggest adding replaceWith in DeprecationLevel.HIDDEN (#1094)
#KT-17917 Fixed
This commit is contained in:
+13
-3
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.ImportPath
|
import org.jetbrains.kotlin.resolve.ImportPath
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
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.calls.model.isReallySuccess
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
@@ -118,9 +119,18 @@ class DeprecatedCallableAddReplaceWithIntention : SelfTargetingRangeIntention<Kt
|
|||||||
val descriptorFqName = DescriptorUtils.getFqName(descriptor).toSafe()
|
val descriptorFqName = DescriptorUtils.getFqName(descriptor).toSafe()
|
||||||
if (descriptorFqName != KotlinBuiltIns.FQ_NAMES.deprecated) continue
|
if (descriptorFqName != KotlinBuiltIns.FQ_NAMES.deprecated) continue
|
||||||
|
|
||||||
val replaceWithArguments = resolvedCall.valueArguments.entries
|
val args = resolvedCall.valueArguments.mapKeys { it.key.name.asString() }
|
||||||
.single { it.key.name.asString() == "replaceWith"/*TODO: kotlin.deprecated::replaceWith.name*/ }.value
|
val replaceWithArguments = args["replaceWith"] /*TODO: kotlin.deprecated::replaceWith.name*/
|
||||||
return if (replaceWithArguments.arguments.isEmpty()) entry else null
|
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
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -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);
|
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")
|
@TestMetadata("ExceptionInPropertyDestructuringEntry.kt")
|
||||||
public void testExceptionInPropertyDestructuringEntry() throws Exception {
|
public void testExceptionInPropertyDestructuringEntry() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/ExceptionInPropertyDestructuringEntry.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/deprecatedCallableAddReplaceWith/ExceptionInPropertyDestructuringEntry.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user