mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tests: simplify IdentifierHighlighterPassFactory.doWithHighlightingEnabled to remove confusion
GitOrigin-RevId: 5f135498ddc65297c82733ee6387bac29aa43c26
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c08bdb7b0c
commit
8427ef6490
+2
-2
@@ -261,7 +261,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testIdentifierHighlighterForStaticImports() {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), ()->{
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), ()->{
|
||||
try {
|
||||
createClass("""
|
||||
|
||||
@@ -329,7 +329,7 @@ public class HighlightUsagesHandlerTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testMethodParameterEndOfIdentifier() {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), ()-> {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), ()-> {
|
||||
try {
|
||||
configureFile();
|
||||
}
|
||||
|
||||
@@ -2274,7 +2274,6 @@ f:com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass
|
||||
f:com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory
|
||||
- <init>():V
|
||||
- createHighlightingPass(com.intellij.psi.PsiFile,com.intellij.openapi.editor.Editor,com.intellij.openapi.util.TextRange):com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass
|
||||
- s:doWithHighlightingEnabled(com.intellij.openapi.project.Project,com.intellij.openapi.Disposable,java.lang.Runnable):V
|
||||
- s:isEnabled():Z
|
||||
- s:waitForIdentifierHighlighting():V
|
||||
c:com.intellij.codeInsight.daemon.impl.IndentGuideRenderer
|
||||
|
||||
+11
-9
@@ -3,7 +3,6 @@ package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.highlighting.BackgroundHighlighter;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -17,6 +16,7 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.TestModeFlags;
|
||||
import com.intellij.util.concurrency.ThreadingAssertions;
|
||||
import com.intellij.util.concurrency.annotations.RequiresEdt;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
@@ -46,15 +46,17 @@ public final class IdentifierHighlighterPassFactory {
|
||||
|
||||
@TestOnly
|
||||
@RequiresEdt
|
||||
public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Disposable parentDisposable, @NotNull Runnable r) {
|
||||
@ApiStatus.Internal
|
||||
public static void doWithHighlightingEnabled(@NotNull Project project, @NotNull Runnable r) {
|
||||
ThreadingAssertions.assertEventDispatchThread();
|
||||
BackgroundHighlighter.Companion.enableListenersInTest(project, parentDisposable);
|
||||
try {
|
||||
TestModeFlags.runWithFlag(ourTestingIdentifierHighlighting, true, r);
|
||||
}
|
||||
finally {
|
||||
waitForIdentifierHighlighting();
|
||||
}
|
||||
BackgroundHighlighter.Companion.runWithEnabledListenersInTest(project, ()-> {
|
||||
try {
|
||||
TestModeFlags.runWithFlag(ourTestingIdentifierHighlighting, true, r);
|
||||
}
|
||||
finally {
|
||||
waitForIdentifierHighlighting();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
|
||||
+8
-1
@@ -82,13 +82,20 @@ internal class BackgroundHighlighter(coroutineScope: CoroutineScope) {
|
||||
|
||||
companion object {
|
||||
@TestOnly
|
||||
fun enableListenersInTest(project: Project, parentDisposable: Disposable) {
|
||||
fun runWithEnabledListenersInTest(project: Project, r: Runnable) {
|
||||
val d = project.service<BackgroundHighlighterPerProject>()
|
||||
val parentDisposable = Disposer.newDisposable()
|
||||
val coroutineScope = d.coroutineScope.childScope("Test Background Highlighter(disposable=$parentDisposable)")
|
||||
Disposer.register(parentDisposable, Disposable {
|
||||
coroutineScope.cancel()
|
||||
})
|
||||
service<BackgroundHighlighter>().registerListeners(project, parentDisposable, coroutineScope)
|
||||
try {
|
||||
r.run()
|
||||
}
|
||||
finally {
|
||||
Disposer.dispose(parentDisposable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -840,7 +840,7 @@ public final class EditorTestUtil {
|
||||
caretModel.removeSecondaryCarets();
|
||||
CharSequence documentSequence = InjectedLanguageEditorUtil.getTopLevelEditor(editor).getDocument().getCharsSequence();
|
||||
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(fixture.getProject(), fixture.getProjectDisposable(), () -> {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(fixture.getProject(), () -> {
|
||||
for (Integer caretsOffset : caretsOffsets) {
|
||||
if (caretsOffset != -1) {
|
||||
caretModel.moveToOffset(caretsOffset);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class PluginXmlIdentifierHighlightingTest extends LightJavaCodeInsightFix
|
||||
}
|
||||
|
||||
public void test_ep_references() {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), () -> {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), () -> {
|
||||
|
||||
myFixture.configureByText("plugin.xml", """
|
||||
<idea-plugin>
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ class EditorConfigHighlightUsagesTest : BasePlatformTestCase() {
|
||||
private fun doTest() {
|
||||
SeveritiesProvider.EP_NAME.point.registerExtension(SEVERITIES_PROVIDER, testRootDisposable)
|
||||
val name = getTestName(true)
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled (project, testRootDisposable, Runnable {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled (project, Runnable {
|
||||
myFixture.configureByFile("${name}/.editorconfig")
|
||||
myFixture.setReadEditorMarkupModel(true)
|
||||
myFixture.checkHighlighting()
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public class GroovyHighlightUsagesTest extends LightGroovyTestCase {
|
||||
|
||||
private void doTest(boolean directoryTest) {
|
||||
SeveritiesProvider.EP_NAME.getPoint().registerExtension(SEVERITIES_PROVIDER, getTestRootDisposable());
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), getTestRootDisposable(), () -> {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(getProject(), () -> {
|
||||
String name = getTestName();
|
||||
JavaCodeInsightTestFixture fixture = getFixture();
|
||||
if (directoryTest) {
|
||||
|
||||
+4
-4
@@ -174,7 +174,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
|
||||
fun testHighlighting() {
|
||||
myFixture.setReadEditorMarkupModel(true)
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable {
|
||||
myFixture.openFileInEditor(getTestFile("Navigation.class"))
|
||||
myFixture.editor.caretModel.moveToOffset(offset(8, 14)) // m2(): usage, declaration
|
||||
assertEquals(2, highlightUnderCaret().size)
|
||||
@@ -196,7 +196,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
fun testNameHighlightingInsideCompiledFile() {
|
||||
myFixture.setReadEditorMarkupModel(true)
|
||||
myFixture.openFileInEditor(getTestFile("NamesHighlightingInsideCompiledFile.class"))
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable {
|
||||
val infos = myFixture.doHighlighting()
|
||||
assertTrue(infos.toString(), infos.all { info: HighlightInfo -> info.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY })
|
||||
assertEquals(68, infos.size)
|
||||
@@ -206,7 +206,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
fun testNameHighlightingInsideCompiledModuleFile() {
|
||||
myFixture.setReadEditorMarkupModel(true)
|
||||
myFixture.openFileInEditor(getTestFile("module-info.class"))
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable {
|
||||
val infos = myFixture.doHighlighting()
|
||||
.filter { it.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY }
|
||||
assertEquals(5, infos.size)
|
||||
@@ -225,7 +225,7 @@ class IdeaDecompilerTest : LightJavaCodeInsightFixtureTestCase() {
|
||||
val testFile = getTestFile("RecordHighlighting.class")
|
||||
testFile.parent.children; testFile.parent.refresh(false, true) // inner classes
|
||||
myFixture.openFileInEditor(testFile)
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable, Runnable {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, Runnable {
|
||||
val infos = myFixture.doHighlighting()
|
||||
.filter { it.severity === HighlightInfoType.SYMBOL_TYPE_SEVERITY }
|
||||
val texts = infos.map { it.text }.toSet()
|
||||
|
||||
+1
-1
@@ -548,7 +548,7 @@ abstract class AbstractPerformanceProjectsTest : UsefulTestCase() {
|
||||
|
||||
internal fun <T> Project.highlightFile(block: () -> T): T {
|
||||
var value: T? = null
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(this, this) {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(this) {
|
||||
value = block()
|
||||
}
|
||||
return value!!
|
||||
|
||||
@@ -30,7 +30,7 @@ class ShHighlightUsagesTest : BasePlatformTestCase() {
|
||||
}
|
||||
|
||||
private fun doTest(vararg expectedHighlighting: String) {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project, testRootDisposable) {
|
||||
IdentifierHighlighterPassFactory.doWithHighlightingEnabled(project) {
|
||||
myFixture.setReadEditorMarkupModel(true)
|
||||
myFixture.configureByFile(getTestName(true) + ".sh")
|
||||
myFixture.doHighlighting()
|
||||
|
||||
Reference in New Issue
Block a user