當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.replace方法代碼示例

本文整理匯總了Java中org.eclipse.jface.text.Document.replace方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.replace方法的具體用法?Java Document.replace怎麽用?Java Document.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jface.text.Document的用法示例。


在下文中一共展示了Document.replace方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cutIndent

import org.eclipse.jface.text.Document; //導入方法依賴的package包/類
/**
 * Cuts the visual equivalent of <code>toDelete</code> characters out of the
 * indentation of line <code>line</code> in <code>document</code>. Leaves
 * leading comment signs alone.
 *
 * @param document the document
 * @param line the line
 * @param toDelete the number of space equivalents to delete
 * @param tabLength the length of a tab
 * @throws BadLocationException on concurrent document modification
 */
private void cutIndent(Document document, int line, int toDelete, int tabLength) throws BadLocationException {
	IRegion region= document.getLineInformation(line);
	int from= region.getOffset();
	int endOffset= region.getOffset() + region.getLength();

	// go behind line comments
	while (from < endOffset - 2 && document.get(from, 2).equals(LINE_COMMENT))
		from += 2;

	int to= from;
	while (toDelete > 0 && to < endOffset) {
		char ch= document.getChar(to);
		if (!Character.isWhitespace(ch))
			break;
		toDelete -= computeVisualLength(ch, tabLength);
		if (toDelete >= 0)
			to++;
		else
			break;
	}

	document.replace(from, to - from, ""); //$NON-NLS-1$
}
 
開發者ID:angelozerr,項目名稱:typescript.java,代碼行數:35,代碼來源:TypeScriptAutoIndentStrategy.java

示例2: addIndent

import org.eclipse.jface.text.Document; //導入方法依賴的package包/類
/**
 * Indents line <code>line</code> in <code>document</code> with <code>indent</code>.
 * Leaves leading comment signs alone.
 *
 * @param document the document
 * @param line the line
 * @param indent the indentation to insert
 * @param tabLength the length of a tab
 * @throws BadLocationException on concurrent document modification
 */
private void addIndent(Document document, int line, CharSequence indent, int tabLength) throws BadLocationException {
	IRegion region= document.getLineInformation(line);
	int insert= region.getOffset();
	int endOffset= region.getOffset() + region.getLength();

	// Compute insert after all leading line comment markers
	int newInsert= insert;
	while (newInsert < endOffset - 2 && document.get(newInsert, 2).equals(LINE_COMMENT))
		newInsert += 2;

	// Heuristic to check whether it is commented code or just a comment
	if (newInsert > insert) {
		int whitespaceCount= 0;
		int i= newInsert;
		while (i < endOffset - 1) {
			 char ch= document.get(i, 1).charAt(0);
			 if (!Character.isWhitespace(ch))
				 break;
			 whitespaceCount= whitespaceCount + computeVisualLength(ch, tabLength);
			 i++;
		}

		if (whitespaceCount != 0 && whitespaceCount >= /*CodeFormatterUtil.getIndentWidth(fProject)*/ fProject.getFormatOptions().getIndentSize())
			insert= newInsert;
	}

	// Insert indent
	document.replace(insert, 0, indent.toString());
}
 
開發者ID:angelozerr,項目名稱:typescript.java,代碼行數:40,代碼來源:TypeScriptAutoIndentStrategy.java


注:本文中的org.eclipse.jface.text.Document.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。