Use information about receivers in completion

- Found few problems during resolving a single functon; disabled
assertions and marked them with TODO
- Add simple completion tests to simplify development
This commit is contained in:
Roman Golyshev
2020-07-01 14:30:40 +03:00
committed by Ilya Kirillov
parent 0f5fc1fa99
commit ffb907150a
18 changed files with 403 additions and 78 deletions
@@ -0,0 +1,11 @@
class A {
fun aa() {}
val aaa = 10
fun test() {
<caret>
}
}
// EXIST: aa
// EXIST: aaa
@@ -0,0 +1,20 @@
class B {
fun bb() {}
val bbb = 20
}
class A {
fun aa() {}
val aaa = 10
fun test() {
val b = B()
b.<caret>
}
}
// EXIST: bb
// EXIST: bbb
// ABSENT: aa
// ABSENT: aaa
@@ -0,0 +1,17 @@
open class A {
fun aa() {}
val aaa = 10
fun test() {
<caret>
}
}
class B : A() {
fun test() {
<caret>
}
}
// EXIST: aa
// EXIST: aaa
@@ -0,0 +1,18 @@
class A {
fun aa() {}
val aaa = 10
inner class AA {
fun bb() {}
val bbb = 20
fun test() {
<caret>
}
}
}
// EXIST: aa
// EXIST: aaa
// EXIST: bb
// EXIST: bbb
@@ -0,0 +1,13 @@
class A {
fun aa() {}
val aaa = 10
}
fun test() {
val a = A()
a.<caret>
}
// EXIST: aa
// EXIST: aaa
@@ -0,0 +1,21 @@
fun Any.anyFun() {}
val Any.anyVal: Int get() = 10
class A
fun A.aFun() {}
val A.aVal: Int get() = 10
class B
fun B.bFun() {}
val B.bVal: Int get() = 10
fun test(a: A) {
a.<caret>
}
// EXIST: anyFun
// EXIST: anyVal
// EXIST: aVal
// EXIST: aFun
// ABSENT: bVal
// ABSENT: bFun
@@ -0,0 +1,23 @@
fun <T : Any> T.anyFun() {}
val <T : Any> T.anyVal: Int get() = 10
open class A
fun <T : A> T.aFun() {}
val <T : A> T.aVal: Int get() = 10
open class B
fun <T : B> T.bFun() {}
val <T : B> T.bVal: Int get() = 10
fun test(a: A) {
a.aFun()
a.<caret>
}
// EXIST: anyFun
// EXIST: anyVal
// EXIST: aVal
// EXIST: aFun
// ABSENT: bVal
// ABSENT: bFun
@@ -0,0 +1,24 @@
class A {
fun aa() {}
val aaa = 10
}
fun A.run(action: A.() -> Unit) {}
fun test(a: A) {
a.run {
<caret>
// remove this
Unit
}
}
// this does not work for some reason
//fun A.test() {
//}
// EXIST: aa
// EXIST: aaa
// EXIST: run
@@ -0,0 +1,9 @@
fun test() {
fun aa() {}
val aaa = 10
<caret>
}
// EXIST: aa
// EXIST: aaa
@@ -0,0 +1,20 @@
fun run(action: () -> Unit) = action()
fun test() {
fun aa() {}
val aaa = 10
run {
fun aabb() {}
val aaabb = 20
<caret>
Unit // remove this
}
}
// EXIST: aa
// EXIST: aaa
// EXIST: aabb
// EXIST: aaabb
@@ -0,0 +1,9 @@
fun aa() {}
val aaa = 10
fun test() {
<caret>
}
// EXIST: aa
// EXIST: aaa
@@ -0,0 +1,11 @@
class A
class OuterClass {
fun A.innerExt() {}
fun test(a: A) {
a.<caret>
}
}
// EXIST: innerExt
@@ -2215,6 +2215,79 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
}
}
@TestMetadata("idea/idea-completion/testData/basic/common/primitiveCompletion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class PrimitiveCompletion extends AbstractJSBasicCompletionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInPrimitiveCompletion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-completion/testData/basic/common/primitiveCompletion"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("classFieldsAndFunctions.kt")
public void testClassFieldsAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctions.kt");
}
@TestMetadata("classFieldsAndFunctionsExplicitReceiver.kt")
public void testClassFieldsAndFunctionsExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsExplicitReceiver.kt");
}
@TestMetadata("classFieldsAndFunctionsFromInheritor.kt")
public void testClassFieldsAndFunctionsFromInheritor() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsFromInheritor.kt");
}
@TestMetadata("classFieldsAndFunctionsFromInnerClass.kt")
public void testClassFieldsAndFunctionsFromInnerClass() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsFromInnerClass.kt");
}
@TestMetadata("explicitReceiverCompletion.kt")
public void testExplicitReceiverCompletion() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/explicitReceiverCompletion.kt");
}
@TestMetadata("extensionPropertyAndFunctionExplicitReceiver.kt")
public void testExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionExplicitReceiver.kt");
}
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
}
@TestMetadata("implicitReceiverCompletion.kt")
public void testImplicitReceiverCompletion() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/implicitReceiverCompletion.kt");
}
@TestMetadata("localVariablesAndFunctions.kt")
public void testLocalVariablesAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/localVariablesAndFunctions.kt");
}
@TestMetadata("localVariablesAndFunctionsFromNestedScope.kt")
public void testLocalVariablesAndFunctionsFromNestedScope() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/localVariablesAndFunctionsFromNestedScope.kt");
}
@TestMetadata("topLevelVariablesAndFunctions.kt")
public void testTopLevelVariablesAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelVariablesAndFunctions.kt");
}
@TestMetadata("twoReceivers.kt")
public void testTwoReceivers() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/twoReceivers.kt");
}
}
@TestMetadata("idea/idea-completion/testData/basic/common/shadowing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -2215,6 +2215,79 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
}
}
@TestMetadata("idea/idea-completion/testData/basic/common/primitiveCompletion")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class PrimitiveCompletion extends AbstractJvmBasicCompletionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
public void testAllFilesPresentInPrimitiveCompletion() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/idea-completion/testData/basic/common/primitiveCompletion"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@TestMetadata("classFieldsAndFunctions.kt")
public void testClassFieldsAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctions.kt");
}
@TestMetadata("classFieldsAndFunctionsExplicitReceiver.kt")
public void testClassFieldsAndFunctionsExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsExplicitReceiver.kt");
}
@TestMetadata("classFieldsAndFunctionsFromInheritor.kt")
public void testClassFieldsAndFunctionsFromInheritor() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsFromInheritor.kt");
}
@TestMetadata("classFieldsAndFunctionsFromInnerClass.kt")
public void testClassFieldsAndFunctionsFromInnerClass() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/classFieldsAndFunctionsFromInnerClass.kt");
}
@TestMetadata("explicitReceiverCompletion.kt")
public void testExplicitReceiverCompletion() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/explicitReceiverCompletion.kt");
}
@TestMetadata("extensionPropertyAndFunctionExplicitReceiver.kt")
public void testExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/extensionPropertyAndFunctionExplicitReceiver.kt");
}
@TestMetadata("genericExtensionPropertyAndFunctionExplicitReceiver.kt")
public void testGenericExtensionPropertyAndFunctionExplicitReceiver() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/genericExtensionPropertyAndFunctionExplicitReceiver.kt");
}
@TestMetadata("implicitReceiverCompletion.kt")
public void testImplicitReceiverCompletion() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/implicitReceiverCompletion.kt");
}
@TestMetadata("localVariablesAndFunctions.kt")
public void testLocalVariablesAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/localVariablesAndFunctions.kt");
}
@TestMetadata("localVariablesAndFunctionsFromNestedScope.kt")
public void testLocalVariablesAndFunctionsFromNestedScope() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/localVariablesAndFunctionsFromNestedScope.kt");
}
@TestMetadata("topLevelVariablesAndFunctions.kt")
public void testTopLevelVariablesAndFunctions() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/topLevelVariablesAndFunctions.kt");
}
@TestMetadata("twoReceivers.kt")
public void testTwoReceivers() throws Exception {
runTest("idea/idea-completion/testData/basic/common/primitiveCompletion/twoReceivers.kt");
}
}
@TestMetadata("idea/idea-completion/testData/basic/common/shadowing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)