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

Classes with no-args-constructor or all-default-values-constructor need not to be annotated with @Dowel #9

Closed
5 tasks done
jayasuryat opened this issue Oct 22, 2022 · 0 comments · Fixed by #13
Closed
5 tasks done
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jayasuryat
Copy link
Owner

jayasuryat commented Oct 22, 2022

What?

Properties of types having a no-args constructor or if all of the properties of a constructor have default values, then there is no need to annotate those class with @Dowel annotation or provide a custom PreviewParameterProvider via @ConsiderForDowel, as those class's instance could be easily created by invoking a no-args constructor.

For example :

@Dowel
data class Article(
    val title: String,
    val story: String,
    val type: Type,
    val meta: MetaData,
) {

    data class Type(
        val genre: String = "news",
    )

    class MetaData {
        var hasAffiliateLinks: Boolean = false
    }
}

As of now, it is an error to have models like this. It is necessary that both Type and MetaData classes be annotated with @Dowel annotation for Dowel to work.

But it is not really necessary, instances of both Type and MetaData classes can be created without any computational overhead, simply by invoking a no-args constructor (like Type() or MetaData()).

How?

This should be pretty straightforward to achieve given they way ClassRepresentation is structured.

A new type under ParameterSpec could be added for such no-args-constructor declarations. Given that ParameterSpec is a sealed type, the Kotlin compiler itself should yell until all of the cases are handled. And the object construction logic should be straightforward as well as classes can be just instantiated with ().

TODO

  • Add a new type under ParameterSpec for no-args-constructor declarations
  • Handle ClassRepresentation mapping
  • Handle object creation logic
  • Add tests
  • Update documentation
@jayasuryat jayasuryat added this to the v0.7.0 milestone Oct 22, 2022
@jayasuryat jayasuryat added the enhancement New feature or request label Oct 22, 2022
@jayasuryat jayasuryat self-assigned this Oct 22, 2022
jayasuryat pushed a commit that referenced this issue Oct 23, 2022
@jayasuryat jayasuryat linked a pull request Oct 24, 2022 that will close this issue
jayasuryat added a commit that referenced this issue Oct 24, 2022
Default support for types with no-args-constructors #9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant