String (@NotNull String relativeLink, @NotNull PsiElement contextElement) { String fragment = null; int hashPosition = relativeLink.indexOf('#'); if (hashPosition >= 0) { fragment = relativeLink.substring(hashPosition + 1); relativeLink = relativeLink.substring(0, hashPosition); } PsiElement targetElement; if (relativeLink.isEmpty()) { targetElement = contextElement instanceof PsiField || contextElement instanceof PsiMethod ? ((PsiMember)contextElement).getContainingClass() : contextElement; } else { if (!(StringUtil.endsWithIgnoreCase(relativeLink, ".htm") || StringUtil.endsWithIgnoreCase(relativeLink, ".html"))) { return null; } relativeLink = relativeLink.substring(0, relativeLink.lastIndexOf('.')); String packageName = getPackageName(contextElement); if (packageName == null) return null; Couple<String> pathWithPackage = removeParentReferences(relativeLink, packageName); if (pathWithPackage == null) return null; relativeLink = pathWithPackage.first; packageName = pathWithPackage.second; relativeLink = relativeLink.replace('/', '.'); String qualifiedTargetName = packageName.isEmpty() ? relativeLink : packageName + '.' + relativeLink; JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(contextElement.getProject()); targetElement = "package-summary".equals(StringUtil.getShortName(qualifiedTargetName)) ? javaPsiFacade.findPackage(StringUtil.getPackageName(qualifiedTargetName)) : javaPsiFacade.findClass(qualifiedTargetName, contextElement.getResolveScope()); } if (targetElement == null) return null; if (fragment != null && targetElement instanceof PsiClass) { if (fragment.indexOf('-') >= 0 || fragment.indexOf('(') >= 0) { for (PsiMethod method : ((PsiClass)targetElement).getMethods()) { Set<String> signatures = JavaDocumentationProvider.getHtmlMethodSignatures(method, null); if (signatures.contains(fragment)) { targetElement = method; fragment = null; break; } } } else { for (PsiField field : ((PsiClass)targetElement).getFields()) { if (fragment.equals(field.getName())) { targetElement = field; fragment = null; break; } } } } StringBuilder builder = new StringBuilder(); builder.append(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL); builder.append(JavaDocUtil.getReferenceText(targetElement.getProject(), targetElement)); if (fragment != null) { builder.append(DocumentationManagerProtocol.PSI_ELEMENT_PROTOCOL_REF_SEPARATOR).append(fragment); } return builder.toString(); }