Martinho0330 / javaparser

Automatically exported from code.google.com/p/javaparser
0 stars 0 forks source link

Return empty lists from nodes that have no children #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
At the moment, AST nodes that have a list of children return null when
there were no child nodes in the input.  This makes processing the tree
awkward.  Processing code is full of pointless null checks.

Instead, the nodes should return an empty list when there are no child nodes.

I think this can be easily implemented by initialising list instance
variables to Collections.emptyList().

Original issue reported on code.google.com by nat.pr...@gmail.com on 3 Mar 2009 at 6:36

GoogleCodeExporter commented 9 years ago

Original comment by jges...@gmail.com on 1 Apr 2009 at 2:18

GoogleCodeExporter commented 9 years ago
I totally agree. See "Item 27: Return zero-length arrays, not nulls" in Josh 
Bloch's
Effective Java Programming Language Guide.

Original comment by mburger313@gmail.com on 19 Apr 2009 at 12:06