org.aspectj.org.eclipse.jdt.internal.formatter.comment
Class CommentRegion

java.lang.Object
  extended by Position
      extended by org.aspectj.org.eclipse.jdt.internal.formatter.comment.CommentRegion
All Implemented Interfaces:
IBorderAttributes, ICommentAttributes, IHtmlTagDelimiters
Direct Known Subclasses:
MultiCommentRegion

public class CommentRegion
extends Position
implements IHtmlTagDelimiters, IBorderAttributes, ICommentAttributes

Comment region in a source code document.

Since:
3.0

Field Summary
protected static java.lang.String COMMENT_RANGE_DELIMITER
          Default comment range delimiter
protected  boolean fClear
          Should all blank lines be cleared during formatting?
protected  DefaultCodeFormatterOptions preferences
          The formatting preferences
protected  Scribe scribe
          the scribe used to create edits
 
Fields inherited from interface org.aspectj.org.eclipse.jdt.internal.formatter.comment.IHtmlTagDelimiters
HTML_CLOSE_PREFIX, HTML_TAG_POSTFIX, HTML_TAG_PREFIX
 
Fields inherited from interface org.aspectj.org.eclipse.jdt.internal.formatter.comment.IBorderAttributes
BORDER_LOWER, BORDER_UPPER
 
Fields inherited from interface org.aspectj.org.eclipse.jdt.internal.formatter.comment.ICommentAttributes
COMMENT_BLANKLINE, COMMENT_BREAK, COMMENT_CLOSE, COMMENT_CODE, COMMENT_FIRST_TOKEN, COMMENT_HTML, COMMENT_IMMUTABLE, COMMENT_NEWLINE, COMMENT_OPEN, COMMENT_PARAGRAPH, COMMENT_PARAMETER, COMMENT_ROOT, COMMENT_SEPARATOR, COMMENT_STARTS_WITH_RANGE_DELIMITER
 
Constructor Summary
CommentRegion(IDocument document, Position position, CodeFormatterVisitor formatter)
          Creates a new comment region.
 
Method Summary
protected  void append(CommentRange range)
          Appends the comment range to this comment region.
protected  boolean canAppend(CommentLine line, CommentRange previous, CommentRange next, int index, int width)
          Can the comment range be appended to the comment line?
protected  boolean canFormat(CommentRange previous, CommentRange next)
          Can the whitespace between the two comment ranges be formatted?
protected  CommentLine createLine()
          Creates a new line for this region.
 TextEdit format(int indentationLevel, boolean returnEdit)
          Formats the comment region with the given indentation level.
protected  void formatRegion(java.lang.String indentation, int width)
          Formats this comment region.
protected  java.lang.String getDelimiter()
          Returns the line delimiter used in this comment region.
protected  java.lang.String getDelimiter(CommentLine predecessor, CommentLine successor, CommentRange previous, CommentRange next, java.lang.String indentation)
          Returns the line delimiter used in this comment line break.
protected  java.lang.String getDelimiter(CommentRange previous, CommentRange next)
          Returns the range delimiter for this comment range break.
protected  IDocument getDocument()
          Returns the document of this comment region.
protected  java.util.LinkedList getRanges()
          Returns the comment ranges in this comment region
protected  int getSize()
          Returns the number of comment lines in this comment region.
protected  java.lang.String getText(int position, int count)
          Returns the text of this comment region in the indicated range.
protected  boolean hasBorder(int border)
          Does the border border exist?
protected  boolean isAlphaNumeric(CommentRange range)
          Does the comment range consist of letters and digits only?
protected  boolean isClearLines()
          Should blank lines be cleared during formatting?
protected  boolean isNonAlphaNumeric(CommentRange range)
          Does the comment range contain no letters and digits?
protected  boolean isSingleLine()
          Is this comment region a single line region?
protected  void logEdit(java.lang.String change, int position, int count)
          Logs a text edit operation occurred during the formatting process
protected  void markRegion()
          Marks the comment ranges in this comment region.
protected  void setBorder(int border)
          Set the border type border to true.
protected  java.lang.String stringToIndent(java.lang.String reference)
          Computes the equivalent indentation for a string
protected  int stringToLength(java.lang.String reference)
          Returns the length of the string in expanded characters.
protected  void tokenizeRegion()
          Tokenizes the comment region.
protected  void wrapRegion(int width)
          Wraps the comment ranges in this comment region into comment lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMENT_RANGE_DELIMITER

protected static final java.lang.String COMMENT_RANGE_DELIMITER
Default comment range delimiter

See Also:
Constant Field Values

fClear

protected boolean fClear
Should all blank lines be cleared during formatting?


preferences

protected final DefaultCodeFormatterOptions preferences
The formatting preferences


scribe

protected Scribe scribe
the scribe used to create edits

Constructor Detail

CommentRegion

public CommentRegion(IDocument document,
                     Position position,
                     CodeFormatterVisitor formatter)
Creates a new comment region.

Parameters:
document - the document which contains the comment region
position - the position of this comment region in the document
formatter - the given code formatter
Method Detail

append

protected final void append(CommentRange range)
Appends the comment range to this comment region.

