Package org.fife.rsta.ac.js.ast.parser
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJavaScriptAstParser.FunctionReturnVisitor(package private) static classJavaScriptAstParser.ProcessFunctionType
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<JavaScriptAstParser.ProcessFunctionType>functions-
Fields inherited from class org.fife.rsta.ac.js.ast.parser.JavaScriptParser
dot, options, provider
-
-
Constructor Summary
Constructors Constructor Description JavaScriptAstParser(SourceCompletionProvider provider, int dot, TypeDeclarationOptions options)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCodeBlock(org.mozilla.javascript.Node parent, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, CodeBlock codeBlock, int offset)for each child of parent AstNode add a new code block and add completions for each block of codeprivate voidaddVariableToResolver(org.mozilla.javascript.ast.AstNode name, org.mozilla.javascript.ast.AstNode target, CodeBlock block, int offset)private booleancanAddVariable(CodeBlock block)private booleancanProcessNode(org.mozilla.javascript.ast.AstNode node)CodeBlockconvertAstNodeToCodeBlock(org.mozilla.javascript.ast.AstRoot root, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered)Converts AstRoot to CodeBlockprivate JavaScriptFunctionDeclarationcreateJavaScriptFunction(java.lang.String lookupName, int offset, CodeBlock block, TypeDeclaration returnType, org.mozilla.javascript.ast.FunctionNode fn)private voidextractVariableForForEach(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset, org.mozilla.javascript.ast.AstNode iteratedObject)Extract variable for each in loop.private voidextractVariableForForIn(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset, org.mozilla.javascript.ast.AstNode iteratedObject)Extract variable for in loop.private JavaScriptVariableDeclarationextractVariableFromNode(org.mozilla.javascript.ast.AstNode node, CodeBlock block, int offset)Extract the variable from the Rhino node and add to the CodeBlockprivate JavaScriptVariableDeclarationextractVariableFromNode(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 CodeBlockprivate voidextractVariableFromNode(org.mozilla.javascript.ast.VariableInitializer initializer, CodeBlock block, int offset)Extract the variable from the Variable initializer and set the TypeintgetDot()private TypeDeclarationgetFunctionType(org.mozilla.javascript.ast.FunctionNode fn)SourceCompletionProvidergetProvider()protected voiditerateNode(org.mozilla.javascript.ast.AstNode child, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, CodeBlock block, int offset)private voidprocessCaseNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)private voidprocessDoNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract while loop from node and add new code blockprivate voidprocessExpressionNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract completions from expression nodeprivate voidprocessExpressionStatement(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)private voidprocessForNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract code fromToken.FORand add completions, then parse body of for-loop.private voidprocessFunctionNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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 applicableprivate voidprocessIfThenElse(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variables from if/else node(s)private voidprocessInfix(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variable from binary operator e.g.private voidprocessSwitchNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract local variables from switch node*private voidprocessTryCatchNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variables from try/catch node(s)private voidprocessVariableNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variable from node and add to code blockprivate voidprocessWhileNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract while loop from node and add new code blockprivate voidreassignVariable(org.mozilla.javascript.ast.AstNode assign, CodeBlock block, int locationOffSet)private voidsetFunctionValues()-
Methods inherited from class org.fife.rsta.ac.js.ast.parser.JavaScriptParser
isPreProcessing
-
-
-
-
Field Detail
-
functions
private java.util.ArrayList<JavaScriptAstParser.ProcessFunctionType> functions
-
-
Constructor Detail
-
JavaScriptAstParser
public JavaScriptAstParser(SourceCompletionProvider provider, int dot, TypeDeclarationOptions options)
-
-
Method Detail
-
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:JavaScriptParserConverts AstRoot to CodeBlock- Specified by:
convertAstNodeToCodeBlockin classJavaScriptParser- Parameters:
root- AstRoot to iterateset- completions setentered- text entered by user- Returns:
- CodeBlock tree
-
setFunctionValues
private void setFunctionValues()
-
addCodeBlock
private void addCodeBlock(org.mozilla.javascript.Node parent, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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 childrenset- completions set to add toentered- Text enteredcodeBlock- parent CodeBlockoffset- codeblock offset
-
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)
-
processExpressionStatement
private void processExpressionStatement(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)
-
processSwitchNode
private void processSwitchNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract local variables from switch node*
-
processTryCatchNode
private void processTryCatchNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variables from try/catch node(s)
-
processIfThenElse
private void processIfThenElse(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variables from if/else node(s)
-
processExpressionNode
private void processExpressionNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract completions from expression node
-
processWhileNode
private void processWhileNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variable from binary operator e.g. <, >, = etc..
-
processFunctionNode
private void processFunctionNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.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(java.lang.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, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract variable from node and add to code block
-
processForNode
private void processForNode(org.mozilla.javascript.Node child, CodeBlock block, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int offset)Extract code fromToken.FORand 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 variableblock- code block to add the variable toooffset- 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 variableblock- code block to add the variable toooffset- 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 variableblock- code block to add the variable toooffset- position of the variable in codeinitializer- node associated with variable
-
getProvider
public SourceCompletionProvider getProvider()
-
getDot
public int getDot()
-
-