Manually maintaining all methods of AppCompatActivity
and the SupportFragment
is impossible. Autogenerated code is the solution.
This generator parses plain .java
files.
Even easier: It parses java files I generated with Android Studio.
By extending the Activity
and override all possible methods (keeping the JavaDoc) Android Studio generates a simple to parse file.
This is by far the easiest solution. Using reflection doesn't work because reading the variable names and JavaDoc isn't possible.
After generating the input files with this method the generator parses the .java
file using RegEx.
The RegEx for parsing methods of a java file isn't perfect but as long as it works it's fine.
Once it breaks it can be adjusted.
It doesn't parse the parts perfectly.
I.e. the method visiblity doesn't get parsed or the method body can only be a single statement (which is the generated super
call).
Once parsed writing the sourcecode is easy. I considered using javapoet but it didn't allow me to write plain text into a file. Parsing the content out of a JavaDoc to put it into the javapoet javadoc method was too hard. With this easy solution I copy the javadoc for every method as I read it in the input file.
The output is readable and valid but not perfectly formatted. I reformat the code using Android Studio and everything is done. As the project grows the formatting takes longer and longer but the generator output is valid and it's possible to work with it while developing.