mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rewrite GroovyPsiEventsTest
This commit is contained in:
+27
-18
@@ -3,39 +3,48 @@ package org.jetbrains.plugins.groovy.lang.psi;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiTreeChangeAdapter;
|
||||
import com.intellij.psi.PsiTreeChangeEvent;
|
||||
import com.intellij.testFramework.PsiTestCase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class GroovyPsiEventsTest extends PsiTestCase {
|
||||
public class GroovyPsiEventsTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testEditingInDocComment() {
|
||||
final Ref<Boolean> gotIt = new Ref<>(false);
|
||||
getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() {
|
||||
Ref<Boolean> gotIt = new Ref<>(false);
|
||||
PsiTreeChangeAdapter listener = new PsiTreeChangeAdapter() {
|
||||
@Override
|
||||
public void childReplaced(@NotNull PsiTreeChangeEvent event) {
|
||||
gotIt.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
GroovyFile file = GroovyPsiElementFactory.getInstance(myProject).createGroovyFile("/** This is doc comment*/class C{}", true, null);
|
||||
final PsiDocumentManager docManager = PsiDocumentManager.getInstance(myProject);
|
||||
final Document doc = docManager.getDocument(file);
|
||||
assertNotNull(doc);
|
||||
CommandProcessor.getInstance().executeCommand(myProject,
|
||||
() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
doc.insertString(3, " ");
|
||||
docManager.commitDocument(doc);
|
||||
}),
|
||||
"file text set",
|
||||
this
|
||||
);
|
||||
};
|
||||
PsiManager manager = getPsiManager();
|
||||
try {
|
||||
manager.addPsiTreeChangeListener(listener);
|
||||
|
||||
Project project = getProject();
|
||||
GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile("/** This is doc comment*/class C{}", true, null);
|
||||
PsiDocumentManager docManager = PsiDocumentManager.getInstance(project);
|
||||
Document doc = docManager.getDocument(file);
|
||||
assertNotNull(doc);
|
||||
CommandProcessor.getInstance().executeCommand(project,
|
||||
() -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
doc.insertString(3, " ");
|
||||
docManager.commitDocument(doc);
|
||||
}),
|
||||
"file text set",
|
||||
this
|
||||
);
|
||||
}
|
||||
finally {
|
||||
manager.removePsiTreeChangeListener(listener);
|
||||
}
|
||||
|
||||
assertTrue(gotIt.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user