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 o) |
File |
file()
The underlying absolute
File . |
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 |
isFile()
Is the component an
InputFile |
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 . |
boolean |
publish() |
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 |
setMetadata(Metadata metadata) |
DefaultInputFile |
setPublish(boolean publish) |
DefaultInputFile |
setStatus(InputFile.Status status) |
InputFile.Status |
status()
|
String |
toString() |
InputFile.Type |
type()
Does it contain main or test code ?
|
void |
validate(TextRange range) |
batchId
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator)
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator, @Nullable String contents)
public void checkMetadata()
public InputStream inputStream() throws IOException
InputFile
inputStream
in interface IndexedFile
inputStream
in interface InputFile
IOException
public String contents() throws IOException
InputFile
InputFile.charset()
.
Since 6.4 BOM is automatically filtered out.contents
in interface InputFile
IOException
public DefaultInputFile setPublish(boolean publish)
public boolean publish()
public String relativePath()
InputFile
FileSystem
. 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 IndexedFile
relativePath
in interface InputFile
relativePath
in interface InputPath
InputFile.relativePath()
,
InputDir.relativePath()
public String absolutePath()
InputFile
file().getCanonicalPath()
to resolve symbolic link.absolutePath
in interface IndexedFile
absolutePath
in interface InputFile
absolutePath
in interface InputPath
InputFile.absolutePath()
,
InputDir.absolutePath()
public File file()
InputFile
File
. It should not be used to read the file in the filesystem.file
in interface IndexedFile
file
in interface InputFile
file
in interface InputPath
InputFile.contents()
,
InputFile.inputStream()
public Path path()
InputFile
Path
.
It should not be used to read the file in the filesystem.path
in interface IndexedFile
path
in interface InputFile
path
in interface InputPath
InputFile.contents()
,
InputFile.inputStream()
@CheckForNull public String language()
InputFile
language
in interface IndexedFile
language
in interface InputFile
public InputFile.Type type()
InputFile
type
in interface IndexedFile
type
in interface InputFile
public String key()
key
in interface InputComponent
public int hashCode()
hashCode
in class DefaultInputComponent
public String toString()
toString
in class DefaultInputComponent
public 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()
InputFile
public Charset charset()
InputFile
public int lastValidOffset()
public int nonBlankLines()
public int[] originalLineOffsets()
public TextPointer newPointer(int line, int lineOffset)
InputFile
TextPointer
in the given file.newPointer
in interface InputFile
line
- Line of the pointer. Start at 1.lineOffset
- Offset in the line. Start at 0.public TextRange newRange(TextPointer start, TextPointer end)
InputFile
TextRange
in the given file.public TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
InputFile
TextRange
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)
InputFile
TextRange
in the given file that select the full line.selectLine
in interface InputFile
line
- 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 o)
equals
in class DefaultInputComponent
public boolean isFile()
InputComponent
InputFile
isFile
in interface InputComponent
Copyright © 2009–2017 SonarSource. All rights reserved.