public void testDocAfterNew() throws Exception { createClass("public class Time { Time() {} Time(long time) {} }"); String path = "/docAfterNew"; configureByFile(path + "/before1.java"); assertTrue(myItems != null && myItems.length >= 1); String doc = new JavaDocumentationProvider().generateDoc( (PsiClass)myItems[0].getObject(), myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()) ); assertEquals(doc, "<html>Candidates for new <b>Time</b>() are:<br> <a href=\"psi_element://Time#Time()\">Time()</a><br> " + " <a href=\"psi_element://Time#Time(long)\">Time(long time)</a><br></html>"); }
@Override public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { ExtensionPoint extensionPoint = findExtensionPoint(element); if (extensionPoint == null) return null; final PsiClass epClass = getExtensionPointClass(extensionPoint); if (epClass != null) { StringBuilder sb = new StringBuilder(); sb.append("<em>EP Definition</em><br/>"); final String quickInfo = StringUtil.notNullize(getQuickNavigateInfo(element, originalElement)); sb.append(quickInfo); sb.append("<br/>"); sb.append("<br/>"); sb.append("<em>EP Implementation</em>"); sb.append(JavaDocumentationProvider.generateExternalJavadoc(epClass)); return sb.toString(); } return null; }
private static String generateClassInfo(PsiClass aClass) { StringBuilder buffer = new StringBuilder(); GroovyFile file = (GroovyFile)aClass.getContainingFile(); String packageName = file.getPackageName(); if (!packageName.isEmpty()) { buffer.append(packageName).append("\n"); } final String classString = aClass.isInterface() ? "interface" : aClass instanceof PsiTypeParameter ? "type parameter" : aClass.isEnum() ? "enum" : "class"; buffer.append(classString).append(" ").append(aClass.getName()); JavaDocumentationProvider.generateTypeParameters(aClass, buffer); JavaDocumentationProvider.writeExtends(aClass, buffer, aClass.getExtendsListTypes()); JavaDocumentationProvider.writeImplements(aClass, buffer, aClass.getImplementsListTypes()); return buffer.toString(); }
public void testEnumConstantOrdinal() throws Exception { PsiClass psiClass = getTestClass(); PsiField field = psiClass.getFields() [0]; String docInfo = new JavaDocumentationProvider().generateDoc(field, field); assertNotNull(docInfo); assertEquals(exampleHtmlFileText(getTestName(true)), replaceEnvironmentDependentContent(docInfo)); docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(field, field); assertNotNull(docInfo); assertEquals(exampleHtmlFileText(getTestName(true) + "_quick"), replaceEnvironmentDependentContent(docInfo)); }
public void testClickableFieldReference() throws Exception { PsiClass aClass = getTestClass(); PsiTypeElement element = aClass.getFields()[0].getTypeElement(); assertNotNull(element); PsiJavaCodeReferenceElement innermostComponentReferenceElement = element.getInnermostComponentReferenceElement(); assertNotNull(innermostComponentReferenceElement); String docInfo = new JavaDocumentationProvider().generateDoc(innermostComponentReferenceElement.resolve(), element); assertNotNull(docInfo); assertEquals(exampleHtmlFileText(getTestName(true)), replaceEnvironmentDependentContent(docInfo)); }
public void testClassTypeParamsPresentation() throws Exception { PsiClass psiClass = getTestClass(); final PsiReferenceList extendsList = psiClass.getExtendsList(); assertNotNull(extendsList); final PsiJavaCodeReferenceElement referenceElement = extendsList.getReferenceElements()[0]; final PsiClass superClass = extendsList.getReferencedTypes()[0].resolve(); String docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(superClass, referenceElement); assertNotNull(docInfo); assertEquals(exampleHtmlFileText(getTestName(true)), replaceEnvironmentDependentContent(docInfo)); }
protected void doTest(String text, String... expected) { myFixture.configureByText("Test.java", text); PsiElement elementAtCaret = myFixture.getElementAtCaret(); PsiMethod member = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethod.class, false); assertNotNull(member); List<String> urls = JavaDocumentationProvider.getExternalJavaDocUrl(member); assertNotNull(urls); List<String> actual = ContainerUtil.map(urls, new Function<String, String>() { @Override public String fun(String url) { return url.substring(url.indexOf('#') + 1); } }); assertOrderedEquals(actual, expected); }
@Override @Nullable public List<String> getUrlFor(PsiElement element, PsiElement originalElement) { List<String> result = new ArrayList<String>(); PsiElement docElement = getDocumentationElement(element, originalElement); if (docElement != null) { ContainerUtil.addIfNotNull(result, docElement.getUserData(NonCodeMembersHolder.DOCUMENTATION_URL)); } List<String> list = JavaDocumentationProvider.getExternalJavaDocUrl(element); if (list != null) { result.addAll(list); } return result.isEmpty() ? null : result; }
public void testEnumConstantOrdinal() throws Exception { PsiClass psiClass = getTestClass(); PsiField field = psiClass.getFields() [0]; final File htmlPath = new File(JavaTestUtil.getJavaTestDataPath() + "/codeInsight/javadocIG/" + getTestName(true) + ".html"); String htmlText = FileUtil.loadFile(htmlPath); String docInfo = new JavaDocumentationProvider().getQuickNavigateInfo(field, field); assertNotNull(docInfo); assertEquals(StringUtil.convertLineSeparators(htmlText.trim()), StringUtil.convertLineSeparators(docInfo.trim())); }
private void doTest(String text, String... expectedSignature) { myFixture.configureByText("Test.java", text); final PsiElement elementAtCaret = myFixture.getElementAtCaret(); final PsiMethod member = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethod.class, false); assertNotNull(member); final String signature = JavaDocumentationProvider.formatMethodSignature(member); assertNotNull(signature); assertEquals("found:" + signature, expectedSignature[0], signature); }
@Override public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) { if (originalElement == null) return null; if (originalElement.getLanguage() == XMLLanguage.INSTANCE || DevKitInspectionBase.isPluginXml(originalElement.getContainingFile())) { final PsiElement context = element.getContext(); String fqn = null; if (originalElement instanceof XmlToken && ((XmlToken)originalElement).getTokenType() == XmlTokenType.XML_NAME) { PsiElement attr; PsiElement tag; if (context != null && (attr = context.getParent()) instanceof XmlAttribute && (tag = attr.getParent()) instanceof XmlTag) { final String interfaceFqn = ((XmlTag)tag).getAttributeValue("interface"); final String beanClassFqn = ((XmlTag)tag).getAttributeValue("beanClass"); fqn = interfaceFqn == null ? beanClassFqn : interfaceFqn; } } if (fqn != null) { final Project project = element.getProject(); final PsiClass psiClass = JavaPsiFacade.getInstance(project).findClass(fqn, GlobalSearchScope.allScope(project)); if (psiClass != null) { return new JavaDocumentationProvider().generateExternalJavadoc(psiClass); } } } return null; }
@Nullable public List<String> getUrlFor(PsiElement element, PsiElement originalElement) { List<String> result = new ArrayList<String>(); PsiElement docElement = getDocumentationElement(element, originalElement); if (docElement != null) { ContainerUtil.addIfNotNull(result, docElement.getUserData(NonCodeMembersHolder.DOCUMENTATION_URL)); } List<String> list = JavaDocumentationProvider.getExternalJavaDocUrl(element); if (list != null) { result.addAll(list); } return result.isEmpty() ? null : result; }
public String getQuickNavigateInfo(final PsiElement element, PsiElement element1) { if (element instanceof VtlVariable) { final VtlVariable variable = (VtlVariable) element; final String name = variable.getName(); PsiType type = variable.getPsiType(); if (type != null) { return type.getPresentableText() + " " + name; } return name; } if (element instanceof BeanPropertyElement) { return JavaDocumentationProvider.generateMethodInfo(((BeanPropertyElement) element).getMethod(), PsiSubstitutor.EMPTY); } return null; }
@NotNull @Override protected ParseSettings getParseSettings(@NotNull String url) { return url.endsWith(JavaDocumentationProvider.PACKAGE_SUMMARY_FILE) ? ourPackageInfoSettings : super .getParseSettings(url); }
private void doTest(String text, String... expectedSignature) { myFixture.configureByText("Test.java", text); final PsiElement elementAtCaret = myFixture.getElementAtCaret(); final PsiMethod member = PsiTreeUtil.getParentOfType(elementAtCaret, PsiMethod.class, false); assertNotNull(member); final String signature = JavaDocumentationProvider.formatMethodSignature(member, true, false); assertNotNull(signature); assertEquals("found:" + signature, expectedSignature[0], signature); }
@NotNull @Override protected ParseSettings getParseSettings(@NotNull String url) { return url.endsWith(JavaDocumentationProvider.PACKAGE_SUMMARY_FILE) ? ourPackageInfoSettings : super.getParseSettings(url); }
@Override public String fetchExternalDocumentation(final Project project, PsiElement element, final List<String> docUrls) { return JavaDocumentationProvider.fetchExternalJavadoc(element, project, docUrls); }
@Override public String generateDocumentationContentStub(PsiComment contextComment) { if (!(contextComment instanceof GrDocComment)) { return null; } final GrDocCommentOwner owner = GrDocCommentUtil.findDocOwner((GrDocComment)contextComment); if (owner == null) return null; Project project = contextComment.getProject(); final CodeDocumentationAwareCommenter commenter = (CodeDocumentationAwareCommenter)LanguageCommenters.INSTANCE.forLanguage(owner.getLanguage()); StringBuilder builder = StringBuilderSpinAllocator.alloc(); try { if (owner instanceof GrMethod) { final GrMethod method = (GrMethod)owner; JavaDocumentationProvider.generateParametersTakingDocFromSuperMethods(project, builder, commenter, method); final PsiType returnType = method.getInferredReturnType(); if ((returnType != null || method.getModifierList().hasModifierProperty(GrModifier.DEF)) && returnType != PsiType.VOID) { builder.append(CodeDocumentationUtil.createDocCommentLine(RETURN_TAG, project, commenter)); builder.append(LINE_SEPARATOR); } final PsiClassType[] references = method.getThrowsList().getReferencedTypes(); for (PsiClassType reference : references) { builder.append(CodeDocumentationUtil.createDocCommentLine(THROWS_TAG, project, commenter)); builder.append(reference.getClassName()); builder.append(LINE_SEPARATOR); } } else if (owner instanceof GrTypeDefinition) { final PsiTypeParameterList typeParameterList = ((PsiClass)owner).getTypeParameterList(); if (typeParameterList != null) { JavaDocumentationProvider.createTypeParamsListComment(builder, project, commenter, typeParameterList); } } return builder.length() > 0 ? builder.toString() : null; } finally { StringBuilderSpinAllocator.dispose(builder); } }
@NotNull @Override protected Trinity<Pattern, Pattern, Boolean> getParseSettings(@NotNull String url) { return url.endsWith(JavaDocumentationProvider.PACKAGE_SUMMARY_FILE) ? ourPackageInfoSettings : super.getParseSettings(url); }
public String fetchExternalDocumentation(final Project project, PsiElement element, final List<String> docUrls) { return JavaDocumentationProvider.fetchExternalJavadoc(element, project, docUrls); }
public String generateDoc(final PsiElement element, final PsiElement originalElement) { if (element instanceof BeanPropertyElement) { return JavaDocumentationProvider.generateExternalJavadoc(((BeanPropertyElement) element).getMethod()); } return null; }