public class DefaultInputFile extends DefaultInputComponent implements InputFile, InputFile
InputFile.Status, InputFile.Type| Constructor and Description |
|---|
DefaultInputFile(String moduleKey,
String relativePath) |
| Modifier and Type | Method and Description |
|---|---|
String |
absolutePath()
Normalized absolute path.
|
Charset |
charset() |
boolean |
equals(Object o) |
File |
file()
The underlying absolute
File |
File |
getFile()
Get the underlying file.
|
File |
getFileBaseDir()
The source base directory, different than the project basedir.
|
InputStream |
getInputStream()
Get an
InputStream that reads from the file. |
String |
getRelativePath()
Path relative to basedir.
|
String |
hash()
Digest hash of the file.
|
int |
hashCode() |
DefaultInputFile |
initMetadata(FileMetadata.Metadata metadata) |
DefaultInputFile |
initMetadata(String content)
For testing purpose
|
boolean |
isEmpty()
Check if the file content is empty (ignore potential BOM).
|
boolean |
isFile()
Is the component an
InputFile |
String |
key()
Component key.
|
String |
language()
Language, for example "java" or "php".
|
int |
lastValidOffset() |
int |
lines()
Number of physical lines.
|
String |
moduleKey() |
TextPointer |
newPointer(int globalOffset) |
TextPointer |
newPointer(int line,
int lineOffset)
Returns a
TextPointer in the given file. |
TextRange |
newRange(int startOffset,
int endOffset)
Create Range from global offsets.
|
TextRange |
newRange(int startLine,
int startLineOffset,
int endLine,
int endLineOffset)
Returns a
TextRange in the given file. |
TextRange |
newRange(TextPointer start,
TextPointer end)
Returns a
TextRange in the given file. |
int |
nonBlankLines() |
int[] |
originalLineOffsets() |
Path |
path()
The underlying absolute
Path |
String |
relativePath()
Path relative to module base directory.
|
TextRange |
selectLine(int line)
Returns a
TextRange in the given file that select the full line. |
DefaultInputFile |
setCharset(Charset charset) |
DefaultInputFile |
setHash(String hash) |
DefaultInputFile |
setLanguage(String language) |
DefaultInputFile |
setLastValidOffset(int lastValidOffset) |
DefaultInputFile |
setLines(int lines) |
DefaultInputFile |
setModuleBaseDir(Path moduleBaseDir)
For testing purpose.
|
DefaultInputFile |
setNonBlankLines(int nonBlankLines) |
DefaultInputFile |
setOriginalLineOffsets(int[] originalLineOffsets) |
DefaultInputFile |
setStatus(InputFile.Status status) |
DefaultInputFile |
setType(InputFile.Type type) |
InputFile.Status |
status()
|
String |
toString() |
InputFile.Type |
type()
Does it contain main or test code ?
|
void |
validate(TextRange range) |
public DefaultInputFile(String moduleKey, String relativePath)
public String relativePath()
InputFileFileSystem. File separator is the forward
slash ('/'), even on Microsoft Windows.
src/main/java/com/Foo.java if module base dir is
/path/to/module and if file is
/path/to/module/src/main/java/com/Foo.java.
relativePath in interface InputPathInputFile.relativePath(),
InputDir.relativePath()public String absolutePath()
InputFilefile().getCanonicalPath() to resolve symbolic link.absolutePath in interface InputPathInputFile.absolutePath(),
InputDir.absolutePath()public File file()
InputFileFilefile in interface InputPathInputFile.file(),
InputDir.file()public Path path()
InputFilePathpath in interface InputPathInputFile.path(),
InputDir.path()@CheckForNull public String language()
InputFilepublic InputFile.Type type()
InputFilepublic InputFile.Status status()
public int lines()
InputFile
Returns 1 if the file is empty.
Returns 2 for foo\nbar.
Returns 3 for foo\nbar\n.
public boolean isEmpty()
InputFilepublic String key()
key in interface InputComponentpublic DefaultInputFile setModuleBaseDir(Path moduleBaseDir)
DefaultFileSystempublic DefaultInputFile setLanguage(@Nullable String language)
public DefaultInputFile setType(InputFile.Type type)
public DefaultInputFile setStatus(InputFile.Status status)
public DefaultInputFile setLines(int lines)
public DefaultInputFile setCharset(Charset charset)
public int lastValidOffset()
public DefaultInputFile setLastValidOffset(int lastValidOffset)
public int nonBlankLines()
public int[] originalLineOffsets()
public DefaultInputFile setHash(String hash)
public DefaultInputFile setNonBlankLines(int nonBlankLines)
public DefaultInputFile setOriginalLineOffsets(int[] originalLineOffsets)
public TextPointer newPointer(int line, int lineOffset)
InputFileTextPointer in the given file.line - Line of the pointer. Start at 1.lineOffset - Offset in the line. Start at 0.public TextRange newRange(TextPointer start, TextPointer end)
InputFileTextRange in the given file.start - start pointerend - end pointerpublic TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
InputFileTextRange in the given file.
newRange(1, 0, 1, 1) selects the first character at line 1newRange(1, 0, 1, 10) selects the 10 first characters at line 1public TextRange selectLine(int line)
InputFileTextRange in the given file that select the full line.line - Start at 1.public TextRange newRange(int startOffset, int endOffset)
public TextPointer newPointer(int globalOffset)
public DefaultInputFile initMetadata(FileMetadata.Metadata metadata)
public DefaultInputFile initMetadata(String content)
public boolean equals(Object o)
equals in class DefaultInputComponentpublic int hashCode()
hashCode in class DefaultInputComponentpublic String toString()
toString in class DefaultInputComponentpublic File getFileBaseDir()
InputFileFor example in maven projects, the basedir of a source file stored in
src/main/java/org/foo/ is the directory src/main/java.
getFileBaseDir in interface InputFilepublic String getRelativePath()
InputFile'/', whatever the platform.
Example on windows: if file basedir is c:\project\src\ and file is c:\project\src\org\foo\Bar.java, then relative path
is org/foo/Bar.java
Example on unix: if file basedir is /project/src and file is /project/src/org/foo/Bar.java, then relative path
is org/foo/Bar.java as well.
getRelativePath in interface InputFilepublic InputStream getInputStream() throws FileNotFoundException
InputFileInputStream that reads from the file.
The returned stream is buffered so there is no need to use a
BufferedInputStream
getInputStream in interface InputFileFileNotFoundException - if the file is not foundpublic boolean isFile()
InputComponentInputFileisFile in interface InputComponentCopyright © 2009–2017 SonarSource. All rights reserved.