Class SourceUnit
- java.lang.Object
-
- ca.cgjennings.apps.arkham.plugins.typescript.SourceUnit
-
- Direct Known Subclasses:
FileSourceUnit
public class SourceUnit extends java.lang.Object
Encapsulates the contents of a source file that may vary over time. The actual content may come from anywhere, such as memory, the file system, a network connection, etc. Source units are identified by a path. Relative paths will be considered to be relative to theCompilationRoot
that contains them.- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description SourceUnit(java.lang.String path)
Creates a new, empty source unit.SourceUnit(java.lang.String identifier, java.lang.String initialText)
Creates a new source unit and updates it with the specified initial text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getPath()
Returns the unique identifier associated with this source unit.java.lang.String
getText()
Returns the current text of the document.java.lang.String
getVersion()
Returns a string that uniquely identifies the current version.java.lang.String
toString()
void
update(java.lang.String currentText)
Updates the text of the document.protected void
updateFromSource(java.lang.String possiblyStaleVersion)
This method is called whenever the source's version or text is requested, before a result is returned.
-
-
-
Constructor Detail
-
SourceUnit
public SourceUnit(java.lang.String path)
Creates a new, empty source unit.- Parameters:
path
- the identifier, such as file path, that identifies the (real or virtual) location of this source unit
-
SourceUnit
public SourceUnit(java.lang.String identifier, java.lang.String initialText)
Creates a new source unit and updates it with the specified initial text.- Parameters:
path
- the identifier, such as file path, that identifies the (real or virtual) location of this source unitinitialText
- the initial source text
-
-
Method Detail
-
getPath
public final java.lang.String getPath()
Returns the unique identifier associated with this source unit.- Returns:
- an identifier, such as a file path
-
getText
public final java.lang.String getText()
Returns the current text of the document. This is the text of the most recent update.- Returns:
- the document text; may return null if the text is unavailable
-
update
public final void update(java.lang.String currentText)
Updates the text of the document.- Parameters:
currentText
- the new file content; may be null if no text is available (for example, if the source was deleted)
-
updateFromSource
protected void updateFromSource(java.lang.String possiblyStaleVersion)
This method is called whenever the source's version or text is requested, before a result is returned. If the source unit subclass knows that a more up-to-date result is available than the one currently stored in the source unit, it can immediately update the source unit to the latest version.This can be used to implement features such as lazily-loaded static files or source units tied to files in the file system that update when the file changes. The base class does meaning, which means that the text of the source unit can only change if explicitly updated.
Subclasses which override this method should ensure that it returns as quickly as possible if the source has not changed.
- Parameters:
possiblyStaleVersion
- the current, possibly out of date, source unit text; may be null
-
getVersion
public final java.lang.String getVersion()
Returns a string that uniquely identifies the current version. After each change to the text this will return a different string.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-