public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormatTextRanges affectedRanges, final boolean formatContextAroundRanges) throws IncorrectOperationException { try { validateModel(model); SequentialTask task = new MyFormattingTask() { @NotNull @Override protected FormatProcessor buildProcessor() { FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges, formatContextAroundRanges); FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), options, getProgressCallback() ); processor.format(model, true); return processor; } }; execute(task); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }
public void formatWithoutModifications(final FormattingDocumentModel model, final Block rootBlock, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange affectedRange) throws IncorrectOperationException { SequentialTask task = new MyFormattingTask() { @NotNull @Override protected FormatProcessor buildProcessor() { FormatProcessor result = new FormatProcessor( model, rootBlock, settings, indentOptions, new FormatTextRanges(affectedRange, true), FormattingProgressCallback.EMPTY ); result.formatWithoutRealModifications(); return result; } }; execute(task); }
@Override public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final CommonCodeStyleSettings.IndentOptions javaIndentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException { SequentialTask task = new MyFormattingTask() { @NotNull @Override protected FormatProcessor buildProcessor() { FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), settings, indentOptions, affectedRanges, FormattingProgressCallback.EMPTY ); processor.setJavaIndentOptions(javaIndentOptions); processor.format(model); return processor; } }; execute(task); }
@Override public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException { SequentialTask task = new MyFormattingTask() { @NotNull @Override protected FormatProcessor buildProcessor() { FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), settings, indentOptions, affectedRanges, getProgressCallback() ); processor.format(model, true); return processor; } }; execute(task); }
@Override public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final CommonCodeStyleSettings.IndentOptions javaIndentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException { try { validateModel(model); SequentialTask task = new MyFormattingTask() { @Nonnull @Override protected FormatProcessor buildProcessor() { FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), settings, indentOptions, affectedRanges, FormattingProgressCallback.EMPTY ); processor.format(model); return processor; } }; execute(task); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }
public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final FormatTextRanges affectedRanges, final boolean formatContextAroundRanges) throws IncorrectOperationException { try { validateModel(model); SequentialTask task = new MyFormattingTask() { @Nonnull @Override protected FormatProcessor buildProcessor() { FormatOptions options = new FormatOptions(settings, indentOptions, affectedRanges, formatContextAroundRanges); FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), options, getProgressCallback() ); processor.format(model, true); return processor; } }; execute(task); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }
public void formatWithoutModifications(final FormattingDocumentModel model, final Block rootBlock, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final TextRange affectedRange) throws IncorrectOperationException { SequentialTask task = new MyFormattingTask() { @Nonnull @Override protected FormatProcessor buildProcessor() { FormatProcessor result = new FormatProcessor( model, rootBlock, settings, indentOptions, new FormatTextRanges(affectedRange, true), FormattingProgressCallback.EMPTY ); result.formatWithoutRealModifications(); return result; } }; execute(task); }
private void execute(@Nonnull SequentialTask task) { disableFormatting(); Application application = ApplicationManager.getApplication(); FormattingProgressTask progressTask = myProgressTask.getAndSet(null); if (progressTask == null || !application.isDispatchThread() || application.isUnitTestMode()) { try { task.prepare(); while (!task.isDone()) { task.iteration(); } } finally { enableFormatting(); } } else { progressTask.setTask(task); Runnable callback = () -> enableFormatting(); for (FormattingProgressCallback.EventType eventType : FormattingProgressCallback.EventType.values()) { progressTask.addCallback(eventType, callback); } ProgressManager.getInstance().run(progressTask); } }
@Override public void format(final FormattingModel model, final CodeStyleSettings settings, final CommonCodeStyleSettings.IndentOptions indentOptions, final CommonCodeStyleSettings.IndentOptions javaIndentOptions, final FormatTextRanges affectedRanges) throws IncorrectOperationException { try { validateModel(model); SequentialTask task = new MyFormattingTask() { @NotNull @Override protected FormatProcessor buildProcessor() { FormatProcessor processor = new FormatProcessor( model.getDocumentModel(), model.getRootBlock(), settings, indentOptions, affectedRanges, FormattingProgressCallback.EMPTY ); processor.setJavaIndentOptions(javaIndentOptions); processor.format(model); return processor; } }; execute(task); } catch (FormattingModelInconsistencyException e) { LOG.error(e); } }
/** * Execute given sequential formatting task. Two approaches are possible: * <pre> * <ul> * <li> * <b>synchronous</b> - the task is completely executed during the current method processing; * </li> * <li> * <b>asynchronous</b> - the task is executed at background thread under the progress dialog; * </li> * </ul> * </pre> * * @param task task to execute */ private void execute(@NotNull SequentialTask task) { disableFormatting(); Application application = ApplicationManager.getApplication(); FormattingProgressTask progressTask = myProgressTask.getAndSet(null); if (progressTask == null || !application.isDispatchThread() || application.isUnitTestMode()) { try { task.prepare(); while (!task.isDone()) { task.iteration(); } } finally { enableFormatting(); } } else { progressTask.setTask(task); Runnable callback = new Runnable() { @Override public void run() { enableFormatting(); } }; for (FormattingProgressCallback.EventType eventType : FormattingProgressCallback.EventType.values()) { progressTask.addCallback(eventType, callback); } ProgressManager.getInstance().run(progressTask); } }
@Override protected void prepare(@NotNull final SequentialTask task) { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { Document document = myDocument.get(); if (document != null) { myDocumentModificationStampBefore = document.getModificationStamp(); } task.prepare(); } }); }
@Override protected void prepare(@Nonnull final SequentialTask task) { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { Document document = myDocument.get(); if (document != null) { myDocumentModificationStampBefore = document.getModificationStamp(); } task.prepare(); } }); }
/** * Allows to define an actual formatting task to process. * <p/> * I.e. the general idea is that given indicator is provided with the task which will be executed from EDT * {@link SequentialTask#iteration() part by part} until the task {@link SequentialTask#isDone() is finished}. * That <code>'part-by-part'</code> processing is assumed to update current indicator (call <code>'beforeXxx()'</code> * and <code>'afterXxx()'</code> methods). * * @param task formatter task to process */ void setTask(@Nullable SequentialTask task);