Arne Vajh?j wrote:
On 13-05-2010 23:13, Mike Schilling wrote:
Arne Vajh?j wrote:
If it is a combined build and one does not need more
functionality than what it has, then I am sure it
Yes. Our build amounted to:
1. Compile the Java classes (and build jars, etc.)
2. Convert the Java to C#
3. Compile the C# into DLLs and EXEs
Being able to do all 3 in ANT (the second was acomplished by
running a Java program, which ANT is also quite good at) was,
How do you do the conversion?
I wrote a Java program to do it, because, at the time, all the
publicly available ones that claimed to do it were crap, especially
Microsoft's JLCA. The syntax conversion was straightforward, since
C# 1.1 and Java 1.4 were, roughly speaking, the same language with
slight variants in syntax. (They have to some extent grown apart,
but those were the current versions when I did this work.) The
procedure was, roughly, 1. Use ANTLR to compile a Java source file into
2. Walk the AST creating a tree of objects corresponding to language
features: classes, methods, various kinds of statement, various
kinds of expression, etc.
3. Transform this object graph as necessary for places where C# and
Java differ: e.g., make the hidden "outer this" parameter to an
inner class constructor explicit. At the same time, detect
untranslatable code, e.g. a return from a finally block.
4. Serialize the transformed graph into C#. This includes mapping
JDK classes and members into their .NET equivalents, e.g.
org.w3c.dom.Element into System.Xml.XmlElement, and of course,
detecting classes and methods did not (yet) have a .NET equivalent.
A necessary part of this is translating JUnit tests into NUnit
tests, so you have immediate confirmation that nothing got broken
along the way. Which is why it was so handy that every step from
Java compilation through running both sets of tests could be done by
the same ANT script.