当前位置: 首页>>代码示例>>Java>>正文


Java TextEdit.getLength方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:21,代码来源:CompilationUnitChangeNode.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:53,代码来源:JavaFormatter.java


注:本文中的org.eclipse.text.edits.TextEdit.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。