Class CompletionMatcherImpl
- java.lang.Object
-
- org.jline.reader.impl.CompletionMatcherImpl
-
- All Implemented Interfaces:
CompletionMatcher
public class CompletionMatcherImpl extends java.lang.Object implements CompletionMatcher
Default implementation of theCompletionMatcher
interface.This matcher provides sophisticated algorithms for matching completion candidates against user input, with support for:
- Prefix matching - candidates that start with the input text
- Substring matching - candidates that contain the input text
- Camel case matching - matching based on camel case patterns
- Fuzzy matching - candidates that approximately match with allowed typos
The matcher uses a chain of matching strategies, trying each one in sequence until matches are found. This allows for a graceful fallback from exact matches to more approximate matches.
The behavior of the matcher can be controlled through LineReader options such as
LineReader.Option.COMPLETE_MATCHER_TYPO
andLineReader.Option.COMPLETE_MATCHER_CAMELCASE
.
-
-
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
-
Constructor Summary
Constructors Constructor Description CompletionMatcherImpl()
-
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 matchersCandidate
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)
-
-
-
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 interfaceCompletionMatcher
- Parameters:
options
- LineReader options that may affect matching behaviorprefix
- true if invoked by complete-prefix or expand-or-complete-prefix widgetline
- the parsed line within which completion has been requestedcaseInsensitive
- true if completion should be case insensitiveerrors
- 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 interfaceCompletionMatcher
- 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 interfaceCompletionMatcher
- 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 interfaceCompletionMatcher
- 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)
-
-