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.AbstractParserParses JavaScript code in anRSyntaxTextArea.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_ASTis fired. Listeners can check the new value of the property for theAstRootbuilt 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 Classes Modifier and Type Class Description static classJavaScriptParser.JSErrorReporterError reporter for Rhino-based parsing.
-
Field Summary
Fields Modifier and Type Field Description private org.mozilla.javascript.ast.AstRootastRootprivate JavaScriptLanguageSupportlangSupportstatic java.lang.StringPROPERTY_ASTThe property change event that's fired when the document is re-parsed.private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResultresultprivate java.beans.PropertyChangeSupportsupportprivate org.fife.ui.rsyntaxtextarea.RSyntaxTextAreatextAreaprivate VariableResolvervariableResolver
-
Constructor Summary
Constructors Constructor Description JavaScriptParser(JavaScriptLanguageSupport langSupport, org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.lang.String prop, java.beans.PropertyChangeListener l)Registers 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, javax.swing.text.Element root)Gathers the syntax errors found by Rhino in-process when parsing the document.org.mozilla.javascript.ast.AstRootgetAstRoot()Returns the AST, ornullif the editor's content has not yet been parsed.intgetJsHintIndent()java.io.FilegetJsHintRCFile(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea)Returns the location of the.jshintrcfile to use if using JsHint as your error parser.VariableResolvergetVariablesAndFunctions()org.fife.ui.rsyntaxtextarea.parser.ParseResultparse(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, java.lang.String style)voidremovePropertyChangeListener(java.lang.String prop, java.beans.PropertyChangeListener l)Removes a property change listener from this parser.voidsetVariablesAndFunctions(VariableResolver variableResolver)
-
-
-
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 oforg.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
-
langSupport
private JavaScriptLanguageSupport langSupport
-
support
private java.beans.PropertyChangeSupport support
-
result
private org.fife.ui.rsyntaxtextarea.parser.DefaultParseResult result
-
variableResolver
private VariableResolver variableResolver
-
-
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 toPROPERTY_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, ornullif 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.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, java.lang.String style)
-
setVariablesAndFunctions
public void setVariablesAndFunctions(VariableResolver variableResolver)
-
getVariablesAndFunctions
public VariableResolver getVariablesAndFunctions()
-
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)
-
-