Package org.fife.rsta.ac.js
Class SourceCompletionProvider
- java.lang.Object
-
- org.fife.ui.autocomplete.CompletionProviderBase
-
- org.fife.ui.autocomplete.AbstractCompletionProvider
-
- org.fife.ui.autocomplete.DefaultCompletionProvider
-
- org.fife.rsta.ac.js.SourceCompletionProvider
-
- All Implemented Interfaces:
org.fife.ui.autocomplete.CompletionProvider
public class SourceCompletionProvider extends org.fife.ui.autocomplete.DefaultCompletionProviderCompletion provider for JavaScript source code (not comments or strings).- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private intdotprivate JavaScriptEngineengineprivate JarManagerjarManagerprivate JavaScriptTypesFactoryjavaScriptTypesFactoryprivate java.lang.StringlastCompletionsAtTextprivate java.util.List<org.fife.ui.autocomplete.Completion>lastParameterizedCompletionsAtprivate JavaScriptCompletionProviderparentprivate PreProcessingScriptspreProcessingprivate java.lang.Stringselfprivate ShorthandCompletionCacheshorthandCacheprivate TypeDeclarationOptionstypeDeclarationOptionsprivate VariableResolvervariableResolverprivate booleanxmlSupported
-
Constructor Summary
Constructors Constructor Description SourceCompletionProvider(boolean xmlSupported)SourceCompletionProvider(java.lang.String javaScriptEngine, boolean xmlSupported)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddShorthandCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set)Adds simple shorthand completions relevant to JavaScript from the shorthand template.voiddebugCodeBlock(CodeBlock block, int tab)JavaScriptVariableDeclarationfindDeclaration(java.lang.String name)Convenience method to call variable resolverJavaScriptVariableDeclarationfindNonLocalDeclaration(java.lang.String name)Convenience method to call variable resolver for non-local variables i.e.java.lang.StringgetAlreadyEnteredText(javax.swing.text.JTextComponent comp)java.util.List<org.fife.ui.autocomplete.Completion>getCompletionsAt(javax.swing.text.JTextComponent tc, java.awt.Point p)protected java.util.List<org.fife.ui.autocomplete.Completion>getCompletionsImpl(javax.swing.text.JTextComponent comp)JarManagergetJarManager()JavaScriptEnginegetJavaScriptEngine()JavaScriptTypesFactorygetJavaScriptTypesFactory()JavaScriptLanguageSupportgetLanguageSupport()PreProcessingScriptsgetPreProcessingScripts()java.lang.StringgetSelf()returns the Base class for the source completion provider.SourceLocationgetSourceLocForClass(java.lang.String className)TypeDeclarationFactorygetTypesFactory()VariableResolvergetVariableResolver()private java.util.List<org.fife.ui.autocomplete.Completion>handleNewFilter(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)protected booleanisValidChar(char ch)booleanisXMLSupported()protected CodeBlockiterateAstRoot(org.mozilla.javascript.ast.AstRoot root, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int dot, TypeDeclarationOptions options)Iterates through AstRoot to extract all code blocks, functions, variables etc...private voidloadECMAClasses(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)Load ECMA JavaScript class completionsvoidparseDocument(int dot)private voidparseTextAndResolve(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)Parse Text and add completions to setprivate booleanpopulateCompletionsFromType(JavaScriptType type, java.util.Set<org.fife.ui.autocomplete.Completion> set)Populate Set of completions if JavaScriptType is not null and return true, otherwise return falseprotected voidrecursivelyAddLocalVars(java.util.Set<org.fife.ui.autocomplete.Completion> completions, CodeBlock block, int dot, java.lang.String text, boolean findMatch, boolean isPreprocessing)Iterate though the CodeBlock and extract all variables within scopeprivate java.util.List<org.fife.ui.autocomplete.Completion>resolveCompletions(java.lang.String text, java.util.Set<org.fife.ui.autocomplete.Completion> set)TypeDeclarationresolveTypeDeclation(java.lang.String name)Convenience method to call variable resolverTypeDeclarationresolveTypeFromFunctionNode(org.mozilla.javascript.ast.AstNode functionNode)Get the source of the node and try to resolve function node:voidsetJarManager(JarManager jarManager)The jar manager is used to parse the JS API for function completionsvoidsetJavaScriptEngine(JavaScriptEngine engine)voidsetJavaScriptTypesFactory(JavaScriptTypesFactory factory)(package private) voidsetParent(JavaScriptCompletionProvider parent)voidsetPreProcessingScripts(PreProcessingScripts preProcessing)voidsetSelf(java.lang.String self)voidsetShorthandCache(ShorthandCompletionCache shorthandCache)Set template completion cache for source completion provider.voidsetTypeDeclationOptions(TypeDeclarationOptions typeDeclarationOptions)Set type declaration options for parservoidsetXMLSupported(boolean xmlSupported)private booleansupportsPreProcessingScripts()-
Methods inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider
getParameterizedCompletions, init, loadFromXML, loadFromXML, loadFromXML, loadFromXML
-
Methods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, removeCompletion
-
Methods inherited from class org.fife.ui.autocomplete.CompletionProviderBase
clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, isAutoActivateOkay, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent
-
-
-
-
Field Detail
-
parent
private JavaScriptCompletionProvider parent
-
jarManager
private JarManager jarManager
-
dot
private int dot
-
engine
private JavaScriptEngine engine
-
javaScriptTypesFactory
private JavaScriptTypesFactory javaScriptTypesFactory
-
variableResolver
private VariableResolver variableResolver
-
preProcessing
private PreProcessingScripts preProcessing
-
shorthandCache
private ShorthandCompletionCache shorthandCache
-
xmlSupported
private boolean xmlSupported
-
self
private java.lang.String self
-
typeDeclarationOptions
private TypeDeclarationOptions typeDeclarationOptions
-
lastCompletionsAtText
private java.lang.String lastCompletionsAtText
-
lastParameterizedCompletionsAt
private java.util.List<org.fife.ui.autocomplete.Completion> lastParameterizedCompletionsAt
-
-
Method Detail
-
addShorthandCompletions
private void addShorthandCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set)
Adds simple shorthand completions relevant to JavaScript from the shorthand template.- Parameters:
set- The set to add to.- See Also:
ShorthandCompletionCache
-
setShorthandCache
public void setShorthandCache(ShorthandCompletionCache shorthandCache)
Set template completion cache for source completion provider.- Parameters:
shorthandCache- The cache to use.
-
getCompletionsAt
public java.util.List<org.fife.ui.autocomplete.Completion> getCompletionsAt(javax.swing.text.JTextComponent tc, java.awt.Point p)- Specified by:
getCompletionsAtin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
getCompletionsAtin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
getCompletionsImpl
protected java.util.List<org.fife.ui.autocomplete.Completion> getCompletionsImpl(javax.swing.text.JTextComponent comp)
- Overrides:
getCompletionsImplin classorg.fife.ui.autocomplete.AbstractCompletionProvider
-
handleNewFilter
private java.util.List<org.fife.ui.autocomplete.Completion> handleNewFilter(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)
-
resolveCompletions
private java.util.List<org.fife.ui.autocomplete.Completion> resolveCompletions(java.lang.String text, java.util.Set<org.fife.ui.autocomplete.Completion> set)
-
loadECMAClasses
private void loadECMAClasses(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)Load ECMA JavaScript class completions- Parameters:
set- completion settext-
-
getSelf
public java.lang.String getSelf()
returns the Base class for the source completion provider. This is represented by a class name or ECMA lookup name e.g. set to 'Global' for server side or 'Window' for client JavaScript support- Returns:
- base class for the completion provider
-
parseTextAndResolve
private void parseTextAndResolve(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text)Parse Text and add completions to set
-
populateCompletionsFromType
private boolean populateCompletionsFromType(JavaScriptType type, java.util.Set<org.fife.ui.autocomplete.Completion> set)
Populate Set of completions if JavaScriptType is not null and return true, otherwise return false
-
getAlreadyEnteredText
public java.lang.String getAlreadyEnteredText(javax.swing.text.JTextComponent comp)
- Specified by:
getAlreadyEnteredTextin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
getAlreadyEnteredTextin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
iterateAstRoot
protected CodeBlock iterateAstRoot(org.mozilla.javascript.ast.AstRoot root, java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String entered, int dot, TypeDeclarationOptions options)
Iterates through AstRoot to extract all code blocks, functions, variables etc... e.g. functions, if statements, variables- Parameters:
root- AstRoot to iterateset- add add completions to set (functions only TODO remove this and do elsewhere)entered- already entered textdot- position in codeoptions- Options for the parsing.- Returns:
-
resolveTypeDeclation
public TypeDeclaration resolveTypeDeclation(java.lang.String name)
Convenience method to call variable resolver- Parameters:
name-- Returns:
-
findDeclaration
public JavaScriptVariableDeclaration findDeclaration(java.lang.String name)
Convenience method to call variable resolver- Parameters:
name-- Returns:
- JavaScript variable declaration
-
findNonLocalDeclaration
public JavaScriptVariableDeclaration findNonLocalDeclaration(java.lang.String name)
Convenience method to call variable resolver for non-local variables i.e. does NOT try to resolve name to any local variables (just pre-processed or system)- Parameters:
name-- Returns:
- JavaScript variable declaration
-
resolveTypeFromFunctionNode
public TypeDeclaration resolveTypeFromFunctionNode(org.mozilla.javascript.ast.AstNode functionNode)
Get the source of the node and try to resolve function node:- Parameters:
functionNode-- Returns:
- a.toString().getCharAt(1); returns String TypeDeclaration
-
setParent
void setParent(JavaScriptCompletionProvider parent)
-
setJavaScriptTypesFactory
public void setJavaScriptTypesFactory(JavaScriptTypesFactory factory)
-
getJavaScriptTypesFactory
public JavaScriptTypesFactory getJavaScriptTypesFactory()
-
recursivelyAddLocalVars
protected void recursivelyAddLocalVars(java.util.Set<org.fife.ui.autocomplete.Completion> completions, CodeBlock block, int dot, java.lang.String text, boolean findMatch, boolean isPreprocessing)Iterate though the CodeBlock and extract all variables within scope- Parameters:
completions-block-dot-text-findMatch-
-
isValidChar
protected boolean isValidChar(char ch)
- Overrides:
isValidCharin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
setJarManager
public void setJarManager(JarManager jarManager)
The jar manager is used to parse the JS API for function completions- Parameters:
jarManager-
-
getJarManager
public JarManager getJarManager()
-
getVariableResolver
public VariableResolver getVariableResolver()
-
getLanguageSupport
public JavaScriptLanguageSupport getLanguageSupport()
-
setPreProcessingScripts
public void setPreProcessingScripts(PreProcessingScripts preProcessing)
-
getPreProcessingScripts
public PreProcessingScripts getPreProcessingScripts()
-
supportsPreProcessingScripts
private boolean supportsPreProcessingScripts()
-
getJavaScriptEngine
public JavaScriptEngine getJavaScriptEngine()
-
setJavaScriptEngine
public void setJavaScriptEngine(JavaScriptEngine engine)
-
getSourceLocForClass
public SourceLocation getSourceLocForClass(java.lang.String className)
-
isXMLSupported
public boolean isXMLSupported()
-
setXMLSupported
public void setXMLSupported(boolean xmlSupported)
-
setSelf
public void setSelf(java.lang.String self)
-
parseDocument
public void parseDocument(int dot)
-
getTypesFactory
public TypeDeclarationFactory getTypesFactory()
-
setTypeDeclationOptions
public void setTypeDeclationOptions(TypeDeclarationOptions typeDeclarationOptions)
Set type declaration options for parser- Parameters:
typeDeclarationOptions-
-
debugCodeBlock
public void debugCodeBlock(CodeBlock block, int tab)
-
-