diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionHandlerTests.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionHandlerTests.kt index 1e297977937..3705c82925d 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionHandlerTests.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionHandlerTests.kt @@ -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.configureCompilerOptions import org.jetbrains.kotlin.idea.test.rollbackCompilerOptions +import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.utils.addToStdlib.indexOfOrNull import java.io.File diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionIncrementalResolveTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionIncrementalResolveTest.kt index 5a7db5065b1..b66d730a927 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionIncrementalResolveTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceCompletionIncrementalResolveTest.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.completion.CompletionBindingContextProvider import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase 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.test.InTextDirectivesUtils diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceHighlightingTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceHighlightingTest.kt index a189e9c4c11..7c9986dc13e 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceHighlightingTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceHighlightingTest.kt @@ -10,6 +10,7 @@ import com.intellij.openapi.application.runWriteAction import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.ensureIndexesUpToDate import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.testFramework.commitAllDocuments /** * inspired by @see AbstractHighlightingTest diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceJavaToKotlinCopyPasteConversionTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceJavaToKotlinCopyPasteConversionTest.kt index fc1fef9e991..857584c2661 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceJavaToKotlinCopyPasteConversionTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceJavaToKotlinCopyPasteConversionTest.kt @@ -8,11 +8,11 @@ package org.jetbrains.kotlin.idea.perf import com.intellij.ide.highlighter.JavaFileType import com.intellij.openapi.actionSystem.IdeActions import com.intellij.openapi.application.runWriteAction -import com.intellij.openapi.util.registry.Registry import com.intellij.psi.PsiDocumentManager import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.idea.conversion.copy.AbstractJavaToKotlinCopyPasteConversionTest 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.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceProjectsTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceProjectsTest.kt index 10af95fd405..e921f73cdb8 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceProjectsTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/AbstractPerformanceProjectsTest.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.idea.perf -import com.intellij.codeInsight.completion.CompletionType import com.intellij.codeInsight.daemon.* import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl 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.xml.XmlFileNSInfoProvider import com.intellij.testFramework.* -import com.intellij.testFramework.fixtures.EditorTestFixture import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl import com.intellij.util.ArrayUtilRt 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.test.ConfigLibraryUtil 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.util.GradleConstants import java.io.File @@ -319,7 +318,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { val fileInEditor = openFileInEditor(project, fileName) val virtualFile = fileInEditor.psiFile.virtualFile 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 try { @@ -336,10 +335,10 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { } editor.caretModel.moveToOffset(editor.caretModel.offset - 1) - editorFixture.type(insertString) + fixture.type(insertString) if (lookupElements.isNotEmpty()) { - val elements = editorFixture.complete(CompletionType.BASIC, 1) ?: emptyArray() + val elements = fixture.complete() val items = elements.map { it.lookupString }.toList() for (lookupElement in lookupElements) { assertTrue("'$lookupElement' has to be present in items", items.contains(lookupElement)) @@ -347,7 +346,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { } } finally { // TODO: [VD] revert ? - //editorFixture.performEditorAction(IdeActions.SELECTED_CHANGES_ROLLBACK) + //fixture.performEditorAction(IdeActions.SELECTED_CHANGES_ROLLBACK) if (revertChangesAtTheEnd) { runWriteAction { editor.document.setText(initialText) @@ -386,7 +385,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { note: String = "" ) { assertTrue("lookupElements has to be not empty", lookupElements.isNotEmpty()) - stats.perfTest, Array>( + stats.perfTest, Array>( warmUpIterations = 8, iterations = 15, testName = "typeAndAutocomplete ${notePrefix(note)}$fileName", @@ -395,7 +394,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { val file = fileInEditor.psiFile val virtualFile = file.virtualFile 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 if (isAKotlinScriptFile(fileName)) { runAndMeasure("update script dependencies for $fileName") { @@ -426,11 +425,11 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { fixture.type(insertString) - it.setUpValue = Pair(initialText, FixtureEditorFile(file, editor.document, fixture)) + it.setUpValue = Pair(initialText, fixture) }, test = { - val fixture = it.setUpValue!!.second.fixture - it.value = fixture.complete(CompletionType.BASIC, 1) ?: emptyArray() + val fixture = it.setUpValue!!.second + it.value = fixture.complete() }, tearDown = { val items = it.value?.map { e -> e.lookupString }?.toList() ?: emptyList() @@ -441,7 +440,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { } finally { it.setUpValue?.let { pair -> val document = pair.second.document - val file = pair.second.psiFile + val file = pair.second.vFile val text = pair.first try { @@ -456,7 +455,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { dispatchAllInvocationEvents() } } finally { - cleanupCaches(project, file.virtualFile) + cleanupCaches(project, file) } } commitAllDocuments() @@ -664,8 +663,6 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() { 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) } \ No newline at end of file diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceProjectsTest.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceProjectsTest.kt index 63939ae6645..546a12f6f9b 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceProjectsTest.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/perf/PerformanceProjectsTest.kt @@ -6,21 +6,16 @@ package org.jetbrains.kotlin.idea.perf 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.Annotator import com.intellij.openapi.editor.EditorFactory -import com.intellij.openapi.extensions.ExtensionPointName import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.psi.PsiElement -import com.intellij.testFramework.PlatformTestUtil -import com.intellij.testFramework.fixtures.EditorTestFixture import com.intellij.testFramework.propertyBased.MadTestingUtil import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager import org.jetbrains.kotlin.idea.highlighter.KotlinPsiChecker import org.jetbrains.kotlin.idea.highlighter.KotlinPsiCheckerAndHighlightingUpdater +import org.jetbrains.kotlin.idea.testFramework.Fixture import java.util.concurrent.atomic.AtomicLong import kotlin.test.assertNotEquals @@ -244,34 +239,24 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() { } private fun replaceWithCustomHighlighter() { - val pointName = ExtensionPointName.create>(LanguageAnnotators.EP_NAME) - val extensionPoint = pointName.getPoint(null) - - val point = LanguageExtensionPoint() - 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) - } + org.jetbrains.kotlin.idea.testFramework.replaceWithCustomHighlighter( + testRootDisposable, + KotlinPsiCheckerAndHighlightingUpdater::class.java.name, + TestKotlinPsiChecker::class.java.name + ) } fun perfKtsFileAnalysisSetUp( project: Project, fileName: String - ): (TestData>>) -> Unit { + ): (TestData>>) -> Unit { return { val fileInEditor = openFileInEditor(project, fileName) val file = fileInEditor.psiFile val virtualFile = file.virtualFile 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 if (isAKotlinScriptFile(fileName)) { @@ -279,14 +264,14 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() { } resetTimestamp() - it.setUpValue = FixtureEditorFile(file, editor.document, fixture) + it.setUpValue = fixture } } - fun perfKtsFileAnalysisTest(): (TestData>>) -> Unit { + fun perfKtsFileAnalysisTest(): (TestData>>) -> Unit { return { - it.value = it.setUpValue?.let { fef -> - Pair(System.nanoTime(), fef.fixture.doHighlighting()) + it.value = it.setUpValue?.let { fixture -> + Pair(System.nanoTime(), fixture.doHighlighting()) } } } @@ -294,9 +279,9 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() { fun perfKtsFileAnalysisTearDown( extraTimingsNs: MutableList, project: Project - ): (TestData>>) -> Unit { + ): (TestData>>) -> Unit { return { - it.setUpValue?.let { fef -> + it.setUpValue?.let { fixture -> it.value?.let { v -> assertTrue(v.second.isNotEmpty()) assertNotEquals(0, timer.get()) @@ -304,7 +289,7 @@ class PerformanceProjectsTest : AbstractPerformanceProjectsTest() { extraTimingsNs.add(timer.get() - v.first) } - cleanupCaches(project, fef.psiFile.virtualFile) + cleanupCaches(project, fixture.vFile) } } } diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt new file mode 100644 index 00000000000..73d71ebb5f4 --- /dev/null +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt @@ -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 = delegate.doHighlighting() ?: emptyList() + + fun type(s: String) { + delegate.type(s) + } + + fun complete(type: CompletionType = CompletionType.BASIC, invocationCount: Int = 1): Array = + delegate.complete(type, invocationCount) ?: emptyArray() +} diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt.182 b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt.182 new file mode 100644 index 00000000000..0c00b95cbe9 --- /dev/null +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/Fixture.kt.182 @@ -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 = TODO() + + fun type(s: String) { + TODO() + } + + fun complete(type: CompletionType = CompletionType.BASIC, invocationCount: Int = 1): Array = + TODO() +} diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt similarity index 70% rename from idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt rename to idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt index 9fdc5bef8e0..d9fd3ae408e 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt @@ -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. */ -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.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 @@ -15,8 +19,8 @@ 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.util.ThrowableRunnable +import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.ui.UIUtil import org.jetbrains.kotlin.idea.parameterInfo.HintType import java.util.concurrent.TimeUnit @@ -56,12 +60,6 @@ fun saveDocument(document: Document) { fun enableHints(enable: Boolean) = HintType.values().forEach { it.option.set(enable) } -fun runInEdtAndWait(block: () -> Unit) { - EdtTestUtil.runInEdtAndWait(ThrowableRunnable { - block() - }) -} - fun dispatchAllInvocationEvents() { runInEdtAndWait { UIUtil.dispatchAllInvocationEvents() @@ -100,4 +98,22 @@ private fun waitABitForEditorLoading(project: Project): Boolean { } } return true -} \ No newline at end of file +} + +fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) { + val pointName = ExtensionPointName.create>(LanguageAnnotators.EP_NAME) + val extensionPoint = pointName.getPoint(null) + + val point = LanguageExtensionPoint() + 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) + } +} diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt.182 b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.182 similarity index 72% rename from idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt.182 rename to idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.182 index 9a71619e8e4..39aa4ca77dc 100644 --- a/idea/performanceTests/org/jetbrains/kotlin/idea/perf/projectRoutines.kt.182 +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.182 @@ -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. */ -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.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 @@ -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) = HintType.values().forEach { it.option.set(enable) } -fun runInEdtAndWait(block: () -> Unit) { - EdtTestUtil.runInEdtAndWait(ThrowableRunnable { - block() - }) -} - fun dispatchAllInvocationEvents() { runInEdtAndWait { UIUtil.dispatchAllInvocationEvents() @@ -56,4 +63,8 @@ fun closeProject(project: Project) { fun waitForAllEditorsFinallyLoaded(project: Project) { // 182 does not have this public api -} \ No newline at end of file +} + +fun replaceWithCustomHighlighter(parentDisposable: Disposable, fromImplementationClass: String, toImplementationClass: String) { + // 182 does not have this public api +} diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 new file mode 100644 index 00000000000..39aa4ca77dc --- /dev/null +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.183 @@ -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 +} diff --git a/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.192 b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.192 new file mode 100644 index 00000000000..d52cf0a827f --- /dev/null +++ b/idea/performanceTests/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.192 @@ -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>(LanguageAnnotators.EP_NAME) + val extensionPoint = pointName.getPoint(null) + + val point = LanguageExtensionPoint() + 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) + } +}