Package org.sonar.api.batch.fs
Interface InputFile
-
- All Superinterfaces:
IndexedFile
,InputComponent
,InputPath
public interface InputFile extends IndexedFile
This layer overFile
adds information for code analyzers. For unit testing purpose, use TestInputFileBuilder available in sonar-plugin-api-impl and initialize the needed fields:new TestInputFileBuilder("moduleKey", "relative/path/from/module/baseDir.java") .setModuleBaseDir(path) .build();
- Since:
- 4.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
InputFile.Status
Deprecated.since 7.7 preview mode was droppedstatic class
InputFile.Type
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description java.lang.String
absolutePath()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingjava.nio.charset.Charset
charset()
Charset to be used to decode this specific file.java.lang.String
contents()
Fetches the entire contents of the file, decoding with thecharset()
.java.io.File
file()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingjava.io.InputStream
inputStream()
Creates a stream of the file's contents.boolean
isEmpty()
Check if the file content is empty (ignore potential BOM).java.lang.String
language()
Language, for example "java" or "php".int
lines()
Number of physical lines.TextPointer
newPointer(int line, int lineOffset)
Returns aTextPointer
in the given file.TextRange
newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
Returns aTextRange
in the given file.TextRange
newRange(TextPointer start, TextPointer end)
Returns aTextRange
in the given file.java.nio.file.Path
path()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingjava.lang.String
relativePath()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingTextRange
selectLine(int line)
Returns aTextRange
in the given file that select the full line.InputFile.Status
status()
Deprecated.since 7.7 preview/issue mode was removedjava.lang.String
toString()
Return a string to identify this file (suitable for logs).InputFile.Type
type()
Does it contain main or test code ?-
Methods inherited from interface org.sonar.api.batch.fs.IndexedFile
filename, uri
-
Methods inherited from interface org.sonar.api.batch.fs.InputComponent
isFile, key
-
-
-
-
Method Detail
-
relativePath
@Deprecated java.lang.String relativePath()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingRelative path to module (for normal Sensors) or project (forglobal
Sensors) base directory. File separator is the forward slash ('/'), even on Microsoft Windows.
Returnssrc/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
.
Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').- Specified by:
relativePath
in interfaceIndexedFile
- Specified by:
relativePath
in interfaceInputPath
- See Also:
relativePath()
,InputDir.relativePath()
-
absolutePath
@Deprecated java.lang.String absolutePath()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingNormalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
This is not canonical path. Symbolic links are not resolved. For example if /project/src links to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Usefile().getCanonicalPath()
to resolve symbolic link.- Specified by:
absolutePath
in interfaceIndexedFile
- Specified by:
absolutePath
in interfaceInputPath
- See Also:
absolutePath()
,InputDir.absolutePath()
-
file
@Deprecated java.io.File file()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingThe underlying absoluteFile
. It should not be used to read the file in the filesystem.- Specified by:
file
in interfaceIndexedFile
- Specified by:
file
in interfaceInputPath
- See Also:
contents()
,inputStream()
-
path
@Deprecated java.nio.file.Path path()
Deprecated.since 6.6 useinputStream()
for file content,IndexedFile.filename()
for file name,IndexedFile.uri()
for an unique identifier, andtoString()
for loggingThe underlying absolutePath
. It should not be used to read the file in the filesystem.- Specified by:
path
in interfaceIndexedFile
- Specified by:
path
in interfaceInputPath
- Since:
- 5.1
- See Also:
contents()
,inputStream()
-
language
@CheckForNull java.lang.String language()
Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.- Specified by:
language
in interfaceIndexedFile
-
type
InputFile.Type type()
Does it contain main or test code ?- Specified by:
type
in interfaceIndexedFile
-
inputStream
java.io.InputStream inputStream() throws java.io.IOException
Creates a stream of the file's contents. Depending on the runtime context, the source might be a file in a physical or virtual filesystem. Typically, it won't be buffered. The stream must be closed by the caller. Since 6.4 BOM is automatically filtered out.- Specified by:
inputStream
in interfaceIndexedFile
- Throws:
java.io.IOException
- Since:
- 6.2
-
contents
java.lang.String contents() throws java.io.IOException
Fetches the entire contents of the file, decoding with thecharset()
. Since 6.4 BOM is automatically filtered out.- Throws:
java.io.IOException
- Since:
- 6.2
-
status
@Deprecated InputFile.Status status()
Deprecated.since 7.7 preview/issue mode was removed
-
lines
int lines()
Number of physical lines. This method supports all end-of-line characters. Formula is (number of line break + 1).Returns 1 if the file is empty.
Returns 2 for foo\nbar.
Returns 3 for foo\nbar\n.
-
isEmpty
boolean isEmpty()
Check if the file content is empty (ignore potential BOM).- Since:
- 5.2
-
newPointer
TextPointer newPointer(int line, int lineOffset)
Returns aTextPointer
in the given file.- Parameters:
line
- Line of the pointer. Start at 1.lineOffset
- Offset in the line. Start at 0.- Throws:
java.lang.IllegalArgumentException
- if line or offset is not valid for the given file.- Since:
- 5.2
-
newRange
TextRange newRange(TextPointer start, TextPointer end)
Returns aTextRange
in the given file.- Parameters:
start
- start pointerend
- end pointer- Throws:
java.lang.IllegalArgumentException
- if start or stop pointers are not valid for the given file.- Since:
- 5.2
-
newRange
TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
Returns aTextRange
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 1
- Throws:
java.lang.IllegalArgumentException
- if start or stop positions are not valid for the given file.- Since:
- 5.2
-
selectLine
TextRange selectLine(int line)
Returns aTextRange
in the given file that select the full line.- Parameters:
line
- Start at 1.- Throws:
java.lang.IllegalArgumentException
- if line is not valid for the given file.- Since:
- 5.2
-
charset
java.nio.charset.Charset charset()
Charset to be used to decode this specific file.- Since:
- 6.0
-
toString
java.lang.String toString()
Return a string to identify this file (suitable for logs).- Overrides:
toString
in classjava.lang.Object
-
-