aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt37
-rw-r--r--plugins/base/src/test/kotlin/translators/Bug1341.kt1
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