-
Notifications
You must be signed in to change notification settings - Fork 234
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
Creating a more versatile annoted class #236
Conversation
* the annotation class and methods can be now type parameterized * change deprecated typeValue.displayName -> typeValue.getDisplayString()
* Now in annotation class extra class fields can be declared * Can be initialized through named params of generated class constructor
* Whenever the annoted class has generative constructors extend that class instead of implementing it. * Thus annoted abstract class can now have methods with body without the need of implementing it in super class. * This also removes the hastle of redefining extra fields and initializing it, as done on prev commit 1137ea2 Signed-off-by: Akash Mondal <a98mondal@gmail.com>
Signed-off-by: Akash Mondal <a98mondal@gmail.com>
Great sample. I would be better the response data was able to use generic data |
* Annoted class can now create multiple generative constructors Generated class will also have multiple generative constructors matching each of their params Signed-off-by: Akash Mondal <a98mondal@gmail.com>
Giving ultimate flexibility to the annoted classSteps to write the code for annoted class (say: AnnotClass):
Your API client is ready to make request :) [NOTE: These commits are made keeping in mind that, it doesn't break any old codes with retrofit generator] |
* In some senario the check for non default constructor failed and the generator created named constructor with 0 name length, so it's better to check for name length. * refactor some pieces of code in order to supress some of dart analytics messages Signed-off-by: Akash Mondal <a98mondal@gmail.com>
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Sorry for the late reply. Any idea for extending the class instead of implementing it? It broke the test on generator |
Actually implementing the annoted(user created) class restricts the class to have only annotation methods and not any custom methods to add some extra functionality. NOTE: just with this version of code, the newly generated code will be a little modified with the generated class extending the annoted class. Here's a package I was designing a few days back with my changes on the generator: Any issue or drawbacks with my changes please let me know. I'll try to resolve as early as possible :) |
* these changes are due to code refactoring, in order to maintain dart coding standards as mentioned below. - Don't access members with `this` unless avoiding shadowing. ref: https://dart-lang.github.io/linter/lints/unnecessary_this.html - Try adding a return type to the method. ref: https://dart-lang.github.io/linter/lints/always_declare_return_types.html * also ignore the default constructor from annoted class constructor list, and thus implements the class if it's the only constructor. Signed-off-by: Akash Mondal <a98mondal@gmail.com>
There are discussions about implement and extends. It will give you a context of how we don't use extends here. |
Your argument for flexibility is invalid. Dio already has interceptors and transformers, which already allows for "ultimate flexibility" by adding flexibility to generated code you are only creating confusion and multiple sources of truth. In your example you really just want easy access to |
And, as I already mentioned with my version of retrofit generator, you can either opt for a completely abstract implementation of annoted class with no generative constructor and then the generated code will only implement the class. Moreover, rather than being a normal functional library, this is code generation library so it should be as robust as possible. You might like to add extension methods to add extra methods and design a mixin on Dio to add extra fields. Someone else might like to keep their code simple and stupid with all relevant methods and fields on the annotation class. And, yeah if this version of generator compromises any code efficiency or performance or breaks in any circumstance, feel free to comment. |
You're right. Impossible to fight stupidity. |
Usecase:
Annoted Class
Generated Code
Though here type parametrized class was not required, it's just to show that it's also possible now.