Class FileContents
java.lang.Object
com.puppycrawl.tools.checkstyle.api.FileContents
- All Implemented Interfaces:
 CommentListener
Represents the contents of a file.
- 
Field Summary
FieldsModifier and TypeFieldDescriptionMap of the C comments indexed on the first line of the comment to a list of comments on that line.Map of the C++ comments indexed on the first line of the comment.Map of the Javadoc comments indexed on the last line of the comment.private static final PatternCompiled regexp to match a single-line comment line.private static final StringThe pattern to match a single-line comment containing only the comment itself -- no code.private final FileTextThe text. - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprivate String[]extractBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Returns the specified block comment as a String array.Returns a map of all block comments.Gets the name of the file.getJavadocBefore(int lineNoBefore) Returns the Javadoc comment before the specified line.getLine(int index) Get the line from text of the file.String[]getLines()Gets the lines in the file.Returns a map of all the single-line comments.getText()Get the full text of the file.private booleanhasIntersectionWithBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a block comment.booleanhasIntersectionWithComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a comment.private booleanhasIntersectionWithSingleLineComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a single-line comment.booleanDeprecated.private booleanisLineBlockComment(int lineNo, TextBlock comment) Checks if the given line is inside a block comment and both the start and end lines contain only the comment.private Stringline(int lineNo) Get a single-line.private booleanlineInsideBlockComment(int lineNo) Checks if the specified line number is inside a block comment.booleanlineIsBlank(int lineNo) Checks if the specified line is blank.booleanlineIsComment(int lineNo) Checks if the specified line is a single-line comment without code.voidreportBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Report the location of a block comment.voidreportBlockComment(String type, int startLineNo, int startColNo, int endLineNo, int endColNo) Report the location of a block comment that can span multiple lines.voidreportSingleLineComment(int startLineNo, int startColNo) Report the location of a single-line comment.voidreportSingleLineComment(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. 
- 
Field Details
- 
MATCH_SINGLELINE_COMMENT_PAT
The pattern to match a single-line comment containing only the comment itself -- no code.- See Also:
 
 - 
MATCH_SINGLELINE_COMMENT
Compiled regexp to match a single-line comment line. - 
text
The text. - 
javadocComments
Map of the Javadoc comments indexed on the last line of the comment. The hack is it assumes that there is only one Javadoc comment per line. - 
cppComments
Map of the C++ comments indexed on the first line of the comment. - 
clangComments
Map of the C comments indexed on the first line of the comment to a list of comments on that line. 
 - 
 - 
Constructor Details
- 
FileContents
Creates a newFileContentsinstance.- Parameters:
 text- the contents of the file
 
 - 
 - 
Method Details
- 
getText
Get the full text of the file.- Returns:
 - an object containing the full text of the file
 
 - 
getLines
Gets the lines in the file.- Returns:
 - the lines in the file
 
 - 
getLine
Get the line from text of the file.- Parameters:
 index- index of the line- Returns:
 - line from text of the file
 
 - 
getFileName
Gets the name of the file.- Returns:
 - the name of the file
 
 - 
reportSingleLineComment
Description copied from interface:CommentListenerReport the location of a single-line comment that extends from the given point to the end of the line. The type of comment is identified by a String whose value depends on the language being parsed, but would typically be the delimiter for the comment.- Specified by:
 reportSingleLineCommentin interfaceCommentListener- Parameters:
 type- an identifier for what type of comment it is.startLineNo- the starting line numberstartColNo- the starting column number
 - 
reportSingleLineComment
Report the location of a single-line comment.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column number
 - 
reportBlockComment
public void reportBlockComment(String type, int startLineNo, int startColNo, int endLineNo, int endColNo) Description copied from interface:CommentListenerReport the location of a block comment that can span multiple lines. The type of comment is identified by a String whose value depends on the language being parsed, but would typically be the delimiter for the comment.- Specified by:
 reportBlockCommentin interfaceCommentListener- Parameters:
 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 number
 - 
reportBlockComment
Report the location of a block comment.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column numberendLineNo- the ending line numberendColNo- the ending column number
 - 
extractBlockComment
Returns the specified block comment as a String array.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column numberendLineNo- the ending line numberendColNo- the ending column number- Returns:
 - block comment as an array
 
 - 
line
Get a single-line. For internal use only, as getText().get(lineNo) is just as suitable for external use and avoids method duplication.- Parameters:
 lineNo- the number of the line to get- Returns:
 - the corresponding line, without terminator
 - Throws:
 IndexOutOfBoundsException- if lineNo is invalid
 - 
getJavadocBefore
Returns the Javadoc comment before the specified line. A return value ofnullmeans there is no such comment.- Parameters:
 lineNoBefore- the line number to check before- Returns:
 - the Javadoc comment, or 
nullif none 
 - 
lineInsideBlockComment
Checks if the specified line number is inside a block comment. This method scans through all block comments (excluding Javadoc comments) and determines whether the given line number falls within any of them- Parameters:
 lineNo- the line number to check- Returns:
 trueif the line is inside a block comment (excluding Javadoc comments) ,falseotherwise
 - 
isLineBlockComment
Checks if the given line is inside a block comment and both the start and end lines contain only the comment.- Parameters:
 lineNo- the line number to checkcomment- the block comment to inspect- Returns:
 trueline is in block comment,falseotherwise
 - 
lineIsBlank
Checks if the specified line is blank.- Parameters:
 lineNo- the line number to check- Returns:
 - if the specified line consists only of tabs and spaces.
 
 - 
lineIsComment
Checks if the specified line is a single-line comment without code.- Parameters:
 lineNo- the line number to check- Returns:
 - if the specified line consists of only a single-line comment without code.
 
 - 
hasIntersectionWithComment
public boolean hasIntersectionWithComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a comment.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column numberendLineNo- the ending line numberendColNo- the ending column number- Returns:
 - true if the positions intersects with a comment.
 
 - 
hasIntersectionWithBlockComment
private boolean hasIntersectionWithBlockComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a block comment.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column numberendLineNo- the ending line numberendColNo- the ending column number- Returns:
 - true if the positions intersects with a block comment.
 
 - 
hasIntersectionWithSingleLineComment
private boolean hasIntersectionWithSingleLineComment(int startLineNo, int startColNo, int endLineNo, int endColNo) Checks if the specified position intersects with a single-line comment.- Parameters:
 startLineNo- the starting line numberstartColNo- the starting column numberendLineNo- the ending line numberendColNo- the ending column number- Returns:
 - true if the positions intersects with a single-line comment.
 
 - 
getSingleLineComments
Returns a map of all the single-line comments. The key is a line number, the value is the commentTextBlockat the line.- Returns:
 - the Map of comments
 
 - 
getBlockComments
Returns a map of all block comments. The key is the line number, the value is aListof block commentTextBlocks that start at that line.- Returns:
 - the map of comments
 
 - 
inPackageInfo
Deprecated.useCheckUtil.isPackageInfo(String)for the same functionality, or useAbstractCheck.getFilePath()to process your own standards.Checks if the current file is a package-info.java file.- Returns:
 - true if the package file.
 
 
 - 
 
CheckUtil.isPackageInfo(String)for the same functionality, or useAbstractCheck.getFilePath()to process your own standards.