Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions cc-xjc-plugin/src/main/java/net/sourceforge/ccxjc/PluginImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public boolean run( final Outline model, final Options options, final ErrorHandl
this.log( Level.WARNING, "couldNotAddStdCtor", clazz.implClass.binaryName() );
}

if ( this.getCopyConstructor( clazz ) == null )
if ( this.getOrGenerateCopyConstructor( clazz ) == null )
{
this.log( Level.WARNING, "couldNotAddCopyCtor", clazz.implClass.binaryName() );
}
Expand Down Expand Up @@ -571,11 +571,16 @@ private JMethod getStandardConstructor( final ClassOutline clazz )

private JMethod getCopyConstructor( final ClassOutline clazz )
{
JMethod ctor = clazz.implClass.getConstructor( new JType[]
final JMethod ctor = clazz.implClass.getConstructor( new JType[]
{
clazz.implClass
} );
return ctor;
}

private JMethod getOrGenerateCopyConstructor( final ClassOutline clazz )
{
JMethod ctor = this.getCopyConstructor(clazz);
if ( ctor == null )
{
ctor = this.generateCopyConstructor( clazz );
Expand Down Expand Up @@ -2473,8 +2478,14 @@ private JMethod generateCloneMethod( final ClassOutline clazz )

final JBlock copyBlock = new JBlock( false, false );
copyBlock.directStatement( "// " + getMessage( "title" ) );
final JVar clone = copyBlock.decl( JMod.FINAL, clazz.implClass, "clone",
JExpr.cast( clazz.implClass, JExpr._super().invoke( "clone" ) ) );

final JExpression jE;
if (!clazz.implClass.isAbstract() && clazz.implClass._extends().isAbstract() && getCopyConstructor(clazz) != null) {
jE = JExpr._new( clazz.implClass ).arg(JExpr._this());
} else {
jE = JExpr.cast( clazz.implClass, JExpr._super().invoke( "clone" ) );
}
final JVar clone = copyBlock.decl( JMod.FINAL, clazz.implClass, "clone", jE );

for ( FieldOutline field : clazz.getDeclaredFields() )
{
Expand Down Expand Up @@ -2718,19 +2729,23 @@ private Collection<String> readTypes( final String fileName ) throws IOException
{
final Collection<String> types = new LinkedList<String>();
final BufferedReader reader = new BufferedReader( new FileReader( fileName ) );
String line;

while ( ( line = reader.readLine() ) != null )
{
if ( line.indexOf( '#' ) > -1 )
{
continue;
}

if ( line.trim().length() > 0 )
try {
String line;

while ( ( line = reader.readLine() ) != null )
{
types.add( line.trim() );
if ( line.indexOf( '#' ) > -1 )
{
continue;
}

if ( line.trim().length() > 0 )
{
types.add( line.trim() );
}
}
} finally {
reader.close();
}

return Collections.unmodifiableCollection( types );
Expand Down