Class JavaScriptAstParser

java.lang.Object
org.fife.rsta.ac.js.ast.parser.JavaScriptParser
org.fife.rsta.ac.js.ast.parser.JavaScriptAstParser
Direct Known Subclasses:
RhinoJavaScriptAstParser

public class JavaScriptAstParser extends JavaScriptParser
  • Field Details

  • Constructor Details

  • Method Details

    • convertAstNodeToCodeBlock

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

      private void setFunctionValues()
    • addCodeBlock

      private void addCodeBlock(org.mozilla.javascript.Node parent, Set<org.fife.ui.autocomplete.Completion> set, String entered, CodeBlock codeBlock, int offset)
      for each child of parent AstNode add a new code block and add completions for each block of code
      Parameters:
      parent - AstNode to iterate children
      set - completions set to add to
      entered - Text entered
      codeBlock - parent CodeBlock
      offset - codeblock offset
    • iterateNode

      protected void iterateNode(org.mozilla.javascript.ast.AstNode child, Set<org.fife.ui.autocomplete.Completion> set, String entered, CodeBlock block, int offset)
    • processExpressionStatement

      private void processExpressionStatement(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
    • reassignVariable

      private void reassignVariable(org.mozilla.javascript.ast.AstNode assign, CodeBlock block, int locationOffSet)
    • addVariableToResolver

      private void addVariableToResolver(org.mozilla.javascript.ast.AstNode name, org.mozilla.javascript.ast.AstNode target, CodeBlock block, int offset)
    • processCaseNode

      private void processCaseNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
    • processSwitchNode

      private void processSwitchNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract local variables from switch node*
    • processTryCatchNode

      private void processTryCatchNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract variables from try/catch node(s)
    • processIfThenElse

      private void processIfThenElse(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract variables from if/else node(s)
    • processExpressionNode

      private void processExpressionNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract completions from expression node
    • processWhileNode

      private void processWhileNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract while loop from node and add new code block
    • processDoNode

      private void processDoNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract while loop from node and add new code block
    • processInfix

      private void processInfix(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract variable from binary operator e.g. invalid input: '<', >, = etc..
    • processFunctionNode

      private void processFunctionNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Add function to completions set and extract local variables to add to code block TODO: functions can have local scope, so add function to it's own codeblock when applicable
    • createJavaScriptFunction

      private JavaScriptFunctionDeclaration createJavaScriptFunction(String lookupName, int offset, CodeBlock block, TypeDeclaration returnType, org.mozilla.javascript.ast.FunctionNode fn)
    • canProcessNode

      private boolean canProcessNode(org.mozilla.javascript.ast.AstNode node)
    • getFunctionType

      private TypeDeclaration getFunctionType(org.mozilla.javascript.ast.FunctionNode fn)
    • processVariableNode

      private void processVariableNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract variable from node and add to code block
    • processForNode

      private void processForNode(org.mozilla.javascript.Node child, CodeBlock block, Set<org.fife.ui.autocomplete.Completion> set, String entered, int offset)
      Extract code from Token.FOR and add completions, then parse body of for-loop.
    • extractVariableFromNode

      private void extractVariableFromNode(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset)
      Extract the variable from the Variable initializer and set the Type
      Parameters:
      initializer - AstNode from which to extract the variable
      block - code block to add the variable too
      offset - position of the variable in code
    • extractVariableForForEach

      private void extractVariableForForEach(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset, org.mozilla.javascript.ast.AstNode iteratedObject)
      Extract variable for each in loop. If the iteratedObject is an Array, then resolve the variable to the array type otherwise set to iterator object type
      Parameters:
      initializer -
      block -
      offset -
      iteratedObject -
    • extractVariableForForIn

      private void extractVariableForForIn(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset, org.mozilla.javascript.ast.AstNode iteratedObject)
      Extract variable for in loop. If the iteratedObject is an Array, then assume the variable to be a number otherwise do not attempt to resolve
      Parameters:
      initializer -
      block -
      offset -
      iteratedObject -
    • canAddVariable

      private boolean canAddVariable(CodeBlock block)
    • extractVariableFromNode

      private JavaScriptVariableDeclaration extractVariableFromNode(org.mozilla.javascript.ast.AstNode node, CodeBlock block, int offset)
      Extract the variable from the Rhino node and add to the CodeBlock
      Parameters:
      node - AstNode node from which to extract the variable
      block - code block to add the variable too
      offset - position of the variable in code
    • extractVariableFromNode

      private JavaScriptVariableDeclaration extractVariableFromNode(org.mozilla.javascript.ast.AstNode node, CodeBlock block, int offset, org.mozilla.javascript.ast.AstNode initializer)
      Extract the variable from the Rhino node and add to the CodeBlock
      Parameters:
      node - AstNode node from which to extract the variable
      block - code block to add the variable too
      offset - position of the variable in code
      initializer - node associated with variable
    • getProvider

      public SourceCompletionProvider getProvider()
    • getDot

      public int getDot()