Throw exception when trying to modify NTA List/Opt children through generated mutator methods

Issue #260 new
Jesper Öqvist created an issue

The regular getter/setter methods are generated for NTA children, however it seems like modifying an NTA child should be disallowed. These are the methods that are automatically generated to modify children which are also generated for NTAs:

List NTA:

  • addX(Type)
  • setX(Type, int)

Optional NTA:

  • setX(Type)

The above methods allowing modifications on the NTA children without throwing an exception, however, the following methods throw an exception with the message "Can not replace NTA child [...]" when trying to call them:

  • Regular NTA: setX(Type)
  • List NTA: setXList(List<Type>)
  • Optional NTA: setXOpt(Opt<Type>)
  • Token NTA: setX(Type)

It seems like an oversigth that one set of mutator methods throws an exception for NTA children, while another set of mutators don't throw an exception. I recently discovered that an NTA in ExtendJ was modified:

LambdaAnonymousDecl decl = new LambdaAnonymousDecl(...);
decl.addImplements(...); // decl.getImplementsList() is NTA!

Comments (0)

  1. Log in to comment