Safe Delete: Add support of default and by-name parameters
This commit is contained in:
+27
-20
@@ -43,15 +43,6 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
|
|||||||
|
|
||||||
val element = reference.getElement() as JetElement
|
val element = reference.getElement() as JetElement
|
||||||
|
|
||||||
val originalDeclaration = method.unwrapped
|
|
||||||
if (originalDeclaration !is PsiMethod && originalDeclaration !is JetDeclaration) return
|
|
||||||
|
|
||||||
val originalParameter = parameter.unwrapped
|
|
||||||
if (originalParameter == null) return
|
|
||||||
|
|
||||||
val parameterIndex = originalParameter.parameterIndex()
|
|
||||||
if (parameterIndex < 0) return
|
|
||||||
|
|
||||||
val callExpression = element.getParentByType(javaClass<JetCallExpression>())
|
val callExpression = element.getParentByType(javaClass<JetCallExpression>())
|
||||||
if (callExpression == null) return
|
if (callExpression == null) return
|
||||||
|
|
||||||
@@ -63,17 +54,33 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
|
|||||||
val descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, calleeExpression)
|
val descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, calleeExpression)
|
||||||
if (descriptor == null) return
|
if (descriptor == null) return
|
||||||
|
|
||||||
if (originalDeclaration == BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)) {
|
val originalDeclaration = method.unwrapped
|
||||||
val args = callExpression.getValueArguments()
|
if (originalDeclaration !is PsiMethod && originalDeclaration !is JetDeclaration) return
|
||||||
val argCount = args.size()
|
|
||||||
if (parameterIndex < argCount) {
|
if (originalDeclaration != BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)) return
|
||||||
usages.add(SafeDeleteValueArgumentListUsageInfo((args.get(parameterIndex) as JetValueArgument), parameter))
|
|
||||||
} else {
|
val args = callExpression.getValueArguments()
|
||||||
val lambdaArgs = callExpression.getFunctionLiteralArguments()
|
|
||||||
val lambdaIndex = parameterIndex - argCount
|
val namedArguments = args.filter { arg -> arg is JetValueArgument && arg.getArgumentName()?.getText() == parameter.getName() }
|
||||||
if (lambdaIndex < lambdaArgs.size()) {
|
if (!namedArguments.empty) {
|
||||||
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(lambdaArgs.get(lambdaIndex), parameter, true))
|
usages.add(SafeDeleteValueArgumentListUsageInfo(namedArguments.first as JetValueArgument, parameter))
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val originalParameter = parameter.unwrapped
|
||||||
|
if (originalParameter == null) return
|
||||||
|
|
||||||
|
val parameterIndex = originalParameter.parameterIndex()
|
||||||
|
if (parameterIndex < 0) return
|
||||||
|
|
||||||
|
val argCount = args.size()
|
||||||
|
if (parameterIndex < argCount) {
|
||||||
|
usages.add(SafeDeleteValueArgumentListUsageInfo((args.get(parameterIndex) as JetValueArgument), parameter))
|
||||||
|
} else {
|
||||||
|
val lambdaArgs = callExpression.getFunctionLiteralArguments()
|
||||||
|
val lambdaIndex = parameterIndex - argCount
|
||||||
|
if (lambdaIndex < lambdaArgs.size()) {
|
||||||
|
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(lambdaArgs.get(lambdaIndex), parameter, true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int, <caret>b: Int = 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(1)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int, b: Int = 0, <caret>c: Int = 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(1)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(a: Int, b: Int = 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun Int.foo(<caret>a: Int, b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
10.foo(a = 1, b = 2)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun Int.foo(b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
10.foo(b = 2)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun Int.foo(<caret>a: Int, b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
10.foo(b = 1, a = 2)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun Int.foo(b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
10.foo(b = 1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(<caret>a: Int, b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(a = 1, b = 2)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(b = 2)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(<caret>a: Int, b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(b = 1, a = 2)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(b: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
foo(b = 1)
|
||||||
|
}
|
||||||
@@ -723,6 +723,26 @@ public class JetSafeDeleteTestGenerated extends AbstractJetSafeDeleteTest {
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParam1.kt")
|
||||||
|
public void testDefaultParam1() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/defaultParam1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultParam2.kt")
|
||||||
|
public void testDefaultParam2() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/defaultParam2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extNamedParam1.kt")
|
||||||
|
public void testExtNamedParam1() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/extNamedParam1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("extNamedParam2.kt")
|
||||||
|
public void testExtNamedParam2() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/extNamedParam2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("hierarchyWithSafeUsages1.kt")
|
@TestMetadata("hierarchyWithSafeUsages1.kt")
|
||||||
public void testHierarchyWithSafeUsages1() throws Exception {
|
public void testHierarchyWithSafeUsages1() throws Exception {
|
||||||
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/hierarchyWithSafeUsages1.kt");
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/hierarchyWithSafeUsages1.kt");
|
||||||
@@ -808,6 +828,16 @@ public class JetSafeDeleteTestGenerated extends AbstractJetSafeDeleteTest {
|
|||||||
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/lambdaArgExt.kt");
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/lambdaArgExt.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("namedParam1.kt")
|
||||||
|
public void testNamedParam1() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/namedParam1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("namedParam2.kt")
|
||||||
|
public void testNamedParam2() throws Exception {
|
||||||
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/namedParam2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("propertyParam1.kt")
|
@TestMetadata("propertyParam1.kt")
|
||||||
public void testPropertyParam1() throws Exception {
|
public void testPropertyParam1() throws Exception {
|
||||||
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/propertyParam1.kt");
|
doValueParameterTest("idea/testData/safeDelete/deleteValueParameter/kotlinValueParameter/propertyParam1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user