Examples of CodeStyleManager


Examples of com.intellij.psi.codeStyle.CodeStyleManager

  @Nullable
  @Override
  public TextRange surroundElements(@NotNull final Project project, @NotNull final Editor editor, final Expression element) throws IncorrectOperationException {
    MathematicaPsiElementFactory factory = new MathematicaPsiElementFactory(project);
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

    Expression parExpr = factory.createExpressionFromText(myOpener + element.getText() + myCloser);
    parExpr = (Expression) codeStyleManager.reformat(parExpr);
    final PsiElement replace = element.replace(parExpr);
    return TextRange.from(replace.getTextOffset() + replace.getTextLength(), 0);
  }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

  @Nullable
  @Override
  public TextRange surroundElements(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws IncorrectOperationException {
    assert (elements.length == 1 && elements[0] != null) || PsiTreeUtil.findCommonParent(elements) == elements[0].getParent();
    final PsiElement e = elements[0];
    CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);

    final PsiFileFactory factory = PsiFileFactory.getInstance(project);
    final StringBuilder stringBuilder = new StringBuilder(myHead + "[{},\n");
    stringBuilder.append(e.getText());
    stringBuilder.append("\n]");

    final PsiFile file = factory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, stringBuilder);
    final FunctionCall[] func = PsiTreeUtil.getChildrenOfType(file, FunctionCall.class);
    assert func != null && func[0] != null;
    func[0] = (FunctionCall) codeStyleManager.reformat(func[0]);
    PsiElement newElement = e.replace(func[0]);

    final List<PsiElement> arguments = MathematicaPsiUtilities.getArguments(newElement);
    if (arguments.isEmpty()) {
      return null;
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

    // run the formatter if the user just completed typing a SIMPLE_INVERSE or a CLOSE_BLOCK_STACHE
    if (closeOrSimpleInverseParent != null) {
      // grab the current caret position (AutoIndentLinesHandler is about to mess with it)
      PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
      CaretModel caretModel = editor.getCaretModel();
      CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
      codeStyleManager.adjustLineIndent(file, editor.getDocument().getLineStartOffset(caretModel.getLogicalPosition().line));
    }
  }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

        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);
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

            installCodeFormatter(settings);
        }
    }

    private void installCodeFormatter(@NotNull Settings settings) {
        CodeStyleManager manager = CodeStyleManager.getInstance(project);
        if (!(manager instanceof EclipseCodeStyleManager) && Settings.Formatter.ECLIPSE.equals(settings.getFormatter())) {
            registerCodeStyleManager(project, new EclipseCodeStyleManager(manager, settings, project));
            // todo nastaveni okna pro formatovani at se otvira
//            if (settings.isOptimizeImports()) {
//                PropertiesComponent.getInstance().setValue(LayoutCodeDialog.OPTIMIZE_IMPORTS_KEY, Boolean.toString(false));
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

//            }
        }
    }

    private void uninstallCodeFormatter() {
        CodeStyleManager manager = CodeStyleManager.getInstance(project);
        while (manager instanceof EclipseCodeStyleManager) {
            manager = ((EclipseCodeStyleManager) manager).getOriginal();
            registerCodeStyleManager(project, manager);
        }
    }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

      installCodeFormatter(settings);
    }
  }

  private void installCodeFormatter(@NotNull Settings settings) {
    CodeStyleManager manager = CodeStyleManager.getInstance(project);
    if (Settings.Formatter.ECLIPSE.equals(settings.getFormatter())) {
      registerCodeStyleManager(project, new EclipseCodeStyleManager(manager, settings, project));

      if (settings.isOptimizeImports()) {
        PropertiesComponent.getInstance().setValue(LayoutCodeConstants.OPTIMIZE_IMPORTS_KEY,
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

    }
    return keymap;
  }

  private void uninstallCodeFormatter() {
    CodeStyleManager manager = CodeStyleManager.getInstance(project);
    while (manager instanceof EclipseCodeStyleManager) {
      manager = ((EclipseCodeStyleManager) manager).getOriginal();
      registerCodeStyleManager(project, manager);
      Keymap parent = getKeyMap();
      uninstallShortcut(parent, OPTIMIZE_IMPORTS_OLD_PLUGIN);
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

            installCodeFormatter(settings);
        }
    }

    private void installCodeFormatter(@NotNull Settings settings) {
        CodeStyleManager manager = CodeStyleManager.getInstance(project);
        if (!(manager instanceof EclipseCodeStyleManager) && Settings.Formatter.ECLIPSE.equals(settings.getFormatter())) {
            registerCodeStyleManager(project, new EclipseCodeStyleManager(manager, settings, project));
        }
    }
View Full Code Here

Examples of com.intellij.psi.codeStyle.CodeStyleManager

            registerCodeStyleManager(project, new EclipseCodeStyleManager(manager, settings, project));
        }
    }

    private void uninstallCodeFormatter() {
        CodeStyleManager manager = CodeStyleManager.getInstance(project);
        while (manager instanceof EclipseCodeStyleManager) {
            manager = ((EclipseCodeStyleManager) manager).getOriginal();
            registerCodeStyleManager(project, manager);
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.