Package org.eclipse.ui.dialogs
Class SearchPattern
java.lang.Object
org.eclipse.ui.dialogs.SearchPattern
A search pattern defines how search results are found.
This class is intended to be subclassed by clients. A default behavior is provided for each of the methods above, that clients can override if they wish.
- Since:
- 3.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Match rule: The search pattern is blank.static final int
Match rule: The search pattern contains a Camel Case expression.static final int
Match rule: The search pattern matches the search result only if cases are the same.static final int
Match rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern.static final int
Match rule: The search pattern contains one or more wild cards ('*' or '?').static final int
Match rule: The search pattern is a prefix of the search result. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of SearchPattern with the following match rules configured:RULE_EXACT_MATCH
|RULE_PREFIX_MATCH
|RULE_PATTERN_MATCH
|RULE_CAMELCASE_MATCH
|RULE_BLANK_MATCH
)SearchPattern
(int allowedRules) Creates a search pattern with the rule to apply for matching index keys. -
Method Summary
Modifier and TypeMethodDescriptionboolean
equalsPattern
(SearchPattern pattern) Tells whether the givenSearchPattern
equals this pattern.final int
Returns the rule to apply for matching keys.Gets string pattern used by matcherprotected boolean
isNameCharAllowed
(char nameChar) Checks character of element's name is allowed for specified set.protected boolean
isPatternCharAllowed
(char patternChar) Checks pattern's character is allowed for specified set.boolean
isSubPattern
(SearchPattern pattern) Tells whether the givenSearchPattern
is a sub-pattern of this pattern.protected boolean
isValidCamelCaseChar
(char ch) Check if character is valid camelCase characterboolean
Matches text with pattern. matching is determine by matchKind.void
setPattern
(String stringPattern)
-
Field Details
-
RULE_EXACT_MATCH
public static final int RULE_EXACT_MATCHMatch rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern. Search pattern should start from lowerCase char.- See Also:
-
RULE_PREFIX_MATCH
public static final int RULE_PREFIX_MATCHMatch rule: The search pattern is a prefix of the search result.- See Also:
-
RULE_PATTERN_MATCH
public static final int RULE_PATTERN_MATCHMatch rule: The search pattern contains one or more wild cards ('*' or '?'). A '*' wild-card can replace 0 or more characters in the search result. A '?' wild-card replaces exactly 1 character in the search result.- See Also:
-
RULE_CASE_SENSITIVE
public static final int RULE_CASE_SENSITIVEMatch rule: The search pattern matches the search result only if cases are the same. Can be combined with previous rules, e.g.RULE_EXACT_MATCH
|RULE_CASE_SENSITIVE
- See Also:
-
RULE_BLANK_MATCH
public static final int RULE_BLANK_MATCHMatch rule: The search pattern is blank.- See Also:
-
RULE_CAMELCASE_MATCH
public static final int RULE_CAMELCASE_MATCHMatch rule: The search pattern contains a Camel Case expression.
Examples:NPE
type string pattern will matchNullPointerException
andNpPermissionException
types,NuPoEx
type string pattern will only matchNullPointerException
type.
Can be combined withRULE_PREFIX_MATCH
match rule. For example, when prefix match rule is combined with Camel Case match rule,"nPE"
pattern will matchnPException
.
Match ruleRULE_PATTERN_MATCH
may also be combined but both rules will not be used simultaneously as they are mutually exclusive. Used match rule depends on whether string pattern contains specific pattern characters (e.g. '*' or '?') or not. If it does, then only Pattern match rule will be used, otherwise only Camel Case match will be used. For example, with"NPE"
string pattern, search will only use Camel Case match rule, but withN*P*E*
string pattern, it will use only Pattern match rule.- See Also:
-
-
Constructor Details
-
SearchPattern
public SearchPattern()Creates a new instance of SearchPattern with the following match rules configured:RULE_EXACT_MATCH
|RULE_PREFIX_MATCH
|RULE_PATTERN_MATCH
|RULE_CAMELCASE_MATCH
|RULE_BLANK_MATCH
) -
SearchPattern
public SearchPattern(int allowedRules) Creates a search pattern with the rule to apply for matching index keys. It can be exact match, prefix match, pattern match or camelCase match. Rule can also be combined with a case sensitivity flag.- Parameters:
allowedRules
- one ofRULE_EXACT_MATCH
,RULE_PREFIX_MATCH
,RULE_PATTERN_MATCH
,RULE_CASE_SENSITIVE
,RULE_CAMELCASE_MATCH
combined with one of following values:RULE_EXACT_MATCH
,RULE_PREFIX_MATCH
,RULE_PATTERN_MATCH
orRULE_CAMELCASE_MATCH
. e.g.RULE_EXACT_MATCH
|RULE_CASE_SENSITIVE
if an exact and case sensitive match is requested,RULE_PREFIX_MATCH
if a prefix non case sensitive match is requested orRULE_EXACT_MATCH
if a non case sensitive and erasure match is requested.
Note also that default behavior for generic types/methods search is to find exact matches.
-
-
Method Details
-
getPattern
Gets string pattern used by matcher- Returns:
- pattern
-
setPattern
- Parameters:
stringPattern
- The stringPattern to set.
-
matches
Matches text with pattern. matching is determine by matchKind.- Parameters:
text
- the text to match- Returns:
- true if search pattern was matched with text false in other way
-
isPatternCharAllowed
protected boolean isPatternCharAllowed(char patternChar) Checks pattern's character is allowed for specified set. It could be override if you want change logic of camelCaseMatch methods.- Parameters:
patternChar
- the char to check- Returns:
- true if patternChar is in set of allowed characters for pattern
-
isNameCharAllowed
protected boolean isNameCharAllowed(char nameChar) Checks character of element's name is allowed for specified set. It could be override if you want change logic of camelCaseMatch methods.- Parameters:
nameChar
- - name of searched element- Returns:
- if nameChar is in set of allowed characters for name of element
-
getMatchRule
public final int getMatchRule()Returns the rule to apply for matching keys. Can be exact match, prefix match, pattern match or camelcase match. Rule can also be combined with a case sensitivity flag.- Returns:
- one of RULE_EXACT_MATCH, RULE_PREFIX_MATCH, RULE_PATTERN_MATCH, RULE_CAMELCASE_MATCH, combined with RULE_CASE_SENSITIVE, e.g. RULE_EXACT_MATCH | RULE_CASE_SENSITIVE if an exact and case sensitive match is requested, or RULE_PREFIX_MATCH if a prefix non case sensitive match is requested.
-
isValidCamelCaseChar
protected boolean isValidCamelCaseChar(char ch) Check if character is valid camelCase character- Parameters:
ch
- character to be validated- Returns:
- true if character is valid
-
equalsPattern
Tells whether the givenSearchPattern
equals this pattern.- Parameters:
pattern
- pattern to be checked- Returns:
- true if the given pattern equals this search pattern
-
isSubPattern
Tells whether the givenSearchPattern
is a sub-pattern of this pattern.WARNING: This method is not defined in reading order, i.e.
a.isSubPattern(b)
istrue
iffb
is a sub-pattern ofa
, and not vice-versa.- Parameters:
pattern
- pattern to be checked- Returns:
- true if the given pattern is a sub pattern of this search pattern
-