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


Java IDocument.getLineOfOffset方法代码示例

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


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

示例1: addErrorMarkers

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private void addErrorMarkers(BashScriptModel model, int severity) {
	if (model == null) {
		return;
	}
	IDocument document = getDocument();
	if (document == null) {
		return;
	}
	Collection<BashError> errors = model.getErrors();
	for (BashError error : errors) {
		int startPos = error.getStart();
		int line;
		try {
			line = document.getLineOfOffset(startPos);
		} catch (BadLocationException e) {
			EclipseUtil.logError("Cannot get line offset for " + startPos, e);
			line = 0;
		}
		BashEditorUtil.addScriptError(this, line, error, severity);
	}

}
 
开发者ID:de-jcup,项目名称:eclipse-bash-editor,代码行数:23,代码来源:BashEditor.java

示例2: getLineByOffset

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static String getLineByOffset(IDocument document, int offset) {
  final Scanner scanner = new Scanner(document.get());
  int lineNumber = 0;
  try {
    while (scanner.hasNextLine()) {
      final String line = scanner.nextLine();
      if (lineNumber == document.getLineOfOffset(offset)) {
        return line;
      }
      lineNumber++;
    }
  } catch (BadLocationException e) {
    e.printStackTrace();
  } finally {
    if (scanner != null)
      scanner.close();
  }
  return "";
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:20,代码来源:EditorUtilities.java

示例3: 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

示例4: toRange

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
public static Range toRange(IOpenable openable, int offset, int length) throws JavaModelException {
	if (offset > 0 || length > 0) {
		int[] loc = null;
		int[] endLoc = null;
		IBuffer buffer = openable.getBuffer();
		// if (buffer != null) {
		// loc = JsonRpcHelpers.toLine(buffer, offset);
		// endLoc = JsonRpcHelpers.toLine(buffer, offset + length);
		// }
		// if (loc == null) {
		// loc = new int[2];
		// }
		// if (endLoc == null) {
		// endLoc = new int[2];
		// }
		// setPosition(range.getStart(), loc);
		// setPosition(range.getEnd(), endLoc);
		IDocument document = toDocument(buffer);
		try {
			int line = document.getLineOfOffset(offset);
			int column = offset - document.getLineOffset(line);
			return new Range(line + 1, column + 1);
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	// TODO Auto-generated method stub
	return null;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:31,代码来源:JDTUtils.java

示例5: 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

示例6: getMethodLineNumber

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
private int getMethodLineNumber(IDocument document, VFMethod method) {
	FindReplaceDocumentAdapter findReplaceDocumentAdapter = new FindReplaceDocumentAdapter(document);
	try {
		method.getSootMethod().getBytecodeSignature();

		IRegion region = findReplaceDocumentAdapter.find(0, method.getSootMethod().getDeclaration(), true, true, false, false);
		return document.getLineOfOffset(region.getOffset());
	} catch (BadLocationException e) {
		e.printStackTrace();
	}
	return -1;

}
 
开发者ID:VisuFlow,项目名称:visuflow-plugin,代码行数:14,代码来源:DataModelImpl.java

示例7: 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

示例8: validateTrimTrailingWhiteSpace

import org.eclipse.jface.text.IDocument; //导入方法依赖的package包/类
/**
 * Validate 'trim_trailing_whitespace' of the lines where region changed if
 * needed and update the given set of marker.
 *
 * @param partition
 *            the region which changed
 * @param remainingMarkers
 *            set of markers to update.
 * @throws BadLocationException
 */
private void validateTrimTrailingWhiteSpace(IDocument document, IRegion partition, Set<IMarker> remainingMarkers)
		throws BadLocationException, CoreException {
	boolean trimTrailingWhiteSpace = preferenceStore.getBoolean(EDITOR_TRIM_TRAILING_WHITESPACE);
	if (!trimTrailingWhiteSpace) {
		return;
	}
	int startLine = document.getLineOfOffset(partition.getOffset());
	int endLine = document.getLineOfOffset(partition.getOffset() + partition.getLength());

	IRegion region = null;
	for (int i = startLine; i < endLine + 1; i++) {
		region = document.getLineInformation(i);
		if (region.getLength() == 0)
			continue;
		int lineStart = region.getOffset();
		int lineExclusiveEnd = lineStart + region.getLength();
		int j = lineExclusiveEnd - 1;
		while (j >= lineStart && Character.isWhitespace(document.getChar(j)))
			--j;
		++j;
		if (j < lineExclusiveEnd) {
			addOrUpdateMarker(j, lineExclusiveEnd, trimTrailingWhitespaceType, document, remainingMarkers);
		}
	}
	if (region != null) {
		for (IMarker marker : new HashSet<>(remainingMarkers)) {
			if (MarkerUtils.getOptionType(marker) == trimTrailingWhitespaceType) {
				int line = MarkerUtilities.getLineNumber(marker) + 1;
				if (line < startLine || line > endLine) {
					remainingMarkers.remove(marker);
				}
			}
		}
	}
}
 
开发者ID:angelozerr,项目名称:ec4e,代码行数:46,代码来源:ValidateAppliedOptionsStrategy.java


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