Package org.eclipse.jface.text.rules
Class WordRule
java.lang.Object
org.eclipse.jface.text.rules.WordRule
- All Implemented Interfaces:
IRule
An implementation of
IRule
capable of detecting words. A word rule also allows to
associate a token to a word. That is, not only can the rule be used to provide tokens for exact
matches, but also for the generalized notion of a word in the context in which it is used. A word
rule uses a word detector to determine what a word is.
Originally since unknown version, but moved to org.eclipse.text in 3.14- Since:
- 3.14
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
The column constraint.protected IToken
The default token to be returned on success and if nothing else has been specified.protected IWordDetector
The word detector used by this rule.The table of predefined words and token for this rule.protected static final int
Internal setting for the un-initialized column constraint. -
Constructor Summary
ConstructorDescriptionWordRule
(IWordDetector detector) Creates a rule which, with the help of an word detector, will return the token associated with the detected word.WordRule
(IWordDetector detector, IToken defaultToken) Creates a rule which, with the help of a word detector, will return the token associated with the detected word.WordRule
(IWordDetector detector, IToken defaultToken, boolean ignoreCase) Creates a rule which, with the help of a word detector, will return the token associated with the detected word. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a word and the token to be returned if it is detected.evaluate
(ICharacterScanner scanner) Evaluates the rule by examining the characters available from the provided character scanner.void
setColumnConstraint
(int column) Sets a column constraint for this rule.protected void
unreadBuffer
(ICharacterScanner scanner) Returns the characters in the buffer to the scanner.
-
Field Details
-
UNDEFINED
protected static final int UNDEFINEDInternal setting for the un-initialized column constraint.- See Also:
-
fDetector
The word detector used by this rule. -
fDefaultToken
The default token to be returned on success and if nothing else has been specified. -
fColumn
protected int fColumnThe column constraint. -
fWords
The table of predefined words and token for this rule.
-
-
Constructor Details
-
WordRule
Creates a rule which, with the help of an word detector, will return the token associated with the detected word. If no token has been associated, the scanner will be rolled back and an undefined token will be returned in order to allow any subsequent rules to analyze the characters.- Parameters:
detector
- the word detector to be used by this rule, may not benull
- See Also:
-
WordRule
Creates a rule which, with the help of a word detector, will return the token associated with the detected word. If no token has been associated, the specified default token will be returned.- Parameters:
detector
- the word detector to be used by this rule, may not benull
defaultToken
- the default token to be returned on success if nothing else is specified, may not benull
- See Also:
-
WordRule
Creates a rule which, with the help of a word detector, will return the token associated with the detected word. If no token has been associated, the specified default token will be returned.- Parameters:
detector
- the word detector to be used by this rule, may not benull
defaultToken
- the default token to be returned on success if nothing else is specified, may not benull
ignoreCase
- the case sensitivity associated with this rule- Since:
- 3.3
- See Also:
-
-
Method Details
-
addWord
Adds a word and the token to be returned if it is detected.- Parameters:
word
- the word this rule will search for, may not benull
token
- the token to be returned if the word has been found, may not benull
-
setColumnConstraint
public void setColumnConstraint(int column) Sets a column constraint for this rule. If set, the rule's token will only be returned if the pattern is detected starting at the specified column. If the column is smaller then 0, the column constraint is considered removed.- Parameters:
column
- the column in which the pattern starts
-
evaluate
Description copied from interface:IRule
Evaluates the rule by examining the characters available from the provided character scanner. The token returned by this rule returnstrue
when callingisUndefined
, if the text that the rule investigated does not match the rule's requirements -
unreadBuffer
Returns the characters in the buffer to the scanner.- Parameters:
scanner
- the scanner to be used
-