Class 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPropertyChangeListener​(java.lang.String prop, java.beans.PropertyChangeListener l)
      Registers a property change listener on this parser.
      static org.mozilla.javascript.CompilerEnvirons createCompilerEnvironment​(org.mozilla.javascript.ErrorReporter errorHandler, JavaScriptLanguageSupport langSupport)
      Creates options for Rhino based off of the user's preferences.
      private void gatherParserErrorsJsHint​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc)
      Launches jshint as an external process, and gathers syntax errors from it.
      private void gatherParserErrorsRhino​(org.mozilla.javascript.ast.ErrorCollector errorHandler, javax.swing.text.Element root)
      Gathers the syntax errors found by Rhino in-process when parsing the document.
      org.mozilla.javascript.ast.AstRoot getAstRoot()
      Returns the AST, or null if the editor's content has not yet been parsed.
      int getJsHintIndent()  
      java.io.File getJsHintRCFile​(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)
      Returns the location of the .jshintrc file to use if using JsHint as your error parser.
      VariableResolver getVariablesAndFunctions()  
      org.fife.ui.rsyntaxtextarea.parser.ParseResult parse​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, java.lang.String style)
      void removePropertyChangeListener​(java.lang.String prop, java.beans.PropertyChangeListener l)
      Removes a property change listener from this parser.
      void setVariablesAndFunctions​(VariableResolver variableResolver)  
      • Methods inherited from class org.fife.ui.rsyntaxtextarea.parser.AbstractParser

        getHyperlinkListener, getImageBase, isEnabled, setEnabled, setHyperlinkListener
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_AST

        public static final java.lang.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:
        Constant Field Values
      • textArea

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

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

        private java.beans.PropertyChangeSupport support
      • result

        private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult result
    • Constructor Detail

      • JavaScriptParser

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

      • addPropertyChangeListener

        public void addPropertyChangeListener​(java.lang.String prop,
                                              java.beans.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:
        removePropertyChangeListener(String, PropertyChangeListener)
      • 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(ErrorCollector, Element)
      • gatherParserErrorsRhino

        private void gatherParserErrorsRhino​(org.mozilla.javascript.ast.ErrorCollector errorHandler,
                                             javax.swing.text.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:
        gatherParserErrorsJsHint(RSyntaxDocument)
      • 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 java.io.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,
                                                                    java.lang.String style)
      • setVariablesAndFunctions

        public void setVariablesAndFunctions​(VariableResolver variableResolver)
      • removePropertyChangeListener

        public void removePropertyChangeListener​(java.lang.String prop,
                                                 java.beans.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:
        addPropertyChangeListener(String, PropertyChangeListener)