diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-19 14:21:46 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-19 16:17:41 +0200 |
commit | cc8c8d6d92c601e3c3b8ea7b62c39d5dae4839b8 (patch) | |
tree | 2fff53b4a32c86f2b7c3840e9c404ff635463e1f /plugins | |
parent | 6bd58a22b06c6e879b8e93ade631ca6f119976e3 (diff) | |
download | dokka-cc8c8d6d92c601e3c3b8ea7b62c39d5dae4839b8.tar.gz dokka-cc8c8d6d92c601e3c3b8ea7b62c39d5dae4839b8.tar.bz2 dokka-cc8c8d6d92c601e3c3b8ea7b62c39d5dae4839b8.zip |
Implement test to reproduce https://github.com/Kotlin/dokka/issues/1341
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 28 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/translators/Bug1341.kt | 62 |
2 files changed, 82 insertions, 8 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 791627cc..27a487b8 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -173,13 +173,19 @@ class DefaultPsiToDocumentableTranslator( val ancestors = ancestryTree.filter { it.level == 0 }.flatMap { listOfNotNull(it.superclass?.let { TypeConstructorWithKind( - typeConstructor = it , + typeConstructor = it, kind = JavaClassKindTypes.CLASS ) - }) + it.interfaces.map { TypeConstructorWithKind(typeConstructor = it, kind = JavaClassKindTypes.INTERFACE) } + }) + it.interfaces.map { + TypeConstructorWithKind( + typeConstructor = it, + kind = JavaClassKindTypes.INTERFACE + ) + } }.toSourceSetDependent() val modifiers = getModifier().toSourceSetDependent() - val implementedInterfacesExtra = ImplementedInterfaces(ancestryTree.flatMap { it.interfaces }.distinct().toSourceSetDependent()) + val implementedInterfacesExtra = + ImplementedInterfaces(ancestryTree.flatMap { it.interfaces }.distinct().toSourceSetDependent()) return when { isAnnotationType -> DAnnotation( @@ -476,12 +482,14 @@ class DefaultPsiToDocumentableTranslator( else -> StringValue(text ?: "") } - private fun PsiAnnotation.toAnnotation() = psiReference?.let { psiElement -> + private fun PsiAnnotation.toAnnotation(): Annotations.Annotation? = psiReference?.let { psiElement -> Annotations.Annotation( - DRI.from(psiElement), - attributes.filter { it !is KtLightAbstractAnnotation }.mapNotNull { it.attributeName to it.toValue() } + dri = DRI.from(psiElement), + params = attributes + .filter { it !is KtLightAbstractAnnotation } + .mapNotNull { it.attributeName to it.toValue() } .toMap(), - (psiElement as PsiClass).annotations.any { + mustBeDocumented = (psiElement as PsiClass).annotations.any { it.hasQualifiedName("java.lang.annotation.Documented") } ) @@ -491,5 +499,9 @@ class DefaultPsiToDocumentableTranslator( get() = getChildOfType<PsiJavaCodeReferenceElement>()?.resolve() } - private data class AncestryLevel(val level: Int, val superclass: TypeConstructor?, val interfaces: List<TypeConstructor>) + private data class AncestryLevel( + val level: Int, + val superclass: TypeConstructor?, + val interfaces: List<TypeConstructor> + ) } diff --git a/plugins/base/src/test/kotlin/translators/Bug1341.kt b/plugins/base/src/test/kotlin/translators/Bug1341.kt new file mode 100644 index 00000000..5305e6b0 --- /dev/null +++ b/plugins/base/src/test/kotlin/translators/Bug1341.kt @@ -0,0 +1,62 @@ +package translators + +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +class Bug1341 : AbstractCoreTest() { + @Test + fun `reproduce bug #1341`() { + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src") + analysisPlatform = "jvm" + } + } + } + + testInline( + """ + /src/com/sample/OtherClass.kt + package com.sample + /** + * @suppress + */ + class OtherClass internal constructor() { + @kotlin.annotation.Retention(AnnotationRetention.SOURCE) + @IntDef(ELEM_1, ELEM_2, ELEM_3) + internal annotation class CustomAnnotation + + companion object { + const val ELEM_1 = 1 + const val ELEM_2 = -1 + const val ELEM_3 = 0 + } + } + + /src/com/sample/ClassUsingAnnotation.java + package com.sample + import static sample.OtherClass.ELEM_1; + + /** + * @suppress + */ + public class ClassUsingAnnotation { + + @OtherClass.CustomAnnotation + public int doSomething() { + return ELEM_1; + } + } + """.trimIndent(), + configuration + ) { + this.documentablesMergingStage = { module -> + assertEquals(DRI("com.sample"), module.packages.single().dri) + } + } + } +} |