diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-03-13 13:18:12 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-17 16:03:36 +0100 |
commit | a01554561ca8d18a1cf3c94df47e4b38fae1c538 (patch) | |
tree | 38ea3044b122b44f57bad45ae98b24679e1316a8 /plugins | |
parent | 7cfdd8a512adb6b8589328610efb5bd56c3c0dd7 (diff) | |
download | dokka-a01554561ca8d18a1cf3c94df47e4b38fae1c538.tar.gz dokka-a01554561ca8d18a1cf3c94df47e4b38fae1c538.tar.bz2 dokka-a01554561ca8d18a1cf3c94df47e4b38fae1c538.zip |
Add annotation parsing in Java sources
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt | 49 |
1 files changed, 38 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 c5c72a65..0e1e0a18 100644 --- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt @@ -59,7 +59,7 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { class DokkaPsiParser( private val platformData: PlatformData, - logger: DokkaLogger + private val logger: DokkaLogger ) { private val javadocParser: JavaDocumentationParser = JavadocParser(logger) @@ -144,7 +144,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { visibility, null, constructors.map { parseFunction(it, dri, true) }, - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<Annotation>() + annotations.toList().toExtra() ) isEnum -> DEnum( dri, @@ -157,7 +158,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { emptyList(), emptyList(), emptyList(), - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<EnumEntry>() + entry.annotations.toList().toExtra() ) }, documentation, @@ -169,7 +171,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, constructors.map { parseFunction(it, dri, true) }, ancestors, - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<Enum>() + annotations.toList().toExtra() ) isInterface -> DInterface( dri, @@ -183,7 +186,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, mapTypeParameters(dri), ancestors, - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<Interface>() + annotations.toList().toExtra() ) else -> DClass( dri, @@ -199,7 +203,8 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { ancestors, documentation, getModifier(), - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<Class>() + annotations.toList().toExtra() ) } } @@ -239,9 +244,9 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { null, psi.getModifier(), listOf(platformData), - PropertyContainer.empty<DFunction>() + InheritedFunction( - isInherited - ) + PropertyContainer.empty<DFunction>() + + InheritedFunction(isInherited) + + psi.annotations.toList().toExtra() ) } @@ -254,7 +259,10 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { val arguments = type.parameters.map { getProjection(it) } TypeConstructor(DRI.from(resolved), arguments) } - is PsiArrayType -> TypeConstructor(DRI("kotlin", "Array"), listOf(getProjection(type.componentType))) + is PsiArrayType -> TypeConstructor( + DRI("kotlin", "Array"), + listOf(getProjection(type.componentType)) + ) is PsiPrimitiveType -> PrimitiveJavaType(type.name) else -> throw IllegalStateException("${type.presentableText} is not supported by PSI parser") } @@ -342,8 +350,27 @@ object DefaultPsiToDocumentableTranslator : PsiToDocumentableTranslator { accessors.firstOrNull { it.hasParameters() }?.let { parseFunction(it, parent) }, accessors.firstOrNull { it.returnType == psi.type }?.let { parseFunction(it, parent) }, psi.getModifier(), - listOf(platformData) + listOf(platformData), + PropertyContainer.empty<Property>() + psi.annotations.toList().toExtra() ) } + + private fun Collection<PsiAnnotation>.toExtra() = mapNotNull { annotation -> + val fqname = annotation.qualifiedName ?: run { + logger.error("No fqName for $annotation!") + return@mapNotNull null + } + + Annotations.Annotation( + DRI(fqname.substringBeforeLast("."), fqname.substringAfterLast(".")), // TODO: create a proper DRI + annotation.attributes.mapNotNull { + if (it is PsiNameValuePair) { + it.attributeName to it.value.toString() + } else { + it.attributeName to "" + } + }.toMap() + ) + }.let(::Annotations) } } |