Skip to content

MappingFile

Mehdi Mohammadi edited this page Dec 29, 2013 · 1 revision

You can map members of Java type to .Net type by writing them in one line separated with '-'

for example with toLowerCase()-ToLower() this translation will be done:

return id.toLowerCase();
return id.ToLower();

You can write Methods and Fields on left side and Methods, Fields and Properties on the right side with same syntax.

You can map parameters with naming them on the left and using them on the right side:
for example with startsWith(a,b)-Substring(b).StartsWith(a)

return currentTag.startsWith(starter, offset);
return currentTag.Substring(offset).StartsWith(starter);

you should name your parameters in the left-side starting from a (, b, c, ...).

You can map JavaType instance methods to other classes static methods with split(a)-Regex.Split(id, a) (id means invocation target)

str.split(pattern);
Regex.Split(str, pattern);

Reverse is also possible for example compare(a,b)-!a.CompareTo(b) ('!' at the beginning of right side means remove invocation target)

Double.compare(x, y);
x.CompareTo(y);

more complex scenarios are also possible:

Mapping constructor with assignment
new Integer(a)-a

int ten = new Integer(10);
int ten = 10;

Mapping static method call with cast:
doubleToLongBits(a)-!(long)a ('!' at beginning of right side means remove invocation target)

long l = Double.doubleToLongBits(d);
long l = (long) d;

You can map one line to multiple lines:

remove(a)-=id[a];Remove(a)

each line separated with ';' and '=' at start of line means set leading line to target:

object o = map.Remove(key);

object o = map[key];
map.Remove(key);

Please check Janett [default mappings] (https://github.com/mehdimo/janett/tree/master/Source/Translator/Mappings/DotNet) for more examples. A good starting point is [String mapping] (https://github.com/mehdimo/janett/tree/master/Source/Translator/Mappings/DotNet/java.lang/String-string.map)

Clone this wiki locally