public interface InputFile extends InputPath
File
adds information for code analyzers.
For unit testing purpose you can create some DefaultInputFile
and initialize
all fields using
new DefaultInputFile("moduleKey", "relative/path/from/module/baseDir.java") .setModuleBaseDir(path) .initMetadata(new FileMetadata().readMetadata(someReader));
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.
|
File |
file()
The underlying absolute
File |
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 InputPath
relativePath()
,
InputDir.relativePath()
String absolutePath()
file().getCanonicalPath()
to resolve symbolic link.absolutePath
in interface InputPath
absolutePath()
,
InputDir.absolutePath()
File file()
File
file
in interface InputPath
file()
,
InputDir.file()
Path path()
Path
path
in interface InputPath
path()
,
InputDir.path()
@CheckForNull String language()
InputFile.Type type()
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–2016 SonarSource. All rights reserved.