Class SourceText

java.lang.Object
codeanalysis.text.SourceText

public class SourceText extends Object
Represents source code to be compiled. It consists of a list of text lines and the entire text.
Version:
1.0
Author:
Siyabend Urun
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes a new instance of the SourceText class with the specified text.
  • Method Summary

    Modifier and Type
    Method
    Description
    char
    charAt(int position)
    Retrieves the character at the specified position.
    static SourceText
    from(String text)
    Creates a new instance of the SourceText class with the specified text.
    int
    getLineIndex(int position)
    Retrieves line index of the character at the specified position.
    Retrieves the list of text lines.
    int
    Retrieves the character length of the source code.
    Retrieves the string representation of the source code.
    toString(int start, int end)
    Retrieves the string representation of the source code between the specified positions.
    Retrieves string representation of the source code between the specified text spans.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SourceText

      public SourceText(String text)
      Initializes a new instance of the SourceText class with the specified text.
      Parameters:
      text - The text of the source code.
  • Method Details

    • getLineIndex

      public int getLineIndex(int position)
      Retrieves line index of the character at the specified position.
      Parameters:
      position - The position of the character.
      Returns:
      The line index.
    • charAt

      public char charAt(int position)
      Retrieves the character at the specified position.
      Parameters:
      position - The position of the character.
      Returns:
      The character.
    • length

      public int length()
      Retrieves the character length of the source code.
      Returns:
      The character length.
    • from

      public static SourceText from(String text)
      Creates a new instance of the SourceText class with the specified text.
      Parameters:
      text - The text of the source code.
      Returns:
      The new instance of the SourceText class.
    • getLines

      public ArrayList<TextLine> getLines()
      Retrieves the list of text lines. The list is created by parsing the source code.
      Returns:
      The list of text lines.
    • toString

      public String toString()
      Retrieves the string representation of the source code.
      Overrides:
      toString in class Object
      Returns:
      The entire text.
    • toString

      public String toString(int start, int end)
      Retrieves the string representation of the source code between the specified positions.
      Parameters:
      start - The start position of the text.
      end - The end position of the text.
      Returns:
      The text between the specified positions.
    • toString

      public String toString(TextSpan span)
      Retrieves string representation of the source code between the specified text spans.
      Parameters:
      span - The text span.
      Returns:
      The text between the specified text spans.