Skip to content

Commit

Permalink
Replace values() with entries() with generated enums
Browse files Browse the repository at this point in the history
  • Loading branch information
Palleas committed Dec 17, 2024
1 parent a93647b commit 20e8348
Show file tree
Hide file tree
Showing 45 changed files with 54 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class ModelGenerator(
val companion = TypeSpec.companionObjectBuilder()
.addProperty(
PropertySpec.builder("mapping", createMapOfStringToNonNullType(enumType))
.initializer("values().associateBy(%T::value)", enumType)
.initializer("entries().associateBy(%T::value)", enumType)
.addModifiers(KModifier.PRIVATE)
.build(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public enum class DogBreed(
;

public companion object {
private val mapping: Map<String, DogBreed> = values().associateBy(DogBreed::value)
private val mapping: Map<String, DogBreed> = entries().associateBy(DogBreed::value)

public fun fromValue(`value`: String): DogBreed? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class PersonWithDefaultsEnumDefault(

public companion object {
private val mapping: Map<String, PersonWithDefaultsEnumDefault> =
values().associateBy(PersonWithDefaultsEnumDefault::value)
entries().associateBy(PersonWithDefaultsEnumDefault::value)

public fun fromValue(`value`: String): PersonWithDefaultsEnumDefault? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class PersonWithDefaultsEnumQuotedDefault(

public companion object {
private val mapping: Map<String, PersonWithDefaultsEnumQuotedDefault> =
values().associateBy(PersonWithDefaultsEnumQuotedDefault::value)
entries().associateBy(PersonWithDefaultsEnumQuotedDefault::value)

public fun fromValue(`value`: String): PersonWithDefaultsEnumQuotedDefault? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class StateBMode(
;

public companion object {
private val mapping: Map<String, StateBMode> = values().associateBy(StateBMode::value)
private val mapping: Map<String, StateBMode> = entries().associateBy(StateBMode::value)

public fun fromValue(`value`: String): StateBMode? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class Status(
;

public companion object {
private val mapping: Map<String, Status> = values().associateBy(Status::value)
private val mapping: Map<String, Status> = entries().associateBy(Status::value)

public fun fromValue(`value`: String): Status? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class StateBMode(
;

public companion object {
private val mapping: Map<String, StateBMode> = values().associateBy(StateBMode::value)
private val mapping: Map<String, StateBMode> = entries().associateBy(StateBMode::value)

public fun fromValue(`value`: String): StateBMode? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class Status(
;

public companion object {
private val mapping: Map<String, Status> = values().associateBy(Status::value)
private val mapping: Map<String, Status> = entries().associateBy(Status::value)

public fun fromValue(`value`: String): Status? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class ContentType(
;

public companion object {
private val mapping: Map<String, ContentType> = values().associateBy(ContentType::value)
private val mapping: Map<String, ContentType> = entries().associateBy(ContentType::value)

public fun fromValue(`value`: String): ContentType? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class EnumHolderArrayOfEnums(

public companion object {
private val mapping: Map<String, EnumHolderArrayOfEnums> =
values().associateBy(EnumHolderArrayOfEnums::value)
entries().associateBy(EnumHolderArrayOfEnums::value)

public fun fromValue(`value`: String): EnumHolderArrayOfEnums? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class EnumHolderInlinedEnum(

public companion object {
private val mapping: Map<String, EnumHolderInlinedEnum> =
values().associateBy(EnumHolderInlinedEnum::value)
entries().associateBy(EnumHolderInlinedEnum::value)

public fun fromValue(`value`: String): EnumHolderInlinedEnum? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class EnumHolderInlinedExtensibleEnum(

public companion object {
private val mapping: Map<String, EnumHolderInlinedExtensibleEnum> =
values().associateBy(EnumHolderInlinedExtensibleEnum::value)
entries().associateBy(EnumHolderInlinedExtensibleEnum::value)

public fun fromValue(`value`: String): EnumHolderInlinedExtensibleEnum? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum class EnumObject(
;

public companion object {
private val mapping: Map<String, EnumObject> = values().associateBy(EnumObject::value)
private val mapping: Map<String, EnumObject> = entries().associateBy(EnumObject::value)

public fun fromValue(`value`: String): EnumObject? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class ExtensibleEnumObject(

public companion object {
private val mapping: Map<String, ExtensibleEnumObject> =
values().associateBy(ExtensibleEnumObject::value)
entries().associateBy(ExtensibleEnumObject::value)

public fun fromValue(`value`: String): ExtensibleEnumObject? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class FooBarsFoo(
;

public companion object {
private val mapping: Map<String, FooBarsFoo> = values().associateBy(FooBarsFoo::value)
private val mapping: Map<String, FooBarsFoo> = entries().associateBy(FooBarsFoo::value)

public fun fromValue(`value`: String): FooBarsFoo? = mapping[value]
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/examples/enumExamples/models/FooFoo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class FooFoo(
;

public companion object {
private val mapping: Map<String, FooFoo> = values().associateBy(FooFoo::value)
private val mapping: Map<String, FooFoo> = entries().associateBy(FooFoo::value)

public fun fromValue(`value`: String): FooFoo? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class ChildDefinitionInlineEnum(

public companion object {
private val mapping: Map<String, ChildDefinitionInlineEnum> =
values().associateBy(ChildDefinitionInlineEnum::value)
entries().associateBy(ChildDefinitionInlineEnum::value)

public fun fromValue(`value`: String): ChildDefinitionInlineEnum? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum class ChildDiscriminator(

public companion object {
private val mapping: Map<String, ChildDiscriminator> =
values().associateBy(ChildDiscriminator::value)
entries().associateBy(ChildDiscriminator::value)

public fun fromValue(`value`: String): ChildDiscriminator? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public enum class ExternalObjectThreeEnum(

public companion object {
private val mapping: Map<String, ExternalObjectThreeEnum> =
values().associateBy(ExternalObjectThreeEnum::value)
entries().associateBy(ExternalObjectThreeEnum::value)

public fun fromValue(`value`: String): ExternalObjectThreeEnum? = mapping[value]
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public enum class ExternalParameter(

public companion object {
private val mapping: Map<String, ExternalParameter> =
values().associateBy(ExternalParameter::value)
entries().associateBy(ExternalParameter::value)

public fun fromValue(`value`: String): ExternalParameter? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class ExternalObjectThreeEnum(

public companion object {
private val mapping: Map<String, ExternalObjectThreeEnum> =
values().associateBy(ExternalObjectThreeEnum::value)
entries().associateBy(ExternalObjectThreeEnum::value)

public fun fromValue(`value`: String): ExternalObjectThreeEnum? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class ContributorStatus(

public companion object {
private val mapping: Map<String, ContributorStatus> =
values().associateBy(ContributorStatus::value)
entries().associateBy(ContributorStatus::value)

public fun fromValue(`value`: String): ContributorStatus? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class OrganisationStatus(

public companion object {
private val mapping: Map<String, OrganisationStatus> =
values().associateBy(OrganisationStatus::value)
entries().associateBy(OrganisationStatus::value)

public fun fromValue(`value`: String): OrganisationStatus? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class PullRequestStatus(

public companion object {
private val mapping: Map<String, PullRequestStatus> =
values().associateBy(PullRequestStatus::value)
entries().associateBy(PullRequestStatus::value)

public fun fromValue(`value`: String): PullRequestStatus? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class RepositoryStatus(

public companion object {
private val mapping: Map<String, RepositoryStatus> =
values().associateBy(RepositoryStatus::value)
entries().associateBy(RepositoryStatus::value)

public fun fromValue(`value`: String): RepositoryStatus? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class RepositoryVisibility(

public companion object {
private val mapping: Map<String, RepositoryVisibility> =
values().associateBy(RepositoryVisibility::value)
entries().associateBy(RepositoryVisibility::value)

public fun fromValue(`value`: String): RepositoryVisibility? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class StatusQueryParam(

public companion object {
private val mapping: Map<String, StatusQueryParam> =
values().associateBy(StatusQueryParam::value)
entries().associateBy(StatusQueryParam::value)

public fun fromValue(`value`: String): StatusQueryParam? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum class ContentModelType(

public companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
entries().associateBy(ContentModelType::value)

public fun fromValue(`value`: String): ContentModelType? = mapping[value]
}
Expand All @@ -71,7 +71,7 @@ public enum class ContentThirdAttr(

public companion object {
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)
entries().associateBy(ContentThirdAttr::value)

public fun fromValue(`value`: String): ContentThirdAttr? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum class ContentModelType(

public companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
entries().associateBy(ContentModelType::value)

public fun fromValue(`value`: String): ContentModelType? = mapping[value]
}
Expand All @@ -74,7 +74,7 @@ public enum class ContentThirdAttr(

public companion object {
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)
entries().associateBy(ContentThirdAttr::value)

public fun fromValue(`value`: String): ContentThirdAttr? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public enum class ContentModelType(

public companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
entries().associateBy(ContentModelType::value)

public fun fromValue(`value`: String): ContentModelType? = mapping[value]
}
Expand All @@ -74,7 +74,7 @@ public enum class ContentThirdAttr(

public companion object {
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)
entries().associateBy(ContentThirdAttr::value)

public fun fromValue(`value`: String): ContentThirdAttr? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class EnumHolderDtoInlinedEnumDto(

public companion object {
private val mapping: Map<String, EnumHolderDtoInlinedEnumDto> =
values().associateBy(EnumHolderDtoInlinedEnumDto::value)
entries().associateBy(EnumHolderDtoInlinedEnumDto::value)

public fun fromValue(`value`: String): EnumHolderDtoInlinedEnumDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum class EnumObjectDto(
;

public companion object {
private val mapping: Map<String, EnumObjectDto> = values().associateBy(EnumObjectDto::value)
private val mapping: Map<String, EnumObjectDto> = entries().associateBy(EnumObjectDto::value)

public fun fromValue(`value`: String): EnumObjectDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class FirstLevelDiscriminatorDto(

public companion object {
private val mapping: Map<String, FirstLevelDiscriminatorDto> =
values().associateBy(FirstLevelDiscriminatorDto::value)
entries().associateBy(FirstLevelDiscriminatorDto::value)

public fun fromValue(`value`: String): FirstLevelDiscriminatorDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class FooBarsDtoFooDto(

public companion object {
private val mapping: Map<String, FooBarsDtoFooDto> =
values().associateBy(FooBarsDtoFooDto::value)
entries().associateBy(FooBarsDtoFooDto::value)

public fun fromValue(`value`: String): FooBarsDtoFooDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class FooFooDto(
;

public companion object {
private val mapping: Map<String, FooFooDto> = values().associateBy(FooFooDto::value)
private val mapping: Map<String, FooFooDto> = entries().associateBy(FooFooDto::value)

public fun fromValue(`value`: String): FooFooDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum class ModeParameterDto(

public companion object {
private val mapping: Map<String, ModeParameterDto> =
values().associateBy(ModeParameterDto::value)
entries().associateBy(ModeParameterDto::value)

public fun fromValue(`value`: String): ModeParameterDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum class RootDiscriminatorDto(

public companion object {
private val mapping: Map<String, RootDiscriminatorDto> =
values().associateBy(RootDiscriminatorDto::value)
entries().associateBy(RootDiscriminatorDto::value)

public fun fromValue(`value`: String): RootDiscriminatorDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum class SecondLevelDiscriminatorDto(

public companion object {
private val mapping: Map<String, SecondLevelDiscriminatorDto> =
values().associateBy(SecondLevelDiscriminatorDto::value)
entries().associateBy(SecondLevelDiscriminatorDto::value)

public fun fromValue(`value`: String): SecondLevelDiscriminatorDto? = mapping[value]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public enum class ContentModelType(

public companion object {
private val mapping: Map<String, ContentModelType> =
values().associateBy(ContentModelType::value)
entries().associateBy(ContentModelType::value)

public fun fromValue(`value`: String): ContentModelType? = mapping[value]
}
Expand All @@ -79,7 +79,7 @@ public enum class ContentThirdAttr(

public companion object {
private val mapping: Map<String, ContentThirdAttr> =
values().associateBy(ContentThirdAttr::value)
entries().associateBy(ContentThirdAttr::value)

public fun fromValue(`value`: String): ContentThirdAttr? = mapping[value]
}
Expand All @@ -94,7 +94,7 @@ public enum class ContentType(
;

public companion object {
private val mapping: Map<String, ContentType> = values().associateBy(ContentType::value)
private val mapping: Map<String, ContentType> = entries().associateBy(ContentType::value)

public fun fromValue(`value`: String): ContentType? = mapping[value]
}
Expand Down
Loading

0 comments on commit 20e8348

Please sign in to comment.