org.eclipse.jface.text.Position.includes()方法的使用及代码示例

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

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

Position.includes介绍

[英]Checks whether the given index is inside of this position's text range.
[中]检查给定索引是否在此位置的文本范围内。

代码示例

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

private boolean includes(Position position, int caretOffset) {
  return position.includes(caretOffset)
  || (position.offset + position.length) == caretOffset;
}

代码示例来源:origin: org.eclipse.platform/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: 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: org.eclipse.scout.sdk.deps/org.eclipse.jface.text

@Override
public void lineGetBackground(LineBackgroundEvent event) {
  /* Don't use cached line information because of patched redrawing events. */
  if (fTextWidget != null) {
    int offset= widgetOffset2ModelOffset(event.lineOffset);
    if (fPosition.includes(offset))
      event.lineBackground= fHighlightColor;
  }
}

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

@Override
public void lineGetBackground(LineBackgroundEvent event) {
  /* Don't use cached line information because of patched redrawing events. */
  if (fTextWidget != null) {
    int offset= widgetOffset2ModelOffset(event.lineOffset);
    if (fPosition.includes(offset))
      event.lineBackground= fHighlightColor;
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core

/**
 * Tells you if the given offset is included in any of the ranges (Positions) passed in.
 * includeEndOffset tells whether or not to include the end offset of each range in the test.
 * 
 * @param javaOffset
 * @param ranges
 * @param includeEndOffset
 * @return
 */
private boolean isInRanges(int javaOffset, HashMap ranges, boolean includeEndOffset) {
  
  Iterator it = ranges.keySet().iterator();
  while(it.hasNext()) {
    Position javaPos = (Position)it.next();
    // also include the start and end offset (only if requested)
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81687
    if(javaPos.includes(javaOffset) || (includeEndOffset && javaPos.offset+javaPos.length == javaOffset)) 
      return true;
  }
  return false;
}

代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core

/**
 * 
 * @return the corresponding JSP offset for a give Java offset
 */
public int getJspOffset(int javaOffset) {
  int result = -1;
  int offsetInRange = 0;
  Position jspPos, javaPos = null;
  // iterate all mapped java ranges
  Iterator it = fJava2JspMap.keySet().iterator();
  while (it.hasNext()) {
    javaPos = (Position) it.next();
    // need to count the last position as included
    if (!javaPos.includes(javaOffset) && !(javaPos.offset+javaPos.length == javaOffset))
      continue;
    offsetInRange = javaOffset - javaPos.offset;
    jspPos = (Position) fJava2JspMap.get(javaPos);
    
    if(jspPos != null)
      result = jspPos.offset + offsetInRange;
    else  {
      Logger.log(Logger.ERROR, "jspPosition was null!" + javaOffset); //$NON-NLS-1$
    }
    break;
  }
  return result;
}

代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core

/**
 * 
 * @return the corresponding Java offset for a give JSP offset
 */
public int getJavaOffset(int jspOffset) {
  int result = -1;
  int offsetInRange = 0;
  Position jspPos, javaPos = null;
  // iterate all mapped jsp ranges
  Iterator it = fJsp2JavaMap.keySet().iterator();
  while (it.hasNext()) {
    jspPos = (Position) it.next();
    // need to count the last position as included
    if (!jspPos.includes(jspOffset) && !(jspPos.offset+jspPos.length == jspOffset))
      continue;
    offsetInRange = jspOffset - jspPos.offset;
    javaPos = (Position) fJsp2JavaMap.get(jspPos);
    if(javaPos != null)
      result = javaPos.offset + offsetInRange;
    else  {
      Logger.log(Logger.ERROR, "JavaPosition was null!" + jspOffset); //$NON-NLS-1$
    }
    break;
  }
  return result;
}

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

@SuppressWarnings("unchecked")
static boolean annotationsIncludeOffset(IAnnotationModel annotationModel, int offset) {
  if (annotationModel == null) {
    return false;
  }
  try {
    // eclipse 3.4
    Iterator<?> annotationIterator = (Iterator<?>) annotationModel.getClass()
        .getMethod("getAnnotationIterator", int.class, int.class, boolean.class, boolean.class).invoke( //$NON-NLS-1$
            annotationModel, offset, 1, true, true);
    return annotationIterator.hasNext();
  } catch (Exception e) {
    // eclipse 3.3
    Iterator<Annotation> annotationIterator = annotationModel.getAnnotationIterator();
    while (annotationIterator.hasNext()) {
      Position position = annotationModel.getPosition(annotationIterator.next());
      if (position != null && (position.offset == offset || position.includes(offset))) {
        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: 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);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.pde.core

for (int i = 0; i < commentPositions.size(); i++) {
  Position pos = commentPositions.get(i);
  if (pos.includes(idx)) {
    valid = false;
    break;

代码示例来源:origin: org.eclipse/org.eclipse.jst.jsp.core

public int getJspOffset(int javaOffset) {
  // copied from JSPTranslation
  int result = -1;
  int offsetInRange = 0;
  Position jspPos, javaPos = null;
  JSPTranslation trans = getJSPTranslation();
  if (trans != null) {
    HashMap java2jspMap = trans.getJava2JspMap();
    // iterate all mapped java ranges
    Iterator it = java2jspMap.keySet().iterator();
    while (it.hasNext()) {
      javaPos = (Position) it.next();
      // need to count the last position as included
      if (!javaPos.includes(javaOffset) && !(javaPos.offset + javaPos.length == javaOffset))
        continue;
      offsetInRange = javaOffset - javaPos.offset;
      jspPos = (Position) java2jspMap.get(javaPos);
      if (jspPos != null)
        result = jspPos.offset + offsetInRange;
      else {
        Logger.log(Logger.ERROR, "jspPosition was null!" + javaOffset); //$NON-NLS-1$
      }
      break;
    }
  }
  return result;
}

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

for (int i = 0; i < commentPositions.size(); i++) {
  Position pos = (Position)commentPositions.get(i);
  if (pos.includes(idx)) {
    valid = false;
    break;

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

for (int i = 0; i < commentPositions.size(); i++) {
  Position pos = (Position)commentPositions.get(i);
  if (pos.includes(idx)) {
    valid = false;
    break;

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

return index;
if (0 < index && index <= fragments.length && fragments[index - 1].includes(offset))
  return index - 1;

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

private void expand() {
  if (isProjectionMode()) {
    Position found= null;
    Annotation bestMatch= null;
    Point selection= getSelectedRange();
    for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
      ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
      if (annotation.isCollapsed()) {
        Position position= fProjectionAnnotationModel.getPosition(annotation);
        // take the first most fine grained match
        if (position != null && touches(selection, position))
          if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) {
            found= position;
            bestMatch= annotation;
          }
      }
    }
    if (bestMatch != null) {
      fProjectionAnnotationModel.expand(bestMatch);
      revealRange(selection.x, selection.y);
    }
  }
}

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

private void expand() {
  if (isProjectionMode()) {
    Position found= null;
    Annotation bestMatch= null;
    Point selection= getSelectedRange();
    for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
      ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
      if (annotation.isCollapsed()) {
        Position position= fProjectionAnnotationModel.getPosition(annotation);
        // take the first most fine grained match
        if (position != null && touches(selection, position))
          if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) {
            found= position;
            bestMatch= annotation;
          }
      }
    }
    if (bestMatch != null) {
      fProjectionAnnotationModel.expand(bestMatch);
      revealRange(selection.x, selection.y);
    }
  }
}

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

private void collapse() {
  if (isProjectionMode()) {
    Position found= null;
    Annotation bestMatch= null;
    Point selection= getSelectedRange();
    for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
      ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
      if (!annotation.isCollapsed()) {
        Position position= fProjectionAnnotationModel.getPosition(annotation);
        // take the first most fine grained match
        if (position != null && touches(selection, position))
          if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) {
            found= position;
            bestMatch= annotation;
          }
      }
    }
    if (bestMatch != null) {
      fProjectionAnnotationModel.collapse(bestMatch);
      revealRange(selection.x, selection.y);
    }
  }
}

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

private void collapse() {
  if (isProjectionMode()) {
    Position found= null;
    Annotation bestMatch= null;
    Point selection= getSelectedRange();
    for (Iterator<Annotation> e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
      ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
      if (!annotation.isCollapsed()) {
        Position position= fProjectionAnnotationModel.getPosition(annotation);
        // take the first most fine grained match
        if (position != null && touches(selection, position))
          if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) {
            found= position;
            bestMatch= annotation;
          }
      }
    }
    if (bestMatch != null) {
      fProjectionAnnotationModel.collapse(bestMatch);
      revealRange(selection.x, selection.y);
    }
  }
}

相关文章