mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
GitOrigin-RevId: a5474db29889f37d01e583fd1ad27e899f0ce331
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0f0df38d0f
commit
4829584d9f
@@ -5,12 +5,12 @@ import com.intellij.ide.plugins.loadExtensionWithText
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.openapi.fileTypes.PlainTextLanguage
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.use
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.LanguageSubstitutor
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
|
||||
class LanguageSubstitutorLoadUnloadTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
fun testBefore() {
|
||||
@@ -19,24 +19,21 @@ class LanguageSubstitutorLoadUnloadTest : LightJavaCodeInsightFixtureTestCase()
|
||||
|
||||
fun testLoadUnload() {
|
||||
val beforeLoading = myFixture.configureByText("dummy.txt", "package hello;")
|
||||
UsefulTestCase.assertInstanceOf(beforeLoading.language, PlainTextLanguage::class.java)
|
||||
assertThat(beforeLoading.language).isInstanceOf(PlainTextLanguage::class.java)
|
||||
|
||||
val virtualFile = beforeLoading.virtualFile
|
||||
val text = "<lang.substitutor language=\"TEXT\" implementationClass=\"${TextToJavaSubstitutor::class.java.name}\"/>"
|
||||
val disposable = loadExtensionWithText(text, javaClass.classLoader)
|
||||
val psiManager = PsiManager.getInstance(myFixture.project)
|
||||
val afterLoading = psiManager.findFile(virtualFile)
|
||||
UsefulTestCase.assertInstanceOf(afterLoading!!.language, JavaLanguage::class.java)
|
||||
|
||||
Disposer.dispose(disposable)
|
||||
val afterUnloading = psiManager.findFile(virtualFile)
|
||||
UsefulTestCase.assertInstanceOf(afterUnloading!!.language, PlainTextLanguage::class.java)
|
||||
}
|
||||
|
||||
private class TextToJavaSubstitutor : LanguageSubstitutor() {
|
||||
override fun getLanguage(file: VirtualFile,
|
||||
project: Project): Language? {
|
||||
return if (file.name.startsWith("dummy")) JavaLanguage.INSTANCE else null
|
||||
loadExtensionWithText(text, javaClass.classLoader).use {
|
||||
val afterLoading = PsiManager.getInstance(myFixture.project).findFile(virtualFile)
|
||||
assertThat(afterLoading!!.language).isInstanceOf(JavaLanguage::class.java)
|
||||
}
|
||||
val afterUnloading = psiManager.findFile(virtualFile)
|
||||
assertThat(afterUnloading!!.language).isInstanceOf(PlainTextLanguage::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private class TextToJavaSubstitutor : LanguageSubstitutor() {
|
||||
override fun getLanguage(file: VirtualFile, project: Project): Language? {
|
||||
return if (file.name.startsWith("dummy")) JavaLanguage.INSTANCE else null
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.util
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
@@ -18,10 +18,13 @@ fun <A : Any, B : Any> Pair<A?, B?>.toNotNull(): kotlin.Pair<A, B> = requireNotN
|
||||
* @see kotlin.io.use
|
||||
* @see Disposer.dispose
|
||||
*/
|
||||
inline fun <T : Disposable?, R> T.use(block: (T) -> R): R =
|
||||
inline fun <T : Disposable?, R> T.use(block: (T) -> R): R {
|
||||
try {
|
||||
block(this)
|
||||
return block(this)
|
||||
}
|
||||
finally {
|
||||
if (this != null) Disposer.dispose(this)
|
||||
if (this != null) {
|
||||
Disposer.dispose(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user