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

Generate model for abstract class if class annotation is present #105

Merged
merged 8 commits into from
Feb 5, 2017

Conversation

elihart
Copy link
Contributor

@elihart elihart commented Feb 2, 2017

@felipecsl @gpeal @seanabraham

This forces the annotation processor to generate a model for abstract model classes if they have the @EpoxyClassModel attribute. Previously abstract classes never had a model generated for them since we couldn't know if they implemented every necessary method. This annotation approach allows users to tell the processor if they want a model generated.

We may like to use an abstract class for all our models to indicate that they shouldn't be instantiated directly, and to prevent people from accidentally using them instead of the generated class.

In this PR I also add a new feature to automatically generate the createNewHolder method on models that use view holders. This method was mostly boilerplate and we can generate it by looking at the type of the class and just returning a new object of that type.

For example, in our sample app we now have the class

@EpoxyModelClass
public abstract class ButtonModel extends EpoxyModelWithHolder<ButtonHolder> {

This is a small win to reduce boilerplate.

Besides that I did some cleanup - moving util methods to a ProcessorUtils class - and a little other refactoring clean up since the processor is getting large and more complicated.

* Generates default implementations of certain model methods if the model is abstract and doesn't
* implement them.
*/
private Iterable<MethodSpec> generateDefaultMethodImplementations(ClassToGenerateInfo info)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elihart What are the pros and cons of creating empty implementation vs having the generated class be abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpeal I can't think of any good cases where you would want the generated class to be abstract. That doesn't seem useful to me, interested to hear if you know a case.

This isn't creating an empty implementation, it's generating a default implementation. In this case the default implementation is very likely what you would have written manually anyway, so it is helping to reduce boilerplate.

@elihart elihart force-pushed the eli/abstract_allowance branch from 705ab09 to 5f63e34 Compare February 5, 2017 05:10
@elihart elihart merged commit 86dcd45 into master Feb 5, 2017
@elihart elihart deleted the eli/abstract_allowance branch February 5, 2017 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants