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


Java DocumentEvent.getLength方法代码示例

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


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

示例1: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
@Override
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());

			if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else{
				end = endOfLineOf(end);
			}

			end = Math.min(partition.getOffset() + partition.getLength(), end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
开发者ID:de-jcup,项目名称:eclipse-batch-editor,代码行数:27,代码来源:PresentationSupport.java

示例2: computeChange

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * Computes the change abstraction given a text event.
 *
 * @param event the text event to analyze
 * @return a change object describing the event
 */
private Change computeChange(TextEvent event) {
	DocumentEvent e = event.getDocumentEvent();
	if (e == null) return new Change(TypingRun.NO_CHANGE, -1);

	int start = e.getOffset();
	int end = e.getOffset() + e.getLength();
	String newText = e.getText();
	if (newText == null) newText = new String();

	if (start == end) {
		// no replace / delete / overwrite
		if (newText.length() == 1) return new Change(TypingRun.INSERT, end + 1);
	} else if (start == end - 1) {
		if (newText.length() == 1) return new Change(TypingRun.OVERTYPE, end);
		if (newText.length() == 0) return new Change(TypingRun.DELETE, start);
	}

	return new Change(TypingRun.UNKNOWN, -1);
}
 
开发者ID:grosenberg,项目名称:fluentmark,代码行数:26,代码来源:TypingRunDetector.java

示例3: updateWithOverStartEvent

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * Update the given position with the given event. The event overlaps with the start of the position.
 * 
 * @param position
 *            The position
 * @param event
 *            The event
 */
private void updateWithOverStartEvent(AttributedPosition position, DocumentEvent event) {
	int eventOffset = event.getOffset();
	int eventEnd = eventOffset + event.getLength();

	String newText = event.getText();
	if (newText == null)
		newText = ""; //$NON-NLS-1$
	int eventNewLength = newText.length();

	int excludedLength = eventNewLength;
	while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1)))
		excludedLength--;
	int deleted = eventEnd - position.getOffset();
	int inserted = eventNewLength - excludedLength;
	position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted);
}
 
开发者ID:cplutte,项目名称:bts,代码行数:25,代码来源:HighlightingPresenter.java

示例4: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
    if (!documentPartitioningChanged) {
        try {

            IRegion info= document.getLineInformationOfOffset(event.getOffset());
            int start= Math.max(partition.getOffset(), info.getOffset());

            int end= event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());

            if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
                // optimize the case of the same line
                end= info.getOffset() + info.getLength();
            } else
                end= endOfLineOf(end);

            end= Math.min(partition.getOffset() + partition.getLength(), end);
            return new Region(start, end - start);

        } catch (BadLocationException x) {
            logger.logInfo("unable to find location in document to repair a given region",x); //$NON-NLS-1$
        }
    }
    return partition;
}
 
开发者ID:anb0s,项目名称:LogViewer,代码行数:25,代码来源:DamageRepairer.java

示例5: updateWithOverStartEvent

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * Update the given position with the given event. The event overlaps with the start of the position.
 *
 * @param position The position
 * @param event The event
 */
