Switch to 181 platform
This commit is contained in:
@@ -16,8 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.asJava
|
||||
|
||||
import com.intellij.injected.editor.EditorWindow
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.asJava.elements.KtLightElement
|
||||
import org.jetbrains.kotlin.idea.core.copied
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
@@ -72,4 +78,58 @@ class KtFileLightClassTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
override fun getTestDataPath(): String {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/asJava/fileLightClass/"
|
||||
}
|
||||
|
||||
fun testInjectedCode() {
|
||||
myFixture.configureByText("foo.kt", """
|
||||
import org.intellij.lang.annotations.Language
|
||||
|
||||
fun foo(@Language("kotlin") a: String){a.toString()}
|
||||
|
||||
fun bar(){ foo("class<caret> A") }
|
||||
""")
|
||||
|
||||
|
||||
myFixture.testHighlighting("foo.kt")
|
||||
|
||||
val injectedFile = (editor as? EditorWindow)?.injectedFile
|
||||
assertEquals("Wrong injection language", "kotlin", injectedFile?.language?.id)
|
||||
assertEquals("Injected class should be `A`", "A", (injectedFile as KtFile).classes.single().name)
|
||||
}
|
||||
|
||||
|
||||
fun testSameVirtualFileForLightElement() {
|
||||
|
||||
val psiFile = myFixture.addFileToProject(
|
||||
"pkg/AnnotatedClass.kt", """
|
||||
package pkg
|
||||
|
||||
class AnnotatedClass {
|
||||
@Deprecated("a")
|
||||
fun bar(param: String) = null
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
fun lightElement(file: PsiFile): PsiElement = (file as KtFile).classes.single()
|
||||
.methods.first { it.name == "bar" }
|
||||
.annotations.first { it.qualifiedName == "kotlin.Deprecated" }.also {
|
||||
// Otherwise following asserts have no sense
|
||||
TestCase.assertTrue("psi element should be light ", it is KtLightElement<*, *>)
|
||||
}
|
||||
|
||||
|
||||
val copied = psiFile.copied()
|
||||
TestCase.assertNull("virtual file for copy should be null", copied.virtualFile)
|
||||
TestCase.assertNotNull("psi element in copy", lightElement(copied))
|
||||
TestCase.assertSame("copy.originalFile should be psiFile", copied.originalFile, psiFile)
|
||||
|
||||
// virtual files should be the same for light and non-light element,
|
||||
// otherwise we will not be able to find proper module by file from light element
|
||||
TestCase.assertSame(
|
||||
"virtualFiles of element and file itself should be the same",
|
||||
lightElement(copied).containingFile.originalFile.virtualFile,
|
||||
copied.originalFile.virtualFile
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user