return new Runnable() {
@Override
public void run() {
try {
TextRange rangeToUse = file.getTextRange();
CodeStyleManager styleManager = CodeStyleManager.getInstance(getProject());
styleManager.reformatText(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
}
catch (IncorrectOperationException e) {
assertTrue(e.getLocalizedMessage(), false);
}
}
};
}
};
// define action to run "Adjust line indent" on every line in the "file" defined by beforeText
FormatRunnableFactory lineFormatRunnableFactory = new FormatRunnableFactory() {
@Override
Runnable createFormatRunnable(final PsiFile file) {
return new Runnable() {
@Override
public void run() {
try {
final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject());
final Document document = manager.getDocument(file);
assert document != null;
for (int lineNum = 0; lineNum < document.getLineCount(); lineNum++) {
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(getProject());
int offset = document.getLineStartOffset(lineNum);
@SuppressWarnings("deprecation") // if this breaks at some point, we should
// refactor to invoke AutoIndentLinesAction
// instead of doing the indent directly
boolean lineToBeIndented = codeStyleManager.isLineToBeIndented(file, offset);
if (lineToBeIndented) {
codeStyleManager.adjustLineIndent(file, offset);
}
}
}
catch (IncorrectOperationException e) {
assertTrue(e.getLocalizedMessage(), false);