Search code examples
scalascalacscala-compiler

obtaining the source of a case class's automatically generated methods


How can one obtain the code of all automatically generated methods of a case class, to cleanly preserve any of them when refactoring to a regular (non-case) class? is there some compilation flag that reveals the case class's auto-generated methods, or some other way, that ultimately reduce this to a cut & paste?

I have been under the impression that there are compilation flags to reveal automatically expanded definitions....


Solution

  • You can see what the compiler desugars the source code to with the -Xprint:<phase> flags. For your example (seeing which code is generated for case classes), run:

    scalac -Xprint:typer YourScala.sca
    

    With -Xshow-phases flag you'll see all the available phases.

    But the output you see is not compilable scala source code, but some intermediate representation.