Class SyntaxChecker

  • Direct Known Subclasses:
    JavaScriptNavigator

    public class SyntaxChecker
    extends AbstractUtilityParser
    Determines the compile-time errors and warnings in a script without executing the script.
    Since:
    3.0
    Author:
    Chris Jennings
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SyntaxChecker.SyntaxError
      Describes a syntax error that has been detected during syntax checking.
    • Constructor Summary

      Constructors 
      Constructor Description
      SyntaxChecker()
      Creates a new syntax checker.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean acceptError​(java.lang.String message, boolean warning, int offset, int length)
      Subclasses may use this to filter for specific error messages.
      SyntaxChecker.SyntaxError[] getErrors()
      Returns an array of the errors and warnings generated by the most-recently parsed script.
      void parse​(java.lang.String script)
      Parses the specified script.
      protected void processTree​(org.mozilla.javascript.ast.AstRoot rootNode)
      This is called after each script is parsed to allow the utility access to the resulting abstract syntax tree.
      • Methods inherited from class java.lang.Object

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

      • SyntaxChecker

        public SyntaxChecker()
        Creates a new syntax checker.
    • Method Detail

      • getErrors

        public SyntaxChecker.SyntaxError[] getErrors()
        Returns an array of the errors and warnings generated by the most-recently parsed script.
        Returns:
        a (possibly empty) array of errors
      • acceptError

        protected boolean acceptError​(java.lang.String message,
                                      boolean warning,
                                      int offset,
                                      int length)
        Subclasses may use this to filter for specific error messages.
        Parameters:
        message - the error message
        warning - true if the message is a warning rather than an error
        offset - the offset into the script
        length - the length of code that is affected
        Returns:
        true if the error should be included in the results
      • processTree

        protected void processTree​(org.mozilla.javascript.ast.AstRoot rootNode)
        Description copied from class: AbstractUtilityParser
        This is called after each script is parsed to allow the utility access to the resulting abstract syntax tree. In the event of a serious parser error that prevents the tree from being generated, the root node will be null.
        Specified by:
        processTree in class AbstractUtilityParser
        Parameters:
        rootNode - the root of the parse tree