1
votes

Assuming you have an instance of a class. What is the best approach to generate valid scala source code, which could be written out into a file and compiled, of that instance during runtime? (Utilizing the scala reflection-api/macros?) Is it possible to parse the AST representation into source code?

1
Could you describe your use case? - Sounds like serialization could be something for you. - Madoc

1 Answers

2
votes

No it's not possible. Class file contains JVM byte-code that has nothing to do with Scala. You can try use Java-decompiler (http://varaneckas.com/jad/ for example), but you wouldn't be able to get something readable.

As I unserstand scala is moving towards new platform (Dotty), and maybe in future it will be possible.