public class SourceFile extends Object implements StaticSourceFile, Serializable
Modifier and Type | Class and Description |
---|---|
static class |
SourceFile.Builder
A builder interface for source files.
|
static interface |
SourceFile.Generator
A JavaScript source code provider.
|
Constructor and Description |
---|
SourceFile(String fileName)
Construct a new abstract source file.
|
Modifier and Type | Method and Description |
---|---|
static SourceFile.Builder |
builder()
Create a new builder for source files.
|
void |
clearCachedSource() |
static SourceFile |
fromCode(String fileName,
String code) |
static SourceFile |
fromFile(File file) |
static SourceFile |
fromFile(File file,
Charset c) |
static SourceFile |
fromFile(String fileName) |
static SourceFile |
fromFile(String fileName,
Charset c) |
static SourceFile |
fromGenerator(String fileName,
SourceFile.Generator generator) |
static SourceFile |
fromInputStream(String fileName,
InputStream s)
Deprecated.
|
static SourceFile |
fromInputStream(String fileName,
InputStream s,
Charset charset) |
static SourceFile |
fromReader(String fileName,
Reader r) |
String |
getCode()
Gets all the code in this source file.
|
Reader |
getCodeReader()
Gets a reader for the code in this source file.
|
int |
getColumnOfOffset(int offset)
Gets the 0-based column number of the given source offset.
|
String |
getLine(int lineNumber)
Gets the source line for the indicated line number.
|
int |
getLineOffset(int lineno)
Returns the offset of the given line number relative to the file start.
|
int |
getLineOfOffset(int offset)
Gets the 1-based line number of the given source offset.
|
String |
getName()
Returns a unique name for the source file.
|
String |
getOriginalPath() |
Region |
getRegion(int lineNumber)
Get a region around the indicated line number.
|
boolean |
isExtern()
Returns whether this is an extern.
|
void |
setOriginalPath(String originalPath) |
String |
toString() |
public SourceFile(String fileName)
fileName
- The file name of the source file. It does not necessarily
need to correspond to a real path. But it should be unique. Will
appear in warning messages emitted by the compiler.public int getLineOffset(int lineno)
StaticSourceFile
getLineOffset
in interface StaticSourceFile
lineno
- the line of the input to get the absolute offset of.public String getCode() throws IOException
IOException
public Reader getCodeReader() throws IOException
IOException
public String getOriginalPath()
public void setOriginalPath(String originalPath)
public void clearCachedSource()
public String getName()
getName
in interface StaticSourceFile
public boolean isExtern()
isExtern
in interface StaticSourceFile
public int getLineOfOffset(int offset)
StaticSourceFile
getLineOfOffset
in interface StaticSourceFile
offset
- An absolute file offset.public int getColumnOfOffset(int offset)
StaticSourceFile
getColumnOfOffset
in interface StaticSourceFile
offset
- An absolute file offset.public String getLine(int lineNumber)
lineNumber
- the line number, 1 being the first line of the file.null
if it does not exist,
or if there was an IO exception.public Region getRegion(int lineNumber)
lineNumber
- the line number, 1 being the first line of the file.null
if it does not exist,
or if there was an IO exception.public static SourceFile fromFile(String fileName, Charset c)
public static SourceFile fromFile(String fileName)
public static SourceFile fromFile(File file, Charset c)
public static SourceFile fromFile(File file)
public static SourceFile fromCode(String fileName, String code)
@Deprecated public static SourceFile fromInputStream(String fileName, InputStream s) throws IOException
fromInputStream(String, InputStream, Charset)
IOException
public static SourceFile fromInputStream(String fileName, InputStream s, Charset charset) throws IOException
IOException
public static SourceFile fromReader(String fileName, Reader r) throws IOException
IOException
public static SourceFile fromGenerator(String fileName, SourceFile.Generator generator)
public static SourceFile.Builder builder()
Copyright © 2009-2015 Google. All Rights Reserved.