mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Kotlin Find Usages: fix search in overriding methods option
^KTIJ-21368 fixed GitOrigin-RevId: c431c5bb542593374479a5fc91017398f150cf07
This commit is contained in:
committed by
intellij-monorepo-bot
parent
936002e042
commit
b12d509fa6
@@ -2309,6 +2309,32 @@ public abstract class FindUsagesWithCompilerReferenceIndexFirTestGenerated exten
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestKotlinMemberFunctionParameterUsages extends AbstractFindUsagesWithCompilerReferenceIndexFirTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsages.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsages() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsages.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestKotlinMemberFunctionParameterUsagesWithSearchInOverridings extends AbstractFindUsagesWithCompilerReferenceIndexFirTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsagesWithSearchInOverridings() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterNameInTextFile extends AbstractFindUsagesWithCompilerReferenceIndexFirTest {
|
||||
@@ -2321,6 +2347,32 @@ public abstract class FindUsagesWithCompilerReferenceIndexFirTestGenerated exten
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterNameInTextFile.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterUsageInAnonymousInheritor extends AbstractFindUsagesWithCompilerReferenceIndexFirTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritor.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritor() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritor.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterUsageInAnonymousInheritorWithSearchInOverridings extends AbstractFindUsagesWithCompilerReferenceIndexFirTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritorWithSearchInOverridings() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -2309,6 +2309,32 @@ public abstract class FindUsagesWithCompilerReferenceIndexTestGenerated extends
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestKotlinMemberFunctionParameterUsages extends AbstractFindUsagesWithCompilerReferenceIndexTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsages.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsages() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsages.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestKotlinMemberFunctionParameterUsagesWithSearchInOverridings extends AbstractFindUsagesWithCompilerReferenceIndexTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsagesWithSearchInOverridings() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterNameInTextFile extends AbstractFindUsagesWithCompilerReferenceIndexTest {
|
||||
@@ -2321,6 +2347,32 @@ public abstract class FindUsagesWithCompilerReferenceIndexTestGenerated extends
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterNameInTextFile.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterUsageInAnonymousInheritor extends AbstractFindUsagesWithCompilerReferenceIndexTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritor.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritor() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritor.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../idea/tests/testData/findUsages/kotlin/findParameterUsages")
|
||||
public static class TestParameterUsageInAnonymousInheritorWithSearchInOverridings extends AbstractFindUsagesWithCompilerReferenceIndexTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritorWithSearchInOverridings() throws Exception {
|
||||
runTest("../../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -969,10 +969,30 @@ public abstract class FindUsagesFirTestGenerated extends AbstractFindUsagesFirTe
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinHighlightParameterUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsages.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsages() throws Exception {
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsagesWithSearchInOverridings() throws Exception {
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterNameInTextFile.0.kt")
|
||||
public void testParameterNameInTextFile() throws Exception {
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterNameInTextFile.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritor.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritor() throws Exception {
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritor.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritorWithSearchInOverridings() throws Exception {
|
||||
runTest("../idea/tests/testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -473,7 +473,10 @@ internal fun findUsages(
|
||||
|
||||
handler.getFindUsagesOptions(null).let {
|
||||
if (it is KotlinFunctionFindUsagesOptions) it.isSearchForBaseMethod = searchSuperDeclaration
|
||||
else if (it is KotlinPropertyFindUsagesOptions) it.isSearchForBaseAccessors = searchSuperDeclaration
|
||||
else if (it is KotlinPropertyFindUsagesOptions) {
|
||||
it.isSearchForBaseAccessors = searchSuperDeclaration
|
||||
it.isSearchInOverridingMethods = if (options is KotlinPropertyFindUsagesOptions) options.isSearchInOverridingMethods else false
|
||||
}
|
||||
}
|
||||
|
||||
options.searchScope = GlobalSearchScope.allScope(project)
|
||||
|
||||
@@ -969,10 +969,30 @@ public abstract class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/kotlinHighlightParameterUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsages.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsages() throws Exception {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsages.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt")
|
||||
public void testKotlinMemberFunctionParameterUsagesWithSearchInOverridings() throws Exception {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterNameInTextFile.0.kt")
|
||||
public void testParameterNameInTextFile() throws Exception {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/parameterNameInTextFile.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritor.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritor() throws Exception {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritor.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt")
|
||||
public void testParameterUsageInAnonymousInheritorWithSearchInOverridings() throws Exception {
|
||||
runTest("testData/findUsages/kotlin/findParameterUsages/parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -88,6 +88,7 @@ internal enum class OptionsParser {
|
||||
"overrides" -> searchOverrides = true
|
||||
"skipRead" -> isReadAccess = false
|
||||
"skipWrite" -> isWriteAccess = false
|
||||
"overridingMethods" -> isSearchInOverridingMethods = true
|
||||
"expected" -> searchExpected = true
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||
// OPTIONS: usages
|
||||
// PSI_ELEMENT_AS_TITLE: "t: T"
|
||||
|
||||
open class MyClass {
|
||||
|
||||
open fun <T> foo(<caret>t: T): T {
|
||||
println(t)
|
||||
return t
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class F : MyClass() {
|
||||
override fun <T> foo(t: T): T {
|
||||
val t2: T = t
|
||||
return t2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
public class JavaClass extends MyClass {
|
||||
|
||||
@Override
|
||||
public <T> T foo(T t) {
|
||||
T myT = t;
|
||||
return myT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Value read 8 println(t)
|
||||
Value read 9 return t
|
||||
@@ -0,0 +1,19 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||
// OPTIONS: usages, overridingMethods
|
||||
// PSI_ELEMENT_AS_TITLE: "t: T"
|
||||
|
||||
open class MyClass {
|
||||
|
||||
open fun <T> foo(<caret>t: T): T {
|
||||
println(t)
|
||||
return t
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class F : MyClass() {
|
||||
override fun <T> foo(t: T): T {
|
||||
val t2: T = t
|
||||
return t2
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class JavaClass extends MyClass {
|
||||
|
||||
@Override
|
||||
public <T> T foo(T t) {
|
||||
T myT = t;
|
||||
return myT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
[kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt] Value read 16 val t2: T = t
|
||||
[kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt] Value read 8 println(t)
|
||||
[kotlinMemberFunctionParameterUsagesWithSearchInOverridings.0.kt] Value read 9 return t
|
||||
[kotlinMemberFunctionParameterUsagesWithSearchInOverridings.1.java] Unclassified 5 T myT = t;
|
||||
@@ -0,0 +1,14 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||
// OPTIONS: usages
|
||||
// PSI_ELEMENT_AS_TITLE: "param: T"
|
||||
|
||||
interface MyInterface {
|
||||
fun<T> myFun(<caret>param: T)
|
||||
}
|
||||
|
||||
|
||||
val d = object : MyInterface {
|
||||
override fun <T> myFun(param: T) {
|
||||
val param2 = param
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public class ImplementAnonymously {
|
||||
void test() {
|
||||
MyInterface m = new MyInterface() {
|
||||
@Override
|
||||
public <T> void myFun(T param) {
|
||||
T param2 = param;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||
// OPTIONS: usages, overridingMethods
|
||||
// PSI_ELEMENT_AS_TITLE: "param: T"
|
||||
|
||||
interface MyInterface {
|
||||
fun<T> myFun(<caret>param: T)
|
||||
}
|
||||
|
||||
|
||||
val d = object : MyInterface {
|
||||
override fun <T> myFun(param: T) {
|
||||
val param2 = param
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
public class ImplementAnonymously {
|
||||
void test() {
|
||||
MyInterface m = new MyInterface() {
|
||||
@Override
|
||||
public <T> void myFun(T param) {
|
||||
T param2 = param;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
[parameterUsageInAnonymousInheritorWithSearchInOverridings.0.kt] Value read 12 val param2 = param
|
||||
[parameterUsageInAnonymousInheritorWithSearchInOverridings.1.java] Unclassified 6 T param2 = param;
|
||||
@@ -165,9 +165,9 @@ abstract class KotlinFindMemberUsagesHandler<T : KtNamedDeclaration> protected c
|
||||
val parameterIndex = element.parameterIndex()
|
||||
|
||||
assert(parameterIndex < parametersCount)
|
||||
return OverridingMethodsSearch.search(method, true)
|
||||
return super.getPrimaryElements() + OverridingMethodsSearch.search(method, true)
|
||||
.filter { method.parameterList.parametersCount == parametersCount }
|
||||
.mapNotNull { method.parameterList.parameters[parameterIndex].unwrapped }
|
||||
.mapNotNull { it.parameterList.parameters[parameterIndex].unwrapped }
|
||||
.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user