Hello folks I am building an AST transformation that will allow me to define a concept of mutable and immutable objects. Java lets me hold mutable objects in immutable object lists (as per the code below). But my DSL also wants to allow immutable objects to be held in mutable lists. The meaning it is conveying is that adding to mutable lists will clone the immutable object and not affect the original ( I use the << operator to denote this. It denotes that the object is being streamed into the list and will not affect the object if list contents are modified) . What is the best way to achieve this? I dont see a type checking extension that will catch this missing "method" and let me override it.
I dont want to create an extension function, because this could be a model I want to follow for several classes and not just Blah. Which is why I want to use the AST route to solve this problem. Any pointers will be very helpful. Assume that I can convert immutable to mutable behind the scenes. Also assume that 100s of classes will follow this model of mutability static class Blah { > static class Immutable { > String getProperty1() { "PROP1" } > } > static class Mutable extends Immutable { > void setProperty1(String value) { > } > } > } > void fn() { > // This works > List<Blah.Immutable> myOtherThings = [] > myOtherThings << new Blah.Immutable() > myOtherThings << new Blah.Mutable() > > // This does not (I want an AST that will make this work) > List<Blah.Mutable> myThings = [] > myThings << new Blah.Immutable() > > // This works > myThings << new Blah.Mutable() > } > regards Saravanan