Class ClassSearchAutoComplete


  • public class ClassSearchAutoComplete
    extends java.lang.Object
    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.
    • 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 void addClassNameVariants​(java.util.Set<java.lang.String> classNames, java.lang.String rawClassName)  
      private void applySelectedSuggestion()  
      static ClassSearchAutoComplete attach​(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 void handleKeyPressed​(java.awt.event.KeyEvent e)  
      private void hidePopup()  
      private void initListeners()  
      private static boolean isDelimiter​(char c)  
      private void onDocumentChanged()  
      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.
      private void showPopup()  
      private void updateSuggestions()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • POPUP_PREFERRED_HEIGHT

        private static final int POPUP_PREFERRED_HEIGHT
        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 field
        candidateSupplier - 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 field
        mainFrame - 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 string
        caretPos - 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 text
        start - start index
        end - end index
        replacement - 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 token
        candidates - available class name candidates
        maxResults - maximum number of suggestions to return
        Returns:
        ordered list of suggestions