當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。