Class CompletionMatcherImpl

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.function.Predicate<java.lang.String> exact  
      protected java.util.List<java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>>> matchers  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean camelMatch​(java.lang.String word, int i, java.lang.String candidate, int j)  
      void compile​(java.util.Map<LineReader.Option,​java.lang.Boolean> options, boolean prefix, CompletingParsedLine line, boolean caseInsensitive, int errors, java.lang.String originalGroupName)
      Initializes the matcher with the current completion context.
      protected void defaultMatchers​(java.util.Map<LineReader.Option,​java.lang.Boolean> options, boolean prefix, CompletingParsedLine line, boolean caseInsensitive, int errors, java.lang.String originalGroupName)
      Default JLine matchers
      Candidate exactMatch()
      Returns a candidate that exactly matches the current input, if any.
      java.lang.String getCommonPrefix()
      Returns the longest common prefix shared by all matched candidates.
      java.util.List<Candidate> matches​(java.util.List<Candidate> candidates)
      Filters the provided candidates based on the current matching criteria.
      protected void reset​(boolean caseInsensitive)  
      protected java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>> simpleMatcher​(java.util.function.Predicate<java.lang.String> predicate)  
      protected java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>> typoMatcher​(java.lang.String word, int errors, boolean caseInsensitive, java.lang.String originalGroupName)  
      • Methods inherited from class java.lang.Object

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

      • exact

        protected java.util.function.Predicate<java.lang.String> exact
      • matchers

        protected java.util.List<java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>>> matchers
    • Constructor Detail

      • CompletionMatcherImpl

        public CompletionMatcherImpl()
    • Method Detail

      • reset

        protected void reset​(boolean caseInsensitive)
      • compile

        public void compile​(java.util.Map<LineReader.Option,​java.lang.Boolean> options,
                            boolean prefix,
                            CompletingParsedLine line,
                            boolean caseInsensitive,
                            int errors,
                            java.lang.String originalGroupName)
        Description copied from interface: CompletionMatcher
        Initializes the matcher with the current completion context.

        This method is called before any matching operations to set up the matcher with the current completion context, including the line being completed, reader options, and other parameters that affect how matching should be performed.

        The matcher uses this information to compile its internal matching functions that will be used to filter candidates.

        Specified by:
        compile in interface CompletionMatcher
        Parameters:
        options - LineReader options that may affect matching behavior
        prefix - true if invoked by complete-prefix or expand-or-complete-prefix widget
        line - the parsed line within which completion has been requested
        caseInsensitive - true if completion should be case insensitive
        errors - number of typo errors accepted in matching (for fuzzy matching)
        originalGroupName - value of the LineReader variable original-group-name
      • matches

        public java.util.List<Candidate> matches​(java.util.List<Candidate> candidates)
        Description copied from interface: CompletionMatcher
        Filters the provided candidates based on the current matching criteria.

        This method applies the matching algorithm to the list of candidates and returns only those that match the current input according to the configured matching rules. The returned list may be sorted based on match quality.

        Specified by:
        matches in interface CompletionMatcher
        Parameters:
        candidates - the list of candidates to filter
        Returns:
        a list of candidates that match the current input
      • exactMatch

        public Candidate exactMatch()
        Description copied from interface: CompletionMatcher
        Returns a candidate that exactly matches the current input, if any.

        An exact match typically means the candidate's value is identical to what the user has typed, possibly ignoring case depending on the matcher configuration. This is used to determine if the completion should be accepted immediately without showing a list of options.

        Specified by:
        exactMatch in interface CompletionMatcher
        Returns:
        a candidate that exactly matches the current input, or null if no exact match is found
      • getCommonPrefix

        public java.lang.String getCommonPrefix()
        Description copied from interface: CompletionMatcher
        Returns the longest common prefix shared by all matched candidates.

        This is used to implement tab completion behavior where pressing tab will automatically complete as much of the input as can be unambiguously determined from the available candidates.

        Specified by:
        getCommonPrefix in interface CompletionMatcher
        Returns:
        the longest common prefix of all matched candidates, or an empty string if none
      • defaultMatchers

        protected void defaultMatchers​(java.util.Map<LineReader.Option,​java.lang.Boolean> options,
                                       boolean prefix,
                                       CompletingParsedLine line,
                                       boolean caseInsensitive,
                                       int errors,
                                       java.lang.String originalGroupName)
        Default JLine matchers
      • simpleMatcher

        protected java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>> simpleMatcher​(java.util.function.Predicate<java.lang.String> predicate)
      • typoMatcher

        protected java.util.function.Function<java.util.Map<java.lang.String,​java.util.List<Candidate>>,​java.util.Map<java.lang.String,​java.util.List<Candidate>>> typoMatcher​(java.lang.String word,
                                                                                                                                                                                                 int errors,
                                                                                                                                                                                                 boolean caseInsensitive,
                                                                                                                                                                                                 java.lang.String originalGroupName)
      • camelMatch

        protected boolean camelMatch​(java.lang.String word,
                                     int i,
                                     java.lang.String candidate,
                                     int j)