/** Uses same fallback as {@link CodeStyleManager#getCurrentFormattingMode}. */ @Override public FormattingMode getCurrentFormattingMode() { if (delegate instanceof FormattingModeAwareIndentAdjuster) { return ((FormattingModeAwareIndentAdjuster) delegate).getCurrentFormattingMode(); } return FormattingMode.REFORMAT; }
@Override public int adjustLineIndent( @NotNull final Document document, final int offset, FormattingMode mode) throws IncorrectOperationException { if (delegate instanceof FormattingModeAwareIndentAdjuster) { return ((FormattingModeAwareIndentAdjuster) delegate) .adjustLineIndent(document, offset, mode); } return offset; }
@Override public int adjustLineIndent(@NotNull Document document, int offset, FormattingMode formattingMode) { if (original instanceof FormattingModeAwareIndentAdjuster) { return ((FormattingModeAwareIndentAdjuster) original).adjustLineIndent(document, offset, formattingMode); } else { return offset; } }
@Override public FormattingMode getCurrentFormattingMode() { if (original instanceof FormattingModeAwareIndentAdjuster) { return ((FormattingModeAwareIndentAdjuster) original).getCurrentFormattingMode(); } else { return FormattingMode.REFORMAT; } }
@NotNull private static Class[] getInterfaces() { try { return new Class[]{FormattingModeAwareIndentAdjuster.class}; } catch (Throwable e) { //old API < IJ ~2017 return new Class[]{}; } }
public void run() { int lineStart = myDocument.getLineStartOffset(myLine); CommandProcessor.getInstance().runUndoTransparentAction(() -> ApplicationManager.getApplication().runWriteAction(() -> { CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(myProject); if (codeStyleManager instanceof FormattingModeAwareIndentAdjuster) { ((FormattingModeAwareIndentAdjuster)codeStyleManager).adjustLineIndent(myDocument, lineStart, FormattingMode.ADJUST_INDENT_ON_ENTER); } })); }