Do not include overriders when analyzing parameter usages unless invoked on parameter
This commit is contained in:
@@ -249,7 +249,7 @@ class InflowSlicer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtParameter.processParameter() {
|
private fun KtParameter.processParameter(includeOverriders: Boolean) {
|
||||||
if (!canProcess()) return
|
if (!canProcess()) return
|
||||||
|
|
||||||
val function = ownerFunction ?: return
|
val function = ownerFunction ?: return
|
||||||
@@ -272,7 +272,7 @@ class InflowSlicer(
|
|||||||
|
|
||||||
val parameterDescriptor = resolveToParameterDescriptorIfAny(BodyResolveMode.FULL) ?: return
|
val parameterDescriptor = resolveToParameterDescriptorIfAny(BodyResolveMode.FULL) ?: return
|
||||||
|
|
||||||
(function as? KtFunction)?.processCalls(parentUsage.scope.toSearchScope(), includeOverriders = true) body@{
|
(function as? KtFunction)?.processCalls(parentUsage.scope.toSearchScope(), includeOverriders) body@{
|
||||||
val refElement = it.element ?: return@body
|
val refElement = it.element ?: return@body
|
||||||
val refParent = refElement.parent
|
val refParent = refElement.parent
|
||||||
|
|
||||||
@@ -394,7 +394,8 @@ class InflowSlicer(
|
|||||||
|
|
||||||
when (element) {
|
when (element) {
|
||||||
is KtProperty -> element.processProperty()
|
is KtProperty -> element.processProperty()
|
||||||
is KtParameter -> element.processParameter()
|
// for parameter, we include overriders only when the feature is invoked on parameter itself
|
||||||
|
is KtParameter -> element.processParameter(includeOverriders = parentUsage.parent == null)
|
||||||
is KtDeclarationWithBody -> element.processFunction()
|
is KtDeclarationWithBody -> element.processFunction()
|
||||||
else -> element.processExpression()
|
else -> element.processExpression()
|
||||||
}
|
}
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
// FLOW: IN
|
||||||
|
|
||||||
|
open class C {
|
||||||
|
var other: C? = null
|
||||||
|
|
||||||
|
fun foo(p: Int) {
|
||||||
|
println(p + 1)
|
||||||
|
other?.bar(p + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(p: Int) {
|
||||||
|
println(<caret>p + 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : C() {
|
||||||
|
var other: D? = null
|
||||||
|
|
||||||
|
override fun foo(p: Int) {
|
||||||
|
println(p + 3)
|
||||||
|
other?.bar(p + 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bar(p: Int) {
|
||||||
|
println(p + 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
|
12 println(<bold>p</bold> + 2)
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[NotNull Values]
|
||||||
|
12 println(<bold>p</bold> + 2)
|
||||||
|
12 println(<bold>p</bold> + 2)
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
12 println(<bold>p</bold> + 2)
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
// FLOW: IN
|
||||||
|
|
||||||
|
open class C {
|
||||||
|
var other: C? = null
|
||||||
|
|
||||||
|
fun foo(p: Int) {
|
||||||
|
println(p + 1)
|
||||||
|
other?.bar(p + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(<caret>p: Int) {
|
||||||
|
println(p + 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D : C() {
|
||||||
|
var other: D? = null
|
||||||
|
|
||||||
|
override fun foo(p: Int) {
|
||||||
|
println(p + 3)
|
||||||
|
other?.bar(p + 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bar(p: Int) {
|
||||||
|
println(p + 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
|
|
||||||
|
21 other?.bar(<bold>p + 3</bold>)
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
21 other?.bar(<bold>p + 3</bold>)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[NotNull Values]
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
11 fun bar(<bold>p: Int</bold>) {
|
||||||
|
8 other?.bar(<bold>p + 1</bold>)
|
||||||
|
21 other?.bar(<bold>p + 3</bold>)
|
||||||
+11
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -228,6 +228,16 @@ public class SlicerLeafGroupingTestGenerated extends AbstractSlicerLeafGroupingT
|
|||||||
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("openFun.kt")
|
||||||
|
public void testOpenFun() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("openFunInvokeOnParameter.kt")
|
||||||
|
public void testOpenFunInvokeOnParameter() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFunInvokeOnParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overrideFun.kt")
|
@TestMetadata("overrideFun.kt")
|
||||||
public void testOverrideFun() throws Exception {
|
public void testOverrideFun() throws Exception {
|
||||||
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
||||||
|
|||||||
+11
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -228,6 +228,16 @@ public class SlicerNullnessGroupingTestGenerated extends AbstractSlicerNullnessG
|
|||||||
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("openFun.kt")
|
||||||
|
public void testOpenFun() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("openFunInvokeOnParameter.kt")
|
||||||
|
public void testOpenFunInvokeOnParameter() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFunInvokeOnParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("overrideFun.kt")
|
@TestMetadata("overrideFun.kt")
|
||||||
public void testOverrideFun() throws Exception {
|
public void testOverrideFun() throws Exception {
|
||||||
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -228,6 +228,16 @@ public class SlicerTreeTestGenerated extends AbstractSlicerTreeTest {
|
|||||||
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
runTest("idea/testData/slicer/inflow/nullsAndNotNulls.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inflow/openFun.kt")
|
||||||
|
public void testInflow_OpenFun() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFun.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inflow/openFunInvokeOnParameter.kt")
|
||||||
|
public void testInflow_OpenFunInvokeOnParameter() throws Exception {
|
||||||
|
runTest("idea/testData/slicer/inflow/openFunInvokeOnParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inflow/overrideFun.kt")
|
@TestMetadata("inflow/overrideFun.kt")
|
||||||
public void testInflow_OverrideFun() throws Exception {
|
public void testInflow_OverrideFun() throws Exception {
|
||||||
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
runTest("idea/testData/slicer/inflow/overrideFun.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user