diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-03-25 15:34:33 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@users.noreply.github.com> | 2020-03-25 15:45:32 +0100 |
commit | af9d525d75a517a5a7cb39d30fd4b2c9e8b93837 (patch) | |
tree | 19466eb468003e17a732ea483837848359ac76e4 /plugins/base/src | |
parent | cf37a3d981bac28e791ec0402fe6f19f986e7a47 (diff) | |
download | dokka-af9d525d75a517a5a7cb39d30fd4b2c9e8b93837.tar.gz dokka-af9d525d75a517a5a7cb39d30fd4b2c9e8b93837.tar.bz2 dokka-af9d525d75a517a5a7cb39d30fd4b2c9e8b93837.zip |
Fix inproper resolution of annotations
Diffstat (limited to 'plugins/base/src')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 26 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/model/JavaTest.kt | 5 |
2 files changed, 14 insertions, 17 deletions
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt index 91a498bc..74a6a7ea 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -4,13 +4,10 @@ import com.intellij.lang.jvm.JvmModifier import com.intellij.lang.jvm.types.JvmReferenceType import com.intellij.psi.* import com.intellij.psi.impl.source.PsiClassReferenceType -import org.jetbrains.dokka.links.* +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.DriOfAny +import org.jetbrains.dokka.links.withClass import org.jetbrains.dokka.model.* -import org.jetbrains.dokka.model.DAnnotation -import org.jetbrains.dokka.model.DEnum -import org.jetbrains.dokka.model.DFunction -import org.jetbrains.dokka.model.Nullable -import org.jetbrains.dokka.model.TypeConstructor import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.plugability.DokkaContext @@ -21,6 +18,7 @@ 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 object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { @@ -291,7 +289,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { if (bounds.isEmpty()) emptyList() else bounds.mapNotNull { (it as? PsiClassType)?.let { classType -> val resolved = classType.resolve()!! - val dri = if(resolved.qualifiedName == "java.lang.Object") DriOfAny + val dri = if (resolved.qualifiedName == "java.lang.Object") DriOfAny else DRI.from(resolved) Nullable(TypeConstructor(dri, emptyList())) } @@ -350,18 +348,18 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { } private fun Collection<PsiAnnotation>.toExtra() = mapNotNull { annotation -> - val fqname = annotation.qualifiedName ?: run { - logger.error("No fqName for $annotation!") + val resolved = annotation.getChildOfType<PsiJavaCodeReferenceElement>()?.resolve() ?: run { + logger.error("$annotation cannot be resolved to symbol!") return@mapNotNull null } Annotations.Annotation( - DRI.from(annotation), - annotation.attributes.mapNotNull { - if (it is PsiNameValuePair) { - it.attributeName to it.value.toString() + DRI.from(resolved), + annotation.attributes.mapNotNull { attr -> + if (attr is PsiNameValuePair) { + attr.value?.text?.let { attr.attributeName to it } } else { - it.attributeName to "" + attr.attributeName to "" } }.toMap() ) diff --git a/plugins/base/src/test/kotlin/model/JavaTest.kt b/plugins/base/src/test/kotlin/model/JavaTest.kt index 2545823b..a0cb68d7 100644 --- a/plugins/base/src/test/kotlin/model/JavaTest.kt +++ b/plugins/base/src/test/kotlin/model/JavaTest.kt @@ -336,10 +336,9 @@ class JavaTest : AbstractModelTest("/src/main/kotlin/java/Test.java", "java") { ) { with((this / "java" / "Attribute").cast<DAnnotation>()) { with(extra[Annotations].assertNotNull("Annotations")) { - content counts 1 - with(content.first()) { + with(content.single()) { dri.classNames equals "Target" - params["value"].assertNotNull("value") equals "PsiArrayInitializerMemberValue:{ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}" + params["value"].assertNotNull("value") equals "{ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}" } } } |