Class ClassSearchAutoComplete

java.lang.Object
edu.umd.cs.findbugs.gui2.ClassSearchAutoComplete

public class ClassSearchAutoComplete extends 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.
  • Field Details

  • 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 field
      candidateSupplier - supplier providing available candidate class names
  • Method Details

    • attach

      public static ClassSearchAutoComplete attach(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 Set<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(Set<String> classNames, String rawClassName)
    • initListeners

      private void initListeners()
    • onDocumentChanged

      private void onDocumentChanged()
    • handleKeyPressed

      private void handleKeyPressed(KeyEvent e)
    • updateSuggestions

      private void updateSuggestions()
    • showPopup

      private void showPopup()
    • hidePopup

      private void hidePopup()
    • applySelectedSuggestion

      private void applySelectedSuggestion()
    • findCurrentTokenRange

      public static int[] findCurrentTokenRange(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 String replaceTokenAtRange(String text, int start, int end, 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 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 token
      candidates - available class name candidates
      maxResults - maximum number of suggestions to return
      Returns:
      ordered list of suggestions