AbstractFormatterTest: cleanup code
This commit is contained in:
@@ -44,19 +44,14 @@ public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase {
|
||||
}
|
||||
|
||||
private static final Map<Action, TestFormatAction> ACTIONS = new EnumMap<Action, TestFormatAction>(Action.class);
|
||||
|
||||
static {
|
||||
ACTIONS.put(Action.REFORMAT, new TestFormatAction() {
|
||||
@Override
|
||||
public void run(PsiFile psiFile, int startOffset, int endOffset) {
|
||||
CodeStyleManager.getInstance(psiFile.getProject()).reformatText(psiFile, startOffset, endOffset);
|
||||
}
|
||||
});
|
||||
ACTIONS.put(Action.INDENT, new TestFormatAction() {
|
||||
@Override
|
||||
public void run(PsiFile psiFile, int startOffset, int endOffset) {
|
||||
CodeStyleManager.getInstance(psiFile.getProject()).adjustLineIndent(psiFile, startOffset);
|
||||
}
|
||||
});
|
||||
ACTIONS.put(Action.REFORMAT,
|
||||
(psiFile, startOffset, endOffset) -> CodeStyleManager.getInstance(psiFile.getProject())
|
||||
.reformatText(psiFile, startOffset, endOffset));
|
||||
ACTIONS.put(Action.INDENT,
|
||||
(psiFile, startOffset, endOffset) -> CodeStyleManager.getInstance(psiFile.getProject())
|
||||
.adjustLineIndent(psiFile, startOffset));
|
||||
}
|
||||
|
||||
private static final String BASE_PATH =
|
||||
@@ -75,40 +70,32 @@ public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase {
|
||||
doTextTest(Action.REFORMAT, text, fileAfter, extension);
|
||||
}
|
||||
|
||||
public void doTextTest(final Action action, final String text, File fileAfter, String extension) throws IncorrectOperationException {
|
||||
final PsiFile file = createFile("A" + extension, text);
|
||||
public void doTextTest(Action action, String text, File fileAfter, String extension) throws IncorrectOperationException {
|
||||
PsiFile file = createFile("A" + extension, text);
|
||||
|
||||
if (myLineRange != null) {
|
||||
DocumentImpl document = new DocumentImpl(text);
|
||||
myTextRange =
|
||||
new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset()));
|
||||
new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()),
|
||||
document.getLineEndOffset(myLineRange.getEndOffset()));
|
||||
}
|
||||
|
||||
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
|
||||
final Document document = manager.getDocument(file);
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
document.replaceString(0, document.getTextLength(), text);
|
||||
manager.commitDocument(document);
|
||||
try {
|
||||
TextRange rangeToUse = myTextRange;
|
||||
if (rangeToUse == null) {
|
||||
rangeToUse = file.getTextRange();
|
||||
}
|
||||
ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
assertTrue(e.getLocalizedMessage(), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
|
||||
Document document = manager.getDocument(file);
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
document.replaceString(0, document.getTextLength(), text);
|
||||
manager.commitDocument(document);
|
||||
try {
|
||||
TextRange rangeToUse = myTextRange;
|
||||
if (rangeToUse == null) {
|
||||
rangeToUse = file.getTextRange();
|
||||
}
|
||||
ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
|
||||
}
|
||||
}, "", "");
|
||||
catch (IncorrectOperationException e) {
|
||||
fail(e.getLocalizedMessage());
|
||||
}
|
||||
}), "", "");
|
||||
|
||||
|
||||
if (document == null) {
|
||||
@@ -154,7 +141,8 @@ public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase {
|
||||
}
|
||||
|
||||
doTextTest(originalFileText, new File(expectedFileNameWithExtension), testFileExtension);
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
codeStyleSettings.clearCodeStyleSettings();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user