Ejemplo n.º 1
0
  /*
   * @see org.eclipse.wst.jsdt.internal.corext.text.comment.CommentLine#adapt(org.eclipse.wst.jsdt.internal.corext.text.comment.CommentLine)
   */
  protected void adapt(final CommentLine previous) {

    if (!hasAttribute(COMMENT_ROOT)
        && !hasAttribute(COMMENT_PARAMETER)
        && !previous.hasAttribute(COMMENT_BLANKLINE))
      fReferenceIndentation = previous.getIndentationReference();
  }
Ejemplo n.º 2
0
  /** Tokenizes the comment region. */
  protected void tokenizeRegion() {

    int index = 0;
    CommentLine line = null;

    for (final Iterator iterator = fLines.iterator(); iterator.hasNext(); index++) {

      line = (CommentLine) iterator.next();

      line.scanLine(index);
      line.tokenizeLine(index);
    }
  }
Ejemplo n.º 3
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);
  }
Ejemplo n.º 4
0
 /**
  * Returns the line delimiter used in this comment line break.
  *
  * @param predecessor the predecessor comment line after the line break
  * @param successor the successor comment line before the line break
  * @param previous the comment range after the line break
  * @param next the comment range before the line break
  * @param indentation indentation of the formatted line break
  * @return the line delimiter for this comment line break
  */
 protected String getDelimiter(
     final CommentLine predecessor,
     final CommentLine successor,
     final CommentRange previous,
     final CommentRange next,
     final String indentation) {
   return fDelimiter + indentation + successor.getContentPrefix();
 }
Ejemplo n.º 5
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;
      }
    }
  }
Ejemplo n.º 6
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
    }
  }
Ejemplo n.º 7
0
  /**
   * Formats this comment region.
   *
   * @param indentation the indentation of this comment region
   * @param width the maximal width of text in this comment region measured in average character
   *     widths
   */
  protected void formatRegion(final String indentation, final int width) {

    final int last = fLines.size() - 1;
    if (last >= 0) {

      CommentLine lastLine = (CommentLine) fLines.get(last);
      CommentRange lastRange = lastLine.getLast();
      lastLine.formatLowerBorder(lastRange, indentation, width);

      CommentLine previous;
      CommentLine next = null;
      CommentRange range = null;
      for (int line = last; line >= 0; line--) {

        previous = next;
        next = (CommentLine) fLines.get(line);

        range = next.formatLine(previous, range, indentation, line);
      }
      next.formatUpperBorder(range, indentation, width);
    }
  }