use of org.eclipse.jface.text.source.ICharacterPairMatcher in project webtools.sourceediting by eclipse.
the class AbstractPairMatcherTest method testBug156426.
public void testBug156426() {
final ICharacterPairMatcher matcher = createMatcher("()[]{}<>");
performMatch(matcher, " #( a < b )% ");
performMatch(matcher, " (% a < b )# ");
performMatch(matcher, " #( a > b )% ");
performMatch(matcher, " (% a > b )# ");
matcher.dispose();
}
use of org.eclipse.jface.text.source.ICharacterPairMatcher in project webtools.sourceediting by eclipse.
the class AbstractPairMatcherTest method testTightPartitioned.
/**
* Test that it works properly next to partition boundaries.
*
* @throws BadLocationException
*/
public void testTightPartitioned() throws BadLocationException {
final ICharacterPairMatcher matcher = createMatcher("()[]{}");
performMatch(matcher, "(|b)%b|");
performMatch(matcher, "(%|b)b|");
performMatch(matcher, "|a(a|)%");
performMatch(matcher, "|a(%a|)");
performMatch(matcher, "|c#(c|)(|c)%c|");
performMatch(matcher, "|c(%c|)(|c)#c|");
performMatch(matcher, "(%|a)a||b)b||c)c|)#");
matcher.dispose();
}
use of org.eclipse.jface.text.source.ICharacterPairMatcher in project webtools.sourceediting by eclipse.
the class AbstractPairMatcherTest method testSimpleMatchSameMatcher.
/**
* Very simple checks.
*
* @throws BadLocationException
*/
public void testSimpleMatchSameMatcher() throws BadLocationException {
final ICharacterPairMatcher matcher = createMatcher("()[]{}");
performMatch(matcher, "#( )%");
performMatch(matcher, "#[ ]%");
performMatch(matcher, "#{ }%");
performMatch(matcher, "(% )#");
performMatch(matcher, "[% ]#");
performMatch(matcher, "{% }#");
matcher.dispose();
}
use of org.eclipse.jface.text.source.ICharacterPairMatcher in project webtools.sourceediting by eclipse.
the class AbstractPairMatcherTest method testPartitioned.
/**
* Test that it doesn't match across different partitions.
*
* @throws BadLocationException
*/
public void testPartitioned() throws BadLocationException {
final ICharacterPairMatcher matcher = createMatcher("()[]{}");
performMatch(matcher, "(% |a a| )#");
performMatch(matcher, "#( |a a| )%");
performMatch(matcher, "|b #( )% b|");
performMatch(matcher, "( |b )% b|");
performMatch(matcher, "(% |b ) b|");
performMatch(matcher, "|a ( a| )%");
performMatch(matcher, "|a (% a| )");
performMatch(matcher, "|c #( c| ) ( |c )% c|");
performMatch(matcher, "|c (% c| ) ( |c )# c|");
performMatch(matcher, "(% |a ) a| |b ) b| |c ) c| )#");
matcher.dispose();
}
use of org.eclipse.jface.text.source.ICharacterPairMatcher in project webtools.sourceediting by eclipse.
the class StructuredTextEditor method gotoMatchingBracket.
/**
* 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;
if (sourceViewer instanceof ITextViewerExtension5) {
ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
} else {
IRegion visibleRegion = sourceViewer.getVisibleRegion();
// http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
visible = (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength());
}
if (!visible) {
setStatusLineErrorMessage(SSEUIMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
sourceViewer.getTextWidget().getDisplay().beep();
return;
}
if (selection.getLength() < 0)
targetOffset -= selection.getLength();
if (sourceViewer != null) {
sourceViewer.setSelectedRange(targetOffset, selection.getLength());
sourceViewer.revealRange(targetOffset, selection.getLength());
}
}
Aggregations