Class ClassSearchAutoComplete
java.lang.Object
edu.umd.cs.findbugs.gui2.ClassSearchAutoComplete
Provides auto-completion functionality for the class name search filter in
the GUI.
Displays matching class names and simple names dynamically as the user types.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Supplier<Collection<String>> private booleanprivate final DefaultListModel<String> private static final intprivate static final intprivate static final intprivate static final intprivate final JPopupMenuprivate final JTextField -
Constructor Summary
ConstructorsConstructorDescriptionClassSearchAutoComplete(JTextField textField, Supplier<Collection<String>> candidateSupplier) Creates and attaches auto-completion support to the given text field. -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidaddClassNameVariants(Set<String> classNames, String rawClassName) private voidstatic ClassSearchAutoCompleteattach(JTextField textField, MainFrame mainFrame) Attaches auto-completion support configured with the MainFrame's bug collection.computeSuggestions(String token, Collection<String> candidates, int maxResults) Computes suggestions for the given token from the candidate collection.static int[]findCurrentTokenRange(String text, int caretPos) Finds the start and end indices of the token surrounding the given caret position.getAvailableClassNames(MainFrame mainFrame) Extracts all unique class names (full qualified and simple names) from the bug collection.private voidprivate voidprivate voidprivate static booleanisDelimiter(char c) private voidstatic StringreplaceTokenAtRange(String text, int start, int end, String replacement) Replaces the substring from start to end with the given replacement string.private voidprivate void
-
Field Details
-
MAX_SUGGESTIONS
private static final int MAX_SUGGESTIONS- See Also:
-
POPUP_PREFERRED_WIDTH
private static final int POPUP_PREFERRED_WIDTH- See Also:
-
POPUP_PREFERRED_HEIGHT
private static final int POPUP_PREFERRED_HEIGHT- See Also:
-
MAX_FUZZY_DISTANCE
private static final int MAX_FUZZY_DISTANCE- See Also:
-
textField
-
candidateSupplier
-
popupMenu
-
suggestionList
-
listModel
-
isUpdatingFromSuggestion
private boolean isUpdatingFromSuggestion
-
-
Constructor Details
-
ClassSearchAutoComplete
public ClassSearchAutoComplete(JTextField textField, Supplier<Collection<String>> candidateSupplier) Creates and attaches auto-completion support to the given text field.- Parameters:
textField- the search text fieldcandidateSupplier- supplier providing available candidate class names
-
-
Method Details
-
attach
Attaches auto-completion support configured with the MainFrame's bug collection.- Parameters:
textField- the search text fieldmainFrame- the main frame instance- Returns:
- the initialized ClassSearchAutoComplete instance
-
getAvailableClassNames
-
addClassNameVariants
-
initListeners
private void initListeners() -
onDocumentChanged
private void onDocumentChanged() -
handleKeyPressed
-
updateSuggestions
private void updateSuggestions() -
showPopup
private void showPopup() -
hidePopup
private void hidePopup() -
applySelectedSuggestion
private void applySelectedSuggestion() -
findCurrentTokenRange
Finds the start and end indices of the token surrounding the given caret position. Tokens are separated by whitespace, comma, or colon.- Parameters:
text- the entire input stringcaretPos- current caret position- Returns:
- an int array of size 2 containing [startIndex, endIndex]
-
isDelimiter
private static boolean isDelimiter(char c) -
replaceTokenAtRange
-
computeSuggestions
public static List<String> computeSuggestions(String token, Collection<String> candidates, int maxResults) Computes suggestions for the given token from the candidate collection. Suggestions are prioritized: prefix matches > substring matches > fuzzy matches.- Parameters:
token- current query tokencandidates- available class name candidatesmaxResults- maximum number of suggestions to return- Returns:
- ordered list of suggestions
-