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

Replace reflection with generated code #29

Open
hamen opened this issue Mar 21, 2016 · 5 comments
Open

Replace reflection with generated code #29

hamen opened this issue Mar 21, 2016 · 5 comments

Comments

@hamen
Copy link
Member

hamen commented Mar 21, 2016

Evaluate if this could actually be done... and do it.

@hamen hamen added this to the 1.0 milestone Mar 21, 2016
@mrsasha
Copy link
Member

mrsasha commented Mar 21, 2016

Yeah, it's doable, I'd say.

@hamen
Copy link
Member Author

hamen commented May 7, 2016

@sockeqwe we could use some pointers here 😄

@sockeqwe
Copy link

sockeqwe commented May 7, 2016

What do you exactly want to delete with annotation processing? I have to dive deeper into your code next week to see what exactly could be eliminated with annotation processing, but from what I have read in the wiki:

It reads the XML, parses the binding string, then through reflection finds the methods and properties in the ViewModel

The problem is, that annotation processing is a java thing. There is no build in functionality so that the annotation processor knows about your android projects res folder. However, you can pass that folder path manually to your annotation processor (annotation processor argument). So once you the path you are ready to scan xml layout files.

Unfortunately this is means a painful setup for the user of this library. But there is more painful things coming. Basically, annotation processor doesn't know about product flavors etc. So the user would also have to pass that as an annotation processor argument to your annotation processor.

But wait, there is more ...
Once you be able to scan all xml layout files, you have to consider that there are same xml layout files with in different qualifiers like layout-w300dp, layout-sw600dp etc. Furthermore, there xml layout files can <include> other xml layout files ...

But wait, there is more ....
Annotation processing doesn't know nothing of R.java. Maybe or maybe not, you need the value of R.id.foo or the package name to your apps R.java to generate code that compiles like findViewById(12348978) or findViewById(com.myapp.R.id.foo). For the first option you have to write a parser that parses R.java file to extract the id constants. For the second option yet another annotation processor argument is needed to let the processor know about that. Not sure if this will work with library projects.

TLDR I think this is a huge amount of work and not sure if it's worth the effort, but if you want to do this I think writing a Gradle Plugin is the better option because then you can access to android's gradle plugin and configurations.

@hamen
Copy link
Member Author

hamen commented May 7, 2016

Thank you for the quick feedback, man. Looks tricky and huge work, indeed. @mrsasha we could decrease the priority of this one and point our efforts to other enhancements first.

@mrsasha
Copy link
Member

mrsasha commented May 8, 2016

Thanks for this, @sockeqwe! I didn't actually think about how it would be done, but I thought that through annotation processing you get a complete access to all the files, and not just the Java sources. So it looks like gradle plugin would be the way to go.

btw, @hamen this was never a very-high priority, more like a nice to have. we'll see. there's lots of other stuff that needs to be done :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants