本文整理匯總了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$
}
示例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());
}