recompose
recompose copied to clipboard
Spike: Writing a "Composer" that has access to the plugin context
Currently the Composer
(code) is an independent class that writes Kotlin code and outputs it as a string. This string is then used by the plugin and CLI.
What if we'd implement a Composer
that knows its inside an IntelliJ / Android Studio plugin and can make use of the environment and tools to write the code to the destination. A big advantage would be that we'd get access to the AST of the surrounding code and could, for example, figure out if a drawable is an image or a vector (#69). Maybe we would also be able to use the internals for generating/writing code and wouldn't need to write a plain string?
Considering the composer is the "backend" and the parser is the "frontend" we may also be able to replace the "frontend" and let IntelliJ parse the XML and give us access to its AST?
A downside of this would be that this would basically reduce this project to the plugin and potentially kill the CLI. But then again, maybe parts of it could also survive in a standalone version. After all projects like detekt also make use of the parts of the Kotlin compiler without being a plugin.
Having a closer look at the Java to Kotlin conversion in the Kotlin plugin may give some hints about what is possible.