Class JavaScriptParser

java.lang.Object
org.fife.ui.rsyntaxtextarea.parser.AbstractParser
org.fife.rsta.ac.js.JavaScriptParser
All Implemented Interfaces:
org.fife.ui.rsyntaxtextarea.parser.Parser

public class JavaScriptParser extends org.fife.ui.rsyntaxtextarea.parser.AbstractParser
Parses JavaScript code in an RSyntaxTextArea.

Like all RSTA Parsers, a JavaScriptParser instance is notified when the RSTA's text content changes. After a small delay, it will parse the content as JS code, building an AST and looking for any errors. When parsing is complete, a property change event of type PROPERTY_AST is fired. Listeners can check the new value of the property for the AstRoot built that represents the source code in the text area.

This parser cannot be shared amongst multiple instances of RSyntaxTextArea.

Please keep in mind that this class is a work-in-progress!

Version:
1.0
  • Field Details

    • PROPERTY_AST

      public static final String PROPERTY_AST
      The property change event that's fired when the document is re-parsed. Applications can listen for this property change and update themselves accordingly. The "new" value of this property will be an instance of org.mozilla.javascript.ast.AstRoot.
      See Also:
    • textArea

      private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea
    • astRoot

      private org.mozilla.javascript.ast.AstRoot astRoot
    • langSupport

      private JavaScriptLanguageSupport langSupport
    • support

      private PropertyChangeSupport support
    • result

      private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult result
    • variableResolver

      private VariableResolver variableResolver
  • Constructor Details

    • JavaScriptParser

      public JavaScriptParser(JavaScriptLanguageSupport langSupport, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
      Constructor.
  • Method Details

    • addPropertyChangeListener

      public void addPropertyChangeListener(String prop, PropertyChangeListener l)
      Registers a property change listener on this parser. You'll probably want to listen for changes to PROPERTY_AST.
      Parameters:
      prop - The property to listen for changes in.
      l - The listener to add.
      See Also:
    • createCompilerEnvironment

      public static org.mozilla.javascript.CompilerEnvirons createCompilerEnvironment(org.mozilla.javascript.ErrorReporter errorHandler, JavaScriptLanguageSupport langSupport)
      Creates options for Rhino based off of the user's preferences.
      Parameters:
      errorHandler - The container for errors found while parsing.
      Returns:
      The properties for the JS compiler to use.
    • gatherParserErrorsJsHint

      private void gatherParserErrorsJsHint(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc)
      Launches jshint as an external process, and gathers syntax errors from it.
      Parameters:
      doc - the document to parse.
      See Also:
    • gatherParserErrorsRhino

      private void gatherParserErrorsRhino(org.mozilla.javascript.ast.ErrorCollector errorHandler, Element root)
      Gathers the syntax errors found by Rhino in-process when parsing the document.
      Parameters:
      errorHandler - The errors found by Rhino.
      root - The root element of the document parsed.
      See Also:
    • getAstRoot

      public org.mozilla.javascript.ast.AstRoot getAstRoot()
      Returns the AST, or null if the editor's content has not yet been parsed.
      Returns:
      The AST, or null.
    • getJsHintIndent

      public int getJsHintIndent()
    • getJsHintRCFile

      public File getJsHintRCFile(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
      Returns the location of the .jshintrc file to use if using JsHint as your error parser.
      Parameters:
      textArea - The text component.
      Returns:
      The .jshintrc file, or null if none; in that case, the JsHint defaults will be used.
    • parse

      public org.fife.ui.rsyntaxtextarea.parser.ParseResult parse(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, String style)
    • setVariablesAndFunctions

      public void setVariablesAndFunctions(VariableResolver variableResolver)
    • getVariablesAndFunctions

      public VariableResolver getVariablesAndFunctions()
    • removePropertyChangeListener

      public void removePropertyChangeListener(String prop, PropertyChangeListener l)
      Removes a property change listener from this parser.
      Parameters:
      prop - The property that was being listened to.
      l - The listener to remove.
      See Also: