Class JavaScriptCompletionResolver

java.lang.Object
org.fife.rsta.ac.js.resolver.JavaScriptResolver
org.fife.rsta.ac.js.resolver.JavaScriptCompletionResolver
Direct Known Subclasses:
JSR223JavaScriptCompletionResolver

public class JavaScriptCompletionResolver extends JavaScriptResolver
Compiles the entered text using Rhino and tries to resolve the JavaScriptType from the AstRoot e.g. var a = ""; "" --> String JavaScriptType var b = a.toString() a.toString --> String JavaScriptType etc.

Note, will resolve any type added to JavaScriptTypesFactory

  • Field Details

    • lastJavaScriptType

      protected JavaScriptType lastJavaScriptType
    • lastLookupName

      protected String lastLookupName
  • Constructor Details

    • JavaScriptCompletionResolver

      public JavaScriptCompletionResolver(SourceCompletionProvider provider)
      Standard ECMA JavaScript resolver
      Parameters:
      provider -
  • Method Details

    • compileText

      public JavaScriptType compileText(String text)
      Compiles Text and resolves the type. e.g. "Hello World".length; //resolve as a Number
      Specified by:
      compileText in class JavaScriptResolver
      Parameters:
      text - to compile and resolve
    • resolveParamNode

      public TypeDeclaration resolveParamNode(String text)
      Resolve node type to TypeDeclaration. Called instead of #compileText(String text) when document is already parsed
      Specified by:
      resolveParamNode in class JavaScriptResolver
      Parameters:
      text - The node to resolve
      Returns:
      TypeDeclaration for node or null if not found.
    • resolveNode

      public TypeDeclaration resolveNode(org.mozilla.javascript.ast.AstNode node)
      Resolve node type to TypeDeclaration. Called instead of #compileText(String text) when document is already parsed
      Specified by:
      resolveNode in class JavaScriptResolver
      Parameters:
      node - AstNode to resolve
      Returns:
      TypeDeclaration for node or null if not found.
    • resolveNativeType

      protected TypeDeclaration resolveNativeType(org.mozilla.javascript.ast.AstNode node)
      Resolve node type to TypeDeclaration N.B called from CompilerNodeVisitor.visit()
      Specified by:
      resolveNativeType in class JavaScriptResolver
      Parameters:
      node - AstNode to resolve
      Returns:
      TypeDeclaration for node or null if not found.
    • testJavaStaticType

      protected TypeDeclaration testJavaStaticType(org.mozilla.javascript.ast.AstNode node)
      Test whether the node can be resolved as a static Java class. Only looks for Token.NAME nodes to test
      Parameters:
      node - node to test
      Returns:
      The type declaration.
    • findJavaStaticType

      protected TypeDeclaration findJavaStaticType(org.mozilla.javascript.ast.AstNode node)
      Try to resolve the Token.NAME AstNode and return a TypeDeclaration
      Parameters:
      node - node to resolve
      Returns:
      TypeDeclaration if the name can be resolved as a Java Class else null
    • lookupFromName

      protected JavaScriptType lookupFromName(org.mozilla.javascript.ast.AstNode node, JavaScriptType lastJavaScriptType)
      Lookup the name of the node within the last JavaScript type. e.g. var a = 1; var b = a.MAX_VALUE; looks up MAX_VALUE within NumberLiteral a where a is resolve before as a JavaScript Number;
      Parameters:
      node -
      lastJavaScriptType -
      Returns:
      The type.
    • lookupFunctionCompletion

      protected JavaScriptType lookupFunctionCompletion(org.mozilla.javascript.ast.AstNode node, JavaScriptType lastJavaScriptType)
      Lookup the function name of the node within the last JavaScript type. e.g. var a = ""; var b = a.toString(); looks up toString() within StringLiteral a where a is resolve before as a JavaScript String;
      Parameters:
      node -
      lastJavaScriptType -
      Returns:
      The type.
    • getLookupText

      public String getLookupText(JSMethodData method, String name)
      Description copied from class: JavaScriptResolver
      Get lookup string for function completions
      Specified by:
      getLookupText in class JavaScriptResolver
      Parameters:
      method - JSMethodData holding method information
      name - name of method
      Returns:
      The lookup text.
    • getFunctionNameLookup

      public String getFunctionNameLookup(org.mozilla.javascript.ast.FunctionCall call, SourceCompletionProvider provider)
      Description copied from class: JavaScriptResolver
      Returns same string format as JavaScriptResolver.getLookupText(JSMethodData, String) but from AstNode Function
      Specified by:
      getFunctionNameLookup in class JavaScriptResolver
      Parameters:
      call -
      provider -
      Returns:
      The function name.
    • lookupJavaScriptType

      private JavaScriptType lookupJavaScriptType(JavaScriptType lastJavaScriptType, String lookupText)
    • createNewTypeDeclaration

      private JavaScriptType createNewTypeDeclaration(SourceCompletionProvider provider, String type, String text)
      Creates a new JavaScriptType based on the String type
      Parameters:
      provider - SourceCompletionProvider
      type - type of JavaScript type to create e.g. java.sql.Connection
      text - Text entered from the user to resolve the node. This will be null if resolveNode(AstNode node) is called
      Returns:
    • resolveTypeFromLastJavaScriptType

      protected TypeDeclaration resolveTypeFromLastJavaScriptType(org.mozilla.javascript.ast.AstNode node)
      Method called if the lastJavaScriptType is not null. i.e. has gone through one iteration at least. Resolves TypeDeclaration for parts of a variable past the first part. e.g. "".toString() //resolve toString() In some circumstances this is useful to resolve this. e.g. for Custom Object completions
      Parameters:
      node - Node to resolve
      Returns:
      Type Declaration