Skip to content

Commit

Permalink
#28 support List and Set of simple types in xpp3-extended-writer
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Mar 9, 2019
1 parent 270e0e8 commit b4d3c2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void createLocationTrackingMethod( JClass jClass )

JSourceCode sc = method.getSourceCode();

sc.add( locationTracker.getName() + " location = locationTracker.getLocation( key );" );
sc.add( locationTracker.getName() + " location = ( locationTracker == null ) ? null : locationTracker.getLocation( key );" );
sc.add( "if ( location != null )" );
sc.add( "{" );
sc.addIndented( "serializer.comment( toString( location ) );" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ private void writeClass( ModelClass modelClass, JClass jClass )

if ( ModelDefault.LIST.equals( type ) || ModelDefault.SET.equals( type ) )
{
boolean isList = ModelDefault.LIST.equals( type );

sc.add( getValueChecker( type, value, association ) );

sc.add( "{" );
Expand All @@ -393,6 +395,15 @@ private void writeClass( ModelClass modelClass, JClass jClass )
sc.add( "serializer.startTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" );
}

if ( isLocationTracking() && !isClassInModel( association.getTo(), modelClass.getModel() ) )
{
sc.add( locationTracker.getName() + " location = " + uncapClassName + ".getLocation( \"" + fieldTagName + "\" );" );
if ( isList )
{
sc.add( "int n = 0;" );
}
}

sc.add( "for ( Iterator iter = " + value + ".iterator(); iter.hasNext(); )" );

sc.add( "{" );
Expand All @@ -406,20 +417,22 @@ private void writeClass( ModelClass modelClass, JClass jClass )
}
else
{
sc.add( toType + " " + singular( uncapitalise( field.getName() ) ) + " = (" + toType
+ ") iter.next();" );
String variable = singular( uncapitalise( field.getName() ) );

sc.add( toType + " " + variable + " = (" + toType + ") iter.next();" );

sc.add( "serializer.startTag( NAMESPACE, " + "\"" + valuesTagName + "\" ).text( "
+ singular( uncapitalise( field.getName() ) ) + " ).endTag( NAMESPACE, " + "\""
+ valuesTagName + "\" );" );
sc.add( "serializer.startTag( NAMESPACE, \"" + valuesTagName + "\" ).text( " + variable
+ " ).endTag( NAMESPACE, \"" + valuesTagName + "\" );" );

writeLocationTracking( sc, "location", isList ? "Integer.valueOf( n++ )" : variable );
}

sc.unindent();
sc.add( "}" );

if ( wrappedItems )
{
sc.add( "serializer.endTag( NAMESPACE, " + "\"" + fieldTagName + "\" );" );
sc.add( "serializer.endTag( NAMESPACE, \"" + fieldTagName + "\" );" );
}

sc.unindent();
Expand Down

0 comments on commit b4d3c2b

Please sign in to comment.