Examples of Converted Code

To set the scene, it might be useful to provide a couple of examples of converted code, illustrating the challenges.

Here's a rather simple method in Java:

@Override
    public AtomicSequence atomize() throws XPathException {
        return tree.getTypedValueOfElement(this);
    }

And here is the C# code that we generate:

public override net.sf.saxon.om.AtomicSequence atomize() {
    return tree.getTypedValueOfElement(this);
}

Nothing very remarkable there, but it actually requires a fair bit of analysis of the Java code to establish that the conversion in this case is fairly trivial. For example:

Now let's take a more complex example. Consider the following Java code:

public Map<String, Sequence> getDefaultOptions()  {
    Map<String, Sequence> result = new HashMap<>();
    for (Map.Entry<String, Sequence> entry : defaultValues.entrySet()) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

In C# this becomes (with abbreviated namespace qualifiers, for readability):

public S.C.G.IDictionary<string, n.s.s.o.Sequence> getDefaultOptions() {
    S.C.G.IDictionary<string, n.s.s.o.Sequence> result = 
            new S.C.G.Dictionary<string, n.s.s.o.Sequence>();
    foreach (S.C.G.KeyValuePair<string, n.s.s.o.Sequence> entry in defaultValues) {
        result[entry.Key] = entry.Value;
    }
    return result;
}

There's a lot going on here: