diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-08-19 14:43:12 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-19 16:17:41 +0200 |
commit | 4e9cc22fca2b6d2f1afc7d5be01deb508cb6c14b (patch) | |
tree | 8937af611941a8f09d5b5077d1f5cf8af37d2288 /plugins | |
parent | a90c30cc9e80cfb45cdb6932caa1e518ac2d8bbb (diff) | |
download | dokka-4e9cc22fca2b6d2f1afc7d5be01deb508cb6c14b.tar.gz dokka-4e9cc22fca2b6d2f1afc7d5be01deb508cb6c14b.tar.bz2 dokka-4e9cc22fca2b6d2f1afc7d5be01deb508cb6c14b.zip |
Mitigate #1341 issue in light classes
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 37 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/translators/Bug1341.kt | 1 |
2 files changed, 27 insertions, 11 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 27a487b8..8dee2478 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -25,12 +25,14 @@ import org.jetbrains.kotlin.asJava.elements.KtLightAbstractAnnotation import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot import org.jetbrains.kotlin.descriptors.Visibilities +import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName import org.jetbrains.kotlin.load.java.propertyNamesBySetMethodName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.psiUtil.getChildOfType import org.jetbrains.kotlin.resolve.DescriptorUtils +import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments import org.jetbrains.kotlin.utils.addToStdlib.safeAs import java.io.File @@ -482,17 +484,32 @@ class DefaultPsiToDocumentableTranslator( else -> StringValue(text ?: "") } - private fun PsiAnnotation.toAnnotation(): Annotations.Annotation? = psiReference?.let { psiElement -> - Annotations.Annotation( - dri = DRI.from(psiElement), - params = attributes - .filter { it !is KtLightAbstractAnnotation } - .mapNotNull { it.attributeName to it.toValue() } - .toMap(), - mustBeDocumented = (psiElement as PsiClass).annotations.any { - it.hasQualifiedName("java.lang.annotation.Documented") + private fun PsiAnnotation.toAnnotation(): Annotations.Annotation? { + // TODO Mitigating workaround for issue https://github.com/Kotlin/dokka/issues/1341 + // Tracking https://youtrack.jetbrains.com/issue/KT-41234 + // Needs to be removed once this issue is fixed in light classes + fun PsiElement.getAnnotationsOrNull(): Array<PsiAnnotation>? { + this as PsiClass + return try { + this.annotations + } catch (e: KotlinExceptionWithAttachments) { + logger.warn("Failed to get annotations from ${this.getKotlinFqName()}") + null } - ) + } + + return psiReference?.let { psiElement -> + Annotations.Annotation( + dri = DRI.from(psiElement), + params = attributes + .filter { it !is KtLightAbstractAnnotation } + .mapNotNull { it.attributeName to it.toValue() } + .toMap(), + mustBeDocumented = psiElement.getAnnotationsOrNull().orEmpty().any { annotation -> + annotation.hasQualifiedName("java.lang.annotation.Documented") + } + ) + } } private val PsiElement.psiReference diff --git a/plugins/base/src/test/kotlin/translators/Bug1341.kt b/plugins/base/src/test/kotlin/translators/Bug1341.kt index 285cd53a..729f981a 100644 --- a/plugins/base/src/test/kotlin/translators/Bug1341.kt +++ b/plugins/base/src/test/kotlin/translators/Bug1341.kt @@ -2,7 +2,6 @@ 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 |