Skip to content

Commit

Permalink
Update Analysis API to 2.1.0-dev-2515 (#3724)
Browse files Browse the repository at this point in the history
Some changes:
- KT-55124
- KT-67786
  • Loading branch information
vmishenev authored Aug 1, 2024
1 parent 89c5200 commit 270c333
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.dokka.plugability.query
import org.jetbrains.dokka.analysis.kotlin.documentable.ExternalDocumentableProvider
import org.jetbrains.kotlin.analysis.api.symbols.KaDeclarationSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassSymbol

internal class SymbolExternalDocumentablesProvider(val context: DokkaContext) : ExternalDocumentableProvider {
Expand All @@ -39,7 +40,7 @@ internal class SymbolExternalDocumentablesProvider(val context: DokkaContext) :
else null
val translator = DokkaSymbolVisitor(sourceSet, sourceSet.displayName, kotlinAnalysis, logger = context.logger, javadocParser)

val parentDRI = symbol.containingSymbol?.let { getDRIFromSymbol(it) } ?: /* top level */ DRI(dri.packageName)
val parentDRI = (symbol.containingSymbol as? KaDeclarationSymbol)?.let { getDRIFromSymbol(it) } ?: /* top level */ DRI(dri.packageName)
with(translator) {
return@analyze visitClassSymbol(symbol, parentDRI)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal fun getDRIFromEnumEntry(symbol: KaEnumEntrySymbol): DRI {
internal fun KaSession.getDRIFromTypeParameter(symbol: KaTypeParameterSymbol): DRI {
val containingSymbol = symbol.containingSymbol
?: throw IllegalStateException("Containing symbol is null for type parameter")
val typeParameters = containingSymbol.typeParameters
val typeParameters = (containingSymbol as KaDeclarationSymbol).typeParameters
val index = typeParameters.indexOfFirst { symbol.name == it.name }
return getDRIFromSymbol(containingSymbol).copy(target = PointingToGenericParameters(index))
}
Expand Down Expand Up @@ -93,7 +93,7 @@ internal fun KaSession.getDRIFromValueParameter(symbol: KaValueParameterSymbol):
* @return [DRI] to receiver type
*/
internal fun KaSession.getDRIFromReceiverParameter(receiverParameterSymbol: KaReceiverParameterSymbol): DRI =
getDRIFromReceiverType(receiverParameterSymbol.type)
getDRIFromReceiverType(receiverParameterSymbol.returnType)

private fun KaSession.getDRIFromReceiverType(type: KaType): DRI {
return when(type) {
Expand All @@ -106,20 +106,21 @@ private fun KaSession.getDRIFromReceiverType(type: KaType): DRI {
is KaCapturedType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
is KaFlexibleType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
is KaIntersectionType -> throw IllegalStateException("Unexpected non-denotable type while creating DRI $type")
else -> throw IllegalStateException("Unexpected type while creating DRI $type")
}
}

internal fun KaSession.getDRIFromSymbol(symbol: KaSymbol): DRI =
when (symbol) {
is KaEnumEntrySymbol -> getDRIFromEnumEntry(symbol)
is KaReceiverParameterSymbol -> getDRIFromReceiverParameter(symbol)
is KaTypeParameterSymbol -> getDRIFromTypeParameter(symbol)
is KaConstructorSymbol -> getDRIFromConstructor(symbol)
is KaValueParameterSymbol -> getDRIFromValueParameter(symbol)
is KaVariableSymbol -> getDRIFromVariable(symbol)
is KaFunctionSymbol -> getDRIFromFunction(symbol)
is KaClassLikeSymbol -> getDRIFromClassLike(symbol)
is KaPackageSymbol -> getDRIFromPackage(symbol)
is KaReceiverParameterSymbol -> getDRIFromReceiverParameter(symbol)
else -> throw IllegalStateException("Unknown symbol while creating DRI $symbol")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ internal class DokkaSymbolVisitor(
) = DParameter(
dri = dri.copy(target = PointingToDeclaration),
name = null,
type = toBoundFrom(receiverParameterSymbol.type),
type = toBoundFrom(receiverParameterSymbol.returnType),
expectPresentInSet = null,
documentation = getDocumentation(receiverParameterSymbol)?.toSourceSetDependent() ?: emptyMap(),
sourceSets = setOf(sourceSet),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private fun KaSession.getTypeReferenceFromPossiblyRecursive(
)
is KaCapturedType -> throw NotImplementedError()
is KaIntersectionType -> throw NotImplementedError()
else -> throw NotImplementedError()
}.let {
if (type.isMarkedNullable) Nullable(it) else it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,28 @@ internal class TypeTranslator(
is KaTypeArgumentWithVariance -> toBoundFrom(typeProjection.type).wrapWithVariance(typeProjection.variance)
}

private fun KaSession.toBoundFromTypeAliased(classType: KaClassType): TypeAliased {
val classSymbol = classType.symbol
/**
* For example,
* ```
* typealias Inner = String
* typealias Outer = Inner
*
* val outer: Outer = ""
* ```
*
* `Outer` is [abbreviationType]
* `String` is [fullyExpandedType]
*/
private fun KaSession.toBoundFromTypeAliased(abbreviationType: KaClassType, fullyExpandedType: Bound): TypeAliased {
val classSymbol = abbreviationType.symbol
return if (classSymbol is KaTypeAliasSymbol)
TypeAliased(
typeAlias = GenericTypeConstructor(
dri = getDRIFromClassType(classType),
projections = classType.typeArguments.map { toProjection(it) }),
inner = toBoundFrom(classType.fullyExpandedType),
dri = getDRIFromClassType(abbreviationType),
projections = abbreviationType.typeArguments.map { toProjection(it) }),
inner = fullyExpandedType,
extra = PropertyContainer.withAll(
getDokkaAnnotationsFrom(classType)?.toSourceSetDependent()?.toAnnotations()
getDokkaAnnotationsFrom(abbreviationType)?.toSourceSetDependent()?.toAnnotations()
)
) else
throw IllegalStateException("Expected type alias symbol in type")
Expand Down Expand Up @@ -75,8 +87,8 @@ internal class TypeTranslator(
when (type) {
is KaUsualClassType -> {
// after KT-66996, [type] is an expanded type
val abbreviatedType = type.abbreviatedType
if (abbreviatedType != null) toBoundFromTypeAliased(abbreviatedType)
val abbreviation = type.abbreviation
if (abbreviation != null) toBoundFromTypeAliased(abbreviation, toTypeConstructorFrom(type))
else toTypeConstructorFrom(type)
}

Expand All @@ -92,8 +104,8 @@ internal class TypeTranslator(
is KaClassErrorType -> UnresolvedBound(type.toString())
is KaFunctionType -> {
// after KT-66996, [type] is an expanded type
val abbreviatedType = type.abbreviatedType
if (abbreviatedType != null) toBoundFromTypeAliased(abbreviatedType)
val abbreviation = type.abbreviation
if (abbreviation != null) toBoundFromTypeAliased(abbreviation, toFunctionalTypeConstructorFrom(type))
else toFunctionalTypeConstructorFrom(type)
}
is KaDynamicType -> Dynamic
Expand All @@ -112,6 +124,7 @@ internal class TypeTranslator(
is KaErrorType -> UnresolvedBound(type.toString())
is KaCapturedType -> throw NotImplementedError()
is KaIntersectionType -> throw NotImplementedError()
else -> throw NotImplementedError()
}.let {
if (type.isMarkedNullable) Nullable(it) else it
}
Expand Down Expand Up @@ -175,6 +188,7 @@ internal class TypeTranslator(
is KaFlexibleType -> throw NotImplementedError()
is KaIntersectionType -> throw NotImplementedError()
is KaTypeParameterType -> throw NotImplementedError()
else -> throw NotImplementedError()
}

private fun KaSession.getDokkaAnnotationsFrom(annotated: KaAnnotated): List<Annotations.Annotation>? =
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ kotlinx-bcv = "0.13.2"

## Analysis
kotlin-compiler = "2.0.20-Beta2"
kotlin-compiler-k2 = "2.0.20-dev-7572"
kotlin-compiler-k2 = "2.1.0-dev-2515"

# MUST match the version of the intellij platform used in the kotlin compiler,
# otherwise this will lead to different versions of psi API and implementations
Expand Down

0 comments on commit 270c333

Please sign in to comment.