https://kotlinlang.org logo
#squarelibraries
Title
# squarelibraries
d

Dariusz Kuc

04/08/2021, 6:06 PM
Hello 👋 I'm using kotlinpoet to generate some data classes with some default values for enums. In order to reference the default value I'm using
MemberName
and it generally works great
Copy code
public data class Result(
  public val myEnum: MyEnum = MyEnum.VALUE
)
Problem arise when I have multiple enums having same value as
MemberName
adds explicit import to that value, i.e.
Copy code
import com.expediagroup.graphql.generated.enums.MyEnum
import com.expediagroup.graphql.generated.enums.MyEnum.VALUE
Any suggestions how to fix that? Should I just reference the
VALUE
from the code without using
MemberName
?
e.g. could just do the
%L
for literal value and just build it out as
enum.value
d

diesieben07

04/08/2021, 6:14 PM
You can probably use
"%T.%N"
and the
TypeName
and name for the constant
d

Dariusz Kuc

04/08/2021, 6:31 PM
cool! using
Copy code
constructorParameter.defaultValue("%T.%N", className, className.member(VALUE))
does not produce the extra unnecessary import