com.intellij.psi.codeStyle.arrangement.Rearranger Java Examples

The following examples show how to use com.intellij.psi.codeStyle.arrangement.Rearranger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonCodeStyleSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean arrangementSettingsEqual(CommonCodeStyleSettings obj) {
  ArrangementSettings theseSettings = myArrangementSettings;
  ArrangementSettings otherSettings = obj.getArrangementSettings();
  if (theseSettings == null && otherSettings != null) {
    Rearranger<?> rearranger = Rearranger.EXTENSION.forLanguage(myLanguage);
    if (rearranger instanceof ArrangementStandardSettingsAware) {
      theseSettings = ((ArrangementStandardSettingsAware)rearranger).getDefaultSettings();
    }
  }
  return Comparing.equal(theseSettings, obj.getArrangementSettings());
}
 
Example #2
Source File: LayoutCodeDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void setUpActions() {
  boolean canOptimizeImports = !LanguageImportStatements.INSTANCE.forFile(myFile).isEmpty();
  myOptimizeImportsCb.setVisible(canOptimizeImports);
  if (canOptimizeImports) {
    myOptimizeImportsCb.setSelected(myLastRunOptions.getLastOptimizeImports());
  }

  boolean canRearrangeCode = Rearranger.EXTENSION.forLanguage(myFile.getLanguage()) != null;
  myRearrangeCodeCb.setVisible(canRearrangeCode);
  if (canRearrangeCode) {
    myRearrangeCodeCb.setSelected(myLastRunOptions.isRearrangeCode(myFile.getLanguage()));
  }

  myOptionalLabel.setVisible(canOptimizeImports || canRearrangeCode);
}
 
Example #3
Source File: RearrangeCodeProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected FutureTask<Boolean> prepareTask(@Nonnull final PsiFile file, final boolean processChangedTextOnly) {
  return new FutureTask<Boolean>(new Callable<Boolean>() {
    @Override
    public Boolean call() throws Exception {
      try {
        Collection<TextRange> ranges = getRangesToFormat(file, processChangedTextOnly);
        Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);

        if (document != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null) {
          PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document);
          PsiDocumentManager.getInstance(myProject).commitDocument(document);
          Runnable command = prepareRearrangeCommand(file, ranges);
          try {
            CommandProcessor.getInstance().executeCommand(myProject, command, COMMAND_NAME, null);
          }
          finally {
            PsiDocumentManager.getInstance(myProject).commitDocument(document);
          }
        }

        return true;
      }
      catch (FilesTooBigForDiffException e) {
        handleFileTooBigException(LOG, e, file);
        return false;
      }
    }
  });
}
 
Example #4
Source File: RearrangeCodeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  PsiFile file = e.getDataContext().getData(CommonDataKeys.PSI_FILE);
  boolean enabled = file != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null;
  e.getPresentation().setEnabled(enabled);
}