Package org.sonar.api.batch.fs
Interface InputFile
-
- All Superinterfaces:
IndexedFile,InputComponent,InputPath
- All Known Implementing Classes:
DefaultInputFile
public interface InputFile extends IndexedFile
This layer overFileadds information for code analyzers. For unit testing purpose, useTestInputFileBuilderand 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 classInputFile.StatusDeprecated.since 7.7 preview mode was droppedstatic classInputFile.Type
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description java.lang.StringabsolutePath()Deprecated.since 6.6 useinputStream()for file content,IndexedFile.filename()for file name,IndexedFile.uri()for an unique identifier, andtoString()for loggingjava.nio.charset.Charsetcharset()Charset to be used to decode this specific file.java.lang.Stringcontents()Fetches the entire contents of the file, decoding with thecharset().java.io.Filefile()Deprecated.since 6.6 useinputStream()for file content,IndexedFile.filename()for file name,IndexedFile.uri()for an unique identifier, andtoString()for loggingjava.io.InputStreaminputStream()Creates a stream of the file's contents.booleanisEmpty()Check if the file content is empty (ignore potential BOM).java.lang.Stringlanguage()Language, for example "java" or "php".intlines()Number of physical lines.TextPointernewPointer(int line, int lineOffset)Returns aTextPointerin the given file.TextRangenewRange(int startLine, int startLineOffset, int endLine, int endLineOffset)Returns aTextRangein the given file.TextRangenewRange(TextPointer start, TextPointer end)Returns aTextRangein the given file.java.nio.file.Pathpath()Deprecated.since 6.6 useinputStream()for file content,IndexedFile.filename()for file name,IndexedFile.uri()for an unique identifier, andtoString()for loggingjava.lang.StringrelativePath()Deprecated.since 6.6 useinputStream()for file content,IndexedFile.filename()for file name,IndexedFile.uri()for an unique identifier, andtoString()for loggingTextRangeselectLine(int line)Returns aTextRangein the given file that select the full line.InputFile.Statusstatus()Deprecated.since 7.7 preview/issue mode was removedjava.lang.StringtoString()Return a string to identify this file (suitable for logs).InputFile.Typetype()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 (forglobalSensors) base directory. File separator is the forward slash ('/'), even on Microsoft Windows.
Returnssrc/main/java/com/Foo.javaif module base dir is/path/to/moduleand 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:
relativePathin interfaceIndexedFile- Specified by:
relativePathin 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:
absolutePathin interfaceIndexedFile- Specified by:
absolutePathin 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:
filein interfaceIndexedFile- Specified by:
filein 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:
pathin interfaceIndexedFile- Specified by:
pathin 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:
languagein interfaceIndexedFile
-
type
InputFile.Type type()
Does it contain main or test code ?- Specified by:
typein interfaceIndexedFile
-
inputStream
java.io.InputStream inputStream() throws java.io.IOExceptionCreates 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:
inputStreamin interfaceIndexedFile- Throws:
java.io.IOException- Since:
- 6.2
-
contents
java.lang.String contents() throws java.io.IOExceptionFetches 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 aTextPointerin 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 aTextRangein 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 aTextRangein 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 aTextRangein 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:
toStringin classjava.lang.Object
-
-