diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetFragments.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetFragments.cs index 1b901e5..7a07c60 100755 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetFragments.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/NetFragments.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; -using System.Text.RegularExpressions; using Antlr.Runtime.Tree; 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 @@ -56,23 +35,11 @@ namespace Twiglet.CS2J.Translator.Transform public string getMethods(string iface, IList tyArgs) { string ret = ""; - MethodMapper mapper = new MethodMapper(this); if (InterfaceMap.ContainsKey(iface)) { string methods = InterfaceMap[iface]; - if (tyArgs != null) - { - 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{} with (possibly transformed) - methods = Regex.Replace(methods, "(?:@m\\{(\\w+)\\})", new MatchEvaluator(mapper.RewriteMethod)); + methods = rewriteCodeFragment(methods, tyArgs); ret += methods; } diff --git a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/SyntaxFragments.cs b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/SyntaxFragments.cs index 429efbe..bd1285a 100644 --- a/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/SyntaxFragments.cs +++ b/CSharpTranslator/antlr3/src/CS2JTranslator/CS2JTransform/SyntaxFragments.cs @@ -38,7 +38,7 @@ namespace Twiglet.CS2J.Translator.Transform 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()); } private string multiDelegateMethodsStr = @" @@ -48,15 +48,15 @@ namespace Twiglet.CS2J.Translator.Transform if (a == null) return b; if (b == null) return a; ${DelClass} ret = new ${DelClass}(); - ret._invocationList = a.GetInvocationList(); - ret._invocationList.addAll(b.GetInvocationList()); + ret._invocationList = a.@m{GetInvocationList}(); + ret._invocationList.addAll(b.@m{GetInvocationList}()); return ret; } public static ${Del} Remove ${TyArgs} (${Del} a, ${Del} b) throws Exception { if (a == null || b == null) return a; - System.Collections.Generic.IList<${Del}> aInvList = a.GetInvocationList(); - System.Collections.Generic.IList<${Del}> newInvList = ListSupport.removeFinalStretch(aInvList, b.GetInvocationList()); + System.Collections.Generic.IList<${Del}> aInvList = a.@m{GetInvocationList}(); + System.Collections.Generic.IList<${Del}> newInvList = ListSupport.removeFinalStretch(aInvList, b.@m{GetInvocationList}()); if (aInvList == newInvList) { return a; }