public class DefaultInputFile extends DefaultInputComponent implements InputFile
InputFile in tests, use TestInputFileBuilder.InputFile.Status, InputFile.Type| Constructor and Description |
|---|
DefaultInputFile(DefaultIndexedFile indexedFile,
Consumer<DefaultInputFile> metadataGenerator) |
DefaultInputFile(DefaultIndexedFile indexedFile,
Consumer<DefaultInputFile> metadataGenerator,
String contents) |
| Modifier and Type | Method and Description |
|---|---|
String |
absolutePath()
Normalized absolute path.
|
Charset |
charset()
Charset to be used to decode this specific file.
|
void |
checkMetadata() |
String |
contents()
Fetches the entire contents of the file, decoding with the
InputFile.charset(). |
boolean |
equals(Object obj) |
File |
file()
The underlying absolute
File. |
String |
filename()
Filename for this file (inclusing extension).
|
String |
getModuleRelativePath() |
String |
getProjectRelativePath() |
String |
hash()
Digest hash of the file.
|
int |
hashCode() |
InputStream |
inputStream()
Creates a stream of the file's contents.
|
boolean |
isEmpty()
Check if the file content is empty (ignore potential BOM).
|
boolean |
isExcludedForCoverage() |
boolean |
isFile()
Is the component an
InputFile |
boolean |
isPublished() |
String |
key()
Component key (without branch).
|
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()
Deprecated.
since 6.6
|
TextRange |
selectLine(int line)
Returns a
TextRange in the given file that select the full line. |
DefaultInputFile |
setCharset(Charset charset) |
DefaultInputFile |
setExcludedForCoverage(boolean excludedForCoverage) |
DefaultInputFile |
setMetadata(Metadata metadata) |
DefaultInputFile |
setPublished(boolean published) |
DefaultInputFile |
setStatus(InputFile.Status status) |
InputFile.Status |
status()
|
String |
toString()
Return a string to identify this file (suitable for logs).
|
InputFile.Type |
type()
Does it contain main or test code ?
|
URI |
uri()
Identifier of the file.
|
void |
validate(TextRange range) |
batchIdpublic DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator)
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents)
public void checkMetadata()
public InputStream inputStream() throws IOException
InputFileinputStream in interface IndexedFileinputStream in interface InputFileIOExceptionpublic String contents() throws IOException
InputFileInputFile.charset().
Since 6.4 BOM is automatically filtered out.contents in interface InputFileIOExceptionpublic DefaultInputFile setPublished(boolean published)
public boolean isPublished()
public DefaultInputFile setExcludedForCoverage(boolean excludedForCoverage)
public boolean isExcludedForCoverage()
@Deprecated public String relativePath()
InputFileglobal Sensors) base directory.
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 IndexedFilerelativePath in interface InputFilerelativePath in interface InputPathInputFile.relativePath(),
InputDir.relativePath()public String getModuleRelativePath()
public String getProjectRelativePath()
public String absolutePath()
InputFilefile().getCanonicalPath() to resolve symbolic link.absolutePath in interface IndexedFileabsolutePath in interface InputFileabsolutePath in interface InputPathInputFile.absolutePath(),
InputDir.absolutePath()public File file()
InputFileFile. It should not be used to read the file in the filesystem.file in interface IndexedFilefile in interface InputFilefile in interface InputPathInputFile.contents(),
InputFile.inputStream()public Path path()
InputFilePath.
It should not be used to read the file in the filesystem.path in interface IndexedFilepath in interface InputFilepath in interface InputPathInputFile.contents(),
InputFile.inputStream()@CheckForNull public String language()
InputFilelanguage in interface IndexedFilelanguage in interface InputFilepublic InputFile.Type type()
InputFiletype in interface IndexedFiletype in interface InputFilepublic String key()
key in interface InputComponentpublic int hashCode()
hashCode in class DefaultInputComponentpublic String toString()
InputFiletoString in interface InputFiletoString in class DefaultInputComponentpublic 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 Charset charset()
InputFilepublic int lastValidOffset()
public int nonBlankLines()
public int[] originalLineOffsets()
public TextPointer newPointer(int line, int lineOffset)
InputFileTextPointer in the given file.newPointer in interface InputFileline - 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.public 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.selectLine in interface InputFileline - Start at 1.public TextRange newRange(int startOffset, int endOffset)
public TextPointer newPointer(int globalOffset)
public DefaultInputFile setStatus(InputFile.Status status)
public DefaultInputFile setCharset(Charset charset)
public DefaultInputFile setMetadata(Metadata metadata)
public boolean equals(Object obj)
equals in class DefaultInputComponentpublic boolean isFile()
InputComponentInputFileisFile in interface InputComponentpublic String filename()
IndexedFilefilename in interface IndexedFilepublic URI uri()
IndexedFileuri in interface IndexedFileuri in interface InputPathCopyright © 2009–2017 SonarSource. All rights reserved.