Package source
Class SourceInput
- java.lang.Object
-
- source.SourceInput
-
public final class SourceInput extends java.lang.ObjectThe SourceInput class is used to store the source code to be used in compilation.Various methods are provided to perform operations on the source code during compilation, many of which are just extensions of String methods. Though other functions are provided which allow the text to be searched, and the line index of a particular substring can be retrieved.
- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description SourceInput(java.lang.String sourceText)Constructs a SourceInput object for storing the source code before compilation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int index)Returns a char found at the specified index.intgetLineIndex(int position)Returns the line that a character is on by using its position.intlength()Returns the length of the source textjava.lang.Stringsubstring(int beginIndex)Return a String from a specified index to the end of the text.java.lang.Stringsubstring(int beginIndex, int endIndex)Return a String from a beginning index to an end index.
-
-
-
Constructor Detail
-
SourceInput
public SourceInput(java.lang.String sourceText)
Constructs a SourceInput object for storing the source code before compilation.The source text is initially cleaned, which (if necessary) adds a line break to the end of the text in order to avoid issues with compilation. The text is then parsed into SourceLine objects, which are used to identify the range and order of each individual line
- Parameters:
sourceText- The source code input
-
-
Method Detail
-
length
public int length()
Returns the length of the source text- Returns:
- The source text length
-
charAt
public char charAt(int index)
Returns a char found at the specified index.- Parameters:
index- The index of the character- Returns:
- The char at the indexes position
-
substring
public java.lang.String substring(int beginIndex)
Return a String from a specified index to the end of the text.- Parameters:
beginIndex- The beginning of the substring- Returns:
- A substring from beginIndex to the end of the text
-
substring
public java.lang.String substring(int beginIndex, int endIndex)Return a String from a beginning index to an end index.- Parameters:
beginIndex- The beginning of the substringendIndex- The end of the substring- Returns:
- A substring from beginIndex to endIndex
-
getLineIndex
public int getLineIndex(int position)
Returns the line that a character is on by using its position.By using the position of the character, and line index can be retrieved.
- Parameters:
position- The position of the character in the text- Returns:
- An int representing the line index
-
-