Fix performanceTests compilation errors
This commit is contained in:
+1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
|
|||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
import org.jetbrains.kotlin.idea.test.configureCompilerOptions
|
||||||
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|||||||
+1
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType
|
|||||||
import org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider
|
import org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
|
||||||
|
|||||||
+1
@@ -10,6 +10,7 @@ import com.intellij.openapi.application.runWriteAction
|
|||||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.ensureIndexesUpToDate
|
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.ensureIndexesUpToDate
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inspired by @see AbstractHighlightingTest
|
* inspired by @see AbstractHighlightingTest
|
||||||
|
|||||||
+1
-1
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.idea.perf
|
|||||||
import com.intellij.ide.highlighter.JavaFileType
|
import com.intellij.ide.highlighter.JavaFileType
|
||||||
import com.intellij.openapi.actionSystem.IdeActions
|
import com.intellij.openapi.actionSystem.IdeActions
|
||||||
import com.intellij.openapi.application.runWriteAction
|
import com.intellij.openapi.application.runWriteAction
|
||||||
import com.intellij.openapi.util.registry.Registry
|
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.idea.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest
|
import org.jetbrains.kotlin.idea.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest
|
||||||
import org.jetbrains.kotlin.idea.conversion.copy.ConvertJavaCopyPasteProcessor
|
import org.jetbrains.kotlin.idea.conversion.copy.ConvertJavaCopyPasteProcessor
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments
|
||||||
import org.jetbrains.kotlin.j2k.J2kConverterExtension
|
import org.jetbrains.kotlin.j2k.J2kConverterExtension
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
|
|||||||
+12
-15
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.perf
|
package org.jetbrains.kotlin.idea.perf
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.CompletionType
|
|
||||||
import com.intellij.codeInsight.daemon.*
|
import com.intellij.codeInsight.daemon.*
|
||||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
|
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
@@ -58,7 +57,6 @@ import com.intellij.psi.search.FilenameIndex
|
|||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
import com.intellij.psi.xml.XmlFileNSInfoProvider
|
import com.intellij.psi.xml.XmlFileNSInfoProvider
|
||||||
import com.intellij.testFramework.*
|
import com.intellij.testFramework.*
|
||||||
import com.intellij.testFramework.fixtures.EditorTestFixture
|
|
||||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
|
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl
|
||||||
import com.intellij.util.ArrayUtilRt
|
import com.intellij.util.ArrayUtilRt
|
||||||
import com.intellij.util.ThrowableRunnable
|
import com.intellij.util.ThrowableRunnable
|
||||||
@@ -75,6 +73,7 @@ import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
|||||||
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
||||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||||
import org.jetbrains.kotlin.idea.test.invalidateLibraryCache
|
import org.jetbrains.kotlin.idea.test.invalidateLibraryCache
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.*
|
||||||
import org.jetbrains.plugins.gradle.service.project.GradleProjectOpenProcessor
|
import org.jetbrains.plugins.gradle.service.project.GradleProjectOpenProcessor
|
||||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -319,7 +318,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
val fileInEditor = openFileInEditor(project, fileName)
|
val fileInEditor = openFileInEditor(project, fileName)
|
||||||
val virtualFile = fileInEditor.psiFile.virtualFile
|
val virtualFile = fileInEditor.psiFile.virtualFile
|
||||||
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
||||||
val editorFixture = EditorTestFixture(project, editor, virtualFile)
|
val fixture = Fixture(project, editor, virtualFile)
|
||||||
|
|
||||||
val initialText = editor.document.text
|
val initialText = editor.document.text
|
||||||
try {
|
try {
|
||||||
@@ -336,10 +335,10 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
editor.caretModel.moveToOffset(editor.caretModel.offset - 1)
|
editor.caretModel.moveToOffset(editor.caretModel.offset - 1)
|
||||||
editorFixture.type(insertString)
|
fixture.type(insertString)
|
||||||
|
|
||||||
if (lookupElements.isNotEmpty()) {
|
if (lookupElements.isNotEmpty()) {
|
||||||
val elements = editorFixture.complete(CompletionType.BASIC, 1) ?: emptyArray()
|
val elements = fixture.complete()
|
||||||
val items = elements.map { it.lookupString }.toList()
|
val items = elements.map { it.lookupString }.toList()
|
||||||
for (lookupElement in lookupElements) {
|
for (lookupElement in lookupElements) {
|
||||||
assertTrue("'$lookupElement' has to be present in items", items.contains(lookupElement))
|
assertTrue("'$lookupElement' has to be present in items", items.contains(lookupElement))
|
||||||
@@ -347,7 +346,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// TODO: [VD] revert ?
|
// TODO: [VD] revert ?
|
||||||
//editorFixture.performEditorAction(IdeActions.SELECTED_CHANGES_ROLLBACK)
|
//fixture.performEditorAction(IdeActions.SELECTED_CHANGES_ROLLBACK)
|
||||||
if (revertChangesAtTheEnd) {
|
if (revertChangesAtTheEnd) {
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
editor.document.setText(initialText)
|
editor.document.setText(initialText)
|
||||||
@@ -386,7 +385,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
note: String = ""
|
note: String = ""
|
||||||
) {
|
) {
|
||||||
assertTrue("lookupElements has to be not empty", lookupElements.isNotEmpty())
|
assertTrue("lookupElements has to be not empty", lookupElements.isNotEmpty())
|
||||||
stats.perfTest<Pair<String, FixtureEditorFile>, Array<LookupElement>>(
|
stats.perfTest<Pair<String, Fixture>, Array<LookupElement>>(
|
||||||
warmUpIterations = 8,
|
warmUpIterations = 8,
|
||||||
iterations = 15,
|
iterations = 15,
|
||||||
testName = "typeAndAutocomplete ${notePrefix(note)}$fileName",
|
testName = "typeAndAutocomplete ${notePrefix(note)}$fileName",
|
||||||
@@ -395,7 +394,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
val file = fileInEditor.psiFile
|
val file = fileInEditor.psiFile
|
||||||
val virtualFile = file.virtualFile
|
val virtualFile = file.virtualFile
|
||||||
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
||||||
val fixture = EditorTestFixture(project, editor, virtualFile)
|
val fixture = Fixture(project, editor, virtualFile)
|
||||||
val initialText = editor.document.text
|
val initialText = editor.document.text
|
||||||
if (isAKotlinScriptFile(fileName)) {
|
if (isAKotlinScriptFile(fileName)) {
|
||||||
runAndMeasure("update script dependencies for $fileName") {
|
runAndMeasure("update script dependencies for $fileName") {
|
||||||
@@ -426,11 +425,11 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
|
|
||||||
fixture.type(insertString)
|
fixture.type(insertString)
|
||||||
|
|
||||||
it.setUpValue = Pair(initialText, FixtureEditorFile(file, editor.document, fixture))
|
it.setUpValue = Pair(initialText, fixture)
|
||||||
},
|
},
|
||||||
test = {
|
test = {
|
||||||
val fixture = it.setUpValue!!.second.fixture
|
val fixture = it.setUpValue!!.second
|
||||||
it.value = fixture.complete(CompletionType.BASIC, 1) ?: emptyArray()
|
it.value = fixture.complete()
|
||||||
},
|
},
|
||||||
tearDown = {
|
tearDown = {
|
||||||
val items = it.value?.map { e -> e.lookupString }?.toList() ?: emptyList()
|
val items = it.value?.map { e -> e.lookupString }?.toList() ?: emptyList()
|
||||||
@@ -441,7 +440,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
} finally {
|
} finally {
|
||||||
it.setUpValue?.let { pair ->
|
it.setUpValue?.let { pair ->
|
||||||
val document = pair.second.document
|
val document = pair.second.document
|
||||||
val file = pair.second.psiFile
|
val file = pair.second.vFile
|
||||||
val text = pair.first
|
val text = pair.first
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -456,7 +455,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
dispatchAllInvocationEvents()
|
dispatchAllInvocationEvents()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cleanupCaches(project, file.virtualFile)
|
cleanupCaches(project, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commitAllDocuments()
|
commitAllDocuments()
|
||||||
@@ -664,8 +663,6 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
|||||||
return virtualFiles.iterator().next().toPsiFile(project)!!
|
return virtualFiles.iterator().next().toPsiFile(project)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
data class FixtureEditorFile(val psiFile: PsiFile, val document: Document, val fixture: EditorTestFixture)
|
|
||||||
|
|
||||||
data class EditorFile(val psiFile: PsiFile, val document: Document)
|
data class EditorFile(val psiFile: PsiFile, val document: Document)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,21 +6,16 @@
|
|||||||
package org.jetbrains.kotlin.idea.perf
|
package org.jetbrains.kotlin.idea.perf
|
||||||
|
|
||||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
import com.intellij.lang.LanguageAnnotators
|
|
||||||
import com.intellij.lang.LanguageExtensionPoint
|
|
||||||
import com.intellij.lang.annotation.AnnotationHolder
|
import com.intellij.lang.annotation.AnnotationHolder
|
||||||
import com.intellij.lang.annotation.Annotator
|
|
||||||
import com.intellij.openapi.editor.EditorFactory
|
import com.intellij.openapi.editor.EditorFactory
|
||||||
import com.intellij.openapi.extensions.ExtensionPointName
|
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.testFramework.PlatformTestUtil
|
|
||||||
import com.intellij.testFramework.fixtures.EditorTestFixture
|
|
||||||
import com.intellij.testFramework.propertyBased.MadTestingUtil
|
import com.intellij.testFramework.propertyBased.MadTestingUtil
|
||||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
|
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
|
||||||
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiChecker
|
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiChecker
|
||||||
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiCheckerAndHighlightingUpdater
|
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiCheckerAndHighlightingUpdater
|
||||||
|
import org.jetbrains.kotlin.idea.testFramework.Fixture
|
||||||
import java.util.concurrent.atomic.AtomicLong
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
import kotlin.test.assertNotEquals
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
@@ -244,34 +239,24 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun replaceWithCustomHighlighter() {
|
private fun replaceWithCustomHighlighter() {
|
||||||
val pointName = ExtensionPointName.create<LanguageExtensionPoint<Annotator>>(LanguageAnnotators.EP_NAME)
|
org.jetbrains.kotlin.idea.testFramework.replaceWithCustomHighlighter(
|
||||||
val extensionPoint = pointName.getPoint(null)
|
testRootDisposable,
|
||||||
|
KotlinPsiCheckerAndHighlightingUpdater::class.java.name,
|
||||||
val point = LanguageExtensionPoint<Annotator>()
|
TestKotlinPsiChecker::class.java.name
|
||||||
point.language = "kotlin"
|
)
|
||||||
point.implementationClass = TestKotlinPsiChecker::class.java.name
|
|
||||||
|
|
||||||
val extensions = extensionPoint.extensions
|
|
||||||
val filteredExtensions =
|
|
||||||
extensions.filter { it.language != "kotlin" || it.implementationClass != KotlinPsiCheckerAndHighlightingUpdater::class.java.name }
|
|
||||||
.toList()
|
|
||||||
// custom highlighter is already registered if filteredExtensions has the same size as extensions
|
|
||||||
if (filteredExtensions.size < extensions.size) {
|
|
||||||
PlatformTestUtil.maskExtensions(pointName, filteredExtensions + listOf(point), testRootDisposable)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun perfKtsFileAnalysisSetUp(
|
fun perfKtsFileAnalysisSetUp(
|
||||||
project: Project,
|
project: Project,
|
||||||
fileName: String
|
fileName: String
|
||||||
): (TestData<FixtureEditorFile, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
): (TestData<Fixture, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
||||||
return {
|
return {
|
||||||
val fileInEditor = openFileInEditor(project, fileName)
|
val fileInEditor = openFileInEditor(project, fileName)
|
||||||
|
|
||||||
val file = fileInEditor.psiFile
|
val file = fileInEditor.psiFile
|
||||||
val virtualFile = file.virtualFile
|
val virtualFile = file.virtualFile
|
||||||
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
val editor = EditorFactory.getInstance().getEditors(fileInEditor.document, project)[0]
|
||||||
val fixture = EditorTestFixture(project, editor, virtualFile)
|
val fixture = Fixture(project, editor, virtualFile)
|
||||||
|
|
||||||
// Note: Kotlin scripts require dependencies to be loaded
|
// Note: Kotlin scripts require dependencies to be loaded
|
||||||
if (isAKotlinScriptFile(fileName)) {
|
if (isAKotlinScriptFile(fileName)) {
|
||||||
@@ -279,14 +264,14 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resetTimestamp()
|
resetTimestamp()
|
||||||
it.setUpValue = FixtureEditorFile(file, editor.document, fixture)
|
it.setUpValue = fixture
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun perfKtsFileAnalysisTest(): (TestData<FixtureEditorFile, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
fun perfKtsFileAnalysisTest(): (TestData<Fixture, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
||||||
return {
|
return {
|
||||||
it.value = it.setUpValue?.let { fef ->
|
it.value = it.setUpValue?.let { fixture ->
|
||||||
Pair(System.nanoTime(), fef.fixture.doHighlighting())
|
Pair(System.nanoTime(), fixture.doHighlighting())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,9 +279,9 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
|
|||||||
fun perfKtsFileAnalysisTearDown(
|
fun perfKtsFileAnalysisTearDown(
|
||||||
extraTimingsNs: MutableList<Long>,
|
extraTimingsNs: MutableList<Long>,
|
||||||
project: Project
|
project: Project
|
||||||
): (TestData<FixtureEditorFile, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
): (TestData<Fixture, Pair<Long, List<HighlightInfo>>>) -> Unit {
|
||||||
return {
|
return {
|
||||||
it.setUpValue?.let { fef ->
|
it.setUpValue?.let { fixture ->
|
||||||
it.value?.let { v ->
|
it.value?.let { v ->
|
||||||
assertTrue(v.second.isNotEmpty())
|
assertTrue(v.second.isNotEmpty())
|
||||||
assertNotEquals(0, timer.get())
|
assertNotEquals(0, timer.get())
|
||||||
@@ -304,7 +289,7 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() {
|
|||||||
extraTimingsNs.add(timer.get() - v.first)
|
extraTimingsNs.add(timer.get() - v.first)
|
||||||
|
|
||||||
}
|
}
|
||||||
cleanupCaches(project, fef.psiFile.virtualFile)
|
cleanupCaches(project, fixture.vFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* 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.testFramework
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.CompletionType
|
||||||
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.testFramework.fixtures.EditorTestFixture
|
||||||
|
|
||||||
|
|
||||||
|
class Fixture(val project: Project, val editor: Editor, val vFile: VirtualFile) {
|
||||||
|
private val delegate = EditorTestFixture(project, editor, vFile)
|
||||||
|
|
||||||
|
val document: Document
|
||||||
|
get() = editor.document
|
||||||
|
|
||||||
|
fun doHighlighting(): List<HighlightInfo> = delegate.doHighlighting() ?: emptyList()
|
||||||
|
|
||||||
|
fun type(s: String) {
|
||||||
|
delegate.type(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun complete(type: CompletionType = CompletionType.BASIC, invocationCount: Int = 1): Array<LookupElement> =
|
||||||
|
delegate.complete(type, invocationCount) ?: emptyArray()
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.testFramework
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.completion.CompletionType
|
||||||
|
import com.intellij.codeInsight.daemon.impl.HighlightInfo
|
||||||
|
import com.intellij.codeInsight.lookup.LookupElement
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
|
||||||
|
|
||||||
|
class Fixture(val project: Project, val editor: Editor, val vFile: VirtualFile) {
|
||||||
|
|
||||||
|
val document: Document
|
||||||
|
get() = TODO()
|
||||||
|
|
||||||
|
fun doHighlighting(): List<HighlightInfo> = TODO()
|
||||||
|
|
||||||
|
fun type(s: String) {
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun complete(type: CompletionType = CompletionType.BASIC, invocationCount: Int = 1): Array<LookupElement> =
|
||||||
|
TODO()
|
||||||
|
}
|
||||||
+27
-11
@@ -3,11 +3,15 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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.perf
|
package org.jetbrains.kotlin.idea.testFramework
|
||||||
|
|
||||||
|
import com.intellij.lang.LanguageAnnotators
|
||||||
|
import com.intellij.lang.LanguageExtensionPoint
|
||||||
|
import com.intellij.lang.annotation.Annotator
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
import com.intellij.openapi.application.runWriteAction
|
|
||||||
import com.intellij.openapi.editor.Document
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.extensions.ExtensionPointName
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl
|
import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl
|
||||||
@@ -15,8 +19,8 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.impl.PsiDocumentManagerBase
|
import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||||
import com.intellij.testFramework.EdtTestUtil
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
import com.intellij.util.ThrowableRunnable
|
import com.intellij.testFramework.runInEdtAndWait
|
||||||
import com.intellij.util.ui.UIUtil
|
import com.intellij.util.ui.UIUtil
|
||||||
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@@ -56,12 +60,6 @@ fun saveDocument(document: Document) {
|
|||||||
fun enableHints(enable: Boolean) =
|
fun enableHints(enable: Boolean) =
|
||||||
HintType.values().forEach { it.option.set(enable) }
|
HintType.values().forEach { it.option.set(enable) }
|
||||||
|
|
||||||
fun runInEdtAndWait(block: () -> Unit) {
|
|
||||||
EdtTestUtil.runInEdtAndWait(ThrowableRunnable {
|
|
||||||
block()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dispatchAllInvocationEvents() {
|
fun dispatchAllInvocationEvents() {
|
||||||
runInEdtAndWait {
|
runInEdtAndWait {
|
||||||
UIUtil.dispatchAllInvocationEvents()
|
UIUtil.dispatchAllInvocationEvents()
|
||||||
@@ -100,4 +98,22 @@ private fun waitABitForEditorLoading(project: Project): Boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) {
|
||||||
|
val pointName = ExtensionPointName.create<LanguageExtensionPoint<Annotator>>(LanguageAnnotators.EP_NAME)
|
||||||
|
val extensionPoint = pointName.getPoint(null)
|
||||||
|
|
||||||
|
val point = LanguageExtensionPoint<Annotator>()
|
||||||
|
point.language = "kotlin"
|
||||||
|
point.implementationClass = toImplementationClass
|
||||||
|
|
||||||
|
val extensions = extensionPoint.extensions
|
||||||
|
val filteredExtensions =
|
||||||
|
extensions.filter { it.language != "kotlin" || it.implementationClass != fromImplementationClass }
|
||||||
|
.toList()
|
||||||
|
// custom highlighter is already registered if filteredExtensions has the same size as extensions
|
||||||
|
if (filteredExtensions.size < extensions.size) {
|
||||||
|
PlatformTestUtil.maskExtensions(pointName, filteredExtensions + listOf(point), parentDisposable)
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-8
@@ -3,13 +3,18 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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.perf
|
package org.jetbrains.kotlin.idea.testFramework
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.project.ex.ProjectManagerEx
|
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.impl.PsiDocumentManagerBase
|
import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||||
import com.intellij.testFramework.EdtTestUtil
|
import com.intellij.testFramework.EdtTestUtil
|
||||||
|
import com.intellij.testFramework.runInEdtAndWait
|
||||||
import com.intellij.util.ThrowableRunnable
|
import com.intellij.util.ThrowableRunnable
|
||||||
import com.intellij.util.ui.UIUtil
|
import com.intellij.util.ui.UIUtil
|
||||||
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
||||||
@@ -33,15 +38,17 @@ fun commitDocument(project: Project, document: Document) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveDocument(document: Document) {
|
||||||
|
val fileDocumentManager = FileDocumentManager.getInstance()
|
||||||
|
|
||||||
|
runInEdtAndWait {
|
||||||
|
fileDocumentManager.saveDocument(document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun enableHints(enable: Boolean) =
|
fun enableHints(enable: Boolean) =
|
||||||
HintType.values().forEach { it.option.set(enable) }
|
HintType.values().forEach { it.option.set(enable) }
|
||||||
|
|
||||||
fun runInEdtAndWait(block: () -> Unit) {
|
|
||||||
EdtTestUtil.runInEdtAndWait(ThrowableRunnable {
|
|
||||||
block()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dispatchAllInvocationEvents() {
|
fun dispatchAllInvocationEvents() {
|
||||||
runInEdtAndWait {
|
runInEdtAndWait {
|
||||||
UIUtil.dispatchAllInvocationEvents()
|
UIUtil.dispatchAllInvocationEvents()
|
||||||
@@ -56,4 +63,8 @@ fun closeProject(project: Project) {
|
|||||||
|
|
||||||
fun waitForAllEditorsFinallyLoaded(project: Project) {
|
fun waitForAllEditorsFinallyLoaded(project: Project) {
|
||||||
// 182 does not have this public api
|
// 182 does not have this public api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) {
|
||||||
|
// 182 does not have this public api
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.testFramework
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
|
import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||||
|
import com.intellij.testFramework.EdtTestUtil
|
||||||
|
import com.intellij.testFramework.runInEdtAndWait
|
||||||
|
import com.intellij.util.ThrowableRunnable
|
||||||
|
import com.intellij.util.ui.UIUtil
|
||||||
|
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
||||||
|
|
||||||
|
fun commitAllDocuments() {
|
||||||
|
ProjectManagerEx.getInstanceEx().openProjects.forEach { project ->
|
||||||
|
val psiDocumentManagerBase = PsiDocumentManager.getInstance(project) as PsiDocumentManagerBase
|
||||||
|
|
||||||
|
EdtTestUtil.runInEdtAndWait(ThrowableRunnable {
|
||||||
|
psiDocumentManagerBase.clearUncommittedDocuments()
|
||||||
|
psiDocumentManagerBase.commitAllDocuments()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun commitDocument(project: Project, document: Document) {
|
||||||
|
val psiDocumentManagerBase = PsiDocumentManager.getInstance(project) as PsiDocumentManagerBase
|
||||||
|
|
||||||
|
EdtTestUtil.runInEdtAndWait(ThrowableRunnable {
|
||||||
|
psiDocumentManagerBase.commitDocument(document)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveDocument(document: Document) {
|
||||||
|
val fileDocumentManager = FileDocumentManager.getInstance()
|
||||||
|
|
||||||
|
runInEdtAndWait {
|
||||||
|
fileDocumentManager.saveDocument(document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enableHints(enable: Boolean) =
|
||||||
|
HintType.values().forEach { it.option.set(enable) }
|
||||||
|
|
||||||
|
fun dispatchAllInvocationEvents() {
|
||||||
|
runInEdtAndWait {
|
||||||
|
UIUtil.dispatchAllInvocationEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeProject(project: Project) {
|
||||||
|
dispatchAllInvocationEvents()
|
||||||
|
val projectManagerEx = ProjectManagerEx.getInstanceEx()
|
||||||
|
projectManagerEx.closeAndDispose(project)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun waitForAllEditorsFinallyLoaded(project: Project) {
|
||||||
|
// 182 does not have this public api
|
||||||
|
}
|
||||||
|
|
||||||
|
fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) {
|
||||||
|
// 182 does not have this public api
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* 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.testFramework
|
||||||
|
|
||||||
|
import com.intellij.lang.LanguageAnnotators
|
||||||
|
import com.intellij.lang.LanguageExtensionPoint
|
||||||
|
import com.intellij.lang.annotation.Annotator
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.application.runWriteAction
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.extensions.ExtensionPointName
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||||
|
import com.intellij.openapi.fileEditor.impl.text.TextEditorImpl
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.project.ex.ProjectManagerEx
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
|
import com.intellij.psi.impl.PsiDocumentManagerBase
|
||||||
|
import com.intellij.testFramework.EdtTestUtil
|
||||||
|
import com.intellij.testFramework.PlatformTestUtil
|
||||||
|
import com.intellij.util.ThrowableRunnable
|
||||||
|
import com.intellij.testFramework.runInEdtAndWait
|
||||||
|
import com.intellij.util.ui.UIUtil
|
||||||
|
import org.jetbrains.kotlin.idea.highlighter.KotlinPsiCheckerAndHighlightingUpdater
|
||||||
|
import org.jetbrains.kotlin.idea.parameterInfo.HintType
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
import java.util.concurrent.TimeoutException
|
||||||
|
|
||||||
|
fun commitAllDocuments() {
|
||||||
|
val fileDocumentManager = FileDocumentManager.getInstance()
|
||||||
|
runInEdtAndWait {
|
||||||
|
fileDocumentManager.saveAllDocuments()
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectManagerEx.getInstanceEx().openProjects.forEach { project ->
|
||||||
|
val psiDocumentManagerBase = PsiDocumentManager.getInstance(project) as PsiDocumentManagerBase
|
||||||
|
|
||||||
|
runInEdtAndWait {
|
||||||
|
psiDocumentManagerBase.clearUncommittedDocuments()
|
||||||
|
psiDocumentManagerBase.commitAllDocuments()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun commitDocument(project: Project, document: Document) {
|
||||||
|
val psiDocumentManagerBase = PsiDocumentManager.getInstance(project) as PsiDocumentManagerBase
|
||||||
|
runInEdtAndWait {
|
||||||
|
psiDocumentManagerBase.commitDocument(document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun saveDocument(document: Document) {
|
||||||
|
val fileDocumentManager = FileDocumentManager.getInstance()
|
||||||
|
|
||||||
|
runInEdtAndWait {
|
||||||
|
fileDocumentManager.saveDocument(document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun enableHints(enable: Boolean) =
|
||||||
|
HintType.values().forEach { it.option.set(enable) }
|
||||||
|
|
||||||
|
fun dispatchAllInvocationEvents() {
|
||||||
|
runInEdtAndWait {
|
||||||
|
UIUtil.dispatchAllInvocationEvents()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeProject(project: Project) {
|
||||||
|
dispatchAllInvocationEvents()
|
||||||
|
val projectManagerEx = ProjectManagerEx.getInstanceEx()
|
||||||
|
projectManagerEx.forceCloseProject(project, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun waitForAllEditorsFinallyLoaded(project: Project) {
|
||||||
|
// routing is obsolete in 192
|
||||||
|
}
|
||||||
|
|
||||||
|
fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) {
|
||||||
|
val pointName = ExtensionPointName.create<LanguageExtensionPoint<Annotator>>(LanguageAnnotators.EP_NAME)
|
||||||
|
val extensionPoint = pointName.getPoint(null)
|
||||||
|
|
||||||
|
val point = LanguageExtensionPoint<Annotator>()
|
||||||
|
point.language = "kotlin"
|
||||||
|
point.implementationClass = toImplementationClass
|
||||||
|
|
||||||
|
val extensions = extensionPoint.extensions
|
||||||
|
val filteredExtensions =
|
||||||
|
extensions.filter { it.language != "kotlin" || it.implementationClass != fromImplementationClass }
|
||||||
|
.toList()
|
||||||
|
// custom highlighter is already registered if filteredExtensions has the same size as extensions
|
||||||
|
if (filteredExtensions.size < extensions.size) {
|
||||||
|
PlatformTestUtil.maskExtensions(pointName, filteredExtensions + listOf(point), parentDisposable)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user