/** * Determines the position of a snippet of text in the document. * * @param contextSnippet A larger snippet containing the actual snippet to look for. * This larger snippet is used to narrow the section of the document * where we look for the actual snippet. This is useful when the snippet * occurs multiple times in the document. * @param focusSnippet The snippet to look for */ public Position positionOf(String longSnippet, String focusSnippet) throws Exception { Range r = rangeOf(longSnippet, focusSnippet); return r==null?null:r.getStart(); }
/** * {@code true} if the {@code smaller} {@link Range range} is inside or equal to * the {@code bigger} range. Otherwise, {@code false}. */ public static boolean containsRange(Range bigger, Range smaller) { Preconditions.checkNotNull(bigger, "bigger"); Preconditions.checkNotNull(smaller, "smaller"); return containsPosition(bigger, smaller.getStart()) && containsPosition(bigger, smaller.getEnd()); }
/** * Returns whether the given range contains the given position, inclusively. */ public static boolean contains(Range range, Position position) { checkArgument(isValid(range), String.format("range is not valid: %s", range.toString())); checkArgument(isValid(position), String.format("position is not valid: %s", position.toString())); return POSITION_COMPARATOR.compare(range.getStart(), position) <= 0 && POSITION_COMPARATOR.compare(range.getEnd(), position) >= 0; }
/** * {@code true} if the {@code smaller} {@link Range range} is inside or equal to * the {@code bigger} range. Otherwise, {@code false}. */ public static boolean containsRange(Range bigger, Range smaller) { Preconditions.checkNotNull(bigger, "bigger"); Preconditions.checkNotNull(smaller, "smaller"); return containsPosition(bigger, smaller.getStart()) && containsPosition(bigger, smaller.getEnd()); }
public String getText(Range rng) { String txt = getText(); int start = Math.max(0, toOffset(rng.getStart())); int end = Math.min(txt.length(), toOffset(rng.getEnd())); return txt.substring(start, end); }
private String problemSumary(Editor editor, List<Diagnostic> actualProblems) throws Exception { StringBuilder buf = new StringBuilder(); for (Diagnostic p : actualProblems) { buf.append("\n----------------------\n"); String snippet = editor.getText(p.getRange()); buf.append("("+p.getRange().getStart().getLine()+", "+p.getRange().getStart().getCharacter()+")["+snippet+"]:\n"); buf.append(" "+p.getMessage()); } return buf.toString(); }
public String getSubstring(final Range range) { final int start = this.getOffSet(range.getStart()); final int end = this.getOffSet(range.getEnd()); return this.contents.substring(start, end); }
/** * {@code true} if the {@link Position position} is either inside or on the * border of the {@link Range range}. Otherwise, {@code false}. */ public static boolean containsPosition(Range range, Position position) { Preconditions.checkNotNull(range, "range"); Preconditions.checkNotNull(position, "position"); return (range.getStart().equals(position) || Positions.isBefore(range.getStart(), position) && (range.getEnd().equals(position) || Positions.isBefore(position, range.getEnd()))); }
/** * {@code true} if the {@link Position position} is either inside or on the * border of the {@link Range range}. Otherwise, {@code false}. */ public static boolean containsPosition(Range range, Position position) { Preconditions.checkNotNull(range, "range"); Preconditions.checkNotNull(position, "position"); return (range.getStart().equals(position) || Positions.isBefore(range.getStart(), position) && (range.getEnd().equals(position) || Positions.isBefore(position, range.getEnd()))); }
/** * Returns whether range1 and range2 intersect. Assumes that a range is inclusive on its start and exclusive on its * end, which means that if range1 ends on the same position as range2 starts, this is not considered intersecting. */ public static boolean intersects(Range range1, Range range2) { checkArgument(isValid(range1), String.format("range1 is not valid: %s", range1.toString())); checkArgument(isValid(range2), String.format("range2 is not valid: %s", range2.toString())); Position maxStart = max(range1.getStart(), range2.getStart()); Position minEnd = min(range1.getEnd(), range2.getEnd()); return POSITION_COMPARATOR.compare(maxStart, minEnd) < 0; }
public static Condition<Diagnostic> isDiagnosticOnLine(int line) { return new Condition<>( (d) -> d.getRange().getStart().getLine()==line, "Diagnostic on line "+line ); }
public RangeDto(org.eclipse.lsp4j.Range o) { if (o.getStart() == null) { setStart((org.eclipse.lsp4j.Position)null); } else { org.eclipse.lsp4j.Position startVal = new PositionDto(o.getStart()); setStart((org.eclipse.lsp4j.Position)startVal); } if (o.getEnd() == null) { setEnd((org.eclipse.lsp4j.Position)null); } else { org.eclipse.lsp4j.Position endVal = new PositionDto(o.getEnd()); setEnd((org.eclipse.lsp4j.Position)endVal); } }
@Override public int compare(Diagnostic o1, Diagnostic o2) { int diff = compare(o1.getRange().getStart(), o2.getRange().getStart()); if (diff!=0) return diff; diff = compare(o1.getRange().getEnd(), o2.getRange().getEnd()); if (diff!=0) return diff; return o1.getMessage().compareTo(o2.getMessage()); }
private IRegion getRegion(Range range, IDocument document) { try { int offset = document.getLineOffset(range.getStart().getLine()) + range.getStart().getCharacter(); int endOffset = document.getLineOffset(range.getEnd().getLine()) + range.getEnd().getCharacter(); int length = endOffset - offset; return new Region(offset, length); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return null; }
Range clone(Range range) { if (range == null) { return null; } Position start = range.getStart(); Position end = range.getEnd(); Range cloned = new Range(); cloned.setStart(clone(start)); cloned.setEnd(clone(end)); return cloned; }
private CodeLens getCodeLens(String type, IJavaElement element, ITypeRoot typeRoot) throws JavaModelException { ISourceRange r = ((ISourceReference) element).getNameRange(); if (r == null) { return null; } CodeLens lens = new CodeLens(); final Range range = JDTUtils.toRange(typeRoot, r.getOffset(), r.getLength()); lens.setRange(range); String uri = ResourceUtils.toClientUri(JDTUtils.toUri(typeRoot)); lens.setData(Arrays.asList(uri, range.getStart(), type)); return lens; }
private static ExtendedTextEdit doConvert(TextEdit edit, StringBuilder currentLine) { ExtendedTextEdit extendedEdit = new ExtendedTextEdit(); extendedEdit.setRange(edit.getRange()); extendedEdit.setNewText(edit.getNewText()); extendedEdit.setLineText(currentLine.toString()); extendedEdit.setInLineStart(edit.getRange().getStart().getCharacter()); if (edit.getRange().getEnd().getLine() == edit.getRange().getStart().getLine()) { extendedEdit.setInLineEnd(edit.getRange().getEnd().getCharacter()); } else { extendedEdit.setInLineEnd(Math.max(0, currentLine.length() - 1)); } return extendedEdit; }
public List<? extends TextEdit> format(final Document document, final XtextResource resource, final DocumentRangeFormattingParams params, final CancelIndicator cancelIndicator) { final int offset = document.getOffSet(params.getRange().getStart()); int _offSet = document.getOffSet(params.getRange().getEnd()); final int length = (_offSet - offset); boolean _hasFormatOverride = FormattingService.OverrideChecker.hasFormatOverride(this.getClass()); if (_hasFormatOverride) { return this.format(resource, document, offset, length); } return this.format(resource, document, offset, length, params.getOptions()); }