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

Fix compilation error when using typealias #6

Merged
Changes from 1 commit
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 @@ -3,6 +3,7 @@ package com.theblueground.fixtures
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSTypeAlias
import com.google.devtools.ksp.symbol.KSValueParameter
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.TypeName
Expand All @@ -20,19 +21,18 @@ internal class ProcessedParameterMapper(

fun mapParameter(parameterValue: KSValueParameter): ProcessedFixtureParameter {
val resolvedType = parameterValue.type.resolve()
return mapParameter(
parameterValue = parameterValue,
parameterType = resolvedType,
parameterClassDeclaration = (resolvedType.declaration as KSClassDeclaration),
)
return when (val declaration = resolvedType.declaration) {
is KSTypeAlias -> mapParameter(parameterValue, declaration.type.resolve())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! Can we also add a test for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test added

else -> mapParameter(parameterValue, resolvedType)
}
}

private fun mapParameter(
parameterValue: KSValueParameter,
parameterType: KSType,
parameterClassDeclaration: KSClassDeclaration,
): ProcessedFixtureParameter {
val name = parameterValue.name!!.asString()
val parameterClassDeclaration = parameterType.declaration as KSClassDeclaration

return when {
parameterType.hasFixtureAdapter(processedFixtureAdapters) -> mapFixtureAdapterParameter(
Expand Down