writeCommandAction.execute();
reformatPositions(statement.getContainingFile(), range);
}
public static void moveSimpleStatementOut(Editor editor, GoIfStatement ifStatement) {
final GoSimpleStatement simpleStatement = ifStatement.getSimpleStatement();
final GoExpr condition = ifStatement.getExpression();
if (simpleStatement == null || condition == null) {
return;
}
moveDependentSimpleStatementsFirst(editor, ifStatement, simpleStatement);
PsiElement outermostIf = ifStatement;
while (outermostIf instanceof GoIfStatement && outermostIf.getParent() instanceof GoIfStatement) {
outermostIf = outermostIf.getParent();
}
final Document document = editor.getDocument();
RangeMarker range = document.createRangeMarker(outermostIf.getTextOffset(), condition.getTextOffset());
final PsiElement finalOutermostIf = outermostIf;
WriteCommandAction writeCommandAction = new WriteCommandAction(ifStatement.getContainingFile().getProject()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
document.deleteString(simpleStatement.getTextOffset(), condition.getTextOffset());
document.insertString(finalOutermostIf.getTextOffset(), simpleStatement.getText() + "\n");
}
};
writeCommandAction.execute();
reformatPositions(ifStatement.getContainingFile(), range);
}