本文整理汇总了Java中org.eclipse.text.edits.TextEdit.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java TextEdit.getOffset方法的具体用法?Java TextEdit.getOffset怎么用?Java TextEdit.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.text.edits.TextEdit
的用法示例。
在下文中一共展示了TextEdit.getOffset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: convertEdit
import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
private static org.eclipse.lsp4j.TextEdit convertEdit(TextEdit edit, IDocument document) {
org.eclipse.lsp4j.TextEdit textEdit = new org.eclipse.lsp4j.TextEdit();
if (edit instanceof ReplaceEdit) {
ReplaceEdit replaceEdit = (ReplaceEdit) edit;
textEdit.setNewText(replaceEdit.getText());
int offset = edit.getOffset();
textEdit.setRange( new Range(createPosition(document, offset),
createPosition(document, offset+edit.getLength())));
}
return textEdit;
}
示例3: 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;
}
示例4: isPacked
import org.eclipse.text.edits.TextEdit; //导入方法依赖的package包/类
/**
* Returns true if the given <code>edit</code> is minimal.
*
* <p>That is if:
*
* <ul>
* <li><b>true</b> if <code>edit</code> is a leaf
* <li>if <code>edit</code> is a inner node then <b>true</b> if
* <ul>
* <li><code>edit</code> has same size as all its children
* <li><code>isPacked</code> is <b>true</b> for all children
* </ul>
* </ul>
*
* @param edit the edit to verify
* @return true if edit is minimal
* @since 3.4
*/
public static boolean isPacked(TextEdit edit) {
if (!(edit instanceof MultiTextEdit)) return true;
if (!edit.hasChildren()) return true;
TextEdit[] children = edit.getChildren();
if (edit.getOffset() != children[0].getOffset()) return false;
if (edit.getExclusiveEnd() != children[children.length - 1].getExclusiveEnd()) return false;
for (int i = 0; i < children.length; i++) {
if (!isPacked(children[i])) return false;
}
return true;
}