Package org.fife.rsta.ac.java
Class SourceCompletionProvider
- java.lang.Object
-
- org.fife.ui.autocomplete.CompletionProviderBase
-
- org.fife.ui.autocomplete.AbstractCompletionProvider
-
- org.fife.ui.autocomplete.DefaultCompletionProvider
-
- org.fife.rsta.ac.java.SourceCompletionProvider
-
- All Implemented Interfaces:
org.fife.ui.autocomplete.CompletionProvider
class SourceCompletionProvider extends org.fife.ui.autocomplete.DefaultCompletionProviderParses a Java AST for code completions. It currently scans the following:- Import statements
- Method names
- Field names
- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private JarManagerjarManagerUsed to get information about what classes match imports.private static java.lang.StringJAVA_LANG_PACKAGEprivate JavaCompletionProviderjavaProviderThe parent completion provider.private ShorthandCompletionCacheshorthandCacheprivate static java.lang.StringTHIS
-
Constructor Summary
Constructors Constructor Description SourceCompletionProvider()Constructor.SourceCompletionProvider(JarManager jarManager)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddCompletionsForExtendedClass(java.util.Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, java.lang.String pkg, java.util.Map<java.lang.String,java.lang.String> typeParamMap)Adds completions for accessible methods and fields of super classes.private voidaddCompletionsForLocalVarsMethods(CompilationUnit cu, LocalVariable var, java.util.Set<org.fife.ui.autocomplete.Completion> retVal)Adds completions for all methods and public fields of a local variable.private voidaddCompletionsForStaticMembers(java.util.Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, java.lang.String pkg)voidaddJar(LibraryInfo info)Adds a jar to read from.private voidaddLocalVarCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, CodeBlock block, int offs)Adds completions for local variables in a code block inside a method.private voidaddLocalVarCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, Method method, int offs)Adds completions for local variables in a method.private voidaddShorthandCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set)Adds simple shorthand completions relevant to Java.private booleancheckStringLiteralMember(javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, CompilationUnit cu, java.util.Set<org.fife.ui.autocomplete.Completion> set)Checks whether the user is typing a completion for a String member after a String literal.voidclearJars()Removes all jars from the "build path".private java.util.Map<java.lang.String,java.lang.String>createTypeParamMap(Type type, ClassFile cf)Creates and returns a mapping of type parameters to type arguments.private ClassFilegetClassFileFor(CompilationUnit cu, java.lang.String className)Gets theClassFilefor a class.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)java.util.List<LibraryInfo>getJars()Returns the jars on the "build path".SourceLocationgetSourceLocForClass(java.lang.String className)private booleanisAccessible(MemberInfo info, java.lang.String pkg)Returns whether a method defined by a super class is accessible to this class.protected booleanisValidChar(char ch)private voidloadCompletionsForCaretPosition(CompilationUnit cu, javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal)Loads completions based on the current caret location in the source.private voidloadCompletionsForCaretPosition(CompilationUnit cu, javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, java.lang.String prefix, int caret)Loads completions based on the current caret location in the source.private voidloadCompletionsForCaretPositionQualified(CompilationUnit cu, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, Method currentMethod, java.lang.String prefix, int offs)Loads completions for the text at the current caret position, if there is a "prefix" of chars and at least one '.' character in the text up to the caret.private voidloadCompletionsForCaretPositionQualifiedCodeBlock(CompilationUnit cu, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, CodeBlock block, java.lang.String prefix, int offs)private voidloadCompletionsForImport(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String importStr, java.lang.String pkgName)Loads completions for a single import statement.private voidloadImportCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text, CompilationUnit cu)Loads completions for all import statements.booleanremoveJar(java.io.File jar)Removes a jar from the "build path".(package private) voidsetJavaProvider(JavaCompletionProvider javaProvider)Sets the parent Java provider.voidsetShorthandCache(ShorthandCompletionCache shorthandCache)Set template completion cache for source completion provider.-
Methods inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider
getAlreadyEnteredText, 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
-
javaProvider
private JavaCompletionProvider javaProvider
The parent completion provider.
-
jarManager
private JarManager jarManager
Used to get information about what classes match imports.
-
JAVA_LANG_PACKAGE
private static final java.lang.String JAVA_LANG_PACKAGE
- See Also:
- Constant Field Values
-
THIS
private static final java.lang.String THIS
- See Also:
- Constant Field Values
-
shorthandCache
private ShorthandCompletionCache shorthandCache
-
-
Constructor Detail
-
SourceCompletionProvider
SourceCompletionProvider()
Constructor.
-
SourceCompletionProvider
SourceCompletionProvider(JarManager jarManager)
Constructor.- Parameters:
jarManager- The jar manager for this provider.
-
-
Method Detail
-
addCompletionsForStaticMembers
private void addCompletionsForStaticMembers(java.util.Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, java.lang.String pkg)
-
addCompletionsForExtendedClass
private void addCompletionsForExtendedClass(java.util.Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, java.lang.String pkg, java.util.Map<java.lang.String,java.lang.String> typeParamMap)Adds completions for accessible methods and fields of super classes. This is only called when the caret is inside of a class. TODO: Handle accessibility correctly!- Parameters:
set- The set of completions to add to.cu- The compilation unit.cf- A class in the chain of classes that a type being parsed inherits from.pkg- The package of the source being parsed.typeParamMap- A mapping of type parameters to type arguments for the object whose fields/methods/etc. are currently being code-completed.
-
addCompletionsForLocalVarsMethods
private void addCompletionsForLocalVarsMethods(CompilationUnit cu, LocalVariable var, java.util.Set<org.fife.ui.autocomplete.Completion> retVal)
Adds completions for all methods and public fields of a local variable. This will add nothing if the local variable is a primitive type.- Parameters:
cu- The compilation unit being parsed.var- The local variable.retVal- The set to add completions to.
-
addShorthandCompletions
private void addShorthandCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set)
Adds simple shorthand completions relevant to Java.- Parameters:
set- The set to add to.
-
setShorthandCache
public void setShorthandCache(ShorthandCompletionCache shorthandCache)
Set template completion cache for source completion provider.- Parameters:
shorthandCache- The new cache.
-
getClassFileFor
private ClassFile getClassFileFor(CompilationUnit cu, java.lang.String className)
Gets theClassFilefor a class.- Parameters:
cu- The compilation unit being parsed.className- The name of the class (fully qualified or not).- Returns:
- The
ClassFilefor the class, ornullifcfrepresentsjava.lang.Object(or if the super class could not be determined).
-
addLocalVarCompletions
private void addLocalVarCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, Method method, int offs)Adds completions for local variables in a method.- Parameters:
set- The set of completions to add to.method- The method being examined.offs- The caret's offset into the source. This should be inside ofmethod.
-
addLocalVarCompletions
private void addLocalVarCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, CodeBlock block, int offs)Adds completions for local variables in a code block inside a method.- Parameters:
set- The set of completions to add to.block- The code block.offs- The caret's offset into the source. This should be inside ofblock.
-
addJar
public void addJar(LibraryInfo info) throws java.io.IOException
Adds a jar to read from.- Parameters:
info- The jar to add. If this isnull, then the current JVM's main JRE jar (rt.jar, or classes.jar on OS X) will be added. If this jar has already been added, adding it again will do nothing (except possibly update its attached source location).- Throws:
java.io.IOException- If an IO error occurs.- See Also:
getJars(),removeJar(File)
-
checkStringLiteralMember
private boolean checkStringLiteralMember(javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, CompilationUnit cu, java.util.Set<org.fife.ui.autocomplete.Completion> set)Checks whether the user is typing a completion for a String member after a String literal.- Parameters:
comp- The text component.alreadyEntered- The text already entered.cu- The compilation unit being parsed.set- The set to add possible completions to.- Returns:
- Whether the user is indeed typing a completion for a String literal member.
-
clearJars
public void clearJars()
Removes all jars from the "build path".- See Also:
removeJar(File),addJar(LibraryInfo),getJars()
-
createTypeParamMap
private java.util.Map<java.lang.String,java.lang.String> createTypeParamMap(Type type, ClassFile cf)
Creates and returns a mapping of type parameters to type arguments.- Parameters:
type- The type of a variable/field/etc. whose fields/methods/etc. are being code completed, as declared in the source. This includes type arguments.cf- TheClassFilerepresenting the actual type of the variable/field/etc. being code completed- Returns:
- A mapping of type parameter names to type arguments (both Strings).
-
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
-
getJars
public java.util.List<LibraryInfo> getJars()
Returns the jars on the "build path".- Returns:
- A list of
LibraryInfos. Modifying aLibraryInfoin this list will have no effect on this completion provider; in order to do that, you must re-add the jar viaaddJar(LibraryInfo). If there are no jars on the "build path," this will be an empty list. - See Also:
addJar(LibraryInfo)
-
getSourceLocForClass
public SourceLocation getSourceLocForClass(java.lang.String className)
-
isAccessible
private boolean isAccessible(MemberInfo info, java.lang.String pkg)
Returns whether a method defined by a super class is accessible to this class.- Parameters:
info- Information about the member.pkg- The package of the source currently being parsed.- Returns:
- Whether the method is accessible.
-
isValidChar
protected boolean isValidChar(char ch)
- Overrides:
isValidCharin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
loadCompletionsForCaretPosition
private void loadCompletionsForCaretPosition(CompilationUnit cu, javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal)
Loads completions based on the current caret location in the source. In other words:- If the caret is anywhere in a class, the names of all methods and fields in the class are loaded. Methods and fields in super classes are also loaded. TODO: Get super methods/fields added correctly by access!
- If the caret is in a field, local variables currently accessible are loaded.
- Parameters:
cu- The compilation unit being parsed.comp- The text component.alreadyEntered- The already-entered text.retVal- The set of values to add to.
-
loadCompletionsForCaretPosition
private void loadCompletionsForCaretPosition(CompilationUnit cu, javax.swing.text.JTextComponent comp, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, java.lang.String prefix, int caret)
Loads completions based on the current caret location in the source. This method is called when the caret is found to be in a specific type declaration. This method checks if the caret is in a child type declaration first, then adds completions for itself next.- If the caret is anywhere in a class, the names of all methods and fields in the class are loaded. Methods and fields in super classes are also loaded. TODO: Get super methods/fields added correctly by access!
- If the caret is in a field, local variables currently accessible are loaded.
- Parameters:
cu- The compilation unit.comp- The text component being analyzed.alreadyEntered- The already-entered text.retVal- The set of returned completions.td- The type declaration.prefix- The prefix.caret- The caret position.
-
loadCompletionsForCaretPositionQualified
private void loadCompletionsForCaretPositionQualified(CompilationUnit cu, java.lang.String alreadyEntered, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, Method currentMethod, java.lang.String prefix, int offs)
Loads completions for the text at the current caret position, if there is a "prefix" of chars and at least one '.' character in the text up to the caret. This is currently very limited and needs to be improved.- Parameters:
cu- The compilation unit being examined.alreadyEntered- The already-entered text.retVal- The return value.td- The type declaration the caret is in.currentMethod- The method the caret is in, ornullif none.prefix- The text up to the current caret position. This is guaranteed to be non-nullnot equal to "this".offs- The offset of the caret in the document.
-
loadCompletionsForCaretPositionQualifiedCodeBlock
private void loadCompletionsForCaretPositionQualifiedCodeBlock(CompilationUnit cu, java.util.Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, CodeBlock block, java.lang.String prefix, int offs)
-
loadCompletionsForImport
private void loadCompletionsForImport(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String importStr, java.lang.String pkgName)Loads completions for a single import statement.- Parameters:
importStr- The import statement.pkgName- The package of the source currently being parsed.
-
loadImportCompletions
private void loadImportCompletions(java.util.Set<org.fife.ui.autocomplete.Completion> set, java.lang.String text, CompilationUnit cu)Loads completions for all import statements.- Parameters:
cu- The compilation unit being parsed.
-
removeJar
public boolean removeJar(java.io.File jar)
Removes a jar from the "build path".- Parameters:
jar- The jar to remove.- Returns:
- Whether the jar was removed. This will be
falseif the jar was not on the build path. - See Also:
addJar(LibraryInfo),getJars(),clearJars()
-
setJavaProvider
void setJavaProvider(JavaCompletionProvider javaProvider)
Sets the parent Java provider.- Parameters:
javaProvider- The parent completion provider.
-
-