diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index fd984305d9c..db77cd669f7 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -46,6 +46,7 @@ import org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateHashCodeAn import org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateTestSupportMethodActionTest import org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateToStringActionTest import org.jetbrains.kotlin.idea.codeInsight.hints.AbstractKotlinLambdasHintsProvider +import org.jetbrains.kotlin.idea.codeInsight.hints.AbstractKotlinReferenceTypeHintsProviderTest import org.jetbrains.kotlin.idea.codeInsight.hints.AbstractKotlinSuspendingCallHintsProviderTest import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractMoveLeftRightTest import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractMoveStatementTest @@ -889,6 +890,10 @@ fun main(args: Array) { model("codeInsight/hints/suspending") } + testClass { + model("codeInsight/hints/types") + } + testClass { model("script/definition/highlighting", extension = null, recursive = false) model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest") diff --git a/idea/testData/codeInsight/hints/types/AnonymousObject.kt b/idea/testData/codeInsight/hints/types/AnonymousObject.kt new file mode 100644 index 00000000000..6f0e0e7afa8 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/AnonymousObject.kt @@ -0,0 +1,7 @@ +// MODE: function_return +val o = object : Iterable { + override fun iterator()<# : Iterator #> = object : Iterator { + override fun next()<# : Int #> = 1 + override fun hasNext()<# : Boolean #> = true + } +} diff --git a/idea/testData/codeInsight/hints/types/AnonymousObjectNoBaseType.kt b/idea/testData/codeInsight/hints/types/AnonymousObjectNoBaseType.kt new file mode 100644 index 00000000000..546faeaa2e1 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/AnonymousObjectNoBaseType.kt @@ -0,0 +1,6 @@ +// MODE: all +fun foo() { + val o = object { + val x: Int = 0 + } +} diff --git a/idea/testData/codeInsight/hints/types/ConstInitializerType.kt b/idea/testData/codeInsight/hints/types/ConstInitializerType.kt new file mode 100644 index 00000000000..ed49b8f2d01 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ConstInitializerType.kt @@ -0,0 +1,2 @@ +// MODE: all +val a = 1 \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ConstructorWithExplicitTypeParametersType.kt b/idea/testData/codeInsight/hints/types/ConstructorWithExplicitTypeParametersType.kt new file mode 100644 index 00000000000..96bc3e184dc --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ConstructorWithExplicitTypeParametersType.kt @@ -0,0 +1,2 @@ +// MODE: all +class Bar; val a = Bar() \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ConstructorWithoutExplicitTypeParametersType.kt b/idea/testData/codeInsight/hints/types/ConstructorWithoutExplicitTypeParametersType.kt new file mode 100644 index 00000000000..965c145ba80 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ConstructorWithoutExplicitTypeParametersType.kt @@ -0,0 +1,2 @@ +// MODE: property +class Bar(val t: T); val a<# : Bar #> = Bar("") \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ConstructorWithoutTypeParametersType.kt b/idea/testData/codeInsight/hints/types/ConstructorWithoutTypeParametersType.kt new file mode 100644 index 00000000000..4175f1f31ce --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ConstructorWithoutTypeParametersType.kt @@ -0,0 +1,2 @@ +// MODE: all +val a = Any() \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/DestructingType.kt b/idea/testData/codeInsight/hints/types/DestructingType.kt new file mode 100644 index 00000000000..aaf40d7fd4a --- /dev/null +++ b/idea/testData/codeInsight/hints/types/DestructingType.kt @@ -0,0 +1,2 @@ +// MODE: local_variable +fun foo() { val (i<# : Int #>, s<# : String #>) = 1 to "" } \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/Destructuring.kt b/idea/testData/codeInsight/hints/types/Destructuring.kt new file mode 100644 index 00000000000..be93ce829bf --- /dev/null +++ b/idea/testData/codeInsight/hints/types/Destructuring.kt @@ -0,0 +1,9 @@ +// MODE: all + +fun main(args: Array) { + val (a: String, b: String, c: String) = x() +} + +fun x() :Triple { + return Triple("A", "B", "C") +} \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/EnumEntry.kt b/idea/testData/codeInsight/hints/types/EnumEntry.kt new file mode 100644 index 00000000000..e6598aa3e78 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/EnumEntry.kt @@ -0,0 +1,3 @@ +// MODE: all +enum class E { ENTRY } +val test = E.ENTRY \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/EnumEntryCompanion.kt b/idea/testData/codeInsight/hints/types/EnumEntryCompanion.kt new file mode 100644 index 00000000000..0feb56be95a --- /dev/null +++ b/idea/testData/codeInsight/hints/types/EnumEntryCompanion.kt @@ -0,0 +1,7 @@ +// MODE: property + +enum class E { + ENTRY; + companion object {} +} +val test<# : E# > = E.Companion diff --git a/idea/testData/codeInsight/hints/types/EnumEntryLikeFunction.kt b/idea/testData/codeInsight/hints/types/EnumEntryLikeFunction.kt new file mode 100644 index 00000000000..da509ebc019 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/EnumEntryLikeFunction.kt @@ -0,0 +1,8 @@ +// MODE: property +enum class E { ENTRY; + companion object { + fun test(): E = ENTRY + } +} + +val test<# : E# > = E.test() diff --git a/idea/testData/codeInsight/hints/types/EnumEntryLikeProperty.kt b/idea/testData/codeInsight/hints/types/EnumEntryLikeProperty.kt new file mode 100644 index 00000000000..2a7f8d5ecc2 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/EnumEntryLikeProperty.kt @@ -0,0 +1,10 @@ +// MODE: property +enum class E { + ENTRY; + companion object { + val test: E = ENTRY + } +} + +val test<# : E# > = E.test + \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/EnumEntryQualified.kt b/idea/testData/codeInsight/hints/types/EnumEntryQualified.kt new file mode 100644 index 00000000000..83b1d6b8ff7 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/EnumEntryQualified.kt @@ -0,0 +1,4 @@ +// MODE: all +package a +enum class E { ENTRY } +val test = a.E.ENTRY diff --git a/idea/testData/codeInsight/hints/types/ErrorType.kt b/idea/testData/codeInsight/hints/types/ErrorType.kt new file mode 100644 index 00000000000..e3b5680e1cc --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ErrorType.kt @@ -0,0 +1,2 @@ +// MODE: all +val x = arrayListOf<>() \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ExpandedTypeAlias.kt b/idea/testData/codeInsight/hints/types/ExpandedTypeAlias.kt new file mode 100644 index 00000000000..31c017de7f5 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ExpandedTypeAlias.kt @@ -0,0 +1,2 @@ +// MODE: property +val x<# : ArrayList #> = arrayListOf(1) \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ImportedEnumEntry.kt b/idea/testData/codeInsight/hints/types/ImportedEnumEntry.kt new file mode 100644 index 00000000000..093e53bc1cf --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ImportedEnumEntry.kt @@ -0,0 +1,4 @@ +// MODE: property +import E.ENTRY +enum class E { ENTRY } +val test<# : E# > = ENTRY diff --git a/idea/testData/codeInsight/hints/types/LocalVariable.kt b/idea/testData/codeInsight/hints/types/LocalVariable.kt new file mode 100644 index 00000000000..a7f95f10c35 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/LocalVariable.kt @@ -0,0 +1,2 @@ +// MODE: local_variable +fun foo() { val a<# : List #> = listOf("a") } \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/LoopParameter.kt b/idea/testData/codeInsight/hints/types/LoopParameter.kt new file mode 100644 index 00000000000..59a5fe7c78a --- /dev/null +++ b/idea/testData/codeInsight/hints/types/LoopParameter.kt @@ -0,0 +1,2 @@ +// MODE: local_variable +fun foo() { for (x<# : String #> in listOf("a")) { } } \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/LoopParameterWithExplicitType.kt b/idea/testData/codeInsight/hints/types/LoopParameterWithExplicitType.kt new file mode 100644 index 00000000000..8b4aee414d2 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/LoopParameterWithExplicitType.kt @@ -0,0 +1,2 @@ +// MODE: all +fun foo() { for (x: String in listOf("a")) { } } \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/NestedClassImports.kt b/idea/testData/codeInsight/hints/types/NestedClassImports.kt new file mode 100644 index 00000000000..6fd0e2d1b85 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/NestedClassImports.kt @@ -0,0 +1,3 @@ +// MODE: property +import kotlin.collections.Map.Entry +val entries<# : Set> #> = mapOf(1 to "1").entries \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/NestedClassWithoutImport.kt b/idea/testData/codeInsight/hints/types/NestedClassWithoutImport.kt new file mode 100644 index 00000000000..4da57df8450 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/NestedClassWithoutImport.kt @@ -0,0 +1,2 @@ +// MODE: property +val entries<# : Set> #> = mapOf(1 to "1").entries \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/ParameterType.kt b/idea/testData/codeInsight/hints/types/ParameterType.kt new file mode 100644 index 00000000000..724bd4a3ba1 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/ParameterType.kt @@ -0,0 +1,7 @@ +// MODE: parameter +fun T.wrap(lambda: (T) -> T) {} +fun foo() { + 12.wrap { elem<# : Int #> -> + elem + } +} diff --git a/idea/testData/codeInsight/hints/types/PropertyType.kt b/idea/testData/codeInsight/hints/types/PropertyType.kt new file mode 100644 index 00000000000..5ade23471ab --- /dev/null +++ b/idea/testData/codeInsight/hints/types/PropertyType.kt @@ -0,0 +1,2 @@ +// MODE: property +val a<# : List #> = listOf("a") diff --git a/idea/testData/codeInsight/hints/types/QualifiedReferences.kt b/idea/testData/codeInsight/hints/types/QualifiedReferences.kt new file mode 100644 index 00000000000..320e4cf7a8c --- /dev/null +++ b/idea/testData/codeInsight/hints/types/QualifiedReferences.kt @@ -0,0 +1,22 @@ +// MODE: local_variable +package p +class A { + class B { + class C { + class D + } + } + inner class E + enum class F { enumCase } +} +fun foo() { + val v1 = A.B.C.D() + val v2 = p.A.B.C.D() + val v3<# : A.E #> = A().E() + val v4 = p.A.F.enumCase + val v5 = A.F.enumCase + val v6 = p.A() + + +} + diff --git a/idea/testData/codeInsight/hints/types/SAMConstructor.kt b/idea/testData/codeInsight/hints/types/SAMConstructor.kt new file mode 100644 index 00000000000..c280125dcaa --- /dev/null +++ b/idea/testData/codeInsight/hints/types/SAMConstructor.kt @@ -0,0 +1 @@ +val x = Runnable { } \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/TypeInCompanion.kt b/idea/testData/codeInsight/hints/types/TypeInCompanion.kt new file mode 100644 index 00000000000..782a8837699 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/TypeInCompanion.kt @@ -0,0 +1,8 @@ +// MODE: property +class A { + companion object { + class InA + fun provideInA() = InA() + } +} +val inA<# : A.InA# > = A.provideInA() \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/TypeInNonDefaultCompanion.kt b/idea/testData/codeInsight/hints/types/TypeInNonDefaultCompanion.kt new file mode 100644 index 00000000000..90244f74d3e --- /dev/null +++ b/idea/testData/codeInsight/hints/types/TypeInNonDefaultCompanion.kt @@ -0,0 +1,8 @@ +// MODE: property +class A { + companion object N { + class InA + fun provideInA() = InA() + } +} +val inA<# : A.N.InA #> = A.provideInA() \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/UnaryConstInitializerType.kt b/idea/testData/codeInsight/hints/types/UnaryConstInitializerType.kt new file mode 100644 index 00000000000..432542119e5 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/UnaryConstInitializerType.kt @@ -0,0 +1,2 @@ +// MODE: all +val a = -1; val b = +1 \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/UnitLocalVariable.kt b/idea/testData/codeInsight/hints/types/UnitLocalVariable.kt new file mode 100644 index 00000000000..c56b163961a --- /dev/null +++ b/idea/testData/codeInsight/hints/types/UnitLocalVariable.kt @@ -0,0 +1,6 @@ +// MODE: local_variable +fun foo() { + val x = + // indent is the same: declaration & initialization + println("Foo") +} \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/UnitLocalVariable2.kt b/idea/testData/codeInsight/hints/types/UnitLocalVariable2.kt new file mode 100644 index 00000000000..27463d238a5 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/UnitLocalVariable2.kt @@ -0,0 +1,5 @@ +// MODE: all +fun foo() { + val x<# : Unit #> = + println("Foo") // indent differs +} \ No newline at end of file diff --git a/idea/testData/codeInsight/hints/types/UnitLocalVariable3.kt b/idea/testData/codeInsight/hints/types/UnitLocalVariable3.kt new file mode 100644 index 00000000000..3bfa96f1719 --- /dev/null +++ b/idea/testData/codeInsight/hints/types/UnitLocalVariable3.kt @@ -0,0 +1,4 @@ +// MODE: local_variable +fun foo() { + val x<# : Unit #> = println("Foo") +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt new file mode 100644 index 00000000000..1672372d99e --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2020 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. + */ + +package org.jetbrains.kotlin.idea.codeInsight.hints + +import com.intellij.openapi.util.io.FileUtil +import com.intellij.testFramework.LightProjectDescriptor +import com.intellij.testFramework.utils.inlays.InlayHintsProviderTestCase +import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import java.io.File + +@Suppress("UnstableApiUsage") +abstract class AbstractKotlinReferenceTypeHintsProviderTest : + InlayHintsProviderTestCase() { // Abstract- prefix is just a convention for GenerateTests + + override fun getProjectDescriptor(): LightProjectDescriptor { + return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE + } + + fun doTest(testPath: String) { // named according to the convention imposed by GenerateTests + assertThatActualHintsMatch(testPath) + } + + private fun assertThatActualHintsMatch(fileName: String) { + with(KotlinReferencesTypeHintsProvider()) { + val fileContents = FileUtil.loadFile(File(fileName), true) + val settings = createSettings() + with(settings) { + when (InTextDirectivesUtils.findStringWithPrefixes(fileContents, "// MODE: ")) { + "function_return" -> set(functionReturn = true) + "local_variable" -> set(localVariable = true) + "parameter" -> set(parameter = true) + "property" -> set(property = true) + "all" -> set(functionReturn = true, localVariable = true, parameter = true, property = true) + else -> set() + } + } + + testProvider("KotlinReferencesTypeHintsProvider.kt", fileContents, this, settings) + } + } + + private fun KotlinReferencesTypeHintsProvider.Settings.set( + functionReturn: Boolean = false, localVariable: Boolean = false, + parameter: Boolean = false, property: Boolean = false + ) { + this.functionReturnType = functionReturn + this.localVariableType = localVariable + this.parameterType = parameter + this.propertyType = property + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java new file mode 100644 index 00000000000..6b38c92c6f5 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java @@ -0,0 +1,185 @@ +/* + * Copyright 2010-2020 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. + */ + +package org.jetbrains.kotlin.idea.codeInsight.hints; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/codeInsight/hints/types") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class KotlinReferenceTypeHintsProviderTestGenerated extends AbstractKotlinReferenceTypeHintsProviderTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInTypes() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/codeInsight/hints/types"), Pattern.compile("^(.+)\\.kt$"), null, true); + } + + @TestMetadata("AnonymousObject.kt") + public void testAnonymousObject() throws Exception { + runTest("idea/testData/codeInsight/hints/types/AnonymousObject.kt"); + } + + @TestMetadata("AnonymousObjectNoBaseType.kt") + public void testAnonymousObjectNoBaseType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/AnonymousObjectNoBaseType.kt"); + } + + @TestMetadata("ConstInitializerType.kt") + public void testConstInitializerType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ConstInitializerType.kt"); + } + + @TestMetadata("ConstructorWithExplicitTypeParametersType.kt") + public void testConstructorWithExplicitTypeParametersType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ConstructorWithExplicitTypeParametersType.kt"); + } + + @TestMetadata("ConstructorWithoutExplicitTypeParametersType.kt") + public void testConstructorWithoutExplicitTypeParametersType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ConstructorWithoutExplicitTypeParametersType.kt"); + } + + @TestMetadata("ConstructorWithoutTypeParametersType.kt") + public void testConstructorWithoutTypeParametersType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ConstructorWithoutTypeParametersType.kt"); + } + + @TestMetadata("DestructingType.kt") + public void testDestructingType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/DestructingType.kt"); + } + + @TestMetadata("Destructuring.kt") + public void testDestructuring() throws Exception { + runTest("idea/testData/codeInsight/hints/types/Destructuring.kt"); + } + + @TestMetadata("EnumEntry.kt") + public void testEnumEntry() throws Exception { + runTest("idea/testData/codeInsight/hints/types/EnumEntry.kt"); + } + + @TestMetadata("EnumEntryCompanion.kt") + public void testEnumEntryCompanion() throws Exception { + runTest("idea/testData/codeInsight/hints/types/EnumEntryCompanion.kt"); + } + + @TestMetadata("EnumEntryLikeFunction.kt") + public void testEnumEntryLikeFunction() throws Exception { + runTest("idea/testData/codeInsight/hints/types/EnumEntryLikeFunction.kt"); + } + + @TestMetadata("EnumEntryLikeProperty.kt") + public void testEnumEntryLikeProperty() throws Exception { + runTest("idea/testData/codeInsight/hints/types/EnumEntryLikeProperty.kt"); + } + + @TestMetadata("EnumEntryQualified.kt") + public void testEnumEntryQualified() throws Exception { + runTest("idea/testData/codeInsight/hints/types/EnumEntryQualified.kt"); + } + + @TestMetadata("ErrorType.kt") + public void testErrorType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ErrorType.kt"); + } + + @TestMetadata("ExpandedTypeAlias.kt") + public void testExpandedTypeAlias() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ExpandedTypeAlias.kt"); + } + + @TestMetadata("ImportedEnumEntry.kt") + public void testImportedEnumEntry() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ImportedEnumEntry.kt"); + } + + @TestMetadata("LocalVariable.kt") + public void testLocalVariable() throws Exception { + runTest("idea/testData/codeInsight/hints/types/LocalVariable.kt"); + } + + @TestMetadata("LoopParameter.kt") + public void testLoopParameter() throws Exception { + runTest("idea/testData/codeInsight/hints/types/LoopParameter.kt"); + } + + @TestMetadata("LoopParameterWithExplicitType.kt") + public void testLoopParameterWithExplicitType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/LoopParameterWithExplicitType.kt"); + } + + @TestMetadata("NestedClassImports.kt") + public void testNestedClassImports() throws Exception { + runTest("idea/testData/codeInsight/hints/types/NestedClassImports.kt"); + } + + @TestMetadata("NestedClassWithoutImport.kt") + public void testNestedClassWithoutImport() throws Exception { + runTest("idea/testData/codeInsight/hints/types/NestedClassWithoutImport.kt"); + } + + @TestMetadata("ParameterType.kt") + public void testParameterType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/ParameterType.kt"); + } + + @TestMetadata("PropertyType.kt") + public void testPropertyType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/PropertyType.kt"); + } + + @TestMetadata("QualifiedReferences.kt") + public void testQualifiedReferences() throws Exception { + runTest("idea/testData/codeInsight/hints/types/QualifiedReferences.kt"); + } + + @TestMetadata("SAMConstructor.kt") + public void testSAMConstructor() throws Exception { + runTest("idea/testData/codeInsight/hints/types/SAMConstructor.kt"); + } + + @TestMetadata("TypeInCompanion.kt") + public void testTypeInCompanion() throws Exception { + runTest("idea/testData/codeInsight/hints/types/TypeInCompanion.kt"); + } + + @TestMetadata("TypeInNonDefaultCompanion.kt") + public void testTypeInNonDefaultCompanion() throws Exception { + runTest("idea/testData/codeInsight/hints/types/TypeInNonDefaultCompanion.kt"); + } + + @TestMetadata("UnaryConstInitializerType.kt") + public void testUnaryConstInitializerType() throws Exception { + runTest("idea/testData/codeInsight/hints/types/UnaryConstInitializerType.kt"); + } + + @TestMetadata("UnitLocalVariable.kt") + public void testUnitLocalVariable() throws Exception { + runTest("idea/testData/codeInsight/hints/types/UnitLocalVariable.kt"); + } + + @TestMetadata("UnitLocalVariable2.kt") + public void testUnitLocalVariable2() throws Exception { + runTest("idea/testData/codeInsight/hints/types/UnitLocalVariable2.kt"); + } + + @TestMetadata("UnitLocalVariable3.kt") + public void testUnitLocalVariable3() throws Exception { + runTest("idea/testData/codeInsight/hints/types/UnitLocalVariable3.kt"); + } +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt deleted file mode 100644 index 1edc6ce9dad..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/InlayTypeHintsTest.kt +++ /dev/null @@ -1,305 +0,0 @@ -/* - * 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. - */ - -package org.jetbrains.kotlin.idea.parameterInfo - -import org.jetbrains.kotlin.idea.codeInsight.hints.HintType -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase -import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner -import org.junit.runner.RunWith - -@RunWith(JUnit3WithIdeaConfigurationRunner::class) -class InlayTypeHintsTest : KotlinLightCodeInsightFixtureTestCase() { - override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE - - fun check(text: String) { - myFixture.configureByText("A.kt", text) - myFixture.testInlays() - } - - fun check(text: String, hintType: HintType) { - hintType.option.set(true) - check(text) - } - - private fun checkLocalVariable(text: String) = check(text.trimIndent(), HintType.LOCAL_VARIABLE_HINT) - private fun checkPropertyHint(text: String) = check(text.trimIndent(), HintType.PROPERTY_HINT) - private fun checkFunctionHint(text: String) = check(text, HintType.FUNCTION_HINT) - private fun checkParameterTypeHint(text: String) = check(text, HintType.PARAMETER_TYPE_HINT) - - fun testLocalVariableType() { - checkLocalVariable("""fun foo() { val a = listOf("a") }""") - } - - fun testDestructuringType() { - checkLocalVariable("""fun foo() { val (i, s) = 1 to "" }""") - } - - fun testQualifiedReferences() { - checkLocalVariable( - """ - package p - class A { - class B { - class C { - class D - } - } - inner class E - enum class F { enumCase } - } - fun foo() { - val v1 = A.B.C.D() - val v2 = p.A.B.C.D() - val v3 = A().E() - val v4 = p.A.F.enumCase - val v5 = A.F.enumCase - val v6 = p.A() - } - """ - ) - } - - fun testPropertyType() { - checkPropertyHint("""val a = listOf("a")""") - } - - fun testConstInitializerType() { - checkPropertyHint("""val a = 1""") - } - - fun testUnaryConstInitializerType() { - checkPropertyHint("""val a = -1; val b = +1""") - } - - fun testConstructorWithoutTypeParametersType() { - checkPropertyHint("""val a = Any()""") - } - - fun testConstructorWithExplicitTypeParametersType() { - checkPropertyHint("""class Bar; val a = Bar()""") - } - - fun testConstructorWithoutExplicitTypeParametersType() { - checkPropertyHint("""class Bar(val t: T); val a = Bar("")""") - } - - fun testLoopParameter() { - checkLocalVariable("""fun foo() { for (x in listOf("a")) { } }""") - } - - fun testLoopParameterWithExplicitType() { - checkLocalVariable("""fun foo() { for (x: String in listOf("a")) { } }""") - } - - fun testErrorType() { - checkPropertyHint("""val x = arrayListOf<>()""") - } - - fun testExpandedTypeAlias() { - checkPropertyHint("""val x = arrayListOf(1)""") - } - - fun testAnonymousObject() { - checkFunctionHint( - """ - val o = object : Iterable { - override fun iterator() = object : Iterator { - override fun next() = 1 - override fun hasNext() = true - } - } - """.trimIndent() - ) - } - - fun testAnonymousObjectNoBaseType() { - checkLocalVariable( - """ - fun foo() { - val o = object { - val x: Int = 0 - } - } - """ - ) - } - - fun testEnumEntry() { - checkPropertyHint( - """ - enum class E { ENTRY } - val test = E.ENTRY - """ - ) - } - - fun testEnumEntryLikeProperty() { - checkPropertyHint( - """ - enum class E { - ENTRY; - companion object { - val test: E = ENTRY - } - } - - val test = E.test - """ - ) - } - - fun testEnumEntryLikeFunction() { - checkPropertyHint( - """ - enum class E { ENTRY; - companion object { - fun test(): E = ENTRY - } - } - - val test = E.test() - """ - ) - } - - fun testImportedEnumEntry() { - checkPropertyHint( - """ - import E.ENTRY - enum class E { ENTRY } - val test = ENTRY - """ - ) - } - - fun testEnumEntryCompanion() { - checkPropertyHint( - """ - enum class E { - ENTRY; - companion object {} - } - val test = E.Companion - """ - ) - } - - fun testEnumEntryQualified() { - checkPropertyHint( - """ - package a - enum class E { ENTRY } - val test = a.E.ENTRY - """ - ) - } - - fun testDestructuring() { - checkLocalVariable( - """ - fun main(args: Array) { - val (a: String, b: String, c: String) = x() - } - - fun x() :Triple { - return Triple("A", "B", "C") - } - """ - ) - } - - fun testSAMConstructor() { - checkPropertyHint("""val x = Runnable { }""") - } - - fun testNestedClassImports() { - checkPropertyHint( - """import kotlin.collections.Map.Entry - val entries = mapOf(1 to "1").entries""" - ) - } - - fun testNestedClassWithoutImport() { - checkPropertyHint( - """val entries = mapOf(1 to "1").entries""" - ) - } - - fun testTypeInCompanion() { - checkPropertyHint( - """ - class A { - companion object { - class InA - fun provideInA() = InA() - } - } - val inA = A.provideInA() - """ - ) - } - - fun testTypeInNonDefaultCompanion() { - checkPropertyHint( - """ - class A { - companion object N { - class InA - fun provideInA() = InA() - } - } - val inA = A.provideInA() - """ - ) - } - - fun testUnitLocalVariable() { - checkLocalVariable( - """ - fun foo() { - val x = - - println("Foo") - } - """ - ) - } - - fun testUnitLocalVariable2() { - checkLocalVariable( - """ - fun foo() { - val x = - println("Foo") - } - """ - ) - } - - fun testUnitLocalVariable3() { - checkLocalVariable( - """ - fun foo() { - val x = println("Foo") - } - """ - ) - } - - fun testParameterType() { - checkParameterTypeHint( - """ - fun T.wrap(lambda: (T) -> T) {} - fun foo() { - 12.wrap { elem -> - elem - } - } - """ - ) - } -}