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.DefaultCompletionProvider
Parses a Java AST for code completions. It currently scans the following:
- Import statements
- Method names
- Field names
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
org.fife.ui.autocomplete.AbstractCompletionProvider.CaseInsensitiveComparator -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate JarManagerUsed to get information about what classes match imports.private static final Stringprivate JavaCompletionProviderThe parent completion provider.private ShorthandCompletionCacheprivate static final StringFields inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider
segFields inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
comparator, completionsFields inherited from class org.fife.ui.autocomplete.CompletionProviderBase
EMPTY_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddCompletionsForExtendedClass(Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, String pkg, Map<String, String> typeParamMap) Adds completions for accessible methods and fields of super classes.private voidaddCompletionsForLocalVarsMethods(CompilationUnit cu, LocalVariable var, Set<org.fife.ui.autocomplete.Completion> retVal) Adds completions for all methods and public fields of a local variable.private voidaddCompletionsForStaticMembers(Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, String pkg) voidaddJar(LibraryInfo info) Adds a jar to read from.private voidaddLocalVarCompletions(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(Set<org.fife.ui.autocomplete.Completion> set, Method method, int offs) Adds completions for local variables in a method.private voidaddShorthandCompletions(Set<org.fife.ui.autocomplete.Completion> set) Adds simple shorthand completions relevant to Java.private booleancheckStringLiteralMember(JTextComponent comp, String alreadyEntered, CompilationUnit cu, Set<org.fife.ui.autocomplete.Completion> set) Checks whether the user is typing a completion for a String member after a String literal.voidRemoves all jars from the "build path".createTypeParamMap(Type type, ClassFile cf) Creates and returns a mapping of type parameters to type arguments.private ClassFilegetClassFileFor(CompilationUnit cu, String className) Gets theClassFilefor a class.List<org.fife.ui.autocomplete.Completion> getCompletionsAt(JTextComponent tc, Point p) protected List<org.fife.ui.autocomplete.Completion> getJars()Returns the jars on the "build path".getSourceLocForClass(String className) private booleanisAccessible(MemberInfo info, String pkg) Returns whether a method defined by a super class is accessible to this class.protected booleanisValidChar(char ch) private voidloadCompletionsForCaretPosition(CompilationUnit cu, JTextComponent comp, String alreadyEntered, Set<org.fife.ui.autocomplete.Completion> retVal) Loads completions based on the current caret location in the source.private voidloadCompletionsForCaretPosition(CompilationUnit cu, JTextComponent comp, String alreadyEntered, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, String prefix, int caret) Loads completions based on the current caret location in the source.private voidloadCompletionsForCaretPositionQualified(CompilationUnit cu, String alreadyEntered, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, Method currentMethod, 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, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, CodeBlock block, String prefix, int offs) private voidloadCompletionsForImport(Set<org.fife.ui.autocomplete.Completion> set, String importStr, String pkgName) Loads completions for a single import statement.private voidloadImportCompletions(Set<org.fife.ui.autocomplete.Completion> set, String text, CompilationUnit cu) Loads completions for all import statements.booleanRemoves 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, loadFromXMLMethods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, removeCompletionMethods inherited from class org.fife.ui.autocomplete.CompletionProviderBase
clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, isAutoActivateOkay, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent
-
Field Details
-
javaProvider
The parent completion provider. -
jarManager
Used to get information about what classes match imports. -
JAVA_LANG_PACKAGE
- See Also:
-
THIS
- See Also:
-
shorthandCache
-
-
Constructor Details
-
SourceCompletionProvider
SourceCompletionProvider()Constructor. -
SourceCompletionProvider
SourceCompletionProvider(JarManager jarManager) Constructor.- Parameters:
jarManager- The jar manager for this provider.
-
-
Method Details
-
addCompletionsForStaticMembers
private void addCompletionsForStaticMembers(Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, String pkg) -
addCompletionsForExtendedClass
private void addCompletionsForExtendedClass(Set<org.fife.ui.autocomplete.Completion> set, CompilationUnit cu, ClassFile cf, String pkg, Map<String, 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, 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
Adds simple shorthand completions relevant to Java.- Parameters:
set- The set to add to.
-
setShorthandCache
Set template completion cache for source completion provider.- Parameters:
shorthandCache- The new cache.
-
getClassFileFor
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(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(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
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:
IOException- If an IO error occurs.- See Also:
-
checkStringLiteralMember
private boolean checkStringLiteralMember(JTextComponent comp, String alreadyEntered, CompilationUnit cu, 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:
-
createTypeParamMap
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
- Specified by:
getCompletionsAtin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
getCompletionsAtin classorg.fife.ui.autocomplete.DefaultCompletionProvider
-
getCompletionsImpl
- Overrides:
getCompletionsImplin classorg.fife.ui.autocomplete.AbstractCompletionProvider
-
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:
-
getSourceLocForClass
-
isAccessible
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, JTextComponent comp, String alreadyEntered, 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, JTextComponent comp, String alreadyEntered, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, 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, String alreadyEntered, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, Method currentMethod, 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, Set<org.fife.ui.autocomplete.Completion> retVal, TypeDeclaration td, CodeBlock block, String prefix, int offs) -
loadCompletionsForImport
private void loadCompletionsForImport(Set<org.fife.ui.autocomplete.Completion> set, String importStr, 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(Set<org.fife.ui.autocomplete.Completion> set, String text, CompilationUnit cu) Loads completions for all import statements.- Parameters:
cu- The compilation unit being parsed.
-
removeJar
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:
-
setJavaProvider
Sets the parent Java provider.- Parameters:
javaProvider- The parent completion provider.
-