Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collect annotations from package-info.java #2331

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ class DefaultPsiToDocumentableTranslator(

suspend fun parsePackage(packageName: String, psiFiles: List<PsiJavaFile>): DPackage = coroutineScope {
val dri = DRI(packageName = packageName)
val documentation = psiFiles.firstOrNull { it.name == "package-info.java" }?.let {
val packageInfo = psiFiles.singleOrNull { it.name == "package-info.java" }
val documentation = packageInfo?.let {
javadocParser.parseDocumentation(it).toSourceSetDependent()
} ?: emptyMap()
}.orEmpty()
val annotations = packageInfo?.packageStatement?.annotationList?.annotations

DPackage(
dri,
Expand All @@ -166,7 +168,10 @@ class DefaultPsiToDocumentableTranslator(
emptyList(),
documentation,
null,
setOf(sourceSetData)
setOf(sourceSetData),
PropertyContainer.withAll(
annotations?.toList().orEmpty().toListOfAnnotations().toSourceSetDependent().toAnnotations()
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package translators
import org.jetbrains.dokka.model.doc.Text
import org.jetbrains.dokka.model.firstMemberOfType
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.Annotations
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -166,4 +168,29 @@ class DefaultPsiToDocumentableTranslatorTest : BaseAbstractTest() {
}
}
}

@Test
fun `java package-info package annotations`() {
testInline(
"""
|/src/main/java/sample/PackageAnnotation.java
|package sample;
|@java.lang.annotation.Target(java.lang.annotation.ElementType.PACKAGE)
|public @interface PackageAnnotation {
|}
|
|/src/main/java/sample/package-info.java
|@PackageAnnotation
|package sample;
""".trimMargin(),
configuration
) {
documentablesMergingStage = { module ->
assertEquals(
Annotations.Annotation(DRI("sample", "PackageAnnotation"), emptyMap()),
module.packages.single().extra[Annotations]?.directAnnotations?.values?.single()?.single()
)
}
}
}
}