Package org.fife.rsta.ac.js
Class JavaScriptHelper
java.lang.Object
org.fife.rsta.ac.js.JavaScriptHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classVisitor for infix expression to work out whether the variable should be a string number literal Only works by determining the presence of StringLiterals and NumberLiterals.static classprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanResolveVariable(org.mozilla.javascript.ast.AstNode target, org.mozilla.javascript.ast.AstNode initializer) Test whether the start of the variable is the same name as the variable being initialised.static StringconvertNodeToSource(org.mozilla.javascript.ast.AstNode node) private static TypeDeclarationcreateArrayType(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) Create array type from AstNode and try to determine the array typestatic TypeDeclarationcreateNewTypeDeclaration(String newName) private static TypeDeclarationfindArrayType(org.mozilla.javascript.ast.ArrayLiteral arrayLit, SourceCompletionProvider provider) Find the array type from ArrayLiteral.static org.mozilla.javascript.ast.FunctionCallfindFunctionCallFromNode(org.mozilla.javascript.ast.AstNode node) Iterate back up through parent nodes and check whether inside a function.private static TypeDeclarationfindGetElementType(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) Check the Get Element and extract the Array type from the variable e.g var a = [1, 2, 3]; var b = a[1]; //b resolves to Numberstatic intReturns the index of the first ( working backwards if there is no matching closing bracketstatic intstatic intprivate static StringfindNewExpressionString(org.mozilla.javascript.ast.AstNode node) Returns the node name from 'Token.NEW' AstNode e.g.static TypeDeclarationfindOrMakeTypeDeclaration(String name, SourceCompletionProvider provider) static StringgetFunctionNameLookup(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) static TypeDeclarationgetTypeDeclaration(String name, SourceCompletionProvider provider) Convenience method to lookup TypeDeclaration through the TypeDeclarationFactory.private static TypeDeclarationgetTypeFromInFixExpression(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) Use a visitor to visit all the nodes to work out which type to return e.g 1 + 1 returns Number 1 + "" returns String true returns Boolean etc.static booleanisInfixOnly(org.mozilla.javascript.ast.AstNode typeNode) static final JavaScriptHelper.ParseTextparseEnteredText(String text) Parse Text with JavaScript Parser and return AstNode from the expression etc.private static TypeDeclarationprocessNewNode(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) static StringremoveLastDotFromText(String text) static final TypeDeclarationtokenToNativeTypeDeclaration(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) Convert AstNode to TypeDeclarationstatic StringtrimFromLastParam(String text) Trims the text from the last , from the string Looks for(or[starting at the end of the string to find out where in the string to substring.
-
Field Details
-
INFIX
-
-
Constructor Details
-
JavaScriptHelper
public JavaScriptHelper()
-
-
Method Details
-
canResolveVariable
public static boolean canResolveVariable(org.mozilla.javascript.ast.AstNode target, org.mozilla.javascript.ast.AstNode initializer) Test whether the start of the variable is the same name as the variable being initialised. This is not possible.- Parameters:
target- Name of variable being createdinitializer- name of initializer- Returns:
- true if name is different
-
parseEnteredText
Parse Text with JavaScript Parser and return AstNode from the expression etc.- Parameters:
text- to parse- Returns:
- expression statement text from source
-
getFunctionNameLookup
public static String getFunctionNameLookup(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) - Parameters:
node- AstNode to look for function- Returns:
- function lookup name from it's AstNode. i.e. concat function name and parameters. If no function is found, then return null
-
findFunctionCallFromNode
public static org.mozilla.javascript.ast.FunctionCall findFunctionCallFromNode(org.mozilla.javascript.ast.AstNode node) Iterate back up through parent nodes and check whether inside a function. If the node is a function, then the Parsed parent node structure is:FunctionCall --> PropertyGet --> NameAnything other structure should be rejected.- Parameters:
node-- Returns:
-
tokenToNativeTypeDeclaration
public static final TypeDeclaration tokenToNativeTypeDeclaration(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) Convert AstNode to TypeDeclaration- Parameters:
typeNode- AstNode to convertprovider- SourceProvider- Returns:
- TypeDeclaration if node resolves to supported type, e.g. Number, New etc., otherwise null
-
findGetElementType
private static TypeDeclaration findGetElementType(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) Check the Get Element and extract the Array type from the variable e.g var a = [1, 2, 3]; var b = a[1]; //b resolves to Number- Parameters:
node-provider-- Returns:
-
createArrayType
private static TypeDeclaration createArrayType(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) Create array type from AstNode and try to determine the array type- Parameters:
typeNode-provider-- Returns:
-
findArrayType
private static TypeDeclaration findArrayType(org.mozilla.javascript.ast.ArrayLiteral arrayLit, SourceCompletionProvider provider) Find the array type from ArrayLiteral. Iterates through elements and checks all the types are the same- Parameters:
arrayLit-provider-- Returns:
- TypeDeclaration if all elements are of the same type else TypeDeclarationFactory.getDefaultTypeDeclaration();
-
processNewNode
private static TypeDeclaration processNewNode(org.mozilla.javascript.ast.AstNode typeNode, SourceCompletionProvider provider) -
findOrMakeTypeDeclaration
public static TypeDeclaration findOrMakeTypeDeclaration(String name, SourceCompletionProvider provider) -
createNewTypeDeclaration
-
isInfixOnly
public static boolean isInfixOnly(org.mozilla.javascript.ast.AstNode typeNode) -
getTypeFromInFixExpression
private static TypeDeclaration getTypeFromInFixExpression(org.mozilla.javascript.ast.AstNode node, SourceCompletionProvider provider) Use a visitor to visit all the nodes to work out which type to return e.g 1 + 1 returns Number 1 + "" returns String true returns Boolean etc.- Parameters:
node-- Returns:
-
convertNodeToSource
-
findIndexOfFirstOpeningBracket
Returns the index of the first ( working backwards if there is no matching closing bracket- Parameters:
text-
-
findIndexOfFirstOpeningSquareBracket
-
findNewExpressionString
Returns the node name from 'Token.NEW' AstNode e.g. new Object --> Object new Date --> Date etc.- Parameters:
node- NewExpression node- Returns:
- Extracts the Name identifier from NewExpression
-
getTypeDeclaration
Convenience method to lookup TypeDeclaration through the TypeDeclarationFactory.- Parameters:
name-- Returns:
-
findLastIndexOfJavaScriptIdentifier
-
removeLastDotFromText
- Parameters:
text- to trim- Returns:
- text up to the last dot e.g. a.getText().length returns a.getText()
-
trimFromLastParam
Trims the text from the last , from the string Looks for(or[starting at the end of the string to find out where in the string to substring. Do not need to trim off if inside either () or []. e.g 1, "".charAt(position).indexOf(2, "") String should be trimmed at the 1, not the 2,- Parameters:
text-- Returns:
-