Parameters:
range - comment range to append to this comment region

canAppend

protected boolean canAppend(CommentLine line,
                            CommentRange previous,
                            CommentRange next,
                            int index,
                            int width)
Can the comment range be appended to the comment line?

Parameters:
line - comment line where to append the comment range
previous - comment range which is the predecessor of the current comment range
next - comment range to test whether it can be appended to the comment line
index - amount of space in the comment line used by already inserted comment ranges
width - the maximal width of text in this comment region measured in average character widths
Returns:
true iff the comment range can be added to the line, false otherwise

canFormat

protected boolean canFormat(CommentRange previous,
                            CommentRange next)
Can the whitespace between the two comment ranges be formatted?

Parameters:
previous - previous comment range which was already formatted, can be null
next - next comment range to be formatted
Returns:
true iff the next comment range can be formatted, false otherwise.

format

public final TextEdit format(int indentationLevel,
                             boolean returnEdit)
Formats the comment region with the given indentation level.

Parameters:
indentationLevel - the indentation level
Returns:
the resulting text edit of the formatting process
Since:
3.1

formatRegion

protected void formatRegion(java.lang.String indentation,
                            int width)
Formats this comment region.

Parameters:
indentation - the indentation of this comment region
width - the maximal width of text in this comment region measured in average character widths

getDelimiter

protected final java.lang.String getDelimiter()
Returns the line delimiter used in this comment region.

Returns:
the line delimiter for this comment region

getDelimiter

protected java.lang.String getDelimiter(CommentLine predecessor,
                                        CommentLine successor,
                                        CommentRange previous,
                                        CommentRange next,
                                        java.lang.String indentation)
Returns the line delimiter used in this comment line break.

Parameters:
predecessor - the predecessor comment line after the line break
successor - the successor comment line before the line break
previous - the comment range after the line break
next - the comment range before the line break
indentation - indentation of the formatted line break
Returns:
the line delimiter for this comment line break

getDelimiter

protected java.lang.String getDelimiter(CommentRange previous,
                                        CommentRange next)
Returns the range delimiter for this comment range break.

Parameters:
previous - the previous comment range to the right of the range delimiter
next - the next comment range to the left of the range delimiter
Returns:
the delimiter for this comment range break

getDocument

protected final IDocument getDocument()
Returns the document of this comment region.

Returns:
the document of this region

getRanges

protected final java.util.LinkedList getRanges()
Returns the comment ranges in this comment region

Returns:
the comment ranges in this region

getSize

protected final int getSize()
Returns the number of comment lines in this comment region.

Returns:
the number of lines in this comment region

getText

protected final java.lang.String getText(int position,
                                         int count)
Returns the text of this comment region in the indicated range.

Parameters:
position - the offset of the comment range to retrieve in comment region coordinates
count - the length of the comment range to retrieve
Returns:
the content of this comment region in the indicated range

hasBorder

protected final boolean hasBorder(int border)
Does the border border exist?

Parameters:
border - the type of the border, must be a border attribute of CommentRegion
Returns:
true iff this border exists, false otherwise

isAlphaNumeric

protected final boolean isAlphaNumeric(CommentRange range)
Does the comment range consist of letters and digits only?

Parameters:
range - the comment range to text
Returns:
true iff the comment range consists of letters and digits only, false otherwise

isNonAlphaNumeric

protected final boolean isNonAlphaNumeric(CommentRange range)
Does the comment range contain no letters and digits?

Parameters:
range - the comment range to text
Returns:
true iff the comment range contains no letters and digits, false otherwise

isClearLines

protected final boolean isClearLines()
Should blank lines be cleared during formatting?

Returns:
true iff blank lines should be cleared, false otherwise

isSingleLine

protected final boolean isSingleLine()
Is this comment region a single line region?

Returns:
true iff this region is single line, false otherwise

logEdit

protected final void logEdit(java.lang.String change,
                             int position,
                             int count)
Logs a text edit operation occurred during the formatting process

Parameters:
change - the changed text
position - offset measured in comment region coordinates where to apply the changed text
count - length of the range where to apply the changed text

markRegion

protected void markRegion()
Marks the comment ranges in this comment region.


setBorder

protected final void setBorder(int border)
Set the border type border to true.

Parameters:
border - the type of the border. Must be a border attribute of CommentRegion

stringToIndent

protected final java.lang.String stringToIndent(java.lang.String reference)
Computes the equivalent indentation for a string

Parameters:
reference - the string to compute the indentation for
Returns:
the indentation string

stringToLength

protected final int stringToLength(java.lang.String reference)
Returns the length of the string in expanded characters.

Parameters:
reference - the string to get the length for
Returns:
the length of the string in expanded characters

tokenizeRegion

protected void tokenizeRegion()
Tokenizes the comment region.


wrapRegion

protected void wrapRegion(int width)
Wraps the comment ranges in this comment region into comment lines.

Parameters:
width - the maximal width of text in this comment region measured in average character widths

createLine

protected CommentLine createLine()
Creates a new line for this region.

Returns:
a new line for this region
Since:
3.1