public interface InputFile extends IndexedFile
File
adds information for code analyzers.
For unit testing purpose, use TestInputFileBuilder
and initialize
the needed fields:
new TestInputFileBuilder("moduleKey", "relative/path/from/module/baseDir.java") .setModuleBaseDir(path) .build();
Modifier and Type | Interface and Description |
---|---|
static class |
InputFile.Status
Status regarding previous analysis
|
static class |
InputFile.Type |
Modifier and Type | Method and Description |
---|---|
String |
absolutePath()
Normalized absolute path.
|
Charset |
charset()
Charset to be used to decode this specific file.
|
default String |
contents()
Fetches the entire contents of the file, decoding with the
charset() . |
File |
file()
The underlying absolute
File . |
default InputStream |
inputStream()
Creates a stream of the file's contents.
|
boolean |
isEmpty()
Check if the file content is empty (ignore potential BOM).
|
String |
language()
Language, for example "java" or "php".
|
int |
lines()
Number of physical lines.
|
TextPointer |
newPointer(int line,
int lineOffset)
Returns a
TextPointer in the given file. |
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. |
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. |
InputFile.Status |
status()
Status regarding previous analysis
|
InputFile.Type |
type()
Does it contain main or test code ?
|
isFile, key
String relativePath()
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 InputPath
relativePath()
,
InputDir.relativePath()
String absolutePath()
file().getCanonicalPath()
to resolve symbolic link.absolutePath
in interface IndexedFile
absolutePath
in interface InputPath
absolutePath()
,
InputDir.absolutePath()
File file()
File
. It should not be used to read the file in the filesystem.file
in interface IndexedFile
file
in interface InputPath
contents()
,
inputStream()
Path path()
Path
.
It should not be used to read the file in the filesystem.path
in interface IndexedFile
path
in interface InputPath
contents()
,
inputStream()
@CheckForNull String language()
language
in interface IndexedFile
InputFile.Type type()
type
in interface IndexedFile
default InputStream inputStream() throws IOException
inputStream
in interface IndexedFile
IOException
default String contents() throws IOException
charset()
.
Note that there is a default implementation.IOException
InputFile.Status status()
int lines()
Returns 1 if the file is empty.
Returns 2 for foo\nbar.
Returns 3 for foo\nbar\n.
boolean isEmpty()
TextPointer newPointer(int line, int lineOffset)
TextPointer
in the given file.line
- Line of the pointer. Start at 1.lineOffset
- Offset in the line. Start at 0.IllegalArgumentException
- if line or offset is not valid for the given file.TextRange newRange(TextPointer start, TextPointer end)
TextRange
in the given file.start
- start pointerend
- end pointerIllegalArgumentException
- if start or stop pointers are not valid for the given file.TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
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 1IllegalArgumentException
- if start or stop positions are not valid for the given file.TextRange selectLine(int line)
TextRange
in the given file that select the full line.line
- Start at 1.IllegalArgumentException
- if line is not valid for the given file.Copyright © 2009–2017 SonarSource. All rights reserved.