Package edu.umd.cs.findbugs.gui2
Class ClassSearchAutoComplete
- java.lang.Object
-
- edu.umd.cs.findbugs.gui2.ClassSearchAutoComplete
-
public class ClassSearchAutoComplete extends java.lang.ObjectProvides 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
Fields Modifier and Type Field Description private java.util.function.Supplier<java.util.Collection<java.lang.String>>candidateSupplierprivate booleanisUpdatingFromSuggestionprivate javax.swing.DefaultListModel<java.lang.String>listModelprivate static intMAX_FUZZY_DISTANCEprivate static intMAX_SUGGESTIONSprivate static intPOPUP_PREFERRED_HEIGHTprivate static intPOPUP_PREFERRED_WIDTHprivate javax.swing.JPopupMenupopupMenuprivate javax.swing.JList<java.lang.String>suggestionListprivate javax.swing.JTextFieldtextField
-
Constructor Summary
Constructors Constructor Description ClassSearchAutoComplete(javax.swing.JTextField textField, java.util.function.Supplier<java.util.Collection<java.lang.String>> candidateSupplier)Creates and attaches auto-completion support to the given text field.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static voidaddClassNameVariants(java.util.Set<java.lang.String> classNames, java.lang.String rawClassName)private voidapplySelectedSuggestion()static ClassSearchAutoCompleteattach(javax.swing.JTextField textField, MainFrame mainFrame)Attaches auto-completion support configured with the MainFrame's bug collection.static java.util.List<java.lang.String>computeSuggestions(java.lang.String token, java.util.Collection<java.lang.String> candidates, int maxResults)Computes suggestions for the given token from the candidate collection.static int[]findCurrentTokenRange(java.lang.String text, int caretPos)Finds the start and end indices of the token surrounding the given caret position.static java.util.Set<java.lang.String>getAvailableClassNames(MainFrame mainFrame)Extracts all unique class names (full qualified and simple names) from the bug collection.private voidhandleKeyPressed(java.awt.event.KeyEvent e)private voidhidePopup()private voidinitListeners()private static booleanisDelimiter(char c)private voidonDocumentChanged()static java.lang.StringreplaceTokenAtRange(java.lang.String text, int start, int end, java.lang.String replacement)Replaces the substring from start to end with the given replacement string.private voidshowPopup()private voidupdateSuggestions()
-
-
-
Field Detail
-
MAX_SUGGESTIONS
private static final int MAX_SUGGESTIONS
- See Also:
- Constant Field Values
-
POPUP_PREFERRED_WIDTH
private static final int POPUP_PREFERRED_WIDTH
- See Also:
- Constant Field Values
-
POPUP_PREFERRED_HEIGHT
private static final int POPUP_PREFERRED_HEIGHT
- See Also:
- Constant Field Values
-
MAX_FUZZY_DISTANCE
private static final int MAX_FUZZY_DISTANCE
- See Also:
- Constant Field Values
-
textField
private final javax.swing.JTextField textField
-
candidateSupplier
private final java.util.function.Supplier<java.util.Collection<java.lang.String>> candidateSupplier
-
popupMenu
private final javax.swing.JPopupMenu popupMenu
-
suggestionList
private final javax.swing.JList<java.lang.String> suggestionList
-
listModel
private final javax.swing.DefaultListModel<java.lang.String> listModel
-
isUpdatingFromSuggestion
private boolean isUpdatingFromSuggestion
-
-
Constructor Detail
-
ClassSearchAutoComplete
public ClassSearchAutoComplete(javax.swing.JTextField textField, java.util.function.Supplier<java.util.Collection<java.lang.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 Detail
-
attach
public static ClassSearchAutoComplete attach(javax.swing.JTextField textField, MainFrame mainFrame)
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
public static java.util.Set<java.lang.String> getAvailableClassNames(MainFrame mainFrame)
Extracts all unique class names (full qualified and simple names) from the bug collection.- Parameters:
mainFrame- the main frame instance- Returns:
- set of available class names
-
addClassNameVariants
private static void addClassNameVariants(java.util.Set<java.lang.String> classNames, java.lang.String rawClassName)
-
initListeners
private void initListeners()
-
onDocumentChanged
private void onDocumentChanged()
-
handleKeyPressed
private void handleKeyPressed(java.awt.event.KeyEvent e)
-
updateSuggestions
private void updateSuggestions()
-
showPopup
private void showPopup()
-
hidePopup
private void hidePopup()
-
applySelectedSuggestion
private void applySelectedSuggestion()
-
findCurrentTokenRange
public static int[] findCurrentTokenRange(java.lang.String text, int caretPos)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
public static java.lang.String replaceTokenAtRange(java.lang.String text, int start, int end, java.lang.String replacement)Replaces the substring from start to end with the given replacement string.- Parameters:
text- original textstart- start indexend- end indexreplacement- replacement string- Returns:
- updated string
-
computeSuggestions
public static java.util.List<java.lang.String> computeSuggestions(java.lang.String token, java.util.Collection<java.lang.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
-
-