diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index 07539b3..da8b323 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -15,11 +15,19 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Setup MSBuild - uses: microsoft/setup-msbuild@v2 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0' - name: Build Release - run: msbuild JavaToCSharp.csproj /p:Configuration=Release /p:Platform="Any CPU" + run: dotnet build -c Release + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: JavaToCSharp-Release + path: bin/Release/net8.0/JavaToCSharp.dll - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/JavaToCSharp.csproj b/JavaToCSharp.csproj index f35331d..fb97858 100644 --- a/JavaToCSharp.csproj +++ b/JavaToCSharp.csproj @@ -1,72 +1,15 @@ - - + + - Debug - AnyCPU - 9.0.30729 - 2.0 - {766E09AF-B872-444D-BD76-C8BB17E38DAC} Exe - Properties - JavaToCSharp - JavaToCSharp - v3.0 - 512 - - - - - 3.5 + net8.0 + enable + enable + false - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - + - + - - + \ No newline at end of file diff --git a/RuleEngine.cs b/RuleEngine.cs index 0b109db..3d8379c 100644 --- a/RuleEngine.cs +++ b/RuleEngine.cs @@ -3,8 +3,8 @@ using System.Text; using System.IO; using System.Reflection; -using JavaToCSharp.Configuration; using System.Configuration; +using JavaToCSharp.Configuration; using JavaToCSharp.Rules; namespace JavaToCSharp @@ -30,8 +30,8 @@ public void LoadRules() foreach (RuleSection rs in config.Rules) { EquivalentRule r = new EquivalentRule(rs.Name); - r.Pattern = rs.Pattern; - r.Replacement = rs.Replacement; + r.PatternValue = rs.Pattern; + r.ReplacementValue = rs.Replacement; //Console.WriteLine(r.ToString()); AddRule(r); } diff --git a/Rules/EquivalentExceptionRule.cs b/Rules/EquivalentExceptionRule.cs index c8c6293..b9b0d81 100644 --- a/Rules/EquivalentExceptionRule.cs +++ b/Rules/EquivalentExceptionRule.cs @@ -6,7 +6,7 @@ namespace JavaToCSharp.Rules { public abstract class EquivalentExceptionRule : EquivalentRule { - protected override sealed string Replacement + protected override string Replacement { get { return this.Pattern; } } @@ -21,7 +21,7 @@ protected override string Pattern get { return @"RuntimeException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "Exception"; } @@ -35,7 +35,7 @@ protected override string Pattern get { return @"ClassCastException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "InvalidCastException"; } @@ -49,7 +49,7 @@ protected override string Pattern get { return @"UnsupportedEncodingException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "EncoderFallbackException"; } @@ -63,7 +63,7 @@ protected override string Pattern get { return @"AssertionFailedError"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "AssertFailedException"; } @@ -77,7 +77,7 @@ protected override string Pattern get { return @"IllegalArgumentException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "ArgumentException"; } @@ -90,7 +90,7 @@ protected override string Pattern get { return @"NumberFormatException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "FormatException"; } @@ -103,7 +103,7 @@ protected override string Pattern get { return @"IllegalAccessError|IllegalStateException"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "InvalidOperationException"; } diff --git a/Rules/EquivalentRule.cs b/Rules/EquivalentRule.cs index c77ed94..89d22fa 100644 --- a/Rules/EquivalentRule.cs +++ b/Rules/EquivalentRule.cs @@ -22,18 +22,28 @@ public override string RuleName get { return _name; } } - public virtual string Replacement + protected virtual string Pattern { get; set; } + + public string PatternValue + { + set { this.Pattern = value; } + } - public virtual string Pattern + protected virtual string Replacement { get; set; } + public string ReplacementValue + { + set { this.Replacement = value; } + } + protected virtual string ReplaceString(Match match) { return this.Replacement; diff --git a/Rules/OtherRule.cs b/Rules/OtherRule.cs index 872816e..2444eea 100644 --- a/Rules/OtherRule.cs +++ b/Rules/OtherRule.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.Text; using System.Text.RegularExpressions; @@ -15,12 +16,12 @@ public override string RuleName } } - public override string Pattern + protected override string Pattern { get { return @"org\.apache\.poi\.([a-zA-Z]+)\."; } } - public override string Replacement + protected override string Replacement { get { return "namespace"; } } @@ -40,12 +41,12 @@ public override string RuleName } } - public override string Replacement + protected override string Replacement { get { return "new Double"; } } - public override string Pattern + protected override string Pattern { get { return @"new Double\((.+)\)"; } } @@ -57,12 +58,12 @@ protected override string ReplaceString(Match match) } public class EquivalentRule2 : EquivalentRule { - public override string Replacement + protected override string Replacement { get { return ".charAt(i)"; } } - public override string Pattern + protected override string Pattern { get { return @"\.charAt\((\w+)\)"; } } @@ -76,12 +77,12 @@ protected override string ReplaceString(Match match) public class EquivalentRule3 : EquivalentRule { - public override string Replacement + protected override string Replacement { get { return "read"; } } - public override string Pattern + protected override string Pattern { get { return @"(\s|\.)(read\S)"; } } @@ -108,12 +109,12 @@ public override string RuleName get { return "Getter"; } } - public override string Pattern + protected override string Pattern { get { return @"\.get([a-zA-Z0-9]+)\(\)"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { if (exclude.Contains(match.Groups[1].Value)) return ".Get" + match.Groups[1].Value + "()"; @@ -136,12 +137,12 @@ public override string RuleName get { return "setter"; } } - public override string Pattern + protected override string Pattern { get { return @"\.set([a-zA-Z0-9]+)\((.*?)\)"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { if (exclude.Contains(match.Groups[1].Value)) return ".Set" + match.Groups[1].Value + "(" + match.Groups[2].Value + ")"; @@ -156,12 +157,12 @@ public override string RuleName get { return "XXXX.class"; } } - public override string Pattern + protected override string Pattern { get { return @"\(([a-zA-Z0-9]+)\.class"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "(typeof(" + match.Groups[1].Value + ")"; } @@ -174,12 +175,12 @@ public override string RuleName get { return "import"; } } - public override string Pattern + protected override string Pattern { get { return @"import\s(.*?)\.([a-zA-Z0-9]+|\*);"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { if (match.Groups[1].Value.StartsWith("junit.")) { @@ -199,12 +200,12 @@ public override string RuleName get { return "package"; } } - public override string Pattern + protected override string Pattern { get { return @"package\s(.*?);"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "namespace " + match.Groups[1].Value + "\r\n{\r\n using System;"; } @@ -217,12 +218,12 @@ public override string RuleName get { return "Assert.AreEqual"; } } - public override string Pattern + protected override string Pattern { get { return @"Assert.AreEqual\(("".*?"".*?),(.*?),(.*?)\);"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return "Assert.AreEqual(" + match.Groups[2].Value + "," + match.Groups[3].Value + "," + match.Groups[1].Value + ");"; } @@ -235,12 +236,12 @@ public override string RuleName get { return "TestFixture Attribute"; } } - public override string Pattern + protected override string Pattern { get { return @"(.*?)\sclass\s(.*?)Test(.*?)\s{"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return " [TestFixture]\r\n " + match.Groups[1].Value + " class " + match.Groups[2].Value + "Test" + match.Groups[3].Value + "\r\n{"; } @@ -253,12 +254,12 @@ public override string RuleName get { return "TestMethod Attribute"; } } - public override string Pattern + protected override string Pattern { get { return @"(public.*?)(t|T)est([a-zA-Z0-9_]+)\(\)\s(.*){"; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return " [Test]\r\n public void Test" + match.Groups[3].Value + "(){"; } @@ -271,12 +272,12 @@ public override string RuleName get { return "IXXXX xxx = "; } } - public override string Pattern + protected override string Pattern { get { return @"\s(HSSF)?(Workbook|Sheet|Cell|Row|Name|Header|Footer|CellStyle|CellType)(\s+|\.)(.*?)="; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return " I" + match.Groups[2].Value + match.Groups[3].Value + match.Groups[4].Value + "="; } @@ -292,7 +293,7 @@ public override string RuleName } } - public override string Pattern + protected override string Pattern { get { @@ -300,7 +301,7 @@ public override string Pattern } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return match.Groups[1].Value + match.Groups[2].Value + "1" + match.Groups[3].Value; } @@ -313,12 +314,12 @@ public override string RuleName get { return "CapitalizeRule2"; } } - public override string Pattern + protected override string Pattern { get { return @"(\w)\.([a-z])([a-zA-Z_0-9]+?)\("; } } - public override string ReplaceString(Match match) + protected override string ReplaceString(Match match) { return match.Groups[1].Value + "." + match.Groups[2].Value.ToUpper() + match.Groups[3].Value + "("; } diff --git a/Rules/RemoveGetRule.cs b/Rules/RemoveGetRule.cs index 2b5c5df..8550297 100644 --- a/Rules/RemoveGetRule.cs +++ b/Rules/RemoveGetRule.cs @@ -7,12 +7,12 @@ namespace JavaToCSharp.Rules { public class RemoveGetRule : EquivalentRule { - public override string Replacement + protected override string Replacement { get { return "GetXXX()"; } } - public override string Pattern + protected override string Pattern { get { return @"Get(FirstRow|Col|XFIndex|Data|LastRow|Column|Sid|Author|TotalSize|Row|FirstColumn|"+ @"LastColumn|InnerValueEval|Height|Width|StringValue|ExternSheetIndex|Sheet|ColumnIndex|RowIndex)\(\)"; }