Package org.eclipse.jface.text.source
Class DefaultCharacterPairMatcher
java.lang.Object
org.eclipse.jface.text.source.DefaultCharacterPairMatcher
- All Implemented Interfaces:
ICharacterPairMatcher,ICharacterPairMatcherExtension
public class DefaultCharacterPairMatcher
extends Object
implements ICharacterPairMatcher, ICharacterPairMatcherExtension
A character pair matcher that matches a specified set of character
pairs against each other. Only characters that occur in the same
partitioning are matched.
- Since:
- 3.3
-
Field Summary
Fields inherited from interface org.eclipse.jface.text.source.ICharacterPairMatcher
LEFT, RIGHT -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCharacterPairMatcher(char[] chars) Creates a new character pair matcher that matches characters within the default partitioning.DefaultCharacterPairMatcher(char[] chars, String partitioning) Creates a new character pair matcher that matches the specified characters within the specified partitioning.DefaultCharacterPairMatcher(char[] chars, String partitioning, boolean caretEitherSideOfBracket) Creates a new character pair matcher that matches the specified characters within the specified partitioning. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears this pair matcher.voiddispose()Disposes this pair matcher.findEnclosingPeerCharacters(IDocument document, int offset, int length) Starting at the given selection, the matcher searches for a pair of enclosing peer characters and if it finds one, returns the minimal region of the document that contains the pair.intReturns the anchor for the region of the matching peer characters.booleanisMatchedChar(char ch) Checks whether the character is one of the characters matched by the pair matcher.booleanisMatchedChar(char ch, IDocument document, int offset) Checks whether the character is one of the characters matched by the pair matcher.booleanisRecomputationOfEnclosingPairRequired(IDocument document, IRegion currentSelection, IRegion previousSelection) Computes whether a client needs to recompute the enclosing pair after a selection change in the document.Starting at the given offset, the matcher chooses a character close to this offset.Starting at the given offset (i.e. length 0) or the selected character, the matcher searches for the matching peer character and if it finds one, returns the minimal region of the document that contains both characters.
-
Constructor Details
-
DefaultCharacterPairMatcher
Creates a new character pair matcher that matches the specified characters within the specified partitioning. The specified list of characters must have the form{ start, end, start, end, ..., start, end }
For instance:char[] chars = new char[] {'(', ')', '{', '}', '[', ']'}; new DefaultCharacterPairMatcher(chars, ...);- Parameters:
chars- a list of characterspartitioning- the partitioning to match within
-
DefaultCharacterPairMatcher
public DefaultCharacterPairMatcher(char[] chars, String partitioning, boolean caretEitherSideOfBracket) Creates a new character pair matcher that matches the specified characters within the specified partitioning. The specified list of characters must have the form{ start, end, start, end, ..., start, end }
For instance:char[] chars = new char[] {'(', ')', '{', '}', '[', ']'}; new DefaultCharacterPairMatcher(chars, ...);- Parameters:
chars- a list of characterspartitioning- the partitioning to match withincaretEitherSideOfBracket- controls the matching behavior. Whentrue, the matching peer will be found when the caret is placed either before or after a character. Whenfalse, the matching peer will be found only when the caret is placed after a character.- Since:
- 3.8
-
DefaultCharacterPairMatcher
public DefaultCharacterPairMatcher(char[] chars) Creates a new character pair matcher that matches characters within the default partitioning. The specified list of characters must have the form{ start, end, start, end, ..., start, end }
For instance:char[] chars= new char[] { '(', ')', '{', '}', '[', ']' }; new DefaultCharacterPairMatcher(chars);- Parameters:
chars- a list of characters
-
-
Method Details
-
match
Description copied from interface:ICharacterPairMatcherStarting at the given offset, the matcher chooses a character close to this offset. The matcher then searches for the matching peer character of the chosen character and if it finds one, returns the minimal region of the document that contains both characters.Since version 3.8 the recommended way for finding matching peers is to use
ICharacterPairMatcherExtension.match(IDocument, int, int).- Specified by:
matchin interfaceICharacterPairMatcher- Parameters:
doc- the document to work onoffset- the start offset- Returns:
- the minimal region containing the peer characters or
nullif there is no peer character.
-
match
Description copied from interface:ICharacterPairMatcherExtensionStarting at the given offset (i.e. length 0) or the selected character, the matcher searches for the matching peer character and if it finds one, returns the minimal region of the document that contains both characters.- Specified by:
matchin interfaceICharacterPairMatcherExtension- Parameters:
document- the document to work onoffset- the start offsetlength- the selection length which can be negative indicating right-to-left selection- Returns:
- the minimal region containing the peer characters or
nullif there is no peer character - Since:
- 3.8
- See Also:
-
findEnclosingPeerCharacters
Description copied from interface:ICharacterPairMatcherExtensionStarting at the given selection, the matcher searches for a pair of enclosing peer characters and if it finds one, returns the minimal region of the document that contains the pair.- Specified by:
findEnclosingPeerCharactersin interfaceICharacterPairMatcherExtension- Parameters:
document- the document to work onoffset- the start offsetlength- the selection length which can be negative indicating right-to-left selection- Returns:
- the minimal region containing the peer characters or
nullif there is no enclosing pair - Since:
- 3.8
- See Also:
-
isMatchedChar
public boolean isMatchedChar(char ch) Description copied from interface:ICharacterPairMatcherExtensionChecks whether the character is one of the characters matched by the pair matcher.- Specified by:
isMatchedCharin interfaceICharacterPairMatcherExtension- Parameters:
ch- the character- Returns:
trueif the the character is one of the characters matched by the pair matcher, andfalseotherwise- Since:
- 3.8
- See Also:
-
isMatchedChar
Description copied from interface:ICharacterPairMatcherExtensionChecks whether the character is one of the characters matched by the pair matcher.Clients can use this method to handle characters which may have special meaning in some situations. E.g. in Java, '<' is used as an angular bracket and as well as less-than operator.
- Specified by:
isMatchedCharin interfaceICharacterPairMatcherExtension- Parameters:
ch- the characterdocument- the documentoffset- the offset in document- Returns:
trueif the the character is one of the characters matched by the pair matcher, andfalseotherwise- Since:
- 3.8
- See Also:
-
isRecomputationOfEnclosingPairRequired
public boolean isRecomputationOfEnclosingPairRequired(IDocument document, IRegion currentSelection, IRegion previousSelection) Description copied from interface:ICharacterPairMatcherExtensionComputes whether a client needs to recompute the enclosing pair after a selection change in the document.This is intended to be a quick test to determine whether a re-computation of the enclosing pair is required, as the re-computation after each selection change via a
ICharacterPairMatcherExtension.findEnclosingPeerCharacters(IDocument, int, int)call can be expensive for some clients.- Specified by:
isRecomputationOfEnclosingPairRequiredin interfaceICharacterPairMatcherExtension- Parameters:
document- the document to work oncurrentSelection- the current selection in the documentpreviousSelection- the previous selection in the document- Returns:
trueif the enclosing pair needs to be recomputed,falseotherwise- Since:
- 3.8
- See Also:
-
getAnchor
public int getAnchor()Description copied from interface:ICharacterPairMatcherReturns the anchor for the region of the matching peer characters. The anchor says whether the character that has been chosen to search for its peer character has been the left or the right character of the pair.- Specified by:
getAnchorin interfaceICharacterPairMatcher- Returns:
RIGHTorLEFT
-
dispose
public void dispose()Description copied from interface:ICharacterPairMatcherDisposes this pair matcher.- Specified by:
disposein interfaceICharacterPairMatcher
-
clear
public void clear()Description copied from interface:ICharacterPairMatcherClears this pair matcher. I.e. the matcher throws away all state it might remember and prepares itself for a new call of thematchmethod.- Specified by:
clearin interfaceICharacterPairMatcher
-