private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); if (d!=0) return d; return p1.getCharacter() - p2.getCharacter(); } };
Position clone(Position position) { if (position == null) { return null; } int line = position.getLine(); int character = position.getCharacter(); Position cloned = new Position(); cloned.setLine(line); cloned.setCharacter(character); return cloned; } }
private static void setPosition(Position position, int[] coords) { assert coords.length == 2; position.setLine(coords[0]); position.setCharacter(coords[1]); }
public Position toPosition(int offset) { int line = lineNumber(offset); int startOfLine = startOfLine(line); int column = offset - startOfLine; Position pos = new Position(); pos.setCharacter(column); pos.setLine(line); return pos; }
if (((position.getLine() == line) && (position.getCharacter() == column))) { return i; if (((position.getLine() == line) && (position.getCharacter() == column))) { return l; String _string = position.toString(); String _xifexpression = null; if (this.printSourceOnError) {
Pair<BLangNode, Object> bLangNodePair = getBLangNode(line, column, docUri, docManager, lsCompiler, context); Position position = new Position(0, 0); Range focus = new Range(position, position); BiConsumer<Integer, Integer> focusLineAcceptor = (focusLine, incrementer) -> { if (focusLine != null) { position.setLine(focusLine); position.setLine(position.getLine() + incrementer); }; List<TextEdit> content = TestGenerator.generate(docManager, bLangNodePair, focusLineAcceptor,
/** * Get the number of lines in the document. Empty document has line count: {@code 1}. */ public int getLineCount() { int _line = this.getPosition(this.contents.length()).getLine(); return (_line + 1); }
public PositionTreeVisitor(LSContext context) { this.context = context; this.position = context.get(DocumentServiceKeys.POSITION_KEY).getPosition(); this.symTable = SymbolTable.getInstance(context.get(DocumentServiceKeys.COMPILER_CONTEXT_KEY)); this.position.setLine(this.position.getLine() + 1); this.nodeStack = new Stack<>(); this.context.put(NodeContextKeys.NODE_STACK_KEY, nodeStack); }
ch = document.getChar(pos); range.getEnd().setCharacter(range.getEnd().getCharacter() + length); length = 1; pos = offset - 1; range.getStart().setCharacter(range.getStart().getCharacter() - length); replacement = checkReplacementEnd(document, replacement, offset); } else if (proposal.getKind() == CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION) { range.getEnd().setCharacter(range.getEnd().getCharacter() + length);
@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Range other = (Range) obj; if (this.start == null) { if (other.start != null) return false; } else if (!this.start.equals(other.start)) return false; if (this.end == null) { if (other.end != null) return false; } else if (!this.end.equals(other.end)) return false; return true; }
/** * 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; }
private static Position createPosition(IDocument document, int offset) { Position start = new Position(); try { int lineOfOffset = document.getLineOfOffset(offset); start.setLine(Integer.valueOf(lineOfOffset)); start.setCharacter(Integer.valueOf(offset - document.getLineOffset(lineOfOffset))); } catch (BadLocationException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); } return start; }
TextPosition cursorPosition = editor.getCursorPosition(); org.eclipse.lsp4j.Position position = dtoFactory.createDto(org.eclipse.lsp4j.Position.class); position.setCharacter(cursorPosition.getCharacter()); position.setLine(cursorPosition.getLine()); params.setPosition(position); String location =
/** * Add the top level node to context if cursor position matches the line of signature. * * @param node node to be compared and added to the context */ private void addTopLevelNodeToContext(BLangNode node, String name, PackageID currentPkg, String symbolKindOfParentNode, String symbolKindOfCurrentNode, BSymbol owner) { if (node.getPosition().sLine == this.position.getLine()) { addPosition(node, this.previousNode, name, currentPkg, symbolKindOfCurrentNode, symbolKindOfParentNode, name, owner); } }
@Override @Pure public boolean equals(final Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Range other = (Range) obj; if (this.start == null) { if (other.start != null) return false; } else if (!this.start.equals(other.start)) return false; if (this.end == null) { if (other.end != null) return false; } else if (!this.end.equals(other.end)) return false; return true; }
@Test public void testContains_invalidPosition() { Position position = position(-1, -1); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage(String.format("position is not valid: %s", position.toString())); Ranges.contains(Ranges.createRange(4, 4, 4, 4), position); }
private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); if (d!=0) return d; return p1.getCharacter() - p2.getCharacter(); } };
@SuppressWarnings("restriction") private static Range convertRange(IOpenable openable, IProblem problem) { try { return JDTUtils.toRange(openable, problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1); } catch (CoreException e) { // In case failed to open the IOpenable's buffer, use the IProblem's information to calculate the range. Position start = new Position(); Position end = new Position(); start.setLine(problem.getSourceLineNumber() - 1);// The protocol is 0-based. end.setLine(problem.getSourceLineNumber() - 1); if (problem instanceof DefaultProblem) { DefaultProblem dProblem = (DefaultProblem) problem; start.setCharacter(dProblem.getSourceColumnNumber() - 1); int offset = 0; if (dProblem.getSourceStart() != -1 && dProblem.getSourceEnd() != -1) { offset = dProblem.getSourceEnd() - dProblem.getSourceStart() + 1; } end.setCharacter(dProblem.getSourceColumnNumber() - 1 + offset); } return new Range(start, end); } }