Class 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 Detail

      • lastLookupName

        protected java.lang.String lastLookupName
    • Constructor Detail

      • JavaScriptCompletionResolver

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

      • compileText

        public JavaScriptType compileText​(java.lang.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​(java.lang.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 java.lang.String getLookupText​(JSMethodData method,
                                              java.lang.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.
      • createNewTypeDeclaration

        private JavaScriptType createNewTypeDeclaration​(SourceCompletionProvider provider,
                                                        java.lang.String type,
                                                        java.lang.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