本文整理汇总了Java中org.eclipse.jface.text.source.ICharacterPairMatcher类的典型用法代码示例。如果您正苦于以下问题:Java ICharacterPairMatcher类的具体用法?Java ICharacterPairMatcher怎么用?Java ICharacterPairMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ICharacterPairMatcher类属于org.eclipse.jface.text.source包,在下文中一共展示了ICharacterPairMatcher类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureSourceViewerDecorationSupport
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
@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");
}
示例2: performMatch
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
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));
}
示例3: configureSourceViewerDecorationSupport
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
@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);
}
示例4: run
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
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());
}
示例5: gotoMatchingBracket
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
/**
* 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());
}
示例6: bindICharacterPairMatcher
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
public ICharacterPairMatcher bindICharacterPairMatcher() {
return new DefaultCharacterPairMatcher(new char[] { '(', ')', '{', '}', '[', ']' });
}
示例7: getCharacterPairMatcher
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
protected ICharacterPairMatcher getCharacterPairMatcher() {
return characterPairMatcher;
}
示例8: getCharacterPairMatcher
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
protected ICharacterPairMatcher getCharacterPairMatcher() {
return this.characterPairMatcher;
}
示例9: createBracketMatcher
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
@Override
protected ICharacterPairMatcher createBracketMatcher() {
return new DefaultCharacterPairMatcher("{}[]()".toCharArray(),
JuliaPartition.JULIA_PARTITIONING);
}
示例10: gotoMatchingBracket
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
/**
* 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);
}
示例11: createBracketMatcher
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
@Override
protected ICharacterPairMatcher createBracketMatcher() {
return new GnPairMatcher();
}
示例12: gotoMatchingBracket
import org.eclipse.jface.text.source.ICharacterPairMatcher; //导入依赖的package包/类
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);
}