void (@NotNull JBPopup popup, @NotNull Editor editor, int line) { RelativePoint point = getPositionForPopup(editor, line); if (point != null) { popup.addListener(new JBPopupListener() { @Override public void beforeShown(@NotNull LightweightWindowEvent event) { Window window = popup.isDisposed() ? null : ComponentUtil.getWindow(popup.getContent()); if (window != null) { Point expected = point.getScreenPoint(); Rectangle screen = ScreenUtil.getScreenRectangle(expected); int y = expected.y - window.getHeight() - editor.getLineHeight(); if (screen.y < y) window.setLocation(window.getX(), y); } } }); popup.show(point); } else { Project project = editor.getProject(); if (project != null) { popup.showCenteredInCurrentWindow(project); } else { popup.showInFocusCenter(); } } }