当前位置: 首页>>代码示例>>Java>>正文


Java ICharacterPairMatcher.RIGHT属性代码示例

本文整理汇总了Java中org.eclipse.jface.text.source.ICharacterPairMatcher.RIGHT属性的典型用法代码示例。如果您正苦于以下问题:Java ICharacterPairMatcher.RIGHT属性的具体用法?Java ICharacterPairMatcher.RIGHT怎么用?Java ICharacterPairMatcher.RIGHT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.eclipse.jface.text.source.ICharacterPairMatcher的用法示例。


在下文中一共展示了ICharacterPairMatcher.RIGHT属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performMatch

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));
}
 
开发者ID:MulgaSoft,项目名称:e4macs,代码行数:19,代码来源:HackDefaultCharacterPairMatcher.java

示例2: run

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());
}
 
开发者ID:eclipse,项目名称:texlipse,代码行数:44,代码来源:GoToMatchingBracketAction.java

示例3: gotoMatchingBracket

/**
 * 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());
}
 
开发者ID:angelozerr,项目名称:typescript.java,代码行数:64,代码来源:JavaScriptLightWeightEditor.java

示例4: gotoMatchingBracket

/**
 * 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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:81,代码来源:JavaEditor.java

示例5: gotoMatchingBracket

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);
}
 
开发者ID:GoClipse,项目名称:goclipse,代码行数:78,代码来源:GotoMatchingBracketManager.java


注:本文中的org.eclipse.jface.text.source.ICharacterPairMatcher.RIGHT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。