1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package translators
import org.jetbrains.dokka.analysis.kotlin.internal.ExternalDocumentablesProvider
import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.model.DInterface
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.utilities.cast
import kotlin.test.Test
import kotlin.test.assertEquals
class ExternalDocumentablesTest : BaseAbstractTest() {
@Test
fun `external documentable from java stdlib`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src")
analysisPlatform = "jvm"
classpath += jvmStdlibPath!!
}
}
}
testInline(
"""
/src/com/sample/MyList.kt
package com.sample
class MyList: ArrayList<Int>()
""".trimIndent(),
configuration
) {
lateinit var provider: ExternalDocumentablesProvider
pluginsSetupStage = {
provider = it.plugin<InternalKotlinAnalysisPlugin>().querySingle { externalDocumentablesProvider }
}
documentablesTransformationStage = { mod ->
val entry = mod.packages.single().classlikes.single().cast<DClass>().supertypes.entries.single()
val res = provider.findClasslike(
entry.value.single().typeConstructor.dri,
entry.key)
assertEquals("ArrayList", res?.name)
assertEquals("java.util/ArrayList///PointingToDeclaration/", res?.dri?.toString())
val supertypes = res?.cast<DClass>()?.supertypes?.values?.single()
?.map { it.typeConstructor.dri.classNames }
assertEquals(
listOf("AbstractList", "RandomAccess", "Cloneable", "Serializable", "MutableList"),
supertypes
)
}
}
}
@Test
fun `external documentable from dependency`() {
val coroutinesPath =
ClassLoader.getSystemResource("kotlinx/coroutines/Job.class")
?.file
?.replace("file:", "")
?.replaceAfter(".jar", "")
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src")
analysisPlatform = "jvm"
classpath += listOf(jvmStdlibPath!!, coroutinesPath!!)
}
}
}
testInline(
"""
/src/com/sample/MyJob.kt
package com.sample
import kotlinx.coroutines.Job
abstract class MyJob: Job
""".trimIndent(),
configuration
) {
lateinit var provider: ExternalDocumentablesProvider
pluginsSetupStage = {
provider = it.plugin<InternalKotlinAnalysisPlugin>().querySingle { externalDocumentablesProvider }
}
documentablesTransformationStage = { mod ->
val entry = mod.packages.single().classlikes.single().cast<DClass>().supertypes.entries.single()
val res = provider.findClasslike(
entry.value.single().typeConstructor.dri,
entry.key)
assertEquals("Job", res?.name)
assertEquals("kotlinx.coroutines/Job///PointingToDeclaration/", res?.dri?.toString())
val supertypes = res?.cast<DInterface>()?.supertypes?.values?.single()
?.map { it.typeConstructor.dri.classNames }
assertEquals(
listOf("CoroutineContext.Element"),
supertypes
)
}
}
}
@Test
fun `external documentable for nested class`() {
val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src")
analysisPlatform = "jvm"
classpath += jvmStdlibPath!!
}
}
}
testInline(
"""
/src/com/sample/MyList.kt
package com.sample
abstract class MyEntry: Map.Entry<Int, String>
""".trimIndent(),
configuration
) {
lateinit var provider: ExternalDocumentablesProvider
pluginsSetupStage = {
provider = it.plugin<InternalKotlinAnalysisPlugin>().querySingle { externalDocumentablesProvider }
}
documentablesTransformationStage = { mod ->
val entry = mod.packages.single().classlikes.single().cast<DClass>().supertypes.entries.single()
val res = provider.findClasslike(
entry.value.single().typeConstructor.dri,
entry.key)
assertEquals("Entry", res?.name)
assertEquals("kotlin.collections/Map.Entry///PointingToDeclaration/", res?.dri?.toString())
}
}
}
}
|