private void updateWithOverStartEvent(HighlightedPosition position, DocumentEvent event) {
	int eventOffset= event.getOffset();
	int eventEnd= eventOffset + event.getLength();

	String newText= event.getText();
	if (newText == null)
		newText= ""; //$NON-NLS-1$
	int eventNewLength= newText.length();

	int excludedLength= eventNewLength;
	while (excludedLength > 0 && Character.isJavaIdentifierPart(newText.charAt(excludedLength - 1)))
		excludedLength--;
	int deleted= eventEnd - position.getOffset();
	int inserted= eventNewLength - excludedLength;
	position.update(eventOffset + excludedLength, position.getLength() - deleted + inserted);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:SemanticHighlightingPresenter.java

示例6: computeChange

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * Computes the change abstraction given a text event.
 *
 * @param event the text event to analyze
 * @return a change object describing the event
 */
private Change computeChange(TextEvent event) {
	DocumentEvent e= event.getDocumentEvent();
	if (e == null)
		return new Change(TypingRun.NO_CHANGE, -1);

	int start= e.getOffset();
	int end= e.getOffset() + e.getLength();
	String newText= e.getText();
	if (newText == null)
		newText= new String();

	if (start == end) {
		// no replace / delete / overwrite
		if (newText.length() == 1)
			return new Change(TypingRun.INSERT, end + 1);
	} else if (start == end - 1) {
		if (newText.length() == 1)
			return new Change(TypingRun.OVERTYPE, end);
		if (newText.length() == 0)
			return new Change(TypingRun.DELETE, start);
	}

	return new Change(TypingRun.UNKNOWN, -1);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:31,代码来源:TypingRunDetector.java

示例7: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent e,
        final boolean documentPartitioningChanged) {
    if (!documentPartitioningChanged) {
        String source = fDocument.get();
        int start = source.substring(0, e.getOffset()).lastIndexOf("/*");
        if (start == -1) {
            start = 0;
        }
        int end = source.indexOf("*/", e.getOffset());
        int end2 = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
        if (end == -1) {
            end = source.length();
        } else if (end2 > end) {
            end = end2;
        } else {
            end++;
        }

        return new Region(start, end - start);
    }
    return partition;
}
 
开发者ID:apache,项目名称:syncope,代码行数:23,代码来源:JavaScriptDamagerRepairer.java

示例8: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
public IRegion getDamageRegion(final ITypedRegion partition, final DocumentEvent e,
        final boolean documentPartitioningChanged) {
    if (!documentPartitioningChanged) {
        String source = fDocument.get();
        int start = source.substring(0, e.getOffset()).lastIndexOf('<');
        if (start == -1) {
            start = 0;
        }
        int end = source.indexOf('>', e.getOffset());
        int nextEnd = source.indexOf('>', end + 1);
        if (nextEnd >= 0 && nextEnd > end) {
            end = nextEnd;
        }
        int end2 = e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
        if (end == -1) {
            end = source.length();
        } else if (end2 > end) {
            end = end2;
        } else {
            end++;
        }

        return new Region(start, end - start);
    }
    return partition;
}
 
开发者ID:apache,项目名称:syncope,代码行数:27,代码来源:HTMLTagDamagerRepairer.java

示例9: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged){
	if (!documentPartitioningChanged){
		try{
			IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());

			if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			}else
				end = endOfLineOf(end);

			end = Math.min(partition.getOffset() + partition.getLength(), end);
			return new Region(start, end - start);

		} catch (BadLocationException e) {
		}
	}

	return partition;
}
 
开发者ID:xbony2,项目名称:Minetweaker-IDE,代码行数:27,代码来源:NonRuleBasedDamagerRepairer.java

示例10: isSelectionReplace

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * Determine if a selection is being replaced by non-emacs+ behavior (or YANK), and save the
 * replaced content in the kill ring. This captures the Eclipse (but not emacs) behavior where
 * typing/pasting into a selection replaces the old with the new, so it is appropriate to save
 * the old text to the kill ring.
 * 
 * @param event the DocumentEvent containing the IDocument, offset, and length
 * @return true if the non-zero length region matches the current selection in the editor
 */
private boolean isSelectionReplace(DocumentEvent event) {
	int len = event.getLength();
	// ignore plain insertion or any emacs+ (except YANK) command invocation
	if (selectionReplace &&  len > 0 && shouldSave()) {
		ITextEditor editor = EmacsPlusUtils.getCurrentEditor();
		// otherwise, if we can get the selection, see if it matches the replace region
		if (editor != null && editor.getDocumentProvider().getDocument(editor.getEditorInput()) == event.getDocument()) {
			ISelection isel = editor.getSelectionProvider().getSelection();
			if (isel instanceof ITextSelection) {
				ITextSelection selection = (ITextSelection)isel;
				boolean result = selection.getOffset() == event.getOffset() && selection.getLength() == len;
				return result;
			}
		}
	}
	return false;
}
 
开发者ID:MulgaSoft,项目名称:e4macs,代码行数:27,代码来源:KillRing.java

示例11: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
public IRegion getDamageRegion(
	ITypedRegion partition,
	DocumentEvent event,
	boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info =
				fDocument.getLineInformationOfOffset(event.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end =
				event.getOffset()
					+ (event.getText() == null
						? event.getLength()
						: event.getText().length());

			if (info.getOffset() <= end
				&& end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else
				end = endOfLineOf(end);

			end =
				Math.min(
					partition.getOffset() + partition.getLength(),
					end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:40,代码来源:NonRuleBasedDamagerRepairer.java

示例12: documentChanged

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
@Override
public void documentChanged(DocumentEvent event) {

	String command = "document.replace(" + event.getOffset() + ", " + event.getLength() + ", \""
			+ toText(event.getText()) + "\");";
	write("\t\t" + command, true);

	//commands.add(new Command(command));
}
 
开发者ID:eclipse,项目名称:tm4e,代码行数:10,代码来源:TMPresentationReconcilerTestGenerator.java

示例13: documentAboutToBeChanged

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
public void documentAboutToBeChanged(DocumentEvent event) {

			// default behavior: any document change outside a linked position
			// causes us to exit
			int end = event.getOffset() + event.getLength();
			for (int offset = event.getOffset(); offset <= end; offset++) {
				if (!fModel.anyPositionContains(offset)) {
					ITextViewer viewer = fCurrentTarget.getViewer();
					if (fFramePosition != null && viewer instanceof IEditingSupportRegistry) {
						IEditingSupport[] helpers = ((IEditingSupportRegistry) viewer).getRegisteredSupports();
						for (int i = 0; i < helpers.length; i++) {
							if (helpers[i].isOriginator(null,
									new Region(fFramePosition.getOffset(), fFramePosition.getLength())))
								return;
						}
					}

					leave(ILinkedModeListener.EXTERNAL_MODIFICATION);
					return;
				}
			}

			// Make sure that any document change is done inside a compound
			// change
			beginCompoundChangeIfNeeded();

		}
 
开发者ID:curiosag,项目名称:ftc,代码行数:28,代码来源:TweakedLinkedModeUI.java

示例14: getDamageRegion

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
/**
 * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
 */
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event,
		boolean documentPartitioningChanged) {
	if (!documentPartitioningChanged) {
		try {

			IRegion info = fDocument.getLineInformationOfOffset(event
					.getOffset());
			int start = Math.max(partition.getOffset(), info.getOffset());

			int end = event.getOffset()
					+ (event.getText() == null ? event.getLength() : event
							.getText().length());

			if (info.getOffset() <= end
					&& end <= info.getOffset() + info.getLength()) {
				// optimize the case of the same line
				end = info.getOffset() + info.getLength();
			} else
				end = endOfLineOf(end);

			end = Math.min(partition.getOffset() + partition.getLength(),
					end);
			return new Region(start, end - start);

		} catch (BadLocationException x) {
		}
	}

	return partition;
}
 
开发者ID:ncleclipse,项目名称:ncl30-eclipse,代码行数:34,代码来源:NonRuleBasedDamagerRepairer.java

示例15: validate

import org.eclipse.jface.text.DocumentEvent; //导入方法依赖的package包/类
public boolean validate(IDocument document, int offset, DocumentEvent event) {
	if (event != null) {
		int oldReplaceContextLength = getReplaceContextLength();
		int diff = event.getText().length() - event.getLength();
		setReplaceContextLength(oldReplaceContextLength + diff);
	}
	try {
		String prefix = document.get(replacementOffset, offset - replacementOffset);
		return matcher.isCandidateMatchingPrefix(replacementString, prefix);
	}
	catch (BadLocationException e) {
		log.info(e.getMessage(), e);
		return false;
	}
}
 
开发者ID:cplutte,项目名称:bts,代码行数:16,代码来源:ConfigurableCompletionProposal.java


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