Class RhinoJavaScriptAstParser


  • public class RhinoJavaScriptAstParser
    extends JavaScriptAstParser
    Rhino specific JavaScriptAstParser. Reads the importPackage and importClass from the parsed document and adds to the RhinoJavaScriptTypesFactory.
    • Field Detail

      • importClasses

        private java.util.LinkedHashSet<java.lang.String> importClasses
      • importPackages

        private java.util.LinkedHashSet<java.lang.String> importPackages
    • Method Detail

      • clearImportCache

        public void clearImportCache​(SourceCompletionProvider provider)
        Clear the importPackage and importClass cache
        Parameters:
        provider - SourceCompletionProvider
      • convertAstNodeToCodeBlock

        public CodeBlock convertAstNodeToCodeBlock​(org.mozilla.javascript.ast.AstRoot root,
                                                   java.util.Set<org.fife.ui.autocomplete.Completion> set,
                                                   java.lang.String entered)
        Description copied from class: JavaScriptParser
        Converts AstRoot to CodeBlock
        Overrides:
        convertAstNodeToCodeBlock in class JavaScriptAstParser
        Parameters:
        root - AstRoot to iterate
        set - completions set
        entered - text entered by user
        Returns:
        CodeBlock tree
      • mergeImportCache

        private void mergeImportCache​(java.util.HashSet<java.lang.String> packages,
                                      java.util.HashSet<java.lang.String> classes)
      • iterateNode

        protected void iterateNode​(org.mozilla.javascript.ast.AstNode child,
                                   java.util.Set<org.fife.ui.autocomplete.Completion> set,
                                   java.lang.String entered,
                                   CodeBlock block,
                                   int offset)
        Overridden iterateNode to intercept Token.EXPR_RESULT and check for importPackage and importClass named nodes If found, then process them and extract the imports and add them to RhinoJavaScriptTypesFactory then return otherwise call super.iterateNode()
        Overrides:
        iterateNode in class JavaScriptAstParser
      • processImportNode

        private boolean processImportNode​(org.mozilla.javascript.ast.AstNode child,
                                          java.util.Set<org.fife.ui.autocomplete.Completion> set,
                                          java.lang.String entered,
                                          CodeBlock block,
                                          int offset)
        Look for text importPackage and importClass and add to cache
        Parameters:
        child - AstNode to check. This will always be Token.EXPR_RESULT AstNode
        set - Set to add completions
        entered - text entered by user if applicable
        block - CodeBlock
        offset - position of AstNode within document
        Returns:
        true if either importPackage or importClass is found
      • removePackages

        public static java.lang.String removePackages​(java.lang.String src)
      • extractNameFromSrc

        private java.lang.String extractNameFromSrc​(java.lang.String src)
        Parameters:
        src - String to extract name
        Returns:
        import statement from withing the ( and ) e.g. importPackage(java.util) importClass(java.util.HashSet) returns java.util or java.util.HashSet respectively
      • processImportPackage

        private void processImportPackage​(java.lang.String src)
        Adds package name to RhinoJavaScriptTypesFactory
        Parameters:
        src - source text to extract the package
      • processImportClass

        private void processImportClass​(java.lang.String src)
        Adds class name to RhinoJavaScriptTypesFactory
        Parameters:
        src - source text to extract the class name