Class Source

java.lang.Object
com.oracle.js.parser.Source

public final class Source extends Object
Source objects track the origin of JavaScript entities.
  • Method Details

    • sourceFor

      public static Source sourceFor(String name, CharSequence content, boolean isEval)
      Returns a Source instance
      Parameters:
      name - source name
      content - contents as CharSequence
      isEval - does this represent code from 'eval' call?
      Returns:
      source instance
    • sourceFor

      public static Source sourceFor(String name, String content)
      Returns a Source instance
      Parameters:
      name - source name
      content - contents as string
      Returns:
      source instance
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getName

      public String getName()
      Get the user supplied name of this script.
      Returns:
      User supplied source name.
    • getLastModified

      public long getLastModified()
      Get the last modified time of this script.
      Returns:
      Last modified time.
    • getBase

      public String getBase()
      Get the "directory" part of the file or "base" of the URL.
      Returns:
      base of file or URL.
    • getString

      public String getString(int start, int len)
      Fetch a portion of source content.
      Parameters:
      start - start index in source
      len - length of portion
      Returns:
      Source content portion.
    • getString

      public String getString(long token)
      Fetch a portion of source content associated with a token.
      Parameters:
      token - Token descriptor.
      Returns:
      Source content portion.
    • getURL

      public URL getURL()
      Returns the source URL of this script Source. Can be null if Source was created from a String or a char[].
      Returns:
      URL source or null
    • getExplicitURL

      public String getExplicitURL()
      Get explicit source URL.
      Returns:
      URL set via sourceURL directive
    • setExplicitURL

      public void setExplicitURL(String explicitURL)
      Set explicit source URL.
      Parameters:
      explicitURL - URL set via sourceURL directive
    • isEvalCode

      public boolean isEvalCode()
      Returns whether this source was submitted via 'eval' call or not.
      Returns:
      true if this source represents code submitted via 'eval'
    • getLine

      public int getLine(int position)
      Return line number of character position.

      This method can be expensive for large sources as it iterates through all characters up to position.

      Parameters:
      position - Position of character in source content.
      Returns:
      Line number.
    • getColumn

      public int getColumn(int position)
      Return column number of character position.
      Parameters:
      position - Position of character in source content.
      Returns:
      Column number.
    • getSourceLine

      public String getSourceLine(int position)
      Return line text including character position.
      Parameters:
      position - Position of character in source content.
      Returns:
      Line text.
    • getContent

      public String getContent()
      Get the content of this source as a String.
    • getLength

      public int getLength()
      Get the length in chars for this source
      Returns:
      length
    • readFully

      public static String readFully(Reader reader) throws IOException
      Read all of the source until end of file.
      Parameters:
      reader - reader opened to source stream
      Returns:
      source as content
      Throws:
      IOException - if source could not be read
    • toString

      public String toString()
      Overrides:
      toString in class Object