mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
run refactoring tests outside the write action and get rid of testRun()
This commit is contained in:
@@ -412,42 +412,46 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void setupCursorAndSelection(Editor editor) {
|
||||
Document document = editor.getDocument();
|
||||
final String text = document.getText();
|
||||
protected void setupCursorAndSelection(final Editor editor) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
Document document = editor.getDocument();
|
||||
final String text = document.getText();
|
||||
|
||||
int caretIndex = text.indexOf(CARET_MARKER);
|
||||
int selStartIndex = text.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = text.indexOf(SELECTION_END_MARKER);
|
||||
int caretIndex = text.indexOf(CARET_MARKER);
|
||||
int selStartIndex = text.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = text.indexOf(SELECTION_END_MARKER);
|
||||
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? document.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? document.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? document.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? document.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(), selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(), selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(), selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(), selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
|
||||
final String newText = document.getText();
|
||||
final String newText = document.getText();
|
||||
|
||||
if (caretMarker != null) {
|
||||
int caretLine = StringUtil.offsetToLineNumber(newText, caretMarker.getStartOffset());
|
||||
int caretCol = caretMarker.getStartOffset() - StringUtil.lineColToOffset(newText, caretLine, 0);
|
||||
LogicalPosition pos = new LogicalPosition(caretLine, caretCol);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
}
|
||||
if (caretMarker != null) {
|
||||
int caretLine = StringUtil.offsetToLineNumber(newText, caretMarker.getStartOffset());
|
||||
int caretCol = caretMarker.getStartOffset() - StringUtil.lineColToOffset(newText, caretLine, 0);
|
||||
LogicalPosition pos = new LogicalPosition(caretLine, caretCol);
|
||||
editor.getCaretModel().moveToLogicalPosition(pos);
|
||||
}
|
||||
|
||||
if (selStartMarker != null) {
|
||||
editor.getSelectionModel().setSelection(selStartMarker.getStartOffset(), selEndMarker.getStartOffset());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
editor.getSelectionModel().setSelection(selStartMarker.getStartOffset(), selEndMarker.getStartOffset());
|
||||
}
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -45,15 +46,20 @@ public abstract class MultiFileTestCase extends CodeInsightTestCase {
|
||||
String path = getTestDataPath() + getTestRoot() + testName;
|
||||
|
||||
String pathBefore = path + "/before";
|
||||
VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, pathBefore, myFilesToDelete, false);
|
||||
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, pathBefore, myFilesToDelete, false);
|
||||
prepareProject(rootDir);
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
|
||||
String pathAfter = path + "/after";
|
||||
VirtualFile rootAfter = LocalFileSystem.getInstance().findFileByPath(pathAfter.replace(File.separatorChar, '/'));
|
||||
final VirtualFile rootAfter = LocalFileSystem.getInstance().findFileByPath(pathAfter.replace(File.separatorChar, '/'));
|
||||
|
||||
performAction.performAction(rootDir, rootAfter);
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
}
|
||||
});
|
||||
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
|
||||
if (myDoCompare) {
|
||||
@@ -72,4 +78,9 @@ public abstract class MultiFileTestCase extends CodeInsightTestCase {
|
||||
protected interface PerformAction {
|
||||
void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user