From 73024429dcb3d50e2a338f596732e6199ef705f2 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 27 Apr 2016 16:13:30 +0300 Subject: [PATCH] Refactoring: use language injection in ResolveElementCache.kt --- .../kotlin/idea/ResolveElementCacheTest.kt | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt index 9b0115e7976..92cec8bb128 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/ResolveElementCacheTest.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.idea import com.intellij.psi.PsiDocumentManager +import org.intellij.lang.annotations.Language import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase @@ -31,6 +32,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode class ResolveElementCacheTest : KotlinLightCodeInsightFixtureTestCase() { override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE + //language=kotlin private val FILE_TEXT = """ class C(param1: String = "", param2: Int = 0) { @@ -269,10 +271,11 @@ class C(param1: String = "", param2: Int = 0) { } fun testAnnotationEntry() { - val file = myFixture.configureByText("Test.kt", """ - annotation class A - @A class B {} - """) as KtFile + val file = configureWithKotlin( + """ + annotation class A + @A class B {} + """) val klass = file.declarations[1] as KtClass val annotationEntry = klass.annotationEntries.single() @@ -282,10 +285,11 @@ class C(param1: String = "", param2: Int = 0) { } fun testFileAnnotationList() { - val file = myFixture.configureByText("Test.kt", """ - @file:Suppress("Some") - @file:JvmName("Hi") - """) as KtFile + val file = configureWithKotlin( + """ + @file:Suppress("Some") + @file:JvmName("Hi") + """) val fileAnnotationList = file.fileAnnotationList!! val context = fileAnnotationList.analyze(BodyResolveMode.PARTIAL) @@ -304,9 +308,10 @@ class C(param1: String = "", param2: Int = 0) { } fun testNamedParametersInFunctionType() { - val file = myFixture.configureByText("Test.kt", """ - fun intercept(block: (key: K, next: (K) -> V, K) -> V) {} - """) as KtFile + val file = configureWithKotlin( + """ + fun intercept(block: (key: K, next: (K) -> V, K) -> V) {} + """) val function = file.declarations[0] as KtNamedFunction val functionType = function.valueParameters.first().typeReference!!.typeElement as KtFunctionType @@ -317,4 +322,8 @@ class C(param1: String = "", param2: Int = 0) { descriptorsForParameters.map { it.name.asString() } ) } + + private fun configureWithKotlin(@Language("kotlin") text: String): KtFile { + return myFixture.configureByText("Test.kt", text.trimIndent()) as KtFile + } }