Add a set of tests for internal callables find usages

Related to KT-19811
This commit is contained in:
Mikhail Glukhikh
2017-09-11 12:37:40 +03:00
parent 97233448d0
commit dd1ac5bb6b
40 changed files with 532 additions and 0 deletions
@@ -0,0 +1,25 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
enum class E {
O
A {
init {
foo(1)
}
override fun foo(n: Int): Int = n + 1
}
B {
init {
foo(1)
}
override fun foo(n: Int): Int = n + 2
}
init {
foo(1)
}
internal open fun <caret>foo(n: Int): Int = n
}
@@ -0,0 +1,3 @@
Function call 14 foo(1)
Function call 21 foo(1)
Function call 7 foo(1)
@@ -0,0 +1,12 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
package server
public open class Server() {
internal open fun <caret>processRequest() = "foo"
}
public class ServerEx(): Server() {
override fun processRequest() = "foofoo"
}
@@ -0,0 +1,8 @@
import server.*;
class Client {
public fun foo() {
Server().processRequest()
ServerEx().processRequest()
}
}
@@ -0,0 +1,2 @@
Function call 5 Server().processRequest()
Function call 6 ServerEx().processRequest()
@@ -0,0 +1,17 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
package server
internal fun <caret>foo() {
}
fun Int.foo() {
}
fun foo(n: Int) {
}
val foo: Int
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
package client
import server.foo
fun test() {
foo()
foo(1)
val t = foo
}
@@ -0,0 +1,2 @@
Function call 8 foo()
Usage in import 5 import server.foo
@@ -0,0 +1,45 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: overloadUsages
interface X<T> {
}
fun <T> X<T>.foo(a: Number, b: Number) {
println("$a$b")
}
fun bar(x: X<String>) {
x.foo(1, 2)
}
open class A<T>: X<T> {
internal open fun <caret>foo(t: T) {
println(t)
}
open fun foo(t: T, tt: T) {
println(t)
}
}
fun <T> A<T>.foo(t: T, x: String) {
foo(t)
println(x)
}
fun bar(a: A<Number>) {
a.foo(1, "")
}
fun B.foo(s: String, n: Number) {
fun <T> A<T>.foo(t: T, x: String) {
foo(t)
println(x)
}
foo(s)
println(n)
}
fun bar(b: B) {
b.foo("", 0)
}
@@ -0,0 +1,13 @@
open class B: A<String>() {
override fun foo(t: String) {
super<A>.foo(t)
}
open fun baz(a: A<String>) {
foo("", 0)
}
open fun baz(a: A<Number>) {
a.foo(0, "")
}
}
@@ -0,0 +1,7 @@
[kotlinOverloadAndExtensionUsages.0.kt] Function call 11 x.foo(1, 2)
[kotlinOverloadAndExtensionUsages.0.kt] Function call 25 foo(t)
[kotlinOverloadAndExtensionUsages.0.kt] Function call 30 a.foo(1, "")
[kotlinOverloadAndExtensionUsages.0.kt] Function call 35 foo(t)
[kotlinOverloadAndExtensionUsages.0.kt] Function call 39 foo(s)
[kotlinOverloadAndExtensionUsages.1.kt] Function call 11 a.foo(0, "")
[kotlinOverloadAndExtensionUsages.1.kt] Function call 3 super<A>.foo(t)
@@ -0,0 +1,6 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages
package server
internal fun <caret>processRequest() = "foo"
@@ -0,0 +1,12 @@
package client
import server.processRequest
class Client {
val methodRef = ::processRequest()
fun doProcessRequest() {
println("Process...")
processRequest()
}
}
@@ -0,0 +1,3 @@
Callable reference 6 val methodRef = ::processRequest()
Function call 10 processRequest()
Usage in import 3 import server.processRequest
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages, skipImports
package server
interface TraitWithImpl {
internal fun <caret>foo() = 1
}
public class TraitWithDelegatedWithImpl(f: TraitWithImpl): TraitWithImpl by f
fun test(twdwi: TraitWithDelegatedWithImpl) = twdwi.foo()
@@ -0,0 +1 @@
Function call 11 fun test(twdwi: TraitWithDelegatedWithImpl) = twdwi.foo()
@@ -0,0 +1,16 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtNamedFunction
// OPTIONS: usages, skipImports
interface A {
internal fun foo()
}
class B: A {
override fun foo() {} // Find usages gives no results
}
fun main(a: A) {
a.<caret>foo()
}
// for KT-3769 Find usages gives no result for overrides
@@ -0,0 +1 @@
Function call 13 a.foo()
@@ -0,0 +1,7 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtClass
// OPTIONS: usages, constructorUsages
fun test() {
val kk: KK = <caret>KK()
}
class KK internal constructor()
@@ -0,0 +1,2 @@
Local variable declaration 4 val kk: KK = KK()
New instance creation 4 val kk: KK = KK()
@@ -0,0 +1,17 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtPrimaryConstructor
// OPTIONS: usages
// FIND_BY_REF
open class A internal constructor(n: Int) {
constructor(): this(1)
}
class B: A {
constructor(n: Int): super(n)
}
class C(): A(1)
fun test() {
A()
<caret>A(1)
}
@@ -0,0 +1,4 @@
New instance creation 16 A(1)
Supertype 12 class C(): A(1)
Unclassified usage 5 constructor(): this(1)
Unclassified usage 9 constructor(n: Int): super(n)
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
package server
interface Some {
companion object {
internal const val <caret>XX = 1
}
}
val a = Some.XX
@@ -0,0 +1 @@
Value read 11 val a = Some.XX
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
package server
fun foo() {
}
internal val <caret>foo: Int = 1
val Int.foo: Int = 2
@@ -0,0 +1,10 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
package client
import server.foo
fun test() {
foo()
val t = 1.foo + foo
}
@@ -0,0 +1,2 @@
Usage in import 5 import server.foo
Value read 9 val t = 1.foo + foo
@@ -0,0 +1,19 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
package server
open class A<T> {
internal open var <caret>foo: T
}
open class B: A<String>() {
open var foo: String
get() {
println("get")
return super<A>.foo
}
set(value: String) {
println("set:" + value)
super<A>.foo = value
}
}
@@ -0,0 +1,13 @@
import server.*;
class Client {
public fun foo() {
val a = A<String>()
a.foo = "a"
println("a.foo = ${a.foo}")
val b = B()
b.foo = "b"
println("b.foo = ${b.foo}")
}
}
@@ -0,0 +1,6 @@
[kotlinPropertyUsages.0.kt] Value read 13 return super<A>.foo
[kotlinPropertyUsages.0.kt] Value write 17 super<A>.foo = value
[kotlinPropertyUsages.1.kt] Value read 11 println("b.foo = ${b.foo}")
[kotlinPropertyUsages.1.kt] Value read 7 println("a.foo = ${a.foo}")
[kotlinPropertyUsages.1.kt] Value write 10 b.foo = "b"
[kotlinPropertyUsages.1.kt] Value write 6 a.foo = "a"
@@ -0,0 +1,6 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
// OPTIONS: usages
package server
internal var <caret>foo: String = "foo"
@@ -0,0 +1,10 @@
package client
import server.foo
class Client {
fun fooBar() {
println("foo = ${server.foo}")
println("length: ${server.foo.length()}")
}
}
@@ -0,0 +1,3 @@
Receiver 8 println("length: ${server.foo.length()}")
Usage in import 3 import server.foo
Value read 7 println("foo = ${server.foo}")
@@ -0,0 +1,9 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtClass
// OPTIONS: usages, constructorUsages
fun test() {
val kk: KK = <caret>KK()
}
class KK {
internal constructor()
}
@@ -0,0 +1,2 @@
Local variable declaration 4 val kk: KK = KK()
New instance creation 4 val kk: KK = KK()
@@ -0,0 +1,29 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtSecondaryConstructor
// OPTIONS: usages
open class B {
internal <caret>constructor() {
}
constructor(a: Int): this() {
}
}
class A : B {
constructor(a: Int) : super() {
}
constructor() {
}
}
class C : B() {
}
fun test() {
B()
}
@@ -0,0 +1,5 @@
New instance creation 28 B()
Supertype 23 class C : B() {
Unclassified usage 14 constructor(a: Int) : super() {
Unclassified usage 18 constructor() {
Unclassified usage 8 constructor(a: Int): this() {
@@ -0,0 +1,25 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtSecondaryConstructor
// OPTIONS: usages
open class B {
constructor(): this("") {
}
internal <caret>constructor(s: String) {
}
}
open class A : B {
constructor(a: Int) : super("") {
}
}
class C: B("") {
}
fun test() {
B("")
}
@@ -0,0 +1,4 @@
New instance creation 24 B("")
Supertype 19 class C: B("") {
Unclassified usage 14 constructor(a: Int) : super("") {
Unclassified usage 4 constructor(): this("") {
@@ -1334,6 +1334,147 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
}
}
@TestMetadata("idea/testData/findUsages/kotlin/internal")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Internal extends AbstractFindUsagesTest {
public void testAllFilesPresentInInternal() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/internal"), Pattern.compile("^(.+)\\.0\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FindFunctionUsages extends AbstractFindUsagesTest {
public void testAllFilesPresentInFindFunctionUsages() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/internal/findFunctionUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("enumFunctionUsages.0.kt")
public void testEnumFunctionUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/enumFunctionUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinMethodUsages.0.kt")
public void testKotlinMethodUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/kotlinMethodUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinMultiRefInImport.0.kt")
public void testKotlinMultiRefInImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/kotlinMultiRefInImport.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinOverloadAndExtensionUsages.0.kt")
public void testKotlinOverloadAndExtensionUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/kotlinOverloadAndExtensionUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinTopLevelMethodUsages.0.kt")
public void testKotlinTopLevelMethodUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/kotlinTopLevelMethodUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinTraitImplThroughDelegate.0.kt")
public void testKotlinTraitImplThroughDelegate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/kotlinTraitImplThroughDelegate.0.kt");
doTest(fileName);
}
@TestMetadata("usagesOfBaseForFunction.0.kt")
public void testUsagesOfBaseForFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findFunctionUsages/usagesOfBaseForFunction.0.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/findUsages/kotlin/internal/findPrimaryConstructorUsages")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FindPrimaryConstructorUsages extends AbstractFindUsagesTest {
public void testAllFilesPresentInFindPrimaryConstructorUsages() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/internal/findPrimaryConstructorUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("constructorCall.0.kt")
public void testConstructorCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPrimaryConstructorUsages/constructorCall.0.kt");
doTest(fileName);
}
@TestMetadata("primaryConstructorByRef.0.kt")
public void testPrimaryConstructorByRef() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPrimaryConstructorUsages/primaryConstructorByRef.0.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/findUsages/kotlin/internal/findPropertyUsages")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FindPropertyUsages extends AbstractFindUsagesTest {
public void testAllFilesPresentInFindPropertyUsages() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/internal/findPropertyUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("kotlinClassObjectPropertyUsage.0.kt")
public void testKotlinClassObjectPropertyUsage() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPropertyUsages/kotlinClassObjectPropertyUsage.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinMultiRefInImport.0.kt")
public void testKotlinMultiRefInImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPropertyUsages/kotlinMultiRefInImport.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinPropertyUsages.0.kt")
public void testKotlinPropertyUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPropertyUsages/kotlinPropertyUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinTopLevelPropertyUsages.0.kt")
public void testKotlinTopLevelPropertyUsages() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findPropertyUsages/kotlinTopLevelPropertyUsages.0.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/findUsages/kotlin/internal/findSecondaryConstructorUsages")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class FindSecondaryConstructorUsages extends AbstractFindUsagesTest {
public void testAllFilesPresentInFindSecondaryConstructorUsages() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/internal/findSecondaryConstructorUsages"), Pattern.compile("^(.+)\\.0\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("constructorCall.0.kt")
public void testConstructorCall() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findSecondaryConstructorUsages/constructorCall.0.kt");
doTest(fileName);
}
@TestMetadata("defaultSecondaryConstructor.0.kt")
public void testDefaultSecondaryConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findSecondaryConstructorUsages/defaultSecondaryConstructor.0.kt");
doTest(fileName);
}
@TestMetadata("secondaryConstructor.0.kt")
public void testSecondaryConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/internal/findSecondaryConstructorUsages/secondaryConstructor.0.kt");
doTest(fileName);
}
}
}
@TestMetadata("idea/testData/findUsages/kotlin/propertyFiles")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)