Class HeaderParser
- java.lang.Object
-
- com.google.code.mojo.license.header.HeaderParser
-
public final class HeaderParser extends java.lang.Object
TheHeaderParser
class is used to get header information about the current header defined in the given file.
The achieve this it will use theHeaderDefinition
associated to the type of the given file. Important: is considered a license header a header which contains the word copyright (case insensitive) within a section of the file which match the givenHeaderDefinition
associated to thisHeaderParser
.- See Also:
HeaderDefinition
-
-
Field Summary
Fields Modifier and Type Field Description private int
beginPosition
private int
endPosition
private boolean
existingHeader
private FileContent
fileContent
private HeaderDefinition
headerDefinition
private java.lang.String[]
keywords
private java.lang.String
line
-
Constructor Summary
Constructors Constructor Description HeaderParser(FileContent fileContent, HeaderDefinition headerDefinition, java.lang.String[] keywords)
Creates aHeaderParser
object linked to the given file content and the associated header definition based on the file type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
findBeginPosition()
private int
findEndPosition()
int
getBeginPosition()
Returns the index position in the content where the header effectively starts.int
getEndPosition()
Returns the index position in the content where the header effectively ends.FileContent
getFileContent()
Returns the file content.HeaderDefinition
getHeaderDefinition()
Returns the header definition associated to this header parser (itself bounded to a file).boolean
gotAnyHeader()
Tells if the given file already contains a license header.private boolean
hasHeader()
-
-
-
Field Detail
-
beginPosition
private final int beginPosition
-
endPosition
private final int endPosition
-
existingHeader
private final boolean existingHeader
-
fileContent
private final FileContent fileContent
-
keywords
private final java.lang.String[] keywords
-
headerDefinition
private HeaderDefinition headerDefinition
-
line
private java.lang.String line
-
-
Constructor Detail
-
HeaderParser
public HeaderParser(FileContent fileContent, HeaderDefinition headerDefinition, java.lang.String[] keywords)
Creates aHeaderParser
object linked to the given file content and the associated header definition based on the file type.- Parameters:
fileContent
- The file content.headerDefinition
- The associated header definition to use.- Throws:
java.lang.IllegalArgumentException
- If the file content is null or if the header definition is null.
-
-
Method Detail
-
getBeginPosition
public int getBeginPosition()
Returns the index position in the content where the header effectively starts.- Returns:
- The index in the content.
-
getEndPosition
public int getEndPosition()
Returns the index position in the content where the header effectively ends.- Returns:
- The index in the content.
-
gotAnyHeader
public boolean gotAnyHeader()
Tells if the given file already contains a license header.- Returns:
- true if a license header has been detect or false.
-
getFileContent
public FileContent getFileContent()
Returns the file content.- Returns:
- The content.
-
getHeaderDefinition
public HeaderDefinition getHeaderDefinition()
Returns the header definition associated to this header parser (itself bounded to a file).- Returns:
- The associated header definition.
-
findBeginPosition
private int findBeginPosition()
-
hasHeader
private boolean hasHeader()
-
findEndPosition
private int findEndPosition()
-
-