Java 类com.intellij.psi.impl.source.codeStyle.IndentHelperImpl 实例源码

项目:intellij-ce-playground    文件:PydevConsoleExecuteActionHandler.java   
private void processOneLine(String line) {
  int indentSize = IndentHelperImpl.getIndent(getProject(), PythonFileType.INSTANCE, line, false);
  line = StringUtil.trimTrailing(line);
  if (StringUtil.isEmptyOrSpaces(line)) {
    doProcessLine("\n");
  }
  else if (indentSize == 0 &&
           indentSize < myCurrentIndentSize &&
           !PyConsoleIndentUtil.shouldIndent(line) &&
           !myConsoleCommunication.isWaitingForInput()) {
    doProcessLine("\n");
    doProcessLine(line);
  }
  else {
    doProcessLine(line);
  }
}
项目:intellij-ce-playground    文件:PostprocessReformattingAspect.java   
private static void adjustIndentationInRange(@NotNull PsiFile file,
                                             @NotNull Document document,
                                             @NotNull TextRange[] indents,
                                             final int indentAdjustment) {
  final CharSequence charsSequence = document.getCharsSequence();
  for (final TextRange indent : indents) {
    final String oldIndentStr = charsSequence.subSequence(indent.getStartOffset() + 1, indent.getEndOffset()).toString();
    final int oldIndent = IndentHelperImpl.getIndent(file.getProject(), file.getFileType(), oldIndentStr, true);
    final String newIndentStr = IndentHelperImpl
      .fillIndent(file.getProject(), file.getFileType(), Math.max(oldIndent + indentAdjustment, 0));
    document.replaceString(indent.getStartOffset() + 1, indent.getEndOffset(), newIndentStr);
  }
}
项目:intellij-ce-playground    文件:PydevConsoleExecuteActionHandler.java   
private void indentEditor(final Editor editor, final int indentSize) {
  new WriteCommandAction(getProject()) {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      EditorModificationUtil.insertStringAtCaret(editor, IndentHelperImpl.fillIndent(getProject(), PythonFileType.INSTANCE, indentSize));
    }
  }.execute();
}
项目:tools-idea    文件:PostprocessReformattingAspect.java   
private static void adjustIndentationInRange(final PsiFile file,
                                             final Document document,
                                             final TextRange[] indents,
                                             final int indentAdjustment) {
  final CharSequence charsSequence = document.getCharsSequence();
  for (final TextRange indent : indents) {
    final String oldIndentStr = charsSequence.subSequence(indent.getStartOffset() + 1, indent.getEndOffset()).toString();
    final int oldIndent = IndentHelperImpl.getIndent(file.getProject(), file.getFileType(), oldIndentStr, true);
    final String newIndentStr = IndentHelperImpl
      .fillIndent(file.getProject(), file.getFileType(), Math.max(oldIndent + indentAdjustment, 0));
    document.replaceString(indent.getStartOffset() + 1, indent.getEndOffset(), newIndentStr);
  }
}
项目:consulo    文件:PostprocessReformattingAspect.java   
private static void adjustIndentationInRange(@Nonnull PsiFile file, @Nonnull Document document, @Nonnull TextRange[] indents, final int indentAdjustment) {
  final CharSequence charsSequence = document.getCharsSequence();
  for (final TextRange indent : indents) {
    final String oldIndentStr = charsSequence.subSequence(indent.getStartOffset() + 1, indent.getEndOffset()).toString();
    final int oldIndent = IndentHelperImpl.getIndent(file.getProject(), file.getFileType(), oldIndentStr, true);
    final String newIndentStr = IndentHelperImpl.fillIndent(CodeStyle.getIndentOptions(file), Math.max(oldIndent + indentAdjustment, 0));
    document.replaceString(indent.getStartOffset() + 1, indent.getEndOffset(), newIndentStr);
  }
}
项目:intellij-ce-playground    文件:PydevConsoleExecuteActionHandler.java   
public void doProcessLine(final String line) {
  if (myInputBuffer == null) {
    myInputBuffer = new StringBuilder();
  }

  if (!StringUtil.isEmptyOrSpaces(line)) {
    myInputBuffer.append(line);
    if (!line.endsWith("\n")) {
      myInputBuffer.append("\n");
    }
  }

  if (StringUtil.isEmptyOrSpaces(line) && StringUtil.isEmptyOrSpaces(myInputBuffer.toString())) {
    myInputBuffer.append("");
  }

  // multiline strings handling
  if (myInMultilineStringState != null) {
    if (PyConsoleUtil.isDoubleQuoteMultilineStarts(line) || PyConsoleUtil.isSingleQuoteMultilineStarts(line)) {
      myInMultilineStringState = null;
      // restore language
      myConsoleView.setLanguage(PythonLanguage.getInstance());
      myConsoleView.setPrompt(PyConsoleUtil.ORDINARY_PROMPT);
    }
    else {
      if (line.equals("\n")) {
        myInputBuffer.append("\n");
      }
      return;
    }
  }
  else {
    if (PyConsoleUtil.isDoubleQuoteMultilineStarts(line)) {
      myInMultilineStringState = PyConsoleUtil.DOUBLE_QUOTE_MULTILINE;
    }
    else if (PyConsoleUtil.isSingleQuoteMultilineStarts(line)) {
      myInMultilineStringState = PyConsoleUtil.SINGLE_QUOTE_MULTILINE;
    }
    if (myInMultilineStringState != null) {
      // change language
      myConsoleView.setLanguage(PlainTextLanguage.INSTANCE);
      myConsoleView.setPrompt(PyConsoleUtil.INDENT_PROMPT);
      return;
    }
  }

  // Process line continuation
  if (line.endsWith("\\")) {
    myConsoleView.setPrompt(PyConsoleUtil.INDENT_PROMPT);
    return;
  }

  if (!StringUtil.isEmptyOrSpaces(line)) {
    int indent = IndentHelperImpl.getIndent(getProject(), PythonFileType.INSTANCE, line, false);
    boolean flag = false;
    if (PyConsoleIndentUtil.shouldIndent(line)) {
      indent += getPythonIndent();
      flag = true;
    }
    if ((myCurrentIndentSize > 0 && indent > 0) || flag) {
      setCurrentIndentSize(indent);
      indentEditor(myConsoleView.getConsoleEditor(), indent);
      more();

      myConsoleCommunication.notifyCommandExecuted(true);
      return;
    }
  }


  sendLineToConsole(new ConsoleCommunication.ConsoleCodeFragment(myInputBuffer.toString(), true));
}
项目:intellij-ce-playground    文件:PydevConsoleExecuteActionHandler.java   
private void sendLineToConsole(@NotNull final ConsoleCommunication.ConsoleCodeFragment code) {
  if (!StringUtil.isEmptyOrSpaces(code.getText())) {
    myIpythonInputPromptCount += 1;
  }
  if (myConsoleCommunication != null) {
    final boolean waitedForInputBefore = myConsoleCommunication.isWaitingForInput();
    if (myConsoleCommunication.isWaitingForInput()) {
      myInputBuffer.setLength(0);
    }
    else {
      executingPrompt();
    }
    myConsoleCommunication.execInterpreter(code, new Function<InterpreterResponse, Object>() {
      @Override
      public Object fun(final InterpreterResponse interpreterResponse) {
        // clear
        myInputBuffer = null;

        //notify listeners like xdebugger variables view re-builder
        getConsoleCommunication().notifyCommandExecuted(interpreterResponse.more);

        // Handle prompt
        if (interpreterResponse.more) {
          more();
          if (myCurrentIndentSize == 0) {
            // compute current indentation
            setCurrentIndentSize(
              IndentHelperImpl.getIndent(getProject(), PythonFileType.INSTANCE, lastLine(code.getText()), false) + getPythonIndent());
            // In this case we can insert indent automatically
            final EditorEx editor = myConsoleView.getConsoleEditor();
            UIUtil.invokeLaterIfNeeded(new Runnable() {
              @Override
              public void run() {
                indentEditor(editor, myCurrentIndentSize);
              }
            });
          }
        }
        else {
          if (!myConsoleCommunication.isWaitingForInput()) {
            inPrompt();
          }
          setCurrentIndentSize(0);
        }

        return null;
      }
    });
    // After requesting input we got no call back to change prompt, change it manually
    if (waitedForInputBefore && !myConsoleCommunication.isWaitingForInput()) {
      myIpythonInputPromptCount -= 1;
      inPrompt();
      setCurrentIndentSize(0);
    }
  }
}