com.puppycrawl.tools.checkstyle.api

Class FileContents

public final class FileContents extends Object implements CommentListener

Represents the contents of a file.

Version: 1.0

Author: Oliver Burn

Constructor Summary
FileContents(String aFilename, String[] aLines)
Creates a new FileContents instance.
Method Summary
MapgetCComments()
Returns a map of all C style comments.
MapgetCppComments()
Returns a map of all the C++ style comments.
StringgetFilename()
TextBlockgetJavadocBefore(int aLineNo)
Returns the Javadoc comment before the specified line.
String[]getLines()
booleanhasIntersectionWithComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
Checks if the specified position intersects with a comment.
booleanlineIsBlank(int aLineNo)
Checks if the specified line is blank.
booleanlineIsComment(int aLineNo)
Checks if the specified line is a single-line comment without code.
voidreportBlockComment(String aType, int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
{@inheritDoc}
voidreportCComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
Report the location of a C-style comment.
voidreportCppComment(int aStartLineNo, int aStartColNo)
Report the location of a C++ style comment.
voidreportSingleLineComment(String aType, int aStartLineNo, int aStartColNo)
{@inheritDoc}

Constructor Detail

FileContents

public FileContents(String aFilename, String[] aLines)
Creates a new FileContents instance.

Parameters: aFilename name of the file aLines the contents of the file

Method Detail

getCComments

public Map getCComments()
Returns a map of all C style comments. The key is the line number, the value is a {@link List} of C style comment {@link TextBlock}s that start at that line.

Returns: the map of comments

getCppComments

public Map getCppComments()
Returns a map of all the C++ style comments. The key is a line number, the value is the comment {@link TextBlock} at the line.

Returns: the Map of comments

getFilename

public String getFilename()

Returns: the name of the file

getJavadocBefore

public TextBlock getJavadocBefore(int aLineNo)
Returns the Javadoc comment before the specified line. A return value of null means there is no such comment.

Parameters: aLineNo the line number to check before

Returns: the Javadoc comment, or null if none

getLines

public String[] getLines()

Returns: the lines in the file

hasIntersectionWithComment

public boolean hasIntersectionWithComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
Checks if the specified position intersects with a comment.

Parameters: aStartLineNo the starting line number aStartColNo the starting column number aEndLineNo the ending line number aEndColNo the ending column number

Returns: true if the positions intersects with a comment.

lineIsBlank

public boolean lineIsBlank(int aLineNo)
Checks if the specified line is blank.

Parameters: aLineNo the line number to check

Returns: if the specified line consists only of tabs and spaces.

lineIsComment

public boolean lineIsComment(int aLineNo)
Checks if the specified line is a single-line comment without code.

Parameters: aLineNo the line number to check

Returns: if the specified line consists of only a single line comment without code.

reportBlockComment

public void reportBlockComment(String aType, int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
{@inheritDoc}

reportCComment

public void reportCComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)
Report the location of a C-style comment.

Parameters: aStartLineNo the starting line number aStartColNo the starting column number aEndLineNo the ending line number aEndColNo the ending column number

reportCppComment

public void reportCppComment(int aStartLineNo, int aStartColNo)
Report the location of a C++ style comment.

Parameters: aStartLineNo the starting line number aStartColNo the starting column number

reportSingleLineComment

public void reportSingleLineComment(String aType, int aStartLineNo, int aStartColNo)
{@inheritDoc}