Role for linking to external Javadoc

def javadoc_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    """ Role for linking to external Javadoc """

    has_explicit_title, title, target = split_explicit_title(text)
    title = utils.unescape(title)
    target = utils.unescape(target)

    if not has_explicit_title:
        target = target.lstrip('~')

        if title[0] == '~':
            title = title[1:].rpartition('.')[2]

    app = inliner.document.settings.env.app
    ref = get_javadoc_ref(app, rawtext, target)

    if not ref:
         raise ValueError("no Javadoc source found for %s in javadoc_url_map" % (target,))

    ref.append(nodes.Text(title, title))

    return [ref], []