Esempio n. 1
0
  /*
   * @see org.eclipse.wst.jsdt.internal.corext.text.comment.CommentLine#append(org.eclipse.wst.jsdt.internal.corext.text.comment.CommentRange)
   */
  protected void append(final CommentRange range) {

    final MultiCommentRegion parent = (MultiCommentRegion) getParent();

    if (range.hasAttribute(COMMENT_PARAMETER)) setAttribute(COMMENT_PARAMETER);
    else if (range.hasAttribute(COMMENT_ROOT)) setAttribute(COMMENT_ROOT);
    else if (range.hasAttribute(COMMENT_BLANKLINE)) setAttribute(COMMENT_BLANKLINE);

    final int ranges = getSize();
    if (ranges == 1) {

      if (parent.isIndentRoots()) {

        final CommentRange first = getFirst();
        final String common =
            parent.getText(first.getOffset(), first.getLength())
                + CommentRegion.COMMENT_RANGE_DELIMITER;

        if (hasAttribute(COMMENT_ROOT)) fReferenceIndentation = common;
        else if (hasAttribute(COMMENT_PARAMETER)) {
          if (parent.isIndentDescriptions()) fReferenceIndentation = "\t" + common; // $NON-NLS-1$
          else fReferenceIndentation = common;
        }
      }
    }
    super.append(range);
  }
Esempio n. 2
0
  /**
   * Wraps the comment ranges in this comment region into comment lines.
   *
   * @param width the maximal width of text in this comment region measured in average character
   *     widths
   */
  protected void wrapRegion(final int width) {

    fLines.clear();

    int index = 0;
    boolean adapted = false;

    CommentLine successor = null;
    CommentLine predecessor = null;

    CommentRange previous = null;
    CommentRange next = null;

    while (!fRanges.isEmpty()) {

      index = 0;
      adapted = false;

      predecessor = successor;
      successor = createLine();
      fLines.add(successor);

      while (!fRanges.isEmpty()) {
        next = (CommentRange) fRanges.getFirst();

        if (canAppend(successor, previous, next, index, width)) {

          if (!adapted && predecessor != null) {

            successor.adapt(predecessor);
            adapted = true;
          }

          fRanges.removeFirst();
          successor.append(next);

          index += (next.getLength() + 1);
          previous = next;
        } else break;
      }
    }
  }
Esempio n. 3
0
  /**
   * Creates a new comment region.
   *
   * @param document the document which contains the comment region
   * @param position the position of this comment region in the document
   * @param formatter the given code formatter
   */
  public CommentRegion(
      final IDocument document, final Position position, final CodeFormatterVisitor formatter) {
    super(position.getOffset(), position.getLength());

    this.preferences = formatter.preferences;
    fDelimiter = this.preferences.line_separator;
    fDocument = document;

    fTabSize =
        DefaultCodeFormatterOptions.SPACE == this.preferences.tab_char
            ? this.preferences.indentation_size
            : this.preferences.tab_size;

    this.scribe = formatter.scribe;

    final ILineTracker tracker = new DefaultLineTracker();

    IRegion range = null;
    CommentLine line = null;

    tracker.set(getText(0, getLength()));
    final int lines = tracker.getNumberOfLines();

    fSingleLine = lines == 1;

    try {

      for (int index = 0; index < lines; index++) {

        range = tracker.getLineInformation(index);
        line = createLine();
        line.append(new CommentRange(range.getOffset(), range.getLength()));

        fLines.add(line);
      }

    } catch (BadLocationException exception) {
      // Should not happen
    }
  }