private static void correctLocation(@NotNull Editor editor,
                                      @NotNull JComponent tooltipComponent,
                                      @NotNull Point p,
                                      boolean alignToRight,
                                      boolean expanded,
                                      int currentWidth) {
    JComponent editorComponent = editor.getComponent();
    JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();

    int widthLimit = layeredPane.getWidth() - 10;
    int heightLimit = layeredPane.getHeight() - 5;

    Dimension dimension =
      correctLocation(editor, p, alignToRight, expanded, tooltipComponent, layeredPane, widthLimit, heightLimit, currentWidth);

    // in order to restrict tooltip size
    tooltipComponent.setSize(dimension);
    tooltipComponent.setMaximumSize(dimension);
    tooltipComponent.setMinimumSize(dimension);
    tooltipComponent.setPreferredSize(dimension);
  }
private static void correctLocation(@NotNull Editor editor,
                                      @NotNull JComponent tooltipComponent,
                                      @NotNull Point p,
                                      boolean alignToRight,
                                      boolean expanded,
                                      int currentWidth)