Refactoring: use language injection in ResolveElementCache.kt
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea
|
package org.jetbrains.kotlin.idea
|
||||||
|
|
||||||
import com.intellij.psi.PsiDocumentManager
|
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.analyze
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|||||||
class ResolveElementCacheTest : KotlinLightCodeInsightFixtureTestCase() {
|
class ResolveElementCacheTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE
|
override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE
|
||||||
|
|
||||||
|
//language=kotlin
|
||||||
private val FILE_TEXT =
|
private val FILE_TEXT =
|
||||||
"""
|
"""
|
||||||
class C(param1: String = "", param2: Int = 0) {
|
class C(param1: String = "", param2: Int = 0) {
|
||||||
@@ -269,10 +271,11 @@ class C(param1: String = "", param2: Int = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testAnnotationEntry() {
|
fun testAnnotationEntry() {
|
||||||
val file = myFixture.configureByText("Test.kt", """
|
val file = configureWithKotlin(
|
||||||
annotation class A
|
"""
|
||||||
@A class B {}
|
annotation class A
|
||||||
""") as KtFile
|
@A class B {}
|
||||||
|
""")
|
||||||
|
|
||||||
val klass = file.declarations[1] as KtClass
|
val klass = file.declarations[1] as KtClass
|
||||||
val annotationEntry = klass.annotationEntries.single()
|
val annotationEntry = klass.annotationEntries.single()
|
||||||
@@ -282,10 +285,11 @@ class C(param1: String = "", param2: Int = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testFileAnnotationList() {
|
fun testFileAnnotationList() {
|
||||||
val file = myFixture.configureByText("Test.kt", """
|
val file = configureWithKotlin(
|
||||||
@file:Suppress("Some")
|
"""
|
||||||
@file:JvmName("Hi")
|
@file:Suppress("Some")
|
||||||
""") as KtFile
|
@file:JvmName("Hi")
|
||||||
|
""")
|
||||||
|
|
||||||
val fileAnnotationList = file.fileAnnotationList!!
|
val fileAnnotationList = file.fileAnnotationList!!
|
||||||
val context = fileAnnotationList.analyze(BodyResolveMode.PARTIAL)
|
val context = fileAnnotationList.analyze(BodyResolveMode.PARTIAL)
|
||||||
@@ -304,9 +308,10 @@ class C(param1: String = "", param2: Int = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testNamedParametersInFunctionType() {
|
fun testNamedParametersInFunctionType() {
|
||||||
val file = myFixture.configureByText("Test.kt", """
|
val file = configureWithKotlin(
|
||||||
fun <K, V> intercept(block: (key: K, next: (K) -> V, K) -> V) {}
|
"""
|
||||||
""") as KtFile
|
fun <K, V> intercept(block: (key: K, next: (K) -> V, K) -> V) {}
|
||||||
|
""")
|
||||||
|
|
||||||
val function = file.declarations[0] as KtNamedFunction
|
val function = file.declarations[0] as KtNamedFunction
|
||||||
val functionType = function.valueParameters.first().typeReference!!.typeElement as KtFunctionType
|
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() }
|
descriptorsForParameters.map { it.name.asString() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun configureWithKotlin(@Language("kotlin") text: String): KtFile {
|
||||||
|
return myFixture.configureByText("Test.kt", text.trimIndent()) as KtFile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user