Refactoring: use language injection in ResolveElementCache.kt

This commit is contained in:
Nikolay Krasko
2016-04-27 16:13:30 +03:00
parent 62ede15241
commit 73024429dc
@@ -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 <K, V> intercept(block: (key: K, next: (K) -> V, K) -> V) {}
""") as KtFile
val file = configureWithKotlin(
"""
fun <K, V> 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
}
}