KT-32368 Rework Inline hints settings // migrate tests for types
KotlinReferencesTypeHintsProvider which in now responsible for type hints is not compatible with the existing InlayTypeHintsTest. Because of that tests were migrated to the new infrastructure.
This commit is contained in:
@@ -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<String>) {
|
||||
model("codeInsight/hints/suspending")
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinReferenceTypeHintsProviderTest> {
|
||||
model("codeInsight/hints/types")
|
||||
}
|
||||
|
||||
testClass<AbstractScriptConfigurationHighlightingTest> {
|
||||
model("script/definition/highlighting", extension = null, recursive = false)
|
||||
model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest")
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// MODE: function_return
|
||||
val o = object : Iterable<Int> {
|
||||
override fun iterator()<# : Iterator<Int> #> = object : Iterator<Int> {
|
||||
override fun next()<# : Int #> = 1
|
||||
override fun hasNext()<# : Boolean #> = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// MODE: all
|
||||
fun foo() {
|
||||
val o = object {
|
||||
val x: Int = 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
val a = 1
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
class Bar<T>; val a = Bar<String>()
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
// MODE: property
|
||||
class Bar<T>(val t: T); val a<# : Bar<String> #> = Bar("")
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
val a = Any()
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: local_variable
|
||||
fun foo() { val (i<# : Int #>, s<# : String #>) = 1 to "" }
|
||||
@@ -0,0 +1,9 @@
|
||||
// MODE: all
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val (a: String, b: String, c: String) = x()
|
||||
}
|
||||
|
||||
fun x() :Triple<String, String,String> {
|
||||
return Triple("A", "B", "C")
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// MODE: all
|
||||
enum class E { ENTRY }
|
||||
val test = E.ENTRY
|
||||
@@ -0,0 +1,7 @@
|
||||
// MODE: property
|
||||
|
||||
enum class E {
|
||||
ENTRY;
|
||||
companion object {}
|
||||
}
|
||||
val test<# : E# > = E.Companion
|
||||
@@ -0,0 +1,8 @@
|
||||
// MODE: property
|
||||
enum class E { ENTRY;
|
||||
companion object {
|
||||
fun test(): E = ENTRY
|
||||
}
|
||||
}
|
||||
|
||||
val test<# : E# > = E.test()
|
||||
@@ -0,0 +1,10 @@
|
||||
// MODE: property
|
||||
enum class E {
|
||||
ENTRY;
|
||||
companion object {
|
||||
val test: E = ENTRY
|
||||
}
|
||||
}
|
||||
|
||||
val test<# : E# > = E.test
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// MODE: all
|
||||
package a
|
||||
enum class E { ENTRY }
|
||||
val test = a.E.ENTRY
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
val x = arrayListOf<>()
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: property
|
||||
val x<# : ArrayList<Int> #> = arrayListOf(1)
|
||||
@@ -0,0 +1,4 @@
|
||||
// MODE: property
|
||||
import E.ENTRY
|
||||
enum class E { ENTRY }
|
||||
val test<# : E# > = ENTRY
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: local_variable
|
||||
fun foo() { val a<# : List<String> #> = listOf("a") }
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: local_variable
|
||||
fun foo() { for (x<# : String #> in listOf("a")) { } }
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
fun foo() { for (x: String in listOf("a")) { } }
|
||||
@@ -0,0 +1,3 @@
|
||||
// MODE: property
|
||||
import kotlin.collections.Map.Entry
|
||||
val entries<# : Set<Entry<Int, String>> #> = mapOf(1 to "1").entries
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: property
|
||||
val entries<# : Set<Map.Entry<Int, String>> #> = mapOf(1 to "1").entries
|
||||
@@ -0,0 +1,7 @@
|
||||
// MODE: parameter
|
||||
fun <T> T.wrap(lambda: (T) -> T) {}
|
||||
fun foo() {
|
||||
12.wrap { elem<# : Int #> ->
|
||||
elem
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: property
|
||||
val a<# : List<String> #> = listOf("a")
|
||||
@@ -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()
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
val x = Runnable { }
|
||||
@@ -0,0 +1,8 @@
|
||||
// MODE: property
|
||||
class A {
|
||||
companion object {
|
||||
class InA
|
||||
fun provideInA() = InA()
|
||||
}
|
||||
}
|
||||
val inA<# : A.InA# > = A.provideInA()
|
||||
@@ -0,0 +1,8 @@
|
||||
// MODE: property
|
||||
class A {
|
||||
companion object N {
|
||||
class InA
|
||||
fun provideInA() = InA()
|
||||
}
|
||||
}
|
||||
val inA<# : A.N.InA #> = A.provideInA()
|
||||
@@ -0,0 +1,2 @@
|
||||
// MODE: all
|
||||
val a = -1; val b = +1
|
||||
@@ -0,0 +1,6 @@
|
||||
// MODE: local_variable
|
||||
fun foo() {
|
||||
val x =
|
||||
// indent is the same: declaration & initialization
|
||||
println("Foo")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// MODE: all
|
||||
fun foo() {
|
||||
val x<# : Unit #> =
|
||||
println("Foo") // indent differs
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// MODE: local_variable
|
||||
fun foo() {
|
||||
val x<# : Unit #> = println("Foo")
|
||||
}
|
||||
+55
@@ -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
|
||||
}
|
||||
}
|
||||
+185
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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<hint text=": List<String>" /> = listOf("a") }""")
|
||||
}
|
||||
|
||||
fun testDestructuringType() {
|
||||
checkLocalVariable("""fun foo() { val (i<hint text=": Int" />, s<hint text=": String" />) = 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<hint text=": A.E"/> = A().E()
|
||||
val v4 = p.A.F.enumCase
|
||||
val v5 = A.F.enumCase
|
||||
val v6 = p.A()
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testPropertyType() {
|
||||
checkPropertyHint("""val a<hint text=": List<String>" /> = 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<T>; val a = Bar<String>()""")
|
||||
}
|
||||
|
||||
fun testConstructorWithoutExplicitTypeParametersType() {
|
||||
checkPropertyHint("""class Bar<T>(val t: T); val a<hint text=": Bar<String>" /> = Bar(<hint text="t:" />"")""")
|
||||
}
|
||||
|
||||
fun testLoopParameter() {
|
||||
checkLocalVariable("""fun foo() { for (x<hint text=": String" /> 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<hint text=": ArrayList<Int>" /> = arrayListOf(1)""")
|
||||
}
|
||||
|
||||
fun testAnonymousObject() {
|
||||
checkFunctionHint(
|
||||
"""
|
||||
val o = object : Iterable<Int> {
|
||||
override fun iterator()<hint text=": Iterator<Int>" /> = object : Iterator<Int> {
|
||||
override fun next()<hint text=": Int" /> = 1
|
||||
override fun hasNext()<hint text=": Boolean" /> = 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<hint text=": E"/> = E.test
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testEnumEntryLikeFunction() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
enum class E { ENTRY;
|
||||
companion object {
|
||||
fun test(): E = ENTRY
|
||||
}
|
||||
}
|
||||
|
||||
val test<hint text=": E"/> = E.test()
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testImportedEnumEntry() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
import E.ENTRY
|
||||
enum class E { ENTRY }
|
||||
val test<hint text=": E"/> = ENTRY
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testEnumEntryCompanion() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
enum class E {
|
||||
ENTRY;
|
||||
companion object {}
|
||||
}
|
||||
val test<hint text=": E"/> = E.Companion
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testEnumEntryQualified() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
package a
|
||||
enum class E { ENTRY }
|
||||
val test = a.E.ENTRY
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testDestructuring() {
|
||||
checkLocalVariable(
|
||||
"""
|
||||
fun main(args: Array<String>) {
|
||||
val (a: String, b: String, c: String) = x()
|
||||
}
|
||||
|
||||
fun x() :Triple<String, String,String> {
|
||||
return Triple(<hint text="first:" />"A", <hint text="second:" />"B", <hint text="third:" />"C")
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testSAMConstructor() {
|
||||
checkPropertyHint("""val x = Runnable { }""")
|
||||
}
|
||||
|
||||
fun testNestedClassImports() {
|
||||
checkPropertyHint(
|
||||
"""import kotlin.collections.Map.Entry
|
||||
val entries<hint text=": Set<Entry<Int, String>>" /> = mapOf(1 to "1").entries"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testNestedClassWithoutImport() {
|
||||
checkPropertyHint(
|
||||
"""val entries<hint text=": Set<Map.Entry<Int, String>>" /> = mapOf(1 to "1").entries"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testTypeInCompanion() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
class A {
|
||||
companion object {
|
||||
class InA
|
||||
fun provideInA() = InA()
|
||||
}
|
||||
}
|
||||
val inA<hint text=": A.InA"/> = A.provideInA()
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testTypeInNonDefaultCompanion() {
|
||||
checkPropertyHint(
|
||||
"""
|
||||
class A {
|
||||
companion object N {
|
||||
class InA
|
||||
fun provideInA() = InA()
|
||||
}
|
||||
}
|
||||
val inA<hint text=": A.N.InA"/> = A.provideInA()
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testUnitLocalVariable() {
|
||||
checkLocalVariable(
|
||||
"""
|
||||
fun foo() {
|
||||
val x =
|
||||
|
||||
println("Foo")
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testUnitLocalVariable2() {
|
||||
checkLocalVariable(
|
||||
"""
|
||||
fun foo() {
|
||||
val x<hint text=": Unit"/> =
|
||||
println("Foo")
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testUnitLocalVariable3() {
|
||||
checkLocalVariable(
|
||||
"""
|
||||
fun foo() {
|
||||
val x<hint text=": Unit"/> = println("Foo")
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
|
||||
fun testParameterType() {
|
||||
checkParameterTypeHint(
|
||||
"""
|
||||
fun <T> T.wrap(lambda: (T) -> T) {}
|
||||
fun foo() {
|
||||
12.wrap { elem<hint text=": Int"/> ->
|
||||
elem
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user