@Override
        public void setVisible(boolean visible) {
            if (visible && this.tooltipAnchorLine >= 0 && editor.getDocument() != null && editor.getTextViewer() != null) {
                try {
                    IRegion modelLineRange = editor.getDocument().getLineInformation(this.tooltipAnchorLine);
                    IRegion visualLineRange = editor.getTextViewer().modelRange2WidgetRange(modelLineRange);
                    StyledText widget = editor.getTextViewer().getTextWidget();
                    int offset = visualLineRange.getOffset();
                    Rectangle localLineBounds =  widget.getTextBounds(offset, offset + visualLineRange.getLength() - 1);
                    Rectangle globalLineBounds = Geometry.toDisplay(widget, localLineBounds);
                    Rectangle globalWidgetBounds = Geometry.toDisplay(widget, widget.getBounds());

                    int y = Math.min(
                        globalLineBounds.y + globalLineBounds.height,
                        globalWidgetBounds.y + globalWidgetBounds.height - widget.getHorizontalBar().getSize().y
                    );
                    boolean hasTooltipRanAway = !globalWidgetBounds.intersects(this.getBounds());

                    Rectangle adjustedBounds = new Rectangle(globalLineBounds.x, y, globalLineBounds.width, globalLineBounds.height);
                    if (this.getBounds().intersects(adjustedBounds) || hasTooltipRanAway) {
                        int x = hasTooltipRanAway
                            ? Math.min(widget.getDisplay().getCursorLocation().x, globalLineBounds.x)
                            : this.getBounds().x;
                        this.setLocation(new Point(x, y));
                    }
                    super.getShell().pack(true);
                } catch (BadLocationException e) {
                    // nah, no way to adjust position
                }
            }
            super.setVisible(visible);
        }
Show info from annotations on the specified line
plugins/org.jkiss.dbeaver.ui.editors.sql/src/org/jkiss/dbeaver/ui/editors/sql/util/SQLAnnotationHover.java