org.eclipse.jface.text.Position类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中org.eclipse.jface.text.Position类的一些代码示例,展示了Position类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Position类的具体详情如下:
包路径:org.eclipse.jface.text.Position
类名称:Position

Position介绍

[英]Positions describe text ranges of a document. Positions are adapted to changes applied to that document. The text range is specified by an offset and a length. Positions can be marked as deleted. Deleted positions are considered to no longer represent a valid text range in the managing document.

Positions attached to documents are usually updated by position updaters. Because position updaters are freely definable and because of the frequency in which they are used, the fields of a position are made publicly accessible. Clients other than position updaters are not allowed to access these public fields.

Positions cannot be used as keys in hash tables as they override equals and hashCode as they would be value objects.
[中]位置描述文档的文本范围。根据应用于该文档的更改调整位置。文本范围由偏移量和长度指定。位置可以标记为已删除。删除的位置将被视为不再代表管理文档中的有效文本范围。
附加到文档的位置通常由位置更新程序更新。由于职位更新程序是可自由定义的,而且使用频率很高,因此职位的字段可以公开访问。不允许位置更新程序以外的客户端访问这些公共字段。
位置不能用作哈希表中的键,因为它们会重写equalshashCode,因为它们是值对象。

代码示例

代码示例来源:origin: org.eclipse.platform/org.eclipse.text

/**
 * Creates a document template context.
 *
 * @param type the context type
 * @param document the document this context applies to
 * @param offset the offset of the document region
 * @param length the length of the document region
 */
