m-m-m / code

Library to parse, analyze, transform and generate code
Apache License 2.0
2 stars 3 forks source link

support for records #45

Open hohwille opened 1 year ago

hohwille commented 1 year ago

In Java 14 records have been introduced. We need to extend mmm-code to support this new language construct.

hohwille commented 1 year ago

Fundamentals are implemented, tested, and working. However, parser needs to be adapted to parse the default record constructor and detect implicitly declared fields, etc.

During this change, I refactored the writing of source-code and moved a lot of that logic from the BaseItems to CodeLanguage. This does not perfectly align with polymorphism but gives the needed flexbility to implement other languages than Java. Initially my design idea was to create the entire CodeItem hierarchy for each programming language. However, I noticed that this would lead to a very large tree of classes for every supported language while most of them (and those in focus) all share the same constructs. So instead Base* types are already the implementation for almost all of the hierarchy and only language, context, and few other constructs need to be language specific. This even makes it possible to more easily transform between JVM languages as constructs can be reused and just be written in a slightly different syntax (e.g. to write Java code as Kotlin). The current drawback is that very different languages like e.g. JavaScript or Haskel do not fit very well and also advanced languages like Scala need some quirks to support constructs like traits that do not exist in Java.