private boolean includes(Position position, int caretOffset) { return position.includes(caretOffset) || (position.offset + position.length) == caretOffset; }
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)); } }
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)); } }
@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; } }
@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; } }
/** * 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; }
/** * * @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; }
/** * * @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; }
@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; } }
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); } }
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); } }
for (int i = 0; i < commentPositions.size(); i++) { Position pos = commentPositions.get(i); if (pos.includes(idx)) { valid = false; break;
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; }
for (int i = 0; i < commentPositions.size(); i++) { Position pos = (Position)commentPositions.get(i); if (pos.includes(idx)) { valid = false; break;
for (int i = 0; i < commentPositions.size(); i++) { Position pos = (Position)commentPositions.get(i); if (pos.includes(idx)) { valid = false; break;
return index; if (0 < index && index <= fragments.length && fragments[index - 1].includes(offset)) return index - 1;
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); } } }
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); } } }
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); } } }
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); } } }