public DocumentTemplateContext(TemplateContextType type, IDocument document, int offset, int length) {
  this(type, document, new Position(offset, length));
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.text

/**
 * Returns the end offset of the keyword.
 *
 * @return the end offset of the keyword
 */
public int getEnd() {
  return fPosition.getOffset() + fPosition.getLength();
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

private boolean willAutoExpand(Position position, int offset, int length) {
  if (position == null || position.isDeleted())
    return false;
  // right or left boundary
  if (position.getOffset() == offset || position.getOffset() + position.getLength() == offset + length)
    return true;
  // completely embedded in given position
  if (position.getOffset() < offset && offset + length < position.getOffset() + position.getLength())
    return true;
  return false;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.text

private boolean isWithinRegion(Position region, Position position, boolean canStartBefore, boolean canEndAfter) {
  if (canStartBefore && canEndAfter) {
    return region.overlapsWith(position.getOffset(), position.getLength());
  } else if (canStartBefore) {
    return region.includes(position.getOffset() + position.getLength() - 1);
  } else if (canEndAfter) {
    return region.includes(position.getOffset());
  } else {
    int start= position.getOffset();
    return region.includes(start) && region.includes(start + position.getLength() - 1);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public void update(int off, int len) {
  synchronized (fLock) {
    super.setOffset(off);
    super.setLength(len);
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.search

public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException {
  int lineOffset= linePosition.getOffset();
  int lineLength= linePosition.getLength();
  
  int charOffset= doc.getLineOffset(lineOffset);
  int charLength= 0;
  if (lineLength > 0) {
    int lastLine= lineOffset+lineLength-1;
    int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine);
    charLength= endPosition-charOffset;
  }
  return new Position(charOffset, charLength);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

@Override
  public void update(DocumentEvent event) {
    int offset= event.getOffset();
    int length= event.getLength();
    int delta= event.getText().length() - length;
    if (offset < fPosition.getOffset())
      fPosition.setOffset(fPosition.getOffset() + delta);
    else if (offset < fPosition.getOffset() + fPosition.getLength())
      fPosition.setLength(fPosition.getLength() + delta);
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ui.workbench.texteditor

/**
 * Hook method which is called when the given editor has been saved.
 *
 * @param part the editor part
 */
public void partSaved(IEditorPart part) {
  // http://dev.eclipse.org/bugs/show_bug.cgi?id=25440
  if (fPosition == null || fPosition.isDeleted())
    fSavedPosition= null;
  else
    fSavedPosition= new Position(fPosition.offset, fPosition.length);
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

@Override
public int getMark() {
  return fMarkPosition == null || fMarkPosition.isDeleted() ? -1 : fMarkPosition.getOffset();
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.jface.text

/**
   * Returns <code>true</code> if inlined annotation is deleted and <code>false</code> otherwise.
   *
   * @param annotation the inlined annotation to check
   * @return <code>true</code> if inlined annotation is deleted and <code>false</code> otherwise.
   */
  private static boolean isDeleted(AbstractInlinedAnnotation annotation) {
    return annotation.isMarkedDeleted() || annotation.getPosition().isDeleted() || annotation.getPosition().getLength() == 0;
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.text

/**
   * If <code>regionOffset</code> is the end of the visible region and the <code>regionLength == 0</code>,
   * the <code>regionOffset</code> is considered overlapping with the visible region.
   *
   * @see org.eclipse.jface.text.Position#overlapsWith(int, int)
   */
  @Override
  public boolean overlapsWith(int regionOffset, int regionLength) {
    boolean appending= (regionOffset == offset + length) && regionLength == 0;
    return appending || super.overlapsWith(regionOffset, regionLength);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

@Override
public void setLength(int length) {
  synchronized (fLock) {
    super.setLength(length);
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.compare

public boolean isDeleted() {
  if (fAncestorPos != null && fAncestorPos.isDeleted())
    return true;
  return fLeftPos.isDeleted() || fRightPos.isDeleted();
}

代码示例来源:origin: org.eclipse.xtext/ui

@Override
public void setOffset(int offset) {
  synchronized (fLock) {
    super.setOffset(offset);
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.text

/**
   * Returns <code>true</code> if the receiver contains <code>position</code>.
   *
   * @param position the position to check
   * @return <code>true</code> if the receiver contains <code>position</code>
   */
  boolean contains(Position position) {
    for (LinkedPosition p : fPositions) {
      if (position.equals(p))
        return true;
    }
    return false;
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.text

private boolean isWithinRegion(int start, int length) {
    if (fCanStartBefore && fCanEndAfter)
      return fRegion.overlapsWith(start, length);
    else if (fCanStartBefore)
      return fRegion.includes(start + length - (length > 0 ? 1 : 0));
    else if (fCanEndAfter)
      return fRegion.includes(start);
    else
      return fRegion.includes(start) && fRegion.includes(start + length - (length > 0 ? 1 : 0));
  }
}

代码示例来源:origin: stackoverflow.com

public List<Position> findPath(Set<Position> closedSet, Position from, Position to) {
  if (from.equals(to)) 
     return List.of(to);
  while (from.hasNeighboursNotIn(closedSet)) {
    Position pos = from.getRandomNeighbourNotIn(closedSet);
    closedSet.add(pos);
    List<Position> path = findPath(closedSet, pos, to);
    if (!path.isEmpty())
      return List.of(pos, path);
  }
  closedSet.add(from);
  return Collection.EMPTY_LIST;
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.search

public static Position convertToCharacterPosition(Position linePosition, IDocument doc) throws BadLocationException {
  int lineOffset= linePosition.getOffset();
  int lineLength= linePosition.getLength();
  int charOffset= doc.getLineOffset(lineOffset);
  int charLength= 0;
  if (lineLength > 0) {
    int lastLine= lineOffset+lineLength-1;
    int endPosition= doc.getLineOffset(lastLine)+doc.getLineLength(lastLine);
    charLength= endPosition-charOffset;
  }
  return new Position(charOffset, charLength);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

@Override
  public void update(DocumentEvent event) {
    int offset= event.getOffset();
    int length= event.getLength();
    int delta= event.getText().length() - length;
    if (offset < fPosition.getOffset())
      fPosition.setOffset(fPosition.getOffset() + delta);
    else if (offset < fPosition.getOffset() + fPosition.getLength())
      fPosition.setLength(fPosition.getLength() + delta);
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.text

private boolean isWithinRegion(Position region, Position position, boolean canStartBefore, boolean canEndAfter) {
  if (canStartBefore && canEndAfter) {
    return region.overlapsWith(position.getOffset(), position.getLength());
  } else if (canStartBefore) {
    return region.includes(position.getOffset() + position.getLength() - 1);
  } else if (canEndAfter) {
    return region.includes(position.getOffset());
  } else {
    int start= position.getOffset();
    return region.includes(start) && region.includes(start + position.getLength() - 1);
  }
}

相关文章