Java 类org.eclipse.jface.text.source.ICharacterPairMatcher 实例源码

项目:ncl30-eclipse    文件:NCLEditor.java   
@Override
protected void configureSourceViewerDecorationSupport(
        SourceViewerDecorationSupport support) {

    super.configureSourceViewerDecorationSupport(support);
    char[] matchChars = { '<', '>' }; // which brackets to match

    ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher(
            matchChars, IDocumentExtension3.DEFAULT_PARTITIONING);

    support.setCharacterPairMatcher(matcher);
    support.setMatchingCharacterPainterPreferenceKeys(
            EDITOR_MATCHING_BRACKETS, EDITOR_MATCHING_BRACKETS_COLOR);

    // Enable bracket highlighting in the preference store
    IPreferenceStore store = getPreferenceStore();
    store.setDefault(EDITOR_MATCHING_BRACKETS, true);
    store.setDefault(EDITOR_MATCHING_BRACKETS_COLOR, "128,128,128");

}
项目:e4macs    文件:HackDefaultCharacterPairMatcher.java   
protected IRegion performMatch(IDocument doc, int caretOffset) throws BadLocationException {
    final int charOffset= caretOffset - 1;
    final char prevChar= doc.getChar(Math.max(charOffset, 0));
    if (!fPairs.contains(prevChar)) return null;
    final boolean isForward= fPairs.isStartCharacter(prevChar);
    fAnchor= isForward ? ICharacterPairMatcher.LEFT : ICharacterPairMatcher.RIGHT;
    final int searchStartPosition= isForward ? caretOffset : caretOffset - 2;
    final int adjustedOffset= isForward ? charOffset : caretOffset;
    final String partition= TextUtilities.getContentType(doc, fPartitioning, charOffset, false);
    final DocumentPartitionAccessor partDoc= new DocumentPartitionAccessor(doc, fPartitioning, partition);
    int endOffset= findMatchingPeer(partDoc, prevChar, fPairs.getMatching(prevChar),
            isForward,  isForward ? doc.getLength() : -1,
            searchStartPosition);
    if (endOffset == -1) return null;
    final int adjustedEndOffset= isForward ? endOffset + 1: endOffset;
    if (adjustedEndOffset == adjustedOffset) return null;
    return new Region(Math.min(adjustedOffset, adjustedEndOffset),
            Math.abs(adjustedEndOffset - adjustedOffset));
}
项目:rustyeclipse    文件:RustEditor.java   
@Override
protected void configureSourceViewerDecorationSupport (@Nullable SourceViewerDecorationSupport support) {
    super.configureSourceViewerDecorationSupport(support);
    IPreferenceStore store = getPreferenceStore();
    char[] matchChars = {'(', ')', '[', ']', '{', '}'}; //which brackets to match
    ICharacterPairMatcher matcher = new DefaultCharacterPairMatcher(matchChars ,
            IDocumentExtension3.DEFAULT_PARTITIONING);
    support.setCharacterPairMatcher(matcher);
    support.setMatchingCharacterPainterPreferenceKeys(RustConstants.EDITOR_MATCHING_BRACKETS,RustConstants. EDITOR_MATCHING_BRACKETS_COLOR);
    //Enable bracket highlighting in the preference store
    store.setDefault(RustConstants.EDITOR_MATCHING_BRACKETS, true);
    store.setDefault(RustConstants.EDITOR_MATCHING_BRACKETS_COLOR, RustConstants.DEFAULT_MATCHING_BRACKETS_COLOR);
}
项目:texlipse    文件:GoToMatchingBracketAction.java   
public void run(IAction action) {
    if (targetEditor == null) return;
    ISourceViewer sourceViewer= targetEditor.getViewer();
    IDocument document= sourceViewer.getDocument();
    if (document == null)
        return;
    ITextSelection selection = (ITextSelection) targetEditor.getSelectionProvider().getSelection();
    SubStatusLineManager slm = 
        (SubStatusLineManager) targetEditor.getEditorSite().getActionBars().getStatusLineManager();

    int selectionLength= Math.abs(selection.getLength());
    if (selectionLength > 1) {
        slm.setErrorMessage(TexlipsePlugin.getResourceString("gotoMatchingBracketNotSelected"));
        slm.setVisible(true);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int sourceCaretOffset= selection.getOffset() + selection.getLength();

    TexPairMatcher fBracketMatcher = new TexPairMatcher("{}[]()");

    IRegion region= fBracketMatcher.match(document, sourceCaretOffset);
    if (region == null) {
        slm.setErrorMessage(TexlipsePlugin.getResourceString("gotoMatchingBracketNotFound"));
        slm.setVisible(true);            
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset= region.getOffset();
    int length= region.getLength();

    if (length < 1) return;

    int anchor = fBracketMatcher.getAnchor();
    int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1: offset + length;

    if (selection.getLength() < 0)
        targetOffset -= selection.getLength();

    sourceViewer.setSelectedRange(targetOffset, selection.getLength());
    sourceViewer.revealRange(targetOffset, selection.getLength());
}
项目:typescript.java    文件:JavaScriptLightWeightEditor.java   
/**
 * Jumps to the matching bracket.
 */
public void gotoMatchingBracket() {

    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(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_invalidSelection);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    // #26314
    int sourceCaretOffset = selection.getOffset() + selection.getLength();
    if (isSurroundedByBrackets(document, sourceCaretOffset))
        sourceCaretOffset -= selection.getLength();

    IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
    if (region == null) {
        setStatusLineErrorMessage(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset = region.getOffset();
    int length = region.getLength();

    if (length < 1)
        return;

    int anchor = fBracketMatcher.getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset = (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : 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(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    if (selection.getLength() < 0)
        targetOffset -= selection.getLength();

    sourceViewer.setSelectedRange(targetOffset, selection.getLength());
    sourceViewer.revealRange(targetOffset, selection.getLength());
}
项目:bts    文件:DefaultUiModule.java   
public ICharacterPairMatcher bindICharacterPairMatcher() {
    return new DefaultCharacterPairMatcher(new char[] { '(', ')', '{', '}', '[', ']' });
}
项目:bts    文件:LexerTokenAndCharacterPairAwareStrategy.java   
protected ICharacterPairMatcher getCharacterPairMatcher() {
    return characterPairMatcher;
}
项目:statecharts    文件:StyledTextXtextAdapter.java   
protected ICharacterPairMatcher getCharacterPairMatcher() {
    return this.characterPairMatcher;
}
项目:JuliaDT    文件:JuliaEditor.java   
@Override
protected ICharacterPairMatcher createBracketMatcher() {
  return new DefaultCharacterPairMatcher("{}[]()".toCharArray(),
      JuliaPartition.JULIA_PARTITIONING);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
/**
 * Jumps to the matching bracket.
 */
public void gotoMatchingBracket() {

    ISourceViewer sourceViewer= getSourceViewer();
    IDocument document= sourceViewer.getDocument();
    if (document == null)
        return;

    IRegion selection= getSignedSelection(sourceViewer);
    if (fPreviousSelections == null)
        initializePreviousSelectionList();

    IRegion region= fBracketMatcher.match(document, selection.getOffset(), selection.getLength());
    if (region == null) {
        region= fBracketMatcher.findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength());
        initializePreviousSelectionList();
        fPreviousSelections.add(selection);
    } else {
        if (fPreviousSelections.size() == 2) {
            if (!selection.equals(fPreviousSelections.get(1))) {
                initializePreviousSelectionList();
            }
        } else if (fPreviousSelections.size() == 3) {
            if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) {
                IRegion originalSelection= fPreviousSelections.get(0);
                sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength());
                sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength());
                initializePreviousSelectionList();
                return;
            }
            initializePreviousSelectionList();
        }
    }

    if (region == null) {
        setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset= region.getOffset();
    int length= region.getLength();

    if (length < 1)
        return;

    int anchor= fBracketMatcher.getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1;

    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(JavaEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int adjustment= getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength());
    targetOffset+= adjustment;
    int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1);
    if (fPreviousSelections.size() == 1 && direction < 0) {
        targetOffset++;
    }

    if (fPreviousSelections.size() > 0) {
        fPreviousSelections.add(new Region(targetOffset, direction));
    }
    sourceViewer.setSelectedRange(targetOffset, direction);
    sourceViewer.revealRange(targetOffset, direction);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaEditor.java   
/**
 * Jumps to the matching bracket.
 */
public void gotoMatchingBracket() {

    ISourceViewer sourceViewer= getSourceViewer();
    IDocument document= sourceViewer.getDocument();
    if (document == null)
        return;

    IRegion selection= getSignedSelection(sourceViewer);
    if (fPreviousSelections == null)
        initializePreviousSelectionList();

    IRegion region= fBracketMatcher.match(document, selection.getOffset(), selection.getLength());
    if (region == null) {
        region= fBracketMatcher.findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength());
        initializePreviousSelectionList();
        fPreviousSelections.add(selection);
    } else {
        if (fPreviousSelections.size() == 2) {
            if (!selection.equals(fPreviousSelections.get(1))) {
                initializePreviousSelectionList();
            }
        } else if (fPreviousSelections.size() == 3) {
            if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) {
                IRegion originalSelection= fPreviousSelections.get(0);
                sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength());
                sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength());
                initializePreviousSelectionList();
                return;
            }
            initializePreviousSelectionList();
        }
    }

    if (region == null) {
        setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset= region.getOffset();
    int length= region.getLength();

    if (length < 1)
        return;

    int anchor= fBracketMatcher.getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1;

    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(JavaEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int adjustment= getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength());
    targetOffset+= adjustment;
    int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1);
    if (fPreviousSelections.size() == 1 && direction < 0) {
        targetOffset++;
    }

    if (fPreviousSelections.size() > 0) {
        fPreviousSelections.add(new Region(targetOffset, direction));
    }
    sourceViewer.setSelectedRange(targetOffset, direction);
    sourceViewer.revealRange(targetOffset, direction);
}
项目:eclipse-gn    文件:GnEditor.java   
@Override
protected ICharacterPairMatcher createBracketMatcher() {
  return new GnPairMatcher();
}
项目:goclipse    文件:GotoMatchingBracketManager.java   
public void gotoMatchingBracket() {
    ITextViewer sourceViewer = langEditor.getSourceViewer_();

    IDocument document= sourceViewer.getDocument();
    if (document == null)
        return;

    IRegion selection= EditorUtils.getSignedSelection(sourceViewer);
    if (fPreviousSelections == null)
        initializePreviousSelectionList();

    IRegion region= getBracketMatcher().match(document, selection.getOffset(), selection.getLength());
    if (region == null) {
        region= getBracketMatcher().findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength());
        initializePreviousSelectionList();
        fPreviousSelections.add(selection);
    } else {
        if (fPreviousSelections.size() == 2) {
            if (!selection.equals(fPreviousSelections.get(1))) {
                initializePreviousSelectionList();
            }
        } else if (fPreviousSelections.size() == 3) {
            if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) {
                IRegion originalSelection= fPreviousSelections.get(0);
                sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength());
                sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength());
                initializePreviousSelectionList();
                return;
            }
            initializePreviousSelectionList();
        }
    }

    if (region == null) {
        langEditor.setStatusLineErrorMessage(LangEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset= region.getOffset();
    int length= region.getLength();

    if (length < 1)
        return;

    int anchor= getBracketMatcher().getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1;

    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) {
        langEditor.setStatusLineErrorMessage(LangEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int adjustment= getBracketMatcher().getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength());
    targetOffset+= adjustment;
    int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1);
    if (fPreviousSelections.size() == 1 && direction < 0) {
        targetOffset++;
    }

    if (fPreviousSelections.size() > 0) {
        fPreviousSelections.add(new Region(targetOffset, direction));
    }
    sourceViewer.setSelectedRange(targetOffset, direction);
    sourceViewer.revealRange(targetOffset, direction);
}