Пример #1
0
  /**
   * Indents line <code>line</code> in <code>document</code> with <code>indent</code>. Leaves
   * leading comment signs alone.
   *
   * @param document the document
   * @param line the line
   * @param indent the indentation to insert
   * @param tabLength the length of a tab
   * @throws BadLocationException on concurrent document modification
   */
  private void addIndent(Document document, int line, CharSequence indent, int tabLength)
      throws BadLocationException {
    IRegion region = document.getLineInformation(line);
    int insert = region.getOffset();
    int endOffset = region.getOffset() + region.getLength();

    // Compute insert after all leading line comment markers
    int newInsert = insert;
    while (newInsert < endOffset - 2 && document.get(newInsert, 2).equals(LINE_COMMENT))
      newInsert += 2;

    // Heuristic to check whether it is commented code or just a comment
    if (newInsert > insert) {
      int whitespaceCount = 0;
      int i = newInsert;
      while (i < endOffset - 1) {
        char ch = document.get(i, 1).charAt(0);
        if (!Character.isWhitespace(ch)) break;
        whitespaceCount = whitespaceCount + computeVisualLength(ch, tabLength);
        i++;
      }

      if (whitespaceCount != 0 && whitespaceCount >= CodeFormatterUtil.getIndentWidth(fProject))
        insert = newInsert;
    }

    // Insert indent
    document.replace(insert, 0, indent.toString());
  }
Пример #2
0
 /**
  * The preference setting for the visual tabulator display.
  *
  * @return the number of spaces displayed for a tabulator in the editor
  */
 private int getVisualTabLengthPreference() {
   return CodeFormatterUtil.getTabWidth(fProject);
 }
 private int getTabDisplaySize() {
   return CodeFormatterUtil.getTabWidth(null);
 }
 private int getIndentSize() {
   return CodeFormatterUtil.getIndentWidth(null);
 }