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)
Deprecated.
|
static SourceFile |
fromFile(File file,
Charset c)
Deprecated.
|
static SourceFile |
fromFile(String fileName) |
static SourceFile |
fromFile(String fileName,
Charset charset) |
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 |
fromPath(Path path,
Charset c) |
static SourceFile |
fromReader(String fileName,
Reader r) |
static SourceFile |
fromZipEntry(String originalZipPath,
String absoluteZipPath,
String entryPath,
Charset inputCharset) |
static List<SourceFile> |
fromZipFile(String zipName,
Charset inputCharset) |
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
@GwtIncompatible(value="java.io.Reader") 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.@GwtIncompatible(value="java.util.zip.ZipFile") public static List<SourceFile> fromZipFile(String zipName, Charset inputCharset) throws IOException
IOException
@GwtIncompatible(value="java.net.URL") public static SourceFile fromZipEntry(String originalZipPath, String absoluteZipPath, String entryPath, Charset inputCharset) throws MalformedURLException
MalformedURLException
@GwtIncompatible(value="java.io.File") public static SourceFile fromFile(String fileName, Charset charset)
@GwtIncompatible(value="java.io.File") public static SourceFile fromFile(String fileName)
@GwtIncompatible(value="java.io.File") public static SourceFile fromPath(Path path, Charset c)
@Deprecated @GwtIncompatible(value="java.io.File") public static SourceFile fromFile(File file, Charset c)
fromPath(Path, Charset)
@Deprecated @GwtIncompatible(value="java.io.File") public static SourceFile fromFile(File file)
fromPath(Path, Charset)
public static SourceFile fromCode(String fileName, String code)
@Deprecated @GwtIncompatible(value="java.io.InputStream") public static SourceFile fromInputStream(String fileName, InputStream s) throws IOException
fromInputStream(String, InputStream, Charset)
IOException
@GwtIncompatible(value="java.io.InputStream") public static SourceFile fromInputStream(String fileName, InputStream s, Charset charset) throws IOException
IOException
@GwtIncompatible(value="java.io.Reader") 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-2017 Google. All Rights Reserved.