## com.puppycrawl.tools.checkstyle.api
Class FileContents

    java.lang.Object
      com.puppycrawl.tools.checkstyle.api.FileContents

All Implemented Interfaces:
  CommentListener

    public final class FileContents

extends Object
implements CommentListener

Represents the contents of a file.

Version:
  1.0
Author:
  Oliver Burn

Constructor Summary
`FileContents(FileText aText)` Creates a new `FileContents` instance.
`FileContents(String aFilename, String[] aLines)` Deprecated. Use `FileContents(FileText)` instead in order to preserve the original line breaks where possible.

Method Summary
`com.google.common.collect.ImmutableMap<Integer,List<TextBlock>>` `getCComments()` Returns a map of all C style comments.
`com.google.common.collect.ImmutableMap<Integer,TextBlock>` `getCppComments()` Returns a map of all the C++ style comments.
`String` `getFilename()`
`TextBlock` `getJavadocBefore(int aLineNo)` Returns the Javadoc comment before the specified line.
`String[]` `getLines()`
`FileText` `getText()` Get the full text of the file.
`boolean` `hasIntersectionWithComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)` Checks if the specified position intersects with a comment.
`boolean` `inPackageInfo()` Checks if the current file is a package-info.java file.
`boolean` `lineIsBlank(int aLineNo)` Checks if the specified line is blank.
`boolean` `lineIsComment(int aLineNo)` Checks if the specified line is a single-line comment without code.
`void` `reportBlockComment(String aType, int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)` Report the location of a block comment that can span multiple lines.
`void` `reportCComment(int aStartLineNo, int aStartColNo, int aEndLineNo, int aEndColNo)` Report the location of a C-style comment.
`void` `reportCppComment(int aStartLineNo, int aStartColNo)` Report the location of a C++ style comment.
`void` `reportSingleLineComment(String aType, int aStartLineNo, int aStartColNo)` Report the location of a single line comment that extends from the given point to the end of the line.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FileContents

    @Deprecated
    public FileContents(String aFilename,
                                   String[] aLines)

  Deprecated. Use `FileContents(FileText)` instead in order to preserve the original line breaks where possible.

  Creates a new `FileContents` instance.

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

### FileContents

    public FileContents(FileText aText)

  Creates a new `FileContents` instance.

  Parameters:
    `aText` - the contents of the file

Method Detail

### reportSingleLineComment

    public void reportSingleLineComment(String aType,
                                        int aStartLineNo,
                                        int aStartColNo)

  Report 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:
    `reportSingleLineComment` in interface `CommentListener`
  Parameters:
    `aType` - an identifier for what type of comment it is.
    `aStartLineNo` - the starting line number
    `aStartColNo` - the starting column number

### reportBlockComment

    public void reportBlockComment(String aType,
                                   int aStartLineNo,
                                   int aStartColNo,
                                   int aEndLineNo,
                                   int aEndColNo)

  Report 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:
    `reportBlockComment` in interface `CommentListener`
  Parameters:
    `aType` - an identifier for what type of comment it is.
    `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

### getCppComments

    public com.google.common.collect.ImmutableMap<Integer,TextBlock> getCppComments()

  Returns a map of all the C++ style comments. The key is a line number, the value is the comment `TextBlock` at the line.

  Returns:
    the Map of comments

### 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

### getCComments

    public com.google.common.collect.ImmutableMap<Integer,List<TextBlock>> getCComments()

  Returns a map of all C style comments. The key is the line number, the value is a `List` of C style comment `TextBlock`s that start at that line.

  Returns:
    the map of comments

### 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

### getText

    public FileText getText()

  Get the full text of the file.

  Returns:
    an object containing the full text of the file

### getLines

    public String[] getLines()

  Returns:
    the lines in the file

### getFilename

    public String getFilename()

  Returns:
    the name of the file

### 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.

### 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.

### inPackageInfo

    public boolean inPackageInfo()

  Checks if the current file is a package-info.java file.

  Returns:
    true if the package file.

Copyright © 2001-2011. All Rights Reserved.