本文整理匯總了Java中org.eclipse.text.edits.TextEdit.getLength方法的典型用法代碼示例。如果您正苦於以下問題:Java TextEdit.getLength方法的具體用法?Java TextEdit.getLength怎麽用?Java TextEdit.getLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.text.edits.TextEdit
的用法示例。
在下文中一共展示了TextEdit.getLength方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: coveredBy
import org.eclipse.text.edits.TextEdit; //導入方法依賴的package包/類
private boolean coveredBy(TextEditBasedChangeGroup group, IRegion sourceRegion) {
int sLength = sourceRegion.getLength();
if (sLength == 0) return false;
int sOffset = sourceRegion.getOffset();
int sEnd = sOffset + sLength - 1;
TextEdit[] edits = group.getTextEdits();
for (int i = 0; i < edits.length; i++) {
TextEdit edit = edits[i];
if (edit.isDeleted()) return false;
int rOffset = edit.getOffset();
int rLength = edit.getLength();
int rEnd = rOffset + rLength - 1;
if (rLength == 0) {
if (!(sOffset < rOffset && rOffset <= sEnd)) return false;
} else {
if (!(sOffset <= rOffset && rEnd <= sEnd)) return false;
}
}
return true;
}
示例2: createRangeMarkers
import org.eclipse.text.edits.TextEdit; //導入方法依賴的package包/類
private List<TypedPosition> createRangeMarkers(TemplateVariable[] variables, IDocument document)
throws MalformedTreeException, BadLocationException {
Map<ReplaceEdit, String> markerToOriginal = new HashMap<ReplaceEdit, String>();
MultiTextEdit root = new MultiTextEdit(0, document.getLength());
List<TextEdit> edits = new ArrayList<TextEdit>();
boolean hasModifications = false;
for (int i = 0; i != variables.length; i++) {
final TemplateVariable variable = variables[i];
int[] offsets = variable.getOffsets();
String value = variable.getDefaultValue();
if (isWhitespaceVariable(value)) {
// replace whitespace positions with unformattable comments
String placeholder = COMMENT_START + value + COMMENT_END;
for (int j = 0; j != offsets.length; j++) {
ReplaceEdit replace = new ReplaceEdit(offsets[j], value.length(), placeholder);
root.addChild(replace);
hasModifications = true;
markerToOriginal.put(replace, value);
edits.add(replace);
}
} else {
for (int j = 0; j != offsets.length; j++) {
RangeMarker marker = new RangeMarker(offsets[j], value.length());
root.addChild(marker);
edits.add(marker);
}
}
}
if (hasModifications) {
// update the document and convert the replaces to markers
root.apply(document, TextEdit.UPDATE_REGIONS);
}
List<TypedPosition> positions = new ArrayList<TypedPosition>();
for (Iterator<TextEdit> it = edits.iterator(); it.hasNext(); ) {
TextEdit edit = it.next();
try {
// abuse TypedPosition to piggy back the original contents of the position
final TypedPosition pos =
new TypedPosition(edit.getOffset(), edit.getLength(), markerToOriginal.get(edit));
document.addPosition(CATEGORY, pos);
positions.add(pos);
} catch (BadPositionCategoryException x) {
Assert.isTrue(false);
}
}
return positions;
}