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

Update GeneratedField.kt #880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -54,48 +54,30 @@ public fun FieldType.toNullable(): FieldType =
* Returns a new fieldType with the same type but with nullability disabled in the column type.
* NOTE: for [FieldType.FrameFieldType], the `nullable` property indicates the nullability of the frame itself, not the type of the column.
*/
public fun FieldType.toNotNullable(): FieldType =
if (isNullable()) {
public fun FieldType.toNotNullable(): FieldType {
fun String.toNotNullableName() = if (this == "*") "Any" else removeSuffix("?")

return if (isNullable()) {
when (this) {
is FieldType.FrameFieldType ->
FieldType.FrameFieldType(
markerName = markerName.let {
if (it == "*") {
"Any"
} else {
it.removeSuffix("?")
}
},
nullable = nullable,
renderAsList = renderAsList,
)

is FieldType.GroupFieldType ->
FieldType.GroupFieldType(
markerName = markerName.let {
if (it == "*") {
"Any"
} else {
it.removeSuffix("?")
}
},
renderAsObject = renderAsObject,
)

is FieldType.ValueFieldType ->
FieldType.ValueFieldType(
typeFqName = typeFqName.let {
if (it == "*") {
"Any"
} else {
it.removeSuffix("?")
}
},
)
is FieldType.FrameFieldType -> FieldType.FrameFieldType(
markerName = markerName.toNotNullableName(),
nullable = nullable,
renderAsList = renderAsList
)

is FieldType.GroupFieldType -> FieldType.GroupFieldType(
markerName = markerName.toNotNullableName(),
renderAsObject = renderAsObject
)

is FieldType.ValueFieldType -> FieldType.ValueFieldType(
typeFqName = typeFqName.toNotNullableName()
)
}
} else {
this
}
}

public val FieldType.name: String
get() = when (this) {
Expand Down
Loading