/**
* Jumps to the matching bracket.
*/
void gotoMatchingBracket() {
ICharacterPairMatcher matcher = createCharacterPairMatcher();
if (matcher == null)
return;
ISourceViewer sourceViewer = getSourceViewer();
IDocument document = sourceViewer.getDocument();
if (document == null)
return;
IRegion selection = getSignedSelection(sourceViewer);
int selectionLength = Math.abs(selection.getLength());
if (selectionLength > 1) {
setStatusLineErrorMessage(SSEUIMessages.GotoMatchingBracket_error_invalidSelection);
sourceViewer.getTextWidget().getDisplay().beep();
return;
}
int sourceCaretOffset = selection.getOffset() + selection.getLength();
IRegion region = matcher.match(document, sourceCaretOffset);
if (region == null) {
setStatusLineErrorMessage(SSEUIMessages.GotoMatchingBracket_error_noMatchingBracket);
sourceViewer.getTextWidget().getDisplay().beep();
return;
}
int offset = region.getOffset();
int length = region.getLength();
if (length < 1)
return;
int anchor = matcher.getAnchor();
// go to after the match if matching to the right
int targetOffset = (ICharacterPairMatcher.RIGHT == anchor) ? offset : offset + length;
boolean visible = false;