Class CompletionVisitor
java.lang.Object
com.blamejared.searchables.api.autcomplete.CompletionVisitor
- All Implemented Interfaces:
Visitor<TokenRange>,Consumer<String>
Generates a list of TokenRanges that can be used to split a given string into parts.
Mainly used to split strings for completion purposes.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidResets this visitor and compiles a list ofTokenRangefrom the given StringpostVisit(TokenRange obj) rangeAt(int position) Gets theTokenRangeat the given position, orTokenRange.EMPTYif out of bounds.protected voidReduces the tokens into their outermost parts.voidreset()Resets this visitor to a state that allows it to run again.tokenAt(int position) Gets theOptional<TokenRange>at the given position.tokens()Gets the tokens in this visitor.visitPaired(PairedExpression expr)
-
Constructor Details
-
CompletionVisitor
public CompletionVisitor()
-
-
Method Details
-
reset
public void reset()Resets this visitor to a state that allows it to run again. -
reduceTokens
protected void reduceTokens()Reduces the tokens into their outermost parts. For example the string"shape:square color:red"will be split into:[ TokenRange(0, 12, [TokenRange(0, 5), TokenRange(5, 6), TokenRange(6, 12)]), TokenRange(13, 22, [TokenRange(13, 18), TokenRange(18, 19), TokenRange(19, 22)]) ] -
tokens
Gets the tokens in this visitor.- Returns:
- The tokens in this visitor.
-
tokenAt
Gets theOptional<TokenRange>at the given position.- Parameters:
position- The current cursor position.- Returns:
- An
Optional<TokenRange>at the given position, or an empty optional if out of bounds.
-
rangeAt
Gets theTokenRangeat the given position, orTokenRange.EMPTYif out of bounds.- Parameters:
position- The current cursor position.- Returns:
- An
TokenRangeat the given range, orTokenRange.EMPTYif out of bounds.
-
visitGrouping
- Specified by:
visitGroupingin interfaceVisitor<TokenRange>
-
visitComponent
- Specified by:
visitComponentin interfaceVisitor<TokenRange>
-
visitLiteral
- Specified by:
visitLiteralin interfaceVisitor<TokenRange>
-
visitPaired
- Specified by:
visitPairedin interfaceVisitor<TokenRange>
-
accept
Resets this visitor and compiles a list ofTokenRangefrom the given String -
postVisit
- Specified by:
postVisitin interfaceVisitor<TokenRange>
-