203: Fix compilation

This commit is contained in:
Florian Kistner
2020-08-31 17:10:20 +02:00
parent 9d12df28c1
commit 9775a2148a
26 changed files with 2709 additions and 21 deletions
@@ -20,16 +20,10 @@ import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest;
public abstract class KotlinCodeInsightTestCase extends CodeInsightTestCase {
@Override
protected void setUp() throws Exception {
VfsRootAccess.allowRootAccess(KotlinTestUtils.getHomeDirectory());
VfsRootAccess.allowRootAccess(getTestRootDisposable(), KotlinTestUtils.getHomeDirectory());
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory());
}
@Override
protected void runTestRunnable(@NotNull ThrowableRunnable<Throwable> testRunnable) throws Throwable {
KotlinTestUtils.runTestWithThrowable(this, () -> super.runTestRunnable(testRunnable));
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.test
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
import com.intellij.util.ThrowableRunnable
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestMetadata
import java.io.File
import kotlin.reflect.full.findAnnotation
abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCodeInsightFixtureTestCase() {
protected open fun isFirPlugin(): Boolean = false
override fun setUp() {
super.setUp()
enableKotlinOfficialCodeStyle(project)
runPostStartupActivitiesOnce(project)
VfsRootAccess.allowRootAccess(testRootDisposable, KotlinTestUtils.getHomeDirectory())
if (!isFirPlugin()) {
invalidateLibraryCache(project)
}
}
override fun tearDown() = runAll(
ThrowableRunnable { disableKotlinOfficialCodeStyle(project) },
ThrowableRunnable { super.tearDown() },
)
protected fun testDataFile(fileName: String): File = File(testDataPath, fileName)
protected fun testDataFile(): File = testDataFile(fileName())
protected fun testPath(fileName: String = fileName()): String = testDataFile(fileName).toString()
protected fun testPath(): String = testPath(fileName())
protected open fun fileName(): String = KotlinTestUtils.getTestDataFileName(this::class.java, this.name) ?: (getTestName(false) + ".kt")
override fun getTestDataPath(): String = this::class.findAnnotation<TestMetadata>()?.value ?: super.getTestDataPath()
}
@@ -0,0 +1,76 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.test
import com.intellij.ide.highlighter.ModuleFileType
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileVisitor
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.psi.PsiDocumentManager
import com.intellij.refactoring.MultiFileTestCase
import com.intellij.testFramework.PsiTestUtil
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.test.KotlinTestUtils
abstract class KotlinMultiFileTestCase : MultiFileTestCase() {
protected var isMultiModule = false
override fun setUp() {
super.setUp()
VfsRootAccess.allowRootAccess(testRootDisposable, KotlinTestUtils.getHomeDirectory())
runWriteAction {
PluginTestCaseBase.addJdk(testRootDisposable, PluginTestCaseBase::mockJdk6)
ProjectRootManager.getInstance(project).projectSdk = PluginTestCaseBase.mockJdk6()
}
}
protected fun getTestDirName(lowercaseFirstLetter: Boolean): String {
val testName = getTestName(lowercaseFirstLetter)
val endIndex = testName.lastIndexOf('_')
if (endIndex < 0) return testName
return testName.substring(0, endIndex).replace('_', '/')
}
protected fun doTestCommittingDocuments(action: (VirtualFile, VirtualFile?) -> Unit) {
super.doTest(
{ rootDir, rootAfter ->
action(rootDir, rootAfter)
PsiDocumentManager.getInstance(project!!).commitAllDocuments()
FileDocumentManager.getInstance().saveAllDocuments()
}, getTestDirName(true)
)
}
override fun prepareProject(rootDir: VirtualFile) {
if (isMultiModule) {
val model = ModuleManager.getInstance(project).modifiableModel
VfsUtilCore.visitChildrenRecursively(
rootDir,
object : VirtualFileVisitor<Any>() {
override fun visitFile(file: VirtualFile): Boolean {
if (!file.isDirectory && file.name.endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) {
model.loadModule(file.path)
return false
}
return true
}
}
)
runWriteAction { model.commit() }
} else {
PsiTestUtil.addSourceContentToRoots(myModule, rootDir)
}
}
}