Skip to content

Commit 1f92f05

Browse files
committed
Merge branch 'master' into adam/kgp-2.2.20-compatibility
2 parents 0758d2e + 7903495 commit 1f92f05

File tree

17 files changed

+506
-108
lines changed

17 files changed

+506
-108
lines changed

dokka-integration-tests/gradle/projects/it-android/expectedData/html/it-android/it.android/-integration-test-activity/index.html

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dokka-runners/dokka-gradle-plugin/settings.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ dependencyResolutionManagement {
3333
google {
3434
setUrl("https://cache-redirector.jetbrains.com/dl.google.com/dl/android/maven2")
3535
name = "Google-JBCache"
36+
mavenContent {
37+
// https://github.com/gradle/gradle/issues/35562
38+
includeGroupAndSubgroups("com.android")
39+
includeGroupAndSubgroups("com.google")
40+
includeGroupAndSubgroups("androidx")
41+
}
3642
}
3743
}
3844

dokka-runners/dokka-gradle-plugin/src/testFixtures/kotlin/GradlePropertiesBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ data class GradlePropertiesBuilder(
126126
putNotNull("org.gradle.logging.level", logLevel?.name?.lowercase())
127127
putNotNull("org.gradle.workers.max", maxWorkers)
128128
putNotNull("org.gradle.parallel", parallel)
129-
putNotNull("org.gradle.stacktrace", stacktrace)
129+
putNotNull("org.gradle.logging.stacktrace", stacktrace)
130130
putNotNull("org.gradle.warning.mode", warningMode)
131131
jvmArgs.buildString().takeIf { it.isNotBlank() }?.let {
132132
put("org.gradle.jvmargs", it)

dokka-subprojects/analysis-kotlin-descriptors-compiler/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/descriptors/compiler/configuration/TypeReferenceFactory.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.jetbrains.dokka.links.*
99
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
1010
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
1111
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
12+
import org.jetbrains.kotlin.resolve.calls.components.isVararg
1213
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
1314
import org.jetbrains.kotlin.resolve.scopes.receivers.ExtensionReceiver
1415
import org.jetbrains.kotlin.types.KotlinType
@@ -27,7 +28,10 @@ internal fun TypeReference.Companion.from(d: ReceiverParameterDescriptor): TypeR
2728
}
2829

2930
internal fun TypeReference.Companion.from(d: ValueParameterDescriptor): TypeReference =
30-
fromPossiblyNullable(d.type, emptyList())
31+
when {
32+
d.isVararg -> Vararg(fromPossiblyNullable(d.varargElementType!!, emptyList()))
33+
else -> fromPossiblyNullable(d.type, emptyList())
34+
}
3135

3236
internal fun TypeReference.Companion.from(@Suppress("UNUSED_PARAMETER") p: PsiClass) = TypeReference
3337

@@ -54,6 +58,7 @@ private fun TypeReference.Companion.from(t: KotlinType, paramTrace: List<KotlinT
5458
is TypeParameterDescriptor -> TypeParam(
5559
d.upperBounds.map { fromPossiblyNullable(it, paramTrace + t) }
5660
)
61+
5762
else -> TypeConstructor(
5863
t.constructorName.orEmpty(),
5964
t.arguments.map { fromProjection(it, paramTrace) }

dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DRIFactory.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal fun KaSession.getDRIFromConstructor(symbol: KaConstructorSymbol): DRI {
5757
return containingClassId.createDRI().copy(
5858
callable = Callable(
5959
name = containingClassId.shortClassName.asString(),
60-
params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType) }
60+
params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType, isVararg = it.isVararg) }
6161
)
6262
)
6363
}
@@ -71,7 +71,7 @@ internal fun KaSession.getDRIFromVariable(symbol: KaVariableSymbol): DRI {
7171

7272

7373
internal fun KaSession.getDRIFromFunction(symbol: KaFunctionSymbol): DRI {
74-
val params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType) }
74+
val params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType, isVararg = it.isVararg) }
7575
val contextParams = @OptIn(KaExperimentalApi::class) symbol.contextParameters.map { getTypeReferenceFrom(it.returnType) }
7676
val receiver = symbol.receiverType?.let {
7777
getTypeReferenceFrom(it)
@@ -100,7 +100,7 @@ internal fun KaSession.getDRIFromReceiverParameter(receiverParameterSymbol: KaRe
100100
getDRIFromReceiverType(receiverParameterSymbol.returnType)
101101

102102
private fun KaSession.getDRIFromReceiverType(type: KaType): DRI {
103-
return when(type) {
103+
return when (type) {
104104
is KaClassType -> getDRIFromClassType(type)
105105
is KaTypeParameterType -> getDRIFromTypeParameter(type.symbol)
106106
is KaDefinitelyNotNullType -> getDRIFromReceiverType(type.original)
@@ -149,7 +149,7 @@ private fun KaSession.getDRIFromLocalFunction(symbol: KaFunctionSymbol): DRI {
149149
return containingSymbolDRI.copy(
150150
callable = Callable(
151151
(symbol as? KaNamedSymbol)?.name?.asString() ?: "",
152-
params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType) },
152+
params = symbol.valueParameters.map { getTypeReferenceFrom(it.returnType, isVararg = it.isVararg) },
153153
receiver = symbol.receiverType?.let {
154154
getTypeReferenceFrom(it)
155155
}

dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/DefaultSymbolToDocumentableTranslator.kt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ internal class DokkaSymbolVisitor(
753753
extra = PropertyContainer.withAll(
754754
valueParameterSymbol.additionalExtras()?.toSourceSetDependent()?.toAdditionalModifiers(),
755755
getDokkaAnnotationsFrom(valueParameterSymbol)?.toSourceSetDependent()?.toAnnotations(),
756-
valueParameterSymbol.getDefaultValue()?.let { DefaultValue(it.toSourceSetDependent()) }
756+
getDefaultValue(valueParameterSymbol, index)?.let { DefaultValue(it.toSourceSetDependent()) }
757757
)
758758
)
759759

@@ -788,9 +788,29 @@ internal class DokkaSymbolVisitor(
788788
)
789789
)
790790

791-
private fun KaValueParameterSymbol.getDefaultValue(): Expression? =
792-
if (origin == KaSymbolOrigin.SOURCE) (psi as? KtParameter)?.defaultValue?.toDefaultValueExpression()
793-
else null
791+
/**
792+
* TODO https://youtrack.jetbrains.com/issue/KT-61254/Analysis-API-Add-a-default-value-for-KtValueParameterSymbol
793+
* Retrieves the default value of a value parameter, if available from sources.
794+
* It may be `null` if the owner function comes from a non-source file.
795+
*/
796+
private fun KaSession.getDefaultValue(symbol: KaValueParameterSymbol, parameterIndex: Int): Expression? {
797+
fun KaValueParameterSymbol.getExplicitDefaultValue(): Expression? =
798+
if (origin == KaSymbolOrigin.SOURCE) (psi as? KtParameter)?.defaultValue?.toDefaultValueExpression() else null
799+
fun KaDeclarationSymbol.findMatchingParameterWithDefaultValue(): Expression? =
800+
(this as? KaFunctionSymbol)?.valueParameters?.getOrNull(parameterIndex)?.getExplicitDefaultValue()
801+
802+
val result = symbol.getExplicitDefaultValue()
803+
return if (result != null)
804+
result
805+
else { // in the case of fake declarations
806+
val ownerFunction = symbol.containingDeclaration as? KaNamedFunctionSymbol ?: return null
807+
808+
//overriding function
809+
if (ownerFunction.isOverride)
810+
ownerFunction.allOverriddenSymbols.firstNotNullOfOrNull { it.findMatchingParameterWithDefaultValue() }
811+
else null
812+
}
813+
}
794814

795815
@OptIn(KaExperimentalApi::class) // due to `KaPropertySymbol.initializer`
796816
private fun KaPropertySymbol.getDefaultValue(): Expression? =

dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/TypeReferenceFactory.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ import org.jetbrains.dokka.links.*
88
import org.jetbrains.kotlin.analysis.api.KaSession
99
import org.jetbrains.kotlin.analysis.api.types.*
1010

11-
internal fun KaSession.getTypeReferenceFrom(type: KaType): TypeReference =
12-
getTypeReferenceFromPossiblyRecursive(type, emptyList())
11+
internal fun KaSession.getTypeReferenceFrom(type: KaType, isVararg: Boolean = false): TypeReference {
12+
val typeReference = getTypeReferenceFromPossiblyRecursive(type, emptyList())
13+
return when {
14+
isVararg -> Vararg(typeReference)
15+
else -> typeReference
16+
}
17+
}
1318

1419

1520
// see `deep recursive typebound #1342` test

dokka-subprojects/analysis-kotlin-symbols/src/main/kotlin/org/jetbrains/dokka/analysis/kotlin/symbols/translators/TypeTranslator.kt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ internal class TypeTranslator(
5151
val classSymbol = abbreviationType.symbol
5252
return if (classSymbol is KaTypeAliasSymbol)
5353
TypeAliased(
54-
typeAlias = GenericTypeConstructor(
55-
dri = getDRIFromClassType(abbreviationType),
56-
projections = abbreviationType.typeArguments.map { toProjection(it) }),
54+
typeAlias = asNullableIfMarked(
55+
abbreviationType,
56+
bound = GenericTypeConstructor(
57+
dri = getDRIFromClassType(abbreviationType),
58+
projections = abbreviationType.typeArguments.map { toProjection(it) }
59+
)
60+
),
5761
inner = fullyExpandedType,
5862
extra = PropertyContainer.withAll(
5963
getDokkaAnnotationsFrom(abbreviationType)?.toSourceSetDependent()?.toAnnotations()
@@ -84,16 +88,18 @@ internal class TypeTranslator(
8488
contextParametersCount = @OptIn(KaExperimentalApi::class) functionalType.contextReceivers.size
8589
)
8690

91+
fun KaSession.toBoundFrom(type: KaType): Bound {
92+
val abbreviation = type.abbreviation
93+
val bound = toBoundFromNoAbbreviation(type)
94+
return when {
95+
abbreviation != null -> toBoundFromTypeAliased(abbreviation, bound)
96+
else -> bound
97+
}
98+
}
8799

88-
fun KaSession.toBoundFrom(type: KaType): Bound =
100+
fun KaSession.toBoundFromNoAbbreviation(type: KaType): Bound =
89101
when (type) {
90-
is KaUsualClassType -> {
91-
// after KT-66996, [type] is an expanded type
92-
val abbreviation = type.abbreviation
93-
if (abbreviation != null) toBoundFromTypeAliased(abbreviation, toTypeConstructorFrom(type))
94-
else toTypeConstructorFrom(type)
95-
}
96-
102+
is KaUsualClassType -> toTypeConstructorFrom(type)
97103
is KaTypeParameterType -> TypeParameter(
98104
dri = getDRIFromTypeParameter(type.symbol),
99105
name = type.name.asString(),
@@ -104,12 +110,7 @@ internal class TypeTranslator(
104110
)
105111

106112
is KaClassErrorType -> UnresolvedBound(type.toString())
107-
is KaFunctionType -> {
108-
// after KT-66996, [type] is an expanded type
109-
val abbreviation = type.abbreviation
110-
if (abbreviation != null) toBoundFromTypeAliased(abbreviation, toFunctionalTypeConstructorFrom(type))
111-
else toFunctionalTypeConstructorFrom(type)
112-
}
113+
is KaFunctionType -> toFunctionalTypeConstructorFrom(type)
113114
is KaDynamicType -> Dynamic
114115
is KaDefinitelyNotNullType -> DefinitelyNonNullable(
115116
toBoundFrom(type.original)
@@ -128,9 +129,13 @@ internal class TypeTranslator(
128129
is KaIntersectionType -> throw NotImplementedError()
129130
else -> throw NotImplementedError()
130131
}.let {
131-
if (type.isMarkedNullable) Nullable(it) else it
132+
asNullableIfMarked(type, it)
132133
}
133134

135+
private fun KaSession.asNullableIfMarked(type: KaType, bound: Bound): Bound =
136+
if (type.isMarkedNullable) Nullable(bound) else bound
137+
138+
134139
fun KaSession.buildAncestryInformationFrom(
135140
type: KaType
136141
): AncestryNode {

dokka-subprojects/core/api/dokka-core.api

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,17 @@ public abstract class org/jetbrains/dokka/links/TypeReference {
665665
public final class org/jetbrains/dokka/links/TypeReference$Companion {
666666
}
667667

668+
public final class org/jetbrains/dokka/links/Vararg : org/jetbrains/dokka/links/TypeReference {
669+
public fun <init> (Lorg/jetbrains/dokka/links/TypeReference;)V
670+
public final fun component1 ()Lorg/jetbrains/dokka/links/TypeReference;
671+
public final fun copy (Lorg/jetbrains/dokka/links/TypeReference;)Lorg/jetbrains/dokka/links/Vararg;
672+
public static synthetic fun copy$default (Lorg/jetbrains/dokka/links/Vararg;Lorg/jetbrains/dokka/links/TypeReference;ILjava/lang/Object;)Lorg/jetbrains/dokka/links/Vararg;
673+
public fun equals (Ljava/lang/Object;)Z
674+
public final fun getElementType ()Lorg/jetbrains/dokka/links/TypeReference;
675+
public fun hashCode ()I
676+
public fun toString ()Ljava/lang/String;
677+
}
678+
668679
public final class org/jetbrains/dokka/model/ActualTypealias : org/jetbrains/dokka/model/properties/ExtraProperty {
669680
public static final field Companion Lorg/jetbrains/dokka/model/ActualTypealias$Companion;
670681
public fun <init> (Lorg/jetbrains/dokka/model/DTypeAlias;)V

dokka-subprojects/core/src/main/kotlin/org/jetbrains/dokka/links/DRI.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public data class Nullable(val wrapped: TypeReference) : TypeReference() {
146146
override fun toString(): String = "$wrapped?"
147147
}
148148

149+
public data class Vararg(val elementType: TypeReference) : TypeReference() {
150+
override fun toString(): String = "vararg($elementType)"
151+
}
152+
149153
public object StarProjection : TypeReference() {
150154
override fun toString(): String = "*"
151155
}

0 commit comments

Comments
 (0)