XSourcePositionImpl (@Nullable VirtualFile file, final int offset) { if (file == null) return null; return new XSourcePositionImpl(file) { private final NotNullLazyValue<Integer> myLine = NotNullLazyValue.atomicLazy(() -> { return ReadAction.compute(() -> { Document document = FileDocumentManager.getInstance().getDocument(file); if (document == null) { return -1; } return DocumentUtil.isValidOffset(offset, document) ? document.getLineNumber(offset) : -1; }); }); @Override public int getLine() { return myLine.getValue(); } @Override public int getOffset() { return offset; } }; }