diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt | 9 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/Kotlin/DocumentationBuilder.kt | 19 | ||||
-rw-r--r-- | core/src/test/kotlin/model/JavaTest.kt | 10 | ||||
-rw-r--r-- | core/testdata/java/suppressTag.java | 10 |
5 files changed, 34 insertions, 17 deletions
diff --git a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt index 9d75792c..5da41f29 100644 --- a/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt +++ b/core/src/main/kotlin/Java/JavaPsiDocumentationBuilder.kt @@ -122,15 +122,12 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { } } - private fun skipElement(element: Any) = skipElementByVisibility(element) || hasSuppressTag(element) + private fun skipElement(element: Any) = skipElementByVisibility(element) || hasSuppressDocTag(element) private fun skipElementByVisibility(element: Any): Boolean = !options.includeNonPublic && element is PsiModifierListOwner && (element.hasModifierProperty(PsiModifier.PRIVATE) || element.hasModifierProperty(PsiModifier.PACKAGE_LOCAL)) - private fun hasSuppressTag(element: Any) = - element is PsiDocCommentOwner && element.docComment?.let { it.findTagByName("suppress") != null } ?: false - fun <T : Any> DocumentationNode.appendMembers(elements: Array<T>, buildFn: T.() -> DocumentationNode) = appendChildren(elements, RefKind.Member, buildFn) @@ -267,3 +264,7 @@ class JavaPsiDocumentationBuilder : JavaDocumentationBuilder { return node } } + +fun hasSuppressDocTag(element: Any?) = + element is PsiDocCommentOwner && element.docComment?.let { it.findTagByName("suppress") != null } ?: false + diff --git a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt index c62f9cbf..3834dbf8 100644 --- a/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt +++ b/core/src/main/kotlin/Kotlin/DeclarationLinkResolver.kt @@ -9,7 +9,6 @@ import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.source.PsiSourceElement class DeclarationLinkResolver @Inject constructor(val resolutionFacade: DokkaResolutionFacade, @@ -62,7 +61,7 @@ class DeclarationLinkResolver val containingClass = symbol.containingDeclaration as? JavaClassDescriptor ?: return null val containingClassLink = buildJdkLink(containingClass) if (containingClassLink != null) { - val psi = (symbol.original.source as? PsiSourceElement)?.psi as? PsiMethod + val psi = symbol.sourcePsi() as? PsiMethod if (psi != null) { val params = psi.parameterList.parameters.joinToString { it.type.canonicalText } return containingClassLink + "#" + symbol.name + "(" + params + ")" diff --git a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt index e67f1aa1..f8df1f2e 100644 --- a/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt +++ b/core/src/main/kotlin/Kotlin/DocumentationBuilder.kt @@ -679,9 +679,14 @@ fun AnnotationDescriptor.mustBeDocumented(): Boolean { fun DeclarationDescriptor.isDocumentationSuppressed(): Boolean { val doc = KDocFinder.findKDoc(this) - return doc is KDocSection && doc.findTagByName("suppress") != null + if (doc is KDocSection && doc.findTagByName("suppress") != null) return true + + return hasSuppressDocTag(sourcePsi()) } +fun DeclarationDescriptor.sourcePsi() = + ((original as DeclarationDescriptorWithSource).source as? PsiSourceElement)?.psi + fun DeclarationDescriptor.isDeprecated(): Boolean = annotations.any { DescriptorUtils.getFqName(it.type.constructor.declarationDescriptor!!).asString() == "kotlin.Deprecated" } || (this is ConstructorDescriptor && containingDeclaration.isDeprecated()) @@ -760,13 +765,11 @@ fun DeclarationDescriptor.signatureWithSourceLocation(): String { } fun DeclarationDescriptor.sourceLocation(): String? { - if (this is DeclarationDescriptorWithSource) { - val psi = (this.source as? PsiSourceElement)?.getPsi() - if (psi != null) { - val fileName = psi.containingFile.name - val lineNumber = psi.lineNumber() - return if (lineNumber != null) "$fileName:$lineNumber" else fileName - } + val psi = sourcePsi() + if (psi != null) { + val fileName = psi.containingFile.name + val lineNumber = psi.lineNumber() + return if (lineNumber != null) "$fileName:$lineNumber" else fileName } return null } diff --git a/core/src/test/kotlin/model/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index 447fa537..a3a3f772 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -2,10 +2,8 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.RefKind +import org.junit.Assert.* import org.junit.Test -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue public class JavaTest { @Test fun function() { @@ -148,6 +146,12 @@ public class JavaTest { } } + @Test fun suppressTag() { + verifyJavaPackageMember("testdata/java/suppressTag.java") { cls -> + assertEquals(1, cls.members(NodeKind.Function).size) + } + } + @Test fun annotatedAnnotation() { verifyJavaPackageMember("testdata/java/annotatedAnnotation.java") { cls -> assertEquals(1, cls.annotations.size) diff --git a/core/testdata/java/suppressTag.java b/core/testdata/java/suppressTag.java new file mode 100644 index 00000000..c26194c8 --- /dev/null +++ b/core/testdata/java/suppressTag.java @@ -0,0 +1,10 @@ +class C { + public static void foo() { + } + + /** + * @suppress + */ + public static void bar() { + } +} |