From 6e3016284a81402855b73bbb5d5bb827c790997c Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 13 Apr 2017 20:07:03 +0300 Subject: [PATCH] Test find usages behaviour when failing to text search on Groovy files Set test directory to directory with test files (not relative to findUsages folder). This way test will be configured as if all testdata is under source root (previously it was copied into package under path with findUsages) and resolvers will see classes under root package. #KT-14974 In Progress --- .../JavaWithGroovyInvoke.0.groovy | 12 ++++++++++ .../JavaWithGroovyInvoke.0.java | 10 +++++++++ .../JavaWithGroovyInvoke.0.kt | 17 ++++++++++++++ .../JavaWithGroovyInvoke.log | 4 ++++ .../JavaWithGroovyInvoke.results.txt | 5 +++++ .../propertyFileUsagesByRef.0.kt | 2 +- .../propertyFileUsagesByRef.1.java | 2 +- .../propertyFileUsagesByRef.results.txt | 4 ++-- .../propertyFiles/propertyUsagesByRef.0.kt | 2 +- .../propertyFiles/propertyFileUsages.1.kt | 4 ++-- .../propertyFileUsages.results.txt | 4 ++-- .../propertyFiles/propertyUsages.1.kt | 16 +++++++------- .../propertyFiles/propertyUsages.2.java | 4 ++-- .../propertyFiles/propertyUsages.results.txt | 6 ++--- .../findUsages/AbstractFindUsagesTest.kt | 22 +++++++++---------- .../findUsages/FindUsagesTestGenerated.java | 6 +++++ 16 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.groovy create mode 100644 idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.java create mode 100644 idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.kt create mode 100644 idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.log create mode 100644 idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.results.txt diff --git a/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.groovy b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.groovy new file mode 100644 index 00000000000..ec2ab33426c --- /dev/null +++ b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.groovy @@ -0,0 +1,12 @@ +class GroovyClass extends JavaWithGroovyInvoke_0 { + def fieldNoType = new JavaWithGroovyInvoke_0.OtherJavaClass() + def JavaWithGroovyInvoke_0.OtherJavaClass fieldWithType = new JavaWithGroovyInvoke_0.OtherJavaClass() + + def methodNoType() { + new JavaWithGroovyInvoke_0.OtherJavaClass() + } + + JavaWithGroovyInvoke_0.OtherJavaClass methodWithType() { + new JavaWithGroovyInvoke_0.OtherJavaClass() + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.java b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.java new file mode 100644 index 00000000000..386687c924f --- /dev/null +++ b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.java @@ -0,0 +1,10 @@ +// PSI_ELEMENT: com.intellij.psi.PsiMethod +// OPTIONS: usages +// PLAIN_WHEN_NEEDED + +public class JavaWithGroovyInvoke_0 { + public void invoke() { + } + + public static class OtherJavaClass extends JavaWithGroovyInvoke_0 {} +} \ No newline at end of file diff --git a/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.kt b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.kt new file mode 100644 index 00000000000..35d6c249b67 --- /dev/null +++ b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.kt @@ -0,0 +1,17 @@ +fun f(c: JavaWithGroovyInvoke_0) { + c() +} + +fun foo(o: JavaWithGroovyInvoke_0.OtherJavaClass) { + o() +} + +fun gr(o: GroovyClass) { + o() + + o.fieldNoType() // Red reference + o.fieldWithType() + + o.methodNoType()() // Red reference + o.methodWithType()() +} \ No newline at end of file diff --git a/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.log b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.log new file mode 100644 index 00000000000..9f0ade80699 --- /dev/null +++ b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.log @@ -0,0 +1,4 @@ +Searched references to JavaWithGroovyInvoke_0 +Used plain search of JavaWithGroovyInvoke_0.invoke() in LocalSearchScope: + JetFile: JavaWithGroovyInvoke.0.kt +Used plain search of JavaWithGroovyInvoke_0.invoke() in whole search scope \ No newline at end of file diff --git a/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.results.txt b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.results.txt new file mode 100644 index 00000000000..d5ba3b984b5 --- /dev/null +++ b/idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.results.txt @@ -0,0 +1,5 @@ +Implicit 'invoke' 10 o() +Implicit 'invoke' 13 o.fieldWithType() +Implicit 'invoke' 16 o.methodWithType()() +Implicit 'invoke' 2 c() +Implicit 'invoke' 6 o() \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.0.kt b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.0.kt index 26c81bd60fc..a95a9cc0fa1 100644 --- a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.0.kt +++ b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.0.kt @@ -2,7 +2,7 @@ // FIND_BY_REF import org.jetbrains.annotations.PropertyKey -public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.kotlin.propertyFiles.propertyFileUsagesByRef.2") key: String) = key +public fun message(@PropertyKey(resourceBundle = "propertyFileUsagesByRef.2") key: String) = key fun test() { message("foo.bar") diff --git a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.1.java b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.1.java index d9f9290f791..8f6252cd685 100644 --- a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.1.java +++ b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.1.java @@ -1,7 +1,7 @@ import org.jetbrains.annotations.PropertyKey; class A { - static String message(@PropertyKey(resourceBundle = "idea.testData.findUsages.kotlin.propertyFiles.propertyFileUsagesByRef.2") String key, Object... args) { + static String message(@PropertyKey(resourceBundle = "propertyFileUsagesByRef.2") String key, Object... args) { return key; } diff --git a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.results.txt b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.results.txt index 1b5fa5ed0dd..3eb3ba5b8dd 100644 --- a/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.results.txt +++ b/idea/testData/findUsages/kotlin/propertyFiles/propertyFileUsagesByRef.results.txt @@ -1,2 +1,2 @@ -[propertyFileUsagesByRef.0.kt] Usage in string constants 5 public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.kotlin.propertyFiles.propertyFileUsagesByRef.2") key: String) = key -[propertyFileUsagesByRef.1.java] Method parameter declaration 4 static String message(@PropertyKey(resourceBundle = "idea.testData.findUsages.kotlin.propertyFiles.propertyFileUsagesByRef.2") String key, Object... args) { +[propertyFileUsagesByRef.0.kt] Usage in string constants 5 public fun message(@PropertyKey(resourceBundle = "propertyFileUsagesByRef.2") key: String) = key +[propertyFileUsagesByRef.1.java] Method parameter declaration 4 static String message(@PropertyKey(resourceBundle = "propertyFileUsagesByRef.2") String key, Object... args) { \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/propertyFiles/propertyUsagesByRef.0.kt b/idea/testData/findUsages/kotlin/propertyFiles/propertyUsagesByRef.0.kt index df0b1f2572d..d6d649408f3 100644 --- a/idea/testData/findUsages/kotlin/propertyFiles/propertyUsagesByRef.0.kt +++ b/idea/testData/findUsages/kotlin/propertyFiles/propertyUsagesByRef.0.kt @@ -2,7 +2,7 @@ // FIND_BY_REF import org.jetbrains.annotations.PropertyKey -public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.kotlin.propertyFiles.propertyUsagesByRef.2") key: String) = key +public fun message(@PropertyKey(resourceBundle = "propertyUsagesByRef.2") key: String) = key fun test() { message("foo.bar") diff --git a/idea/testData/findUsages/propertyFiles/propertyFileUsages.1.kt b/idea/testData/findUsages/propertyFiles/propertyFileUsages.1.kt index 889999c1ab9..2239000db36 100644 --- a/idea/testData/findUsages/propertyFiles/propertyFileUsages.1.kt +++ b/idea/testData/findUsages/propertyFiles/propertyFileUsages.1.kt @@ -1,8 +1,8 @@ import org.jetbrains.annotations.PropertyKey -private val BUNDLE_NAME = "idea.testData.findUsages.propertyFiles.propertyFileUsages.0" +private val BUNDLE_NAME = "propertyFileUsages.0" -public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyFileUsages.0") key: String) = key +public fun message(@PropertyKey(resourceBundle = "propertyFileUsages.0") key: String) = key public fun message2(@PropertyKey(resourceBundle = BUNDLE_NAME) key: String) = key fun test() { diff --git a/idea/testData/findUsages/propertyFiles/propertyFileUsages.results.txt b/idea/testData/findUsages/propertyFiles/propertyFileUsages.results.txt index db2ad326284..e5c45c4ae05 100644 --- a/idea/testData/findUsages/propertyFiles/propertyFileUsages.results.txt +++ b/idea/testData/findUsages/propertyFiles/propertyFileUsages.results.txt @@ -1,2 +1,2 @@ -Usage in string constants 3 private val BUNDLE_NAME = "idea.testData.findUsages.propertyFiles.propertyFileUsages.0" -Usage in string constants 5 public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyFileUsages.0") key: String) = key +Usage in string constants 3 private val BUNDLE_NAME = "propertyFileUsages.0" +Usage in string constants 5 public fun message(@PropertyKey(resourceBundle = "propertyFileUsages.0") key: String) = key \ No newline at end of file diff --git a/idea/testData/findUsages/propertyFiles/propertyUsages.1.kt b/idea/testData/findUsages/propertyFiles/propertyUsages.1.kt index de0e157c8be..2cd780469b7 100644 --- a/idea/testData/findUsages/propertyFiles/propertyUsages.1.kt +++ b/idea/testData/findUsages/propertyFiles/propertyUsages.1.kt @@ -1,20 +1,20 @@ import org.jetbrains.annotations.PropertyKey -public fun message(@PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") key: String) = key +public fun message(@PropertyKey(resourceBundle = "propertyUsages.0") key: String) = key -public fun String.infixMessage(@PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") key: String) = key +public fun String.infixMessage(@PropertyKey(resourceBundle = "propertyUsages.0") key: String) = key -public fun @receiver:PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String.infixMessage2(s: String) = this +public fun @receiver:PropertyKey(resourceBundle = "propertyUsages.0") String.infixMessage2(s: String) = this -public fun @receiver:PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String.unaryMinus() = this +public fun @receiver:PropertyKey(resourceBundle = "propertyUsages.0") String.unaryMinus() = this -public fun Int.get(@PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") key: String) = this +public fun Int.get(@PropertyKey(resourceBundle = "propertyUsages.0") key: String) = this -public fun @receiver:PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String.get(s: String) = this +public fun @receiver:PropertyKey(resourceBundle = "propertyUsages.0") String.get(s: String) = this fun test() { - @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") val s1 = "foo.bar" - @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") val s2 = "foo.baz" + @PropertyKey(resourceBundle = "propertyUsages.0") val s1 = "foo.bar" + @PropertyKey(resourceBundle = "propertyUsages.0") val s2 = "foo.baz" message("foo.bar") message("foo.baz") diff --git a/idea/testData/findUsages/propertyFiles/propertyUsages.2.java b/idea/testData/findUsages/propertyFiles/propertyUsages.2.java index e3902ffd6ab..83a3e7d4e41 100644 --- a/idea/testData/findUsages/propertyFiles/propertyUsages.2.java +++ b/idea/testData/findUsages/propertyFiles/propertyUsages.2.java @@ -1,7 +1,7 @@ class A { void test() { - @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String s1 = "foo.bar" - @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String s2 = "foo.baz" + @PropertyKey(resourceBundle = "propertyUsages.0") String s1 = "foo.bar" + @PropertyKey(resourceBundle = "propertyUsages.0") String s2 = "foo.baz" PropertyUsages_1Kt.message("foo.bar"); PropertyUsages_1Kt.message("foo.baz"); } diff --git a/idea/testData/findUsages/propertyFiles/propertyUsages.results.txt b/idea/testData/findUsages/propertyFiles/propertyUsages.results.txt index 462052f70d9..ec0a2c29051 100644 --- a/idea/testData/findUsages/propertyFiles/propertyUsages.results.txt +++ b/idea/testData/findUsages/propertyFiles/propertyUsages.results.txt @@ -1,4 +1,4 @@ -[propertyUsages.1.kt] Usage in string constants 16 @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") val s1 = "foo.bar" +[propertyUsages.1.kt] Usage in string constants 16 @PropertyKey(resourceBundle = "propertyUsages.0") val s1 = "foo.bar" [propertyUsages.1.kt] Usage in string constants 18 message("foo.bar") [propertyUsages.1.kt] Usage in string constants 21 "test" infixMessage "foo.bar" [propertyUsages.1.kt] Usage in string constants 23 "foo.bar" infixMessage2 "test" @@ -6,5 +6,5 @@ [propertyUsages.1.kt] Usage in string constants 26 -"foo.bar" [propertyUsages.1.kt] Usage in string constants 27 1["foo.bar"] [propertyUsages.1.kt] Usage in string constants 28 "foo.bar"["test"] -[propertyUsages.2.java] Usage in string constants 3 @PropertyKey(resourceBundle = "idea.testData.findUsages.propertyFiles.propertyUsages.0") String s1 = "foo.bar" -[propertyUsages.2.java] Usage in string constants 5 PropertyUsages_1Kt.message("foo.bar"); +[propertyUsages.2.java] Usage in string constants 3 @PropertyKey(resourceBundle = "propertyUsages.0") String s1 = "foo.bar" +[propertyUsages.2.java] Usage in string constants 5 PropertyUsages_1Kt.message("foo.bar"); \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt index 117bbf8b6a1..0df300a3442 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractFindUsagesTest.kt @@ -64,11 +64,6 @@ abstract class AbstractFindUsagesTest : KotlinLightCodeInsightFixtureTestCase() override fun getProjectDescriptor(): LightProjectDescriptor = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - public override fun setUp() { - super.setUp() - myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/findUsages" - } - // used in Spring tests (outside main project!) protected open fun extraConfig(path: String) { } @@ -110,17 +105,13 @@ abstract class AbstractFindUsagesTest : KotlinLightCodeInsightFixtureTestCase() if (!name.startsWith(prefix) || name == mainFileName) return@listFiles false val ext = FileUtilRt.getExtension(name) - ext == "kt" - || ext == "java" - || ext == "xml" - || ext == "properties" - || ext == "txt" && !name.endsWith(".results.txt") + ext in SUPPORTED_EXTENSIONS && !name.endsWith(".results.txt") } for (file in extraFiles) { - myFixture.configureByFile(rootPath + file.name) + myFixture.configureByFile(file.name) } - myFixture.configureByFile(path) + myFixture.configureByFile(mainFileName) val caretElement = if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF")) TargetElementUtilBase.findTargetElement(myFixture.editor, @@ -169,6 +160,10 @@ abstract class AbstractFindUsagesTest : KotlinLightCodeInsightFixtureTestCase() ExpressionsOfTypeProcessor.testLog = logList } + if (InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// PLAIN_WHEN_NEEDED")) { + ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.PLAIN_WHEN_NEEDED + } + findUsages(caretElement, options, highlightingMode) } finally { @@ -176,6 +171,8 @@ abstract class AbstractFindUsagesTest : KotlinLightCodeInsightFixtureTestCase() if (logList.size > 0) { log = logList.sorted().joinToString("\n") } + + ExpressionsOfTypeProcessor.mode = ExpressionsOfTypeProcessor.Mode.ALWAYS_SMART } val filteringRules = instantiateClasses(mainFileText, "// FILTERING_RULES: ") @@ -274,6 +271,7 @@ abstract class AbstractFindUsagesTest : KotlinLightCodeInsightFixtureTestCase() } companion object { + val SUPPORTED_EXTENSIONS = setOf("kt", "java", "xml", "properties", "txt", "groovy") val USAGE_VIEW_PRESENTATION = UsageViewPresentation() diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java index fb88f6553af..c1ecaf25276 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java @@ -1639,6 +1639,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest { doTest(fileName); } + @TestMetadata("JavaWithGroovyInvoke.0.java") + public void testJavaWithGroovyInvoke() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/JavaWithGroovyInvoke.0.java"); + doTest(fileName); + } + @TestMetadata("MismatchedAccessor.0.java") public void testMismatchedAccessor() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/java/findJavaMethodUsages/MismatchedAccessor.0.java");