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()
Deprecated.
since 6.6 use
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for logging |
Charset |
charset()
Charset to be used to decode this specific file.
|
String |
contents()
Fetches the entire contents of the file, decoding with the
charset(). |
File |
file()
Deprecated.
since 6.6 use
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for logging |
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()
Deprecated.
since 6.6 use
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for logging |
String |
relativePath()
Deprecated.
since 6.6 use
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for logging |
TextRange |
selectLine(int line)
Returns a
TextRange in the given file that select the full line. |
InputFile.Status |
status()
Status regarding previous analysis
|
String |
toString()
Return a string to identify this file (suitable for logs).
|
InputFile.Type |
type()
Does it contain main or test code ?
|
filename, uriisFile, key@Deprecated String relativePath()
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for loggingglobal 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 InputPathrelativePath(),
InputDir.relativePath()@Deprecated String absolutePath()
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for loggingfile().getCanonicalPath() to resolve symbolic link.absolutePath in interface IndexedFileabsolutePath in interface InputPathabsolutePath(),
InputDir.absolutePath()@Deprecated File file()
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for loggingFile. It should not be used to read the file in the filesystem.file in interface IndexedFilefile in interface InputPathcontents(),
inputStream()@Deprecated Path path()
inputStream() for file content, IndexedFile.filename() for file name, IndexedFile.uri() for an unique identifier, and toString() for loggingPath.
It should not be used to read the file in the filesystem.path in interface IndexedFilepath in interface InputPathcontents(),
inputStream()@CheckForNull String language()
language in interface IndexedFileInputFile.Type type()
type in interface IndexedFileInputStream inputStream() throws IOException
inputStream in interface IndexedFileIOExceptionString contents() throws IOException
charset().
Since 6.4 BOM is automatically filtered out.IOExceptionInputFile.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.