Package org.fife.rsta.ac.js
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classError reporter for Rhino-based parsing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.mozilla.javascript.ast.AstRootprivate JavaScriptLanguageSupportstatic final StringThe property change event that's fired when the document is re-parsed.private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResultprivate PropertyChangeSupportprivate org.fife.ui.rsyntaxtextarea.RSyntaxTextAreaprivate VariableResolver -
Constructor Summary
ConstructorsConstructorDescriptionJavaScriptParser(JavaScriptLanguageSupport langSupport, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a property change listener on this parser.static org.mozilla.javascript.CompilerEnvironscreateCompilerEnvironment(org.mozilla.javascript.ErrorReporter errorHandler, JavaScriptLanguageSupport langSupport) Creates options for Rhino based off of the user's preferences.private voidgatherParserErrorsJsHint(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc) Launches jshint as an external process, and gathers syntax errors from it.private voidgatherParserErrorsRhino(org.mozilla.javascript.ast.ErrorCollector errorHandler, Element root) Gathers the syntax errors found by Rhino in-process when parsing the document.org.mozilla.javascript.ast.AstRootReturns the AST, ornullif the editor's content has not yet been parsed.intgetJsHintRCFile(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea) Returns the location of the.jshintrcfile to use if using JsHint as your error parser.org.fife.ui.rsyntaxtextarea.parser.ParseResultvoidRemoves a property change listener from this parser.voidsetVariablesAndFunctions(VariableResolver variableResolver) Methods inherited from class org.fife.ui.rsyntaxtextarea.parser.AbstractParser
getHyperlinkListener, getImageBase, isEnabled, setEnabled, setHyperlinkListener
-
Field Details
-
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 oforg.mozilla.javascript.ast.AstRoot.- See Also:
-
textArea
private org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea -
astRoot
private org.mozilla.javascript.ast.AstRoot astRoot -
langSupport
-
support
-
result
private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult result -
variableResolver
-
-
Constructor Details
-
JavaScriptParser
public JavaScriptParser(JavaScriptLanguageSupport langSupport, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea) Constructor.
-
-
Method Details
-
addPropertyChangeListener
Registers a property change listener on this parser. You'll probably want to listen for changes toPROPERTY_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, ornullif the editor's content has not yet been parsed.- Returns:
- The AST, or
null.
-
getJsHintIndent
public int getJsHintIndent() -
getJsHintRCFile
Returns the location of the.jshintrcfile to use if using JsHint as your error parser.- Parameters:
textArea- The text component.- Returns:
- The
.jshintrcfile, ornullif 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
-
getVariablesAndFunctions
-
removePropertyChangeListener
Removes a property change listener from this parser.- Parameters:
prop- The property that was being listened to.l- The listener to remove.- See Also:
-