Community
Participate
Working Groups
3.0 Dealing with modifiers in the new 3.0 API is complicated especially if you want to copy modifiers of an existing node into a new node. To ease this all ASTNodes that deal with modifiers should offer a method setModifiers(List modifiers). This methods copies the modifiers from the parameter list into the modifier list managed by the node. The current list should be emptied first.
Jim, Do you want to add this API?
Me and Dirk had a lengthy discussion about the topic and Dirk still couldn't convince me that 'setModifiers' is a good idea. I think ASTNode.copySubtrees would do the job -> newDecl.modifiers().addAll( ASTNode.copySubtrees(newAST, oldDecl.modifiers())); But in general I agree with Dirk that working with modifiers got quite nasty with the AST-3 and we should think about if we can add a bit more convenience for working with the modifier nodes. A first suggestion from my side would be an addition to ast.newModifier ast.newModifiers(int modifierFlags) : List creating modifier nodes from a bitSet (in a default order)
Martin, I agree that setModifiers does not seem like much of a value-add. I like the idea of adding a convenience method for creating modifier nodes from modifier bit flags, and automatically arranging them in JLS-recommended order.
Added convenience methods to AST: public List newModifiers(int flags); Added tests. Updated build notes. Released to HEAD. Dirk/Martin, Please reopen if there are additional things that could make JLS3 modifiers more useable.