Issue Type: Improvement Improvement
Assignee: Unassigned
Components: CodeGen
Created: 22/Apr/13 8:02 AM
Description:

Currently the CollectionMethodsDecorator methods sizeXXX, addXXX and clearXXX are not null-safe.

The behaviour for these methods in case of a null-collection would be:

  • size: return 0
  • add: create a LinkedList before adding
  • clear: do nothing

I think this could be easily archieved by a simple change:

@@ -48,8 +48,8 @@ public class CollectionMethodsDecorator implements ClassDecorator

/** Text for template class. */

private static final String s_classText = "class Gorph { java.util.List $1; " +

- "/** Get the number of $0 items.\n * @return count\n */\npublic int size$5() { return $1.size(); }" +

- "/** Add a $0 item.\n * @param item\n */\npublic void add$2($3 item) { $1.add(item); }" +

+ "/** Get the number of $0 items.\n * @return count\n */\npublic int size$5() { return ($1 == null) ? 0 : $1.size(); }" +

+ "/** Add a $0 item.\n * @param item\n */\npublic void add$2($3 item) { if($1 == null) { $1 = new java.util.LinkedList(); } $1.add(item); }" +

"/** Get $0 item by position.\n * @return item\n * @param index\n */\npublic $3 get$2(int index) { return $4$1.get(index); }" +

- "/** Remove all $0 items.\n */\npublic void clear$5() { $1.clear(); } }";

+ "/** Remove all $0 items.\n */\npublic void clear$5() { if($1 != null) { $1.clear(); } } }";

// where $0 is the description text, $1 is the field name, $2 is the value name with initial uppercase character,

// $3 is the type, and $4 is a cast if an untyped list is used, or empty if a typed list is used

TODO: The initialization for the add-method is not yet using the list class specified by the ListImplementationDecorator.

Project: JiBX
Priority: Major Major
Reporter: Christian Spriegel
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
jibx-devs mailing list
jibx-devs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-devs

Reply via email to