Search in sources :

Example 21 with ICharacterPairMatcher

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();
}
Also used : ICharacterPairMatcher(org.eclipse.jface.text.source.ICharacterPairMatcher)

Example 22 with ICharacterPairMatcher

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();
}
Also used : ICharacterPairMatcher(org.eclipse.jface.text.source.ICharacterPairMatcher)

Example 23 with ICharacterPairMatcher

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();
}
Also used : ICharacterPairMatcher(org.eclipse.jface.text.source.ICharacterPairMatcher)

Example 24 with ICharacterPairMatcher

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();
}
Also used : ICharacterPairMatcher(org.eclipse.jface.text.source.ICharacterPairMatcher)

Example 25 with ICharacterPairMatcher

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());
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) ICharacterPairMatcher(org.eclipse.jface.text.source.ICharacterPairMatcher) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point)

Aggregations

ICharacterPairMatcher (org.eclipse.jface.text.source.ICharacterPairMatcher)26 Test (org.junit.Test)12 DefaultCharacterPairMatcher (org.eclipse.jface.text.source.DefaultCharacterPairMatcher)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 Point (org.eclipse.swt.graphics.Point)2 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ExtendedConfigurationBuilder (org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder)1