mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
use rewriteMethods from base, mark method calls in code fragment
This commit is contained in:
parent
f61a635bc1
commit
7f0cc54156
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
using Antlr.Runtime.Tree;
|
using Antlr.Runtime.Tree;
|
||||||
using Antlr.Runtime;
|
using Antlr.Runtime;
|
||||||
@ -23,26 +22,6 @@ namespace Twiglet.CS2J.Translator.Transform
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|
||||||
private class MethodMapper
|
|
||||||
{
|
|
||||||
|
|
||||||
CommonWalker walker = null;
|
|
||||||
|
|
||||||
public MethodMapper(CommonWalker inWalker) {
|
|
||||||
walker = inWalker;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RewriteMethod(Match m)
|
|
||||||
{
|
|
||||||
if (walker.Cfg.TranslatorMakeJavaNamingConventions)
|
|
||||||
{
|
|
||||||
return walker.toJavaConvention(CSharpEntity.METHOD, m.Groups[1].Value);
|
|
||||||
}
|
|
||||||
return m.Groups[1].Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
///
|
///
|
||||||
/// Methods to convert Interfaces to Java equivalents
|
/// Methods to convert Interfaces to Java equivalents
|
||||||
@ -56,23 +35,11 @@ namespace Twiglet.CS2J.Translator.Transform
|
|||||||
public string getMethods(string iface, IList<string> tyArgs)
|
public string getMethods(string iface, IList<string> tyArgs)
|
||||||
{
|
{
|
||||||
string ret = "";
|
string ret = "";
|
||||||
MethodMapper mapper = new MethodMapper(this);
|
|
||||||
|
|
||||||
if (InterfaceMap.ContainsKey(iface))
|
if (InterfaceMap.ContainsKey(iface))
|
||||||
{
|
{
|
||||||
string methods = InterfaceMap[iface];
|
string methods = InterfaceMap[iface];
|
||||||
if (tyArgs != null)
|
methods = rewriteCodeFragment(methods, tyArgs);
|
||||||
{
|
|
||||||
int idx = 0;
|
|
||||||
foreach (string t in tyArgs)
|
|
||||||
{
|
|
||||||
string toReplace = "${T" + (idx == 0 ? "" : Convert.ToString(idx)) + "}";
|
|
||||||
methods = methods.Replace(toReplace,tyArgs[idx]);
|
|
||||||
idx++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// replace @m{<method name>} with (possibly transformed) <method name>
|
|
||||||
methods = Regex.Replace(methods, "(?:@m\\{(\\w+)\\})", new MatchEvaluator(mapper.RewriteMethod));
|
|
||||||
ret += methods;
|
ret += methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace Twiglet.CS2J.Translator.Transform
|
|||||||
|
|
||||||
public string MultiDelegateMethods(string Del, string DelClass, string TyArgs)
|
public string MultiDelegateMethods(string Del, string DelClass, string TyArgs)
|
||||||
{
|
{
|
||||||
return multiDelegateMethodsStr.Replace("${Del}", Del).Replace("${DelClass}", DelClass).Replace("${TyArgs}", TyArgs);
|
return rewriteCodeFragment(multiDelegateMethodsStr.Replace("${Del}", Del).Replace("${DelClass}", DelClass).Replace("${TyArgs}", TyArgs), new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private string multiDelegateMethodsStr = @"
|
private string multiDelegateMethodsStr = @"
|
||||||
@ -48,15 +48,15 @@ namespace Twiglet.CS2J.Translator.Transform
|
|||||||
if (a == null) return b;
|
if (a == null) return b;
|
||||||
if (b == null) return a;
|
if (b == null) return a;
|
||||||
${DelClass} ret = new ${DelClass}();
|
${DelClass} ret = new ${DelClass}();
|
||||||
ret._invocationList = a.GetInvocationList();
|
ret._invocationList = a.@m{GetInvocationList}();
|
||||||
ret._invocationList.addAll(b.GetInvocationList());
|
ret._invocationList.addAll(b.@m{GetInvocationList}());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ${Del} Remove ${TyArgs} (${Del} a, ${Del} b) throws Exception {
|
public static ${Del} Remove ${TyArgs} (${Del} a, ${Del} b) throws Exception {
|
||||||
if (a == null || b == null) return a;
|
if (a == null || b == null) return a;
|
||||||
System.Collections.Generic.IList<${Del}> aInvList = a.GetInvocationList();
|
System.Collections.Generic.IList<${Del}> aInvList = a.@m{GetInvocationList}();
|
||||||
System.Collections.Generic.IList<${Del}> newInvList = ListSupport.removeFinalStretch(aInvList, b.GetInvocationList());
|
System.Collections.Generic.IList<${Del}> newInvList = ListSupport.removeFinalStretch(aInvList, b.@m{GetInvocationList}());
|
||||||
if (aInvList == newInvList) {
|
if (aInvList == newInvList) {
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user