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/base/src/main | |
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/base/src/main')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 37 |
1 files changed, 27 insertions, 10 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 |