Getting default value from overriding method
This commit is contained in:
@@ -120,6 +120,11 @@ public object OptionalParametersHelper {
|
||||
public fun defaultParameterValue(parameter: ValueParameterDescriptor, project: Project): DefaultValue? {
|
||||
if (!parameter.hasDefaultValue()) return null
|
||||
|
||||
if (!parameter.declaresDefaultValue()) {
|
||||
val overridden = parameter.getOverriddenDescriptors().firstOrNull { it.hasDefaultValue() } ?: return null
|
||||
return defaultParameterValue(overridden, project)
|
||||
}
|
||||
|
||||
//TODO: parameter in overriding method!
|
||||
//TODO: it's a temporary code while we don't have default values accessible from descriptors
|
||||
var declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter) as? JetParameter ?: return null
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace with 'newFun(p1, p2, p3)'" "true"
|
||||
|
||||
interface I {
|
||||
@deprecated("", ReplaceWith("newFun(p1, p2, p3)"))
|
||||
fun oldFun(p1: String, p2: Int = 0, p3: Int = 1)
|
||||
|
||||
fun newFun(p1: String, p2: Int = 1, p3: Int = 1)
|
||||
}
|
||||
|
||||
abstract class C : I {
|
||||
override fun newFun(p1: String, p2: Int, p3: Int) { }
|
||||
|
||||
}
|
||||
|
||||
fun foo(c: C) {
|
||||
c.<caret>oldFun("")
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace with 'newFun(p1, p2, p3)'" "true"
|
||||
|
||||
interface I {
|
||||
@deprecated("", ReplaceWith("newFun(p1, p2, p3)"))
|
||||
fun oldFun(p1: String, p2: Int = 0, p3: Int = 1)
|
||||
|
||||
fun newFun(p1: String, p2: Int = 1, p3: Int = 1)
|
||||
}
|
||||
|
||||
abstract class C : I {
|
||||
override fun newFun(p1: String, p2: Int, p3: Int) { }
|
||||
|
||||
}
|
||||
|
||||
fun foo(c: C) {
|
||||
c.<caret>newFun("", 0)
|
||||
}
|
||||
@@ -3284,6 +3284,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/optionalParameters/optionalParameters9.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overridingMethod.kt")
|
||||
public void testOverridingMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/optionalParameters/overridingMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/safeCall")
|
||||
|
||||
Reference in New Issue
Block a user