private Object getHoverInfoImpl(ITextViewer textViewer, IRegion hoverRegion, Integer anchorLine) {
        if (!(textViewer instanceof ISourceViewer)) {
            return null;
        }
        Map<String, AnnotationsGroupInfo> linkGroupsByMessage = new HashMap<>();
        IAnnotationModel annotationModel = ((ISourceViewer) textViewer).getAnnotationModel();
        for (Iterator<Annotation> ai = annotationModel.getAnnotationIterator(); ai.hasNext(); ) {
            Annotation anno = ai.next();
            if (isSupportedAnnotation(anno)) {
                Position annoPosition = annotationModel.getPosition(anno);
                if (annoPosition != null) {
                    if (annoPosition.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
                        linkGroupsByMessage.computeIfAbsent(anno.getText(), AnnotationsGroupInfo::new).add(anno, annoPosition);
                    }
                }
            }
        }

        if (linkGroupsByMessage.isEmpty()) {
            return null;
        } else {
            List<AnnotationsGroupInfo> annotationsGroups = linkGroupsByMessage.values().stream()
                .sorted(Comparator.comparing(g -> g.getFirstPosition().getOffset()))
                .toList();

            if (anchorLine == null) {
                Position lastAnnotationPos = annotationsGroups.stream().max(Comparator.comparing(
                    g -> g.getLastPosition().getOffset() + g.getLastPosition().getLength()
                )).get().getLastPosition();
                int lastAnnotationOffset = lastAnnotationPos.getOffset() + lastAnnotationPos.getLength();
                try {
                    anchorLine = editor.getDocument().getLineOfOffset(lastAnnotationOffset);
                } catch (BadLocationException e) {
                    log.debug("Error obtaining anchor line of annotation offset " + lastAnnotationPos, e);
                    try {
                        anchorLine = editor.getDocument().getLineOfOffset(hoverRegion.getOffset());
                    } catch (BadLocationException ex) {
                        log.debug("Error obtaining anchor line of hover region offset " + hoverRegion.getOffset(), e);
                        anchorLine = -1;
                    }
                }
            }
            return new AnnotationsHoverInfo(annotationsGroups, anchorLine);
        }
    }
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