You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Apologies if there is already a way to do this, but I have not had any luck coming up with a particularly intuitive way of doing this.
Let's say I am trying to achieve a nested structure for a number of data classes
data classUser(valname:String, valmetadata:Metadata) {
companionobject {
funnew(): User { /**/ }
}
data classMetadata(valage:Int, val weight) {
companionobject {
// Main problem 👇funnew(): Metadata { /**/ }
}
}
}
Most of this is quite easily achievable in Kotlinpoet. However, what I am struggling with is a concise way to properly assign the return type of Metadata.new. When writing this manually, it is perfect valid to simply specify Metadata as the return type, no need for additional imports. However, there does not seem to be an easy way to express this in Kotlinpoet.
My current approach is to resort to a recursion tracker so that I can keep track of $BASE_PACKAGE.User.Metadata (in my actual code this can be of arbitrary depth).
Describe the solution you'd like
A way to allow users to define ClassNames that are guaranteed to already be imported. Alternatively, a way to access the ClassName from within a TypeSpec.Builder however, I am not sure that is feasible, would totally make sense if that information is not available until the actual TypeSpec is constructed
Describe alternatives you've considered
Oh... see above
Additional context
N/A
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Apologies if there is already a way to do this, but I have not had any luck coming up with a particularly intuitive way of doing this.
Let's say I am trying to achieve a nested structure for a number of data classes
Most of this is quite easily achievable in Kotlinpoet. However, what I am struggling with is a concise way to properly assign the return type of
Metadata.new
. When writing this manually, it is perfect valid to simply specifyMetadata
as the return type, no need for additional imports. However, there does not seem to be an easy way to express this in Kotlinpoet.My current approach is to resort to a recursion tracker so that I can keep track of
$BASE_PACKAGE.User.Metadata
(in my actual code this can be of arbitrary depth).Describe the solution you'd like
A way to allow users to define ClassNames that are guaranteed to already be imported. Alternatively, a way to access the
ClassName
from within aTypeSpec.Builder
however, I am not sure that is feasible, would totally make sense if that information is not available until the actualTypeSpec
is constructedDescribe alternatives you've considered
Oh... see above
Additional context
N/A
The text was updated successfully, but these errors were encountered: