class JellyHyperlinkProvider implements HyperlinkProviderExt {

    static @CheckForNull String correspondingJellyResource(Document doc, int offset) {
        int[] span = hyperlinkSpan(doc, offset);
        if (span[1] == 0) {
            return null;
        }
        try {
            String fqn = doc.getText(span[0], span[1] - span[0]);
            int colon = fqn.indexOf(':');
            assert colon != -1 : fqn;
            String prefix = fqn.substring(0, colon);
            String element = fqn.substring(colon + 1);
            String all = doc.getText(0, doc.getLength());
            String decl = "xmlns:" + prefix + "=\"/";
            int declStart = all.indexOf(decl);
            if (declStart == -1) {
                return null;
            }
            int path = declStart + decl.length() - /* '/' */1;
            int end = all.indexOf('"', path);
            if (end == -1) {
                return null;
            }
            return all.substring(path, end) + "/" + element + ".jelly";
        } catch (BadLocationException x) {
            Exceptions.printStackTrace(x);
            return null;
        }
    }

}