public class DefaultInputFile extends DefaultInputComponent implements InputFile, InputFile
InputFile.Status, InputFile.Type
Constructor and Description |
---|
DefaultInputFile(String moduleKey,
String relativePath) |
Modifier and Type | Method and Description |
---|---|
String |
absolutePath()
Normalized absolute path.
|
Charset |
charset() |
boolean |
equals(Object o) |
File |
file()
The underlying absolute
File |
File |
getFile()
Get the underlying file.
|
File |
getFileBaseDir()
The source base directory, different than the project basedir.
|
InputStream |
getInputStream()
Get an
InputStream that reads from the file. |
String |
getRelativePath()
Path relative to basedir.
|
String |
hash()
Digest hash of the file.
|
int |
hashCode() |
DefaultInputFile |
initMetadata(FileMetadata.Metadata metadata) |
boolean |
isEmpty()
Check if the file content is empty (ignore potential BOM).
|
boolean |
isFile()
Is the component an
InputFile |
String |
key()
Component key.
|
String |
language()
Language, for example "java" or "php".
|
int |
lastValidOffset() |
int |
lines()
Number of physical lines.
|
String |
moduleKey() |
TextPointer |
newPointer(int globalOffset) |
TextPointer |
newPointer(int line,
int lineOffset)
Returns a
TextPointer in the given file. |
TextRange |
newRange(int startOffset,
int endOffset)
Create Range from global offsets.
|
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. |
int |
nonBlankLines() |
int[] |
originalLineOffsets() |
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. |
DefaultInputFile |
setCharset(Charset charset) |
DefaultInputFile |
setHash(String hash) |
DefaultInputFile |
setLanguage(String language) |
DefaultInputFile |
setLastValidOffset(int lastValidOffset) |
DefaultInputFile |
setLines(int lines) |
DefaultInputFile |
setModuleBaseDir(Path moduleBaseDir)
For testing purpose.
|
DefaultInputFile |
setNonBlankLines(int nonBlankLines) |
DefaultInputFile |
setOriginalLineOffsets(int[] originalLineOffsets) |
DefaultInputFile |
setStatus(InputFile.Status status) |
DefaultInputFile |
setType(InputFile.Type type) |
InputFile.Status |
status()
|
String |
toString() |
InputFile.Type |
type()
Does it contain main or test code ?
|
void |
validate(TextRange range) |
public DefaultInputFile(String moduleKey, String relativePath)
public String relativePath()
InputFile
FileSystem
. File separator is the forward
slash ('/'), even on Microsoft Windows.
Returns 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
.
Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').relativePath
in interface InputPath
InputFile.relativePath()
,
InputDir.relativePath()
public String absolutePath()
InputFile
file().getCanonicalPath()
to resolve symbolic link.absolutePath
in interface InputPath
InputFile.absolutePath()
,
InputDir.absolutePath()
public File file()
InputFile
File
file
in interface InputPath
InputFile.file()
,
InputDir.file()
public Path path()
InputFile
Path
path
in interface InputPath
InputFile.path()
,
InputDir.path()
@CheckForNull public String language()
InputFile
public InputFile.Type type()
InputFile
public InputFile.Status status()
public int lines()
InputFile
public boolean isEmpty()
InputFile
public String key()
key
in interface InputComponent
public DefaultInputFile setModuleBaseDir(Path moduleBaseDir)
DefaultFileSystem
public DefaultInputFile setLanguage(@Nullable String language)
public DefaultInputFile setType(InputFile.Type type)
public DefaultInputFile setStatus(InputFile.Status status)
public DefaultInputFile setLines(int lines)
public DefaultInputFile setCharset(Charset charset)
public int lastValidOffset()
public DefaultInputFile setLastValidOffset(int lastValidOffset)
public int nonBlankLines()
public int[] originalLineOffsets()
public DefaultInputFile setHash(String hash)
public DefaultInputFile setNonBlankLines(int nonBlankLines)
public DefaultInputFile setOriginalLineOffsets(int[] originalLineOffsets)
public TextPointer newPointer(int line, int lineOffset)
InputFile
TextPointer
in the given file.line
- Line of the pointer. Start at 1.lineOffset
- Offset in the line. Start at 0.public TextRange newRange(TextPointer start, TextPointer end)
InputFile
TextRange
in the given file.start
- start pointerend
- end pointerpublic TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset)
InputFile
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 1public TextRange selectLine(int line)
InputFile
TextRange
in the given file that select the full line.line
- Start at 1.public TextRange newRange(int startOffset, int endOffset)
public TextPointer newPointer(int globalOffset)
public DefaultInputFile initMetadata(FileMetadata.Metadata metadata)
public boolean equals(Object o)
equals
in class DefaultInputComponent
public int hashCode()
hashCode
in class DefaultInputComponent
public String toString()
toString
in class DefaultInputComponent
public File getFileBaseDir()
InputFile
For example in maven projects, the basedir of a source file stored in
src/main/java/org/foo/
is the directory src/main/java
.
getFileBaseDir
in interface InputFile
public String getRelativePath()
InputFile
'/'
, whatever the platform.
Example on windows: if file basedir is c:\project\src\
and file is c:\project\src\org\foo\Bar.java
, then relative path
is org/foo/Bar.java
Example on unix: if file basedir is /project/src
and file is /project/src/org/foo/Bar.java
, then relative path
is org/foo/Bar.java
as well.
getRelativePath
in interface InputFile
public InputStream getInputStream() throws FileNotFoundException
InputFile
InputStream
that reads from the file.
The returned stream is buffered so there is no need to use a
BufferedInputStream
getInputStream
in interface InputFile
FileNotFoundException
- if the file is not foundpublic boolean isFile()
InputComponent
InputFile
isFile
in interface InputComponent
Copyright © 2009–2016 SonarSource. All rights reserved.