public final class FileContents extends java.lang.Object implements CommentListener
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.lang.Integer,java.util.List<TextBlock>> |
clangComments
Map of the C comments indexed on the first line of the comment to a list
of comments on that line.
|
private java.util.Map<java.lang.Integer,TextBlock> |
cppComments
Map of the C++ comments indexed on the first line of the comment.
|
private java.util.Map<java.lang.Integer,TextBlock> |
javadocComments
Map of the Javadoc comments indexed on the last line of the comment.
|
private static java.util.regex.Pattern |
MATCH_SINGLELINE_COMMENT
Compiled regexp to match a single-line comment line.
|
private static java.lang.String |
MATCH_SINGLELINE_COMMENT_PAT
The pattern to match a single line comment containing only the comment
itself -- no code.
|
private FileText |
text
The text.
|
| Constructor and Description |
|---|
FileContents(FileText text)
Creates a new
FileContents instance. |
| Modifier and Type | Method and Description |
|---|---|
private java.lang.String[] |
extractBlockComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Returns the specified block comment as a String array.
|
java.util.Map<java.lang.Integer,java.util.List<TextBlock>> |
getBlockComments()
Returns a map of all block comments.
|
java.lang.String |
getFileName()
Gets the name of the file.
|
TextBlock |
getJavadocBefore(int lineNoBefore)
Returns the Javadoc comment before the specified line.
|
java.lang.String |
getLine(int index)
Get the line from text of the file.
|
java.lang.String[] |
getLines()
Gets the lines in the file.
|
java.util.Map<java.lang.Integer,TextBlock> |
getSingleLineComments()
Returns a map of all the single line comments.
|
FileText |
getText()
Get the full text of the file.
|
private boolean |
hasIntersectionWithBlockComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Checks if the specified position intersects with a block comment.
|
boolean |
hasIntersectionWithComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Checks if the specified position intersects with a comment.
|
private boolean |
hasIntersectionWithSingleLineComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Checks if the specified position intersects with a single line comment.
|
boolean |
inPackageInfo()
Checks if the current file is a package-info.java file.
|
private java.lang.String |
line(int lineNo)
Get a single line.
|
boolean |
lineIsBlank(int lineNo)
Checks if the specified line is blank.
|
boolean |
lineIsComment(int lineNo)
Checks if the specified line is a single-line comment without code.
|
void |
reportBlockComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Report the location of a block comment.
|
void |
reportBlockComment(java.lang.String type,
int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Report the location of a block comment that can span multiple lines.
|
void |
reportSingleLineComment(int startLineNo,
int startColNo)
Report the location of a single line comment.
|
void |
reportSingleLineComment(java.lang.String type,
int startLineNo,
int startColNo)
Report the location of a single line comment that extends from the
given point to the end of the line.
|
private static final java.lang.String MATCH_SINGLELINE_COMMENT_PAT
private static final java.util.regex.Pattern MATCH_SINGLELINE_COMMENT
private final java.util.Map<java.lang.Integer,TextBlock> javadocComments
private final java.util.Map<java.lang.Integer,TextBlock> cppComments
private final java.util.Map<java.lang.Integer,java.util.List<TextBlock>> clangComments
public FileContents(FileText text)
FileContents instance.text - the contents of the filepublic FileText getText()
public java.lang.String[] getLines()
public java.lang.String getLine(int index)
index - index of the linepublic java.lang.String getFileName()
public void reportSingleLineComment(java.lang.String type, int startLineNo, int startColNo)
CommentListenerreportSingleLineComment in interface CommentListenertype - an identifier for what type of comment it is.startLineNo - the starting line numberstartColNo - the starting column numberpublic void reportSingleLineComment(int startLineNo, int startColNo)
startLineNo - the starting line numberstartColNo - the starting column numberpublic void reportBlockComment(java.lang.String type, int startLineNo, int startColNo, int endLineNo, int endColNo)
CommentListenerreportBlockComment in interface CommentListenertype - an identifier for what type of comment it is.startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberpublic void reportBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberprivate java.lang.String[] extractBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberprivate java.lang.String line(int lineNo)
lineNo - the number of the line to getjava.lang.IndexOutOfBoundsException - if lineNo is invalidpublic TextBlock getJavadocBefore(int lineNoBefore)
null means there is no such comment.lineNoBefore - the line number to check beforenull if nonepublic boolean lineIsBlank(int lineNo)
lineNo - the line number to checkpublic boolean lineIsComment(int lineNo)
lineNo - the line number to checkpublic boolean hasIntersectionWithComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberprivate boolean hasIntersectionWithBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberprivate boolean hasIntersectionWithSingleLineComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
startLineNo - the starting line numberstartColNo - the starting column numberendLineNo - the ending line numberendColNo - the ending column numberpublic java.util.Map<java.lang.Integer,TextBlock> getSingleLineComments()
TextBlock at the line.public java.util.Map<java.lang.Integer,java.util.List<TextBlock>> getBlockComments()
List of block comment TextBlocks
that start at that line.public boolean inPackageInfo()
Copyright © 2001-2022. All Rights Reserved.