1

I'm trying to use Sharpen in Eclipse to convert a java project (full source) into C#

I followed the guidelines from this blog that worked pretty well: http://tumblr.com/ZVuYOwDv6mdu (which suggest using Lluis Sanchez’s compiled version of Sharpen over the source control)

But I'm getting errors in a few classes that extend on ByteArrayInputStream and ByteArrayOutputStream. Any reference to a property and method of the "super" is returned with "Failed to map"

Example:

[exec] ERROR: /sharpened/src/com/netnumber/dns/message/DnsOutputStream.java:176: failed to map: 'this.nameTable.put(name,new Integer(super.count))' [exec] java.lang.IllegalArgumentException: /sharpened/src/com/netnumber/dns/message/DnsOutputStream.java:176: failed to map: 'this.nameTable.put(name,new Integer(super.count))'

I wondered if there were any easy solution for this via Sharpen or if I would have to take the time and re-write the java code (multiple code files) to "mimic" the references and not using extends and then write the C# code using MemoryStream in the final converted code project?

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
Quintium
  • 499
  • 5
  • 22
  • Did you ever resolve this problem? If not, could you please share a more detailed error dump to show exactly in which location of the Sharpen code the error is identified? – Anders Gustafsson Jun 13 '12 at 19:14
  • I did not. And have since gone beyond the issue and did it "by hand" without making use of the Java project in the end. – Quintium Jun 13 '12 at 19:23
  • Although you managed to solve your porting issue without Sharpen, I did some investigation of this issue on my own. I hope you'll find my findings in the answer below valuable regardless. – Anders Gustafsson Jun 18 '12 at 07:18

1 Answers1

2

I have made a very simple test, and the following conversion will indeed fail:

public class DnsOutputStream extends ByteArrayOutputStream {
  public int count() {
    return super.count;
  }
}

The specific error message indicates that access to a field in the super class is not supported:

 [exec] Caused by: java.lang.IllegalArgumentException: /sharpened/src/DnsOutputStream.java:16: super.count
 [exec]     at sharpen.core.CSharpBuilder.notImplemented(CSharpBuilder.java:243)
 [exec]     at sharpen.core.CSharpBuilder.visit(CSharpBuilder.java:227)
 [exec]     at org.eclipse.jdt.core.dom.SuperFieldAccess.accept0(SuperFieldAccess.java:165)
 [exec]     at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2514)
 [exec]     at sharpen.core.CSharpBuilder.mapExpression(CSharpBuilder.java:3343)

On the other hand, if I replace super.count with super.size() the Java code is successfully converted into this C# code:

public class DnsOutputStream : ByteArrayOutputStream {
  public virtual int Count()
  {
    return base.Size();
  }
}

In summary: Sharpen does not support accessing fields in a super class. However, access to super class methods is supported. When there is an applicable replacement for the super class field, the Java code can thus be modified to use the alternative constructs before conversion.

Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114