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.lang.String |
fileName
The file name.
|
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. |
FileContents(java.lang.String filename,
java.lang.String... lines)
Deprecated.
Use
FileContents(FileText) instead
in order to preserve the original line breaks where possible. |
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.
|
com.google.common.collect.ImmutableMap<java.lang.Integer,java.util.List<TextBlock>> |
getBlockComments()
Returns a map of all block comments.
|
com.google.common.collect.ImmutableMap<java.lang.Integer,java.util.List<TextBlock>> |
getCComments()
Deprecated.
Use
getBlockComments() instead. |
com.google.common.collect.ImmutableMap<java.lang.Integer,TextBlock> |
getCppComments()
Deprecated.
Use
getSingleLineComments() instead. |
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.
|
com.google.common.collect.ImmutableMap<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 |
reportCComment(int startLineNo,
int startColNo,
int endLineNo,
int endColNo)
Deprecated.
Use
reportBlockComment(int, int, int, int) instead. |
void |
reportCppComment(int startLineNo,
int startColNo)
Deprecated.
Use
reportSingleLineComment(int, int) instead. |
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.lang.String fileName
private final FileText text
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
@Deprecated public FileContents(java.lang.String filename, java.lang.String... lines)
FileContents(FileText)
instead
in order to preserve the original line breaks where possible.FileContents
instance.filename
- name of the filelines
- the contents of the filepublic FileContents(FileText text)
FileContents
instance.text
- the contents of the filepublic void reportSingleLineComment(java.lang.String type, int startLineNo, int startColNo)
CommentListener
reportSingleLineComment
in interface CommentListener
type
- 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)
CommentListener
reportBlockComment
in interface CommentListener
type
- 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 number@Deprecated public void reportCppComment(int startLineNo, int startColNo)
reportSingleLineComment(int, int)
instead.startLineNo
- the starting line numberstartColNo
- the starting column number@Deprecated public com.google.common.collect.ImmutableMap<java.lang.Integer,TextBlock> getCppComments()
getSingleLineComments()
instead.TextBlock
at the line.public com.google.common.collect.ImmutableMap<java.lang.Integer,TextBlock> getSingleLineComments()
TextBlock
at the line.@Deprecated public void reportCComment(int startLineNo, int startColNo, int endLineNo, int endColNo)
reportBlockComment(int, int, int, int)
instead.startLineNo
- the starting line numberstartColNo
- the starting column numberendLineNo
- the ending line numberendColNo
- the ending column number@Deprecated public com.google.common.collect.ImmutableMap<java.lang.Integer,java.util.List<TextBlock>> getCComments()
getBlockComments()
instead.List
of C style comment TextBlock
s
that start at that line.public com.google.common.collect.ImmutableMap<java.lang.Integer,java.util.List<TextBlock>> getBlockComments()
List
of block comment TextBlock
s
that start at that line.private 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 numberpublic TextBlock getJavadocBefore(int lineNoBefore)
null
means there is no such comment.lineNoBefore
- the line number to check beforenull
if noneprivate java.lang.String line(int lineNo)
lineNo
- the number of the line to getjava.lang.IndexOutOfBoundsException
- if lineNo is invalidpublic FileText getText()
public java.lang.String[] getLines()
public java.lang.String getLine(int index)
index
- index of the linepublic java.lang.String getFileName()
public 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 numberpublic boolean inPackageInfo()
private 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 number