Class JavaScriptHelper

java.lang.Object
org.fife.rsta.ac.js.JavaScriptHelper

public class JavaScriptHelper extends Object
  • Field Details

    • INFIX

      private static final String 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 created
      initializer - name of initializer
      Returns:
      true if name is different
    • parseEnteredText

      public static final JavaScriptHelper.ParseText parseEnteredText(String text)
      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 --> Name Anything 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 convert
      provider - 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

      public static TypeDeclaration createNewTypeDeclaration(String newName)
    • 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

      public static String convertNodeToSource(org.mozilla.javascript.ast.AstNode node)
    • findIndexOfFirstOpeningBracket

      public static int findIndexOfFirstOpeningBracket(String text)
      Returns the index of the first ( working backwards if there is no matching closing bracket
      Parameters:
      text -
    • findIndexOfFirstOpeningSquareBracket

      public static int findIndexOfFirstOpeningSquareBracket(String text)
    • findNewExpressionString

      private static String findNewExpressionString(org.mozilla.javascript.ast.AstNode node)
      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

      public static TypeDeclaration getTypeDeclaration(String name, SourceCompletionProvider provider)
      Convenience method to lookup TypeDeclaration through the TypeDeclarationFactory.
      Parameters:
      name -
      Returns:
    • findLastIndexOfJavaScriptIdentifier

      public static int findLastIndexOfJavaScriptIdentifier(String input)
    • removeLastDotFromText

      public static String removeLastDotFromText(String text)
      Parameters:
      text - to trim
      Returns:
      text up to the last dot e.g. a.getText().length returns a.getText()
    • trimFromLastParam

      public static String trimFromLastParam(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. 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: