/** * Convert line, column to a document offset. * @param buffer * @param line * @param column * @return */ public static int toOffset(IBuffer buffer, int line, int column){ if (buffer != null) { return toOffset(toDocument(buffer), line, column); } return -1; }
private List<DocumentHighlight> computeOccurrences(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { if (unit != null) { try { int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); OccurrencesFinder finder = new OccurrencesFinder(); CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor); if (ast != null) { String error = finder.initialize(ast, offset, 0); if (error == null){ List<DocumentHighlight> result = new ArrayList<>(); OccurrenceLocation[] occurrences = finder.getOccurrences(); if (occurrences != null) { for (OccurrenceLocation loc : occurrences) { if (monitor.isCanceled()) { return Collections.emptyList(); } result.add(convertToHighlight(unit, loc)); } } return result; } } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem with compute occurrences for" + unit.getElementName(), e); } } return Collections.emptyList(); }
/** * Gets the end offset for the diagnostic. * * @param unit * @param range * @return starting offset or negative value if can not be determined */ public static int getEndOffset(ICompilationUnit unit, Range range){ try { return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getEnd().getLine(), range.getEnd().getCharacter()); } catch (JavaModelException e) { return -1; } }
/** * Gets the start offset for the diagnostic. * * @param unit * @param range * @return starting offset or negative value if can not be determined */ public static int getStartOffset(ICompilationUnit unit, Range range){ try { return JsonRpcHelpers.toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter()); } catch (JavaModelException e) { return -1; } } /**
IType type = resolveType(frame); if (type != null && type.getCompilationUnit() != null) { final int offset = JsonRpcHelpers.toOffset(type.getCompilationUnit().getBuffer(), frame.location().lineNumber(), 0); CompletionProposalRequestor collector = new CompletionProposalRequestor(type.getCompilationUnit(), offset);
return null; int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); if (offset > -1) { return unit.codeSelect(offset, 0);
final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); CompletionProposalRequestor collector = new CompletionProposalRequestor(unit, offset);
final int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), position.getPosition().getLine(), position.getPosition().getCharacter()); int[] contextInfomation = getContextInfomation(unit.getBuffer(), offset); if (contextInfomation[0] == -1) {
int startOffset = JsonRpcHelpers.toOffset(unit.getBuffer(), range.getStart().getLine(), range.getStart().getCharacter());
private Location computeTypeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { try { CompilationUnit ast = CoreASTProvider.getInstance().getAST(unit, CoreASTProvider.WAIT_YES, monitor); int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), line, column); if (ast == null || offset < 0) { return null;
int offset = JsonRpcHelpers.toOffset(unit.getBuffer(), params.getPosition().getLine(), params.getPosition().getCharacter()); String error = finder.initialize(ast, offset, 0); if (error == null) {