Package org.fife.rsta.ac.js.resolver
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 JavaScriptTypeetc.Note, will resolve any type added to JavaScriptTypesFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classJavaScriptCompletionResolver.CompilerNodeVisitorprivate static classJavaScriptCompletionResolver.VisitorAllVisit all nodes in the AstNode tree and all to a single list
-
Field Summary
Fields Modifier and Type Field Description protected JavaScriptTypelastJavaScriptTypeprotected java.lang.StringlastLookupName-
Fields inherited from class org.fife.rsta.ac.js.resolver.JavaScriptResolver
provider
-
-
Constructor Summary
Constructors Constructor Description JavaScriptCompletionResolver(SourceCompletionProvider provider)Standard ECMA JavaScript resolver
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JavaScriptTypecompileText(java.lang.String text)Compiles Text and resolves the type.private JavaScriptTypecreateNewTypeDeclaration(SourceCompletionProvider provider, java.lang.String type, java.lang.String text)Creates a new JavaScriptType based on the String typeprotected TypeDeclarationfindJavaStaticType(org.mozilla.javascript.ast.AstNode node)Try to resolve the Token.NAME AstNode and return a TypeDeclarationjava.lang.StringgetFunctionNameLookup(org.mozilla.javascript.ast.FunctionCall call, SourceCompletionProvider provider)Returns same string format asJavaScriptResolver.getLookupText(JSMethodData, String)but from AstNode Functionjava.lang.StringgetLookupText(JSMethodData method, java.lang.String name)Get lookup string for function completionsprotected JavaScriptTypelookupFromName(org.mozilla.javascript.ast.AstNode node, JavaScriptType lastJavaScriptType)Lookup the name of the node within the last JavaScript type.protected JavaScriptTypelookupFunctionCompletion(org.mozilla.javascript.ast.AstNode node, JavaScriptType lastJavaScriptType)Lookup the function name of the node within the last JavaScript type.private JavaScriptTypelookupJavaScriptType(JavaScriptType lastJavaScriptType, java.lang.String lookupText)protected TypeDeclarationresolveNativeType(org.mozilla.javascript.ast.AstNode node)Resolve node type to TypeDeclaration N.B called fromCompilerNodeVisitor.visit()TypeDeclarationresolveNode(org.mozilla.javascript.ast.AstNode node)Resolve node type to TypeDeclaration.TypeDeclarationresolveParamNode(java.lang.String text)Resolve node type to TypeDeclaration.protected TypeDeclarationresolveTypeFromLastJavaScriptType(org.mozilla.javascript.ast.AstNode node)Method called if the lastJavaScriptType is not null.protected TypeDeclarationtestJavaStaticType(org.mozilla.javascript.ast.AstNode node)Test whether the node can be resolved as a static Java class.
-
-
-
Field Detail
-
lastJavaScriptType
protected JavaScriptType lastJavaScriptType
-
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:
compileTextin classJavaScriptResolver- 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:
resolveParamNodein classJavaScriptResolver- 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:
resolveNodein classJavaScriptResolver- 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 fromCompilerNodeVisitor.visit()- Specified by:
resolveNativeTypein classJavaScriptResolver- 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:JavaScriptResolverGet lookup string for function completions- Specified by:
getLookupTextin classJavaScriptResolver- Parameters:
method- JSMethodData holding method informationname- name of method- Returns:
- The lookup text.
-
getFunctionNameLookup
public java.lang.String getFunctionNameLookup(org.mozilla.javascript.ast.FunctionCall call, SourceCompletionProvider provider)Description copied from class:JavaScriptResolverReturns same string format asJavaScriptResolver.getLookupText(JSMethodData, String)but from AstNode Function- Specified by:
getFunctionNameLookupin classJavaScriptResolver- Returns:
- The function name.
-
lookupJavaScriptType
private JavaScriptType lookupJavaScriptType(JavaScriptType lastJavaScriptType, java.lang.String lookupText)
-
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- SourceCompletionProvidertype- type of JavaScript type to create e.g. java.sql.Connectiontext- 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
-
-