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


Java IDocument.getLineLength方法代码示例

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


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

示例1: getLineInformationOfRegion

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
/**
 * Similar to {@link IDocument#getLineInformationOfOffset(int)}, but the client can provide a text region instead of
 * only an offset. If the given region spans multiple lines, all affected lines will be returned, i.e. entire line
 * containing beginning of region, all lines contained in the region, and entire line containing the end of the
 * region.
 */
public static IRegion getLineInformationOfRegion(IDocument doc, int offset, int length,
		boolean includeLineDelimiterOfLastLine) throws BadLocationException {
	// get the line containing the beginning of the given text region
	final int firstLineNo = doc.getLineOfOffset(offset);
	// get the line containing the end of the given text region
	// (may be the same line if removal does not span multiple lines)
	final int lastLineNo = doc.getLineOfOffset(offset + length);
	// compute result
	final int startOffset = doc.getLineOffset(firstLineNo);
	final int endOffset = doc.getLineOffset(lastLineNo) + (includeLineDelimiterOfLastLine ?
			doc.getLineLength(lastLineNo) // includes line delimiters!
			: doc.getLineInformation(lastLineNo).getLength()); // does *not* include line delimiters!
	return new Region(
			startOffset,
			endOffset - startOffset);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:23,代码来源:DocumentUtilN4.java

示例2: getOffsetAtLine

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
@Override
protected int getOffsetAtLine(int lineIndex) {
	IDocument document = getTextViewer().getDocument();
	try {
		int lo = document.getLineOffset(lineIndex);
		int ll = document.getLineLength(lineIndex);
		String line = document.get(lo, ll);
		return super.getOffsetAtLine(lineIndex) + getLeadingSpaces(line);
	} catch (BadLocationException e) {
		return -1;
	}
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:13,代码来源:CodeLensViewZone.java

示例3: getLineText

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private static String getLineText(IDocument document, int line, boolean withLineDelimiter) {
	try {
		int lo = document.getLineOffset(line);
		int ll = document.getLineLength(line);
		if (!withLineDelimiter) {
			String delim = document.getLineDelimiter(line);
			ll = ll - (delim != null ? delim.length() : 0);
		}
		return document.get(lo, ll);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:15,代码来源:ClassReferencesCodeLensProvider.java

示例4: getAllSnippetsAnnotations

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
	Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
	IDocument document = getDocument();
	int curOffset = 0;
	FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
	try {
		IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
		while (startRegion != null && startRegion.getOffset() >= curOffset) {
			int startLine = document.getLineOfOffset(startRegion.getOffset());
			int startOffset = document.getLineOffset(startLine);
			curOffset = startOffset + document.getLineLength(startLine);
			IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false); //$NON-NLS-1$
			if (endRegion != null) {
				int endLine = document.getLineOfOffset(endRegion.getOffset());
				int endOffset = document.getLineOffset(endLine);
				endOffset += document.getLineLength(endLine);
				curOffset = endOffset;
				String text = document.get(startOffset, endOffset - startOffset);
				ProjectionAnnotation annotation = new ProjectionAnnotation(true);
				annotation.setText(text);
				annotation.setRangeIndication(true);
				annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
			}
			if (curOffset < document.getLength()) {
				startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
			}
		}

	} catch (BadLocationException e) {

	}
	return annotations;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:34,代码来源:SourceViewer.java

示例5: hasSnippetsModifications

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private boolean hasSnippetsModifications() {
	IDocument document = getDocument();
	if (document == null) {
		return false;
	}
	int curNbAnnotations = oldAnnotations.size();
	int actualNbAnnotations = 0;
	int curOffset = 0;
	FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
	try {
		IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
		while (startRegion != null && startRegion.getOffset() >= curOffset) {
			int startLine = document.getLineOfOffset(startRegion.getOffset());
			int startOffset = document.getLineOffset(startLine);
			curOffset = startOffset + document.getLineLength(startLine);
			IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false); //$NON-NLS-1$
			if (endRegion != null) {
				actualNbAnnotations++;
				int endLine = document.getLineOfOffset(endRegion.getOffset());
				int endOffset = document.getLineOffset(endLine);
				endOffset += document.getLineLength(endLine);
				curOffset = endOffset;
				boolean contains = false;
				String text = document.get(startOffset, endOffset - startOffset);
				for (ProjectionAnnotation annotation : oldAnnotations.keySet()) {
					Position pos = oldAnnotations.get(annotation);
					if (annotation.getText().equals(text) && (startOffset == pos.getOffset())) {
						contains = true;
					}
				}
				if (!contains) {
					return true;
				}
			}
			if (curOffset < document.getLength()) {
				startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false); //$NON-NLS-1$
			}
		}

	} catch (BadLocationException e) {

	}
	if (curNbAnnotations != actualNbAnnotations) {
		return true;
	}
	return false;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:48,代码来源:SourceViewer.java


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