From 6c349b2a69f646e3fc1f11e4de814c8f2bdc1194 Mon Sep 17 00:00:00 2001 From: Christophe Bronner Date: Sun, 7 Dec 2025 07:10:19 -0500 Subject: [PATCH 1/4] Bump to .NET 10 --- JavaToCSharp.Tests/JavaToCSharp.Tests.csproj | 2 +- JavaToCSharp/JavaToCSharp.csproj | 2 +- JavaToCSharpCli/JavaToCSharpCli.csproj | 2 +- JavaToCSharpGui/JavaToCSharpGui.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj b/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj index a21d46f3..c5511e8c 100644 --- a/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj +++ b/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net10.0 false enable latest diff --git a/JavaToCSharp/JavaToCSharp.csproj b/JavaToCSharp/JavaToCSharp.csproj index aa310b6e..98294ffd 100644 --- a/JavaToCSharp/JavaToCSharp.csproj +++ b/JavaToCSharp/JavaToCSharp.csproj @@ -1,7 +1,7 @@  4.0.0 - net8.0 + net10.0 enable enable nullable diff --git a/JavaToCSharpCli/JavaToCSharpCli.csproj b/JavaToCSharpCli/JavaToCSharpCli.csproj index a2a5b7cd..baced5ef 100644 --- a/JavaToCSharpCli/JavaToCSharpCli.csproj +++ b/JavaToCSharpCli/JavaToCSharpCli.csproj @@ -2,7 +2,7 @@ 4.0.0 Exe - net8.0 + net10.0 latest enable enable diff --git a/JavaToCSharpGui/JavaToCSharpGui.csproj b/JavaToCSharpGui/JavaToCSharpGui.csproj index 7c2ed3c4..992cb7a2 100644 --- a/JavaToCSharpGui/JavaToCSharpGui.csproj +++ b/JavaToCSharpGui/JavaToCSharpGui.csproj @@ -4,7 +4,7 @@ true app.manifest WinExe - net8.0 + net10.0 latest enable enable From 60ed1b218d8b99bfc056e6be73836b996cb79a2e Mon Sep 17 00:00:00 2001 From: Christophe Bronner Date: Sun, 7 Dec 2025 07:37:17 -0500 Subject: [PATCH 2/4] Bump dependencies --- JavaToCSharp.Tests/JavaToCSharp.Tests.csproj | 10 +- JavaToCSharp/JavaToCSharp.csproj | 8 +- JavaToCSharpCli/JavaToCSharpCli.csproj | 4 +- JavaToCSharpCli/Program.cs | 220 +++++++++---------- JavaToCSharpGui/App.axaml | 5 +- JavaToCSharpGui/JavaToCSharpGui.csproj | 25 ++- 6 files changed, 136 insertions(+), 136 deletions(-) diff --git a/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj b/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj index c5511e8c..54e5aede 100644 --- a/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj +++ b/JavaToCSharp.Tests/JavaToCSharp.Tests.csproj @@ -10,17 +10,17 @@ - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/JavaToCSharp/JavaToCSharp.csproj b/JavaToCSharp/JavaToCSharp.csproj index 98294ffd..66903f14 100644 --- a/JavaToCSharp/JavaToCSharp.csproj +++ b/JavaToCSharp/JavaToCSharp.csproj @@ -16,10 +16,10 @@ - - - - + + + + diff --git a/JavaToCSharpCli/JavaToCSharpCli.csproj b/JavaToCSharpCli/JavaToCSharpCli.csproj index baced5ef..6c36c40a 100644 --- a/JavaToCSharpCli/JavaToCSharpCli.csproj +++ b/JavaToCSharpCli/JavaToCSharpCli.csproj @@ -9,8 +9,8 @@ nullable - - + + diff --git a/JavaToCSharpCli/Program.cs b/JavaToCSharpCli/Program.cs index 1301eb8d..43208e69 100644 --- a/JavaToCSharpCli/Program.cs +++ b/JavaToCSharpCli/Program.cs @@ -13,66 +13,64 @@ public class Program private static readonly ILoggerFactory _loggerFactory; private static readonly ILogger _logger; - private static readonly Option _includeSubdirectoriesOption = new( - name: "--include-subdirectories", - description: "When the command is dir, converts files in all subdirectories", - getDefaultValue: () => true); - - private static readonly Option _includeUsingsOption = new( - name: "--include-usings", - description: "Include using directives in output", - getDefaultValue: () => true); - - private static readonly Option _includeNamespaceOption = new( - name: "--include-namespace", - description: "Include namespace in output", - getDefaultValue: () => true); - - private static readonly Option _includeCommentsOption = new( - name: "--include-comments", - description: "Include comments in output", - getDefaultValue: () => true); - - private static readonly Option _useDebugAssertOption = new( - name: "--use-debug-assert", - description: "Use Debug.Assert for asserts", - getDefaultValue: () => false); - - private static readonly Option _startInterfaceNamesWithIOption = new( - name: "--start-interface-names-with-i", - description: "Prefix interface names with the letter I", - getDefaultValue: () => true); - - private static readonly Option _commentUnrecognizedCodeOption = new( - name: "--comment-unrecognized-code", - description: "Include unrecognized code in output as commented-out code", - getDefaultValue: () => true); - - private static readonly Option _systemOutToConsoleOption = new( - name: "--system-out-to-console", - description: "Convert System.out calls to Console", - getDefaultValue: () => false); - - private static readonly Option _fileScopedNamespacesOption = new( - name: "--file-scoped-namespaces", - description: "Use file-scoped namespaces in C# output", - getDefaultValue: () => false); - - private static readonly Option _clearDefaultUsingsOption = new( - name: "--clear-usings", - description: "Remove all default usings provided by this app", - getDefaultValue: () => false); - - private static readonly Option> _addUsingsOption = new( - name: "--add-using", - description: "Adds a using directive to the collection of usings") - { - ArgumentHelpName = "namespace" + private static readonly Option _includeSubdirectoriesOption = new("--include-subdirectories") { + Description = "When the command is dir, converts files in all subdirectories", + DefaultValueFactory = _ => true, + }; + + private static readonly Option _includeUsingsOption = new("--include-usings") { + Description = "Include using directives in output", + DefaultValueFactory = _ => true, + }; + + private static readonly Option _includeNamespaceOption = new("--include-namespace") { + Description = "Include namespace in output", + DefaultValueFactory = _ => true + }; + + private static readonly Option _includeCommentsOption = new("--include-comments") { + Description = "Include comments in output", + DefaultValueFactory = _ => true + }; + + private static readonly Option _useDebugAssertOption = new("--use-debug-assert") { + Description = "Use Debug.Assert for asserts", + DefaultValueFactory = _ => false + }; + + private static readonly Option _startInterfaceNamesWithIOption = new("--start-interface-names-with-i") { + Description = "Prefix interface names with the letter I", + DefaultValueFactory = _ => true + }; + + private static readonly Option _commentUnrecognizedCodeOption = new("--comment-unrecognized-code") { + Description = "Include unrecognized code in output as commented-out code", + DefaultValueFactory = _ => true }; - private static readonly Option _mappingsFileNameOption = new( - name: "--mappings-file", - description: "A yaml file with syntax mappings from imports, methods and annotations"); + private static readonly Option _systemOutToConsoleOption = new("--system-out-to-console") { + Description = "Convert System.out calls to Console", + DefaultValueFactory = _ => false + }; + + private static readonly Option _fileScopedNamespacesOption = new("--file-scoped-namespaces") { + Description = "Use file-scoped namespaces in C# output", + DefaultValueFactory = _ => false + }; + + private static readonly Option _clearDefaultUsingsOption = new("--clear-usings") { + Description = "Remove all default usings provided by this app", + DefaultValueFactory = _ => false + }; + + private static readonly Option> _addUsingsOption = new("--add-using") { + Description = "Adds a using directive to the collection of usings", + HelpName = "namespace" + }; + + private static readonly Option _mappingsFileNameOption = new("--mappings-file") { + Description = "A yaml file with syntax mappings from imports, methods and annotations" + }; static Program() { @@ -88,23 +86,23 @@ public static async Task Main(string[] args) Description = "A syntactic transformer of source code from Java to C#." }; - rootCommand.AddCommand(CreateFileCommand()); - rootCommand.AddCommand(CreateDirectoryCommand()); + rootCommand.Subcommands.Add(CreateFileCommand()); + rootCommand.Subcommands.Add(CreateDirectoryCommand()); - rootCommand.AddGlobalOption(_includeSubdirectoriesOption); - rootCommand.AddGlobalOption(_includeUsingsOption); - rootCommand.AddGlobalOption(_includeNamespaceOption); - rootCommand.AddGlobalOption(_includeCommentsOption); - rootCommand.AddGlobalOption(_useDebugAssertOption); - rootCommand.AddGlobalOption(_startInterfaceNamesWithIOption); - rootCommand.AddGlobalOption(_commentUnrecognizedCodeOption); - rootCommand.AddGlobalOption(_systemOutToConsoleOption); - rootCommand.AddGlobalOption(_fileScopedNamespacesOption); - rootCommand.AddGlobalOption(_clearDefaultUsingsOption); - rootCommand.AddGlobalOption(_addUsingsOption); - rootCommand.AddGlobalOption(_mappingsFileNameOption); + rootCommand.Options.Add(_includeSubdirectoriesOption); + rootCommand.Options.Add(_includeUsingsOption); + rootCommand.Options.Add(_includeNamespaceOption); + rootCommand.Options.Add(_includeCommentsOption); + rootCommand.Options.Add(_useDebugAssertOption); + rootCommand.Options.Add(_startInterfaceNamesWithIOption); + rootCommand.Options.Add(_commentUnrecognizedCodeOption); + rootCommand.Options.Add(_systemOutToConsoleOption); + rootCommand.Options.Add(_fileScopedNamespacesOption); + rootCommand.Options.Add(_clearDefaultUsingsOption); + rootCommand.Options.Add(_addUsingsOption); + rootCommand.Options.Add(_mappingsFileNameOption); - await rootCommand.InvokeAsync(args); + await rootCommand.Parse(args).InvokeAsync(); // flush logs _loggerFactory.Dispose(); @@ -112,48 +110,48 @@ public static async Task Main(string[] args) private static Command CreateFileCommand() { - var inputArgument = new Argument( - name: "input", - description: "A Java source code file to convert"); + var inputArgument = new Argument("input") { + Description = "A Java source code file to convert" + }; - var outputArgument = new Argument( - name: "output", - description: "Path to place the C# output file, or stdout if omitted", - getDefaultValue: () => null); + var outputArgument = new Argument("output") { + Description = "Path to place the C# output file, or stdout if omitted", + DefaultValueFactory = _ => null + }; var fileCommand = new Command("file", "Convert a Java file to C#"); - fileCommand.AddArgument(inputArgument); - fileCommand.AddArgument(outputArgument); + fileCommand.Arguments.Add(inputArgument); + fileCommand.Arguments.Add(outputArgument); - fileCommand.SetHandler(context => + fileCommand.SetAction(context => { - var input = context.ParseResult.GetValueForArgument(inputArgument); - var output = context.ParseResult.GetValueForArgument(outputArgument); + var input = context.GetValue(inputArgument); + var output = context.GetValue(outputArgument); var options = GetJavaConversionOptions(context); - ConvertToCSharpFile(input, output, options); + ConvertToCSharpFile(input!, output, options); }); return fileCommand; } - private static JavaConversionOptions GetJavaConversionOptions(InvocationContext context) + private static JavaConversionOptions GetJavaConversionOptions(ParseResult context) { var options = new JavaConversionOptions { - IncludeSubdirectories = context.ParseResult.GetValueForOption(_includeSubdirectoriesOption), - IncludeUsings = context.ParseResult.GetValueForOption(_includeUsingsOption), - IncludeComments = context.ParseResult.GetValueForOption(_includeCommentsOption), - IncludeNamespace = context.ParseResult.GetValueForOption(_includeNamespaceOption), - ConvertSystemOutToConsole = context.ParseResult.GetValueForOption(_systemOutToConsoleOption), - StartInterfaceNamesWithI = context.ParseResult.GetValueForOption(_startInterfaceNamesWithIOption), - UseDebugAssertForAsserts = context.ParseResult.GetValueForOption(_useDebugAssertOption), - UseUnrecognizedCodeToComment = context.ParseResult.GetValueForOption(_commentUnrecognizedCodeOption), - UseFileScopedNamespaces = context.ParseResult.GetValueForOption(_fileScopedNamespacesOption), + IncludeSubdirectories = context.GetValue(_includeSubdirectoriesOption), + IncludeUsings = context.GetValue(_includeUsingsOption), + IncludeComments = context.GetValue(_includeCommentsOption), + IncludeNamespace = context.GetValue(_includeNamespaceOption), + ConvertSystemOutToConsole = context.GetValue(_systemOutToConsoleOption), + StartInterfaceNamesWithI = context.GetValue(_startInterfaceNamesWithIOption), + UseDebugAssertForAsserts = context.GetValue(_useDebugAssertOption), + UseUnrecognizedCodeToComment = context.GetValue(_commentUnrecognizedCodeOption), + UseFileScopedNamespaces = context.GetValue(_fileScopedNamespacesOption), }; - if (context.ParseResult.GetValueForOption(_clearDefaultUsingsOption)) + if (context.GetValue(_clearDefaultUsingsOption)) { options.ClearUsings(); } @@ -166,12 +164,12 @@ private static JavaConversionOptions GetJavaConversionOptions(InvocationContext options.AddUsing("System.Text"); } - foreach (string ns in context.ParseResult.GetValueForOption(_addUsingsOption) ?? new List()) + foreach (string ns in context.GetValue(_addUsingsOption) ?? new List()) { options.AddUsing(ns); } - var mappingsFile = context.ParseResult.GetValueForOption(_mappingsFileNameOption); + var mappingsFile = context.GetValue(_mappingsFileNameOption); if (!string.IsNullOrEmpty(mappingsFile)) { options.SyntaxMappings = ReadMappingsFile(mappingsFile); @@ -189,26 +187,26 @@ private static SyntaxMapping ReadMappingsFile(string mappingsFile) private static Command CreateDirectoryCommand() { - var inputArgument = new Argument( - name: "input", - description: "A directory containing Java source code files to convert"); + var inputArgument = new Argument("input") { + Description = "A directory containing Java source code files to convert" + }; - var outputArgument = new Argument( - name: "output", - description: "Path to place the C# output files"); + var outputArgument = new Argument("output") { + Description = "Path to place the C# output files" + }; var dirCommand = new Command("dir", "Convert a directory containing Java files to C#"); - dirCommand.AddArgument(inputArgument); - dirCommand.AddArgument(outputArgument); + dirCommand.Arguments.Add(inputArgument); + dirCommand.Arguments.Add(outputArgument); - dirCommand.SetHandler(context => + dirCommand.SetAction(context => { - var input = context.ParseResult.GetValueForArgument(inputArgument); - var output = context.ParseResult.GetValueForArgument(outputArgument); + var input = context.GetValue(inputArgument); + var output = context.GetValue(outputArgument); var options = GetJavaConversionOptions(context); - ConvertToCSharpDir(input, output, options); + ConvertToCSharpDir(input!, output!, options); }); return dirCommand; diff --git a/JavaToCSharpGui/App.axaml b/JavaToCSharpGui/App.axaml index 3253d7b7..7445ef17 100644 --- a/JavaToCSharpGui/App.axaml +++ b/JavaToCSharpGui/App.axaml @@ -1,5 +1,6 @@  @@ -9,7 +10,7 @@ - - + + diff --git a/JavaToCSharpGui/JavaToCSharpGui.csproj b/JavaToCSharpGui/JavaToCSharpGui.csproj index 992cb7a2..170f0084 100644 --- a/JavaToCSharpGui/JavaToCSharpGui.csproj +++ b/JavaToCSharpGui/JavaToCSharpGui.csproj @@ -16,21 +16,22 @@ - - - + + + - + - - - - + + + + - - - - + + + + + From 12785d492037a0058c0be091e4cc95bf43701040 Mon Sep 17 00:00:00 2001 From: Christophe Bronner Date: Tue, 9 Dec 2025 13:02:29 -0500 Subject: [PATCH 3/4] Update Github workflows --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5fec5114..cdff9d1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,10 +11,10 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v1 - - name: Setup .NET 8 + - name: Setup .NET 10 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.x + dotnet-version: 10.x - name: Build JavaToCSharp run: dotnet build ./JavaToCSharp/JavaToCSharp.csproj --configuration Release @@ -30,10 +30,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Setup .NET 8 + - name: Setup .NET 10 uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.x + dotnet-version: 10.x - name: Build JavaToCSharp run: dotnet build ./JavaToCSharp/JavaToCSharp.csproj --configuration Release From 63e12afe6e9c166bc51a3d91573ed523918ec1e8 Mon Sep 17 00:00:00 2001 From: Paul Irwin Date: Wed, 10 Dec 2025 20:38:48 -0700 Subject: [PATCH 4/4] Copilot PR feedback and code style formatting --- JavaToCSharpCli/Program.cs | 86 ++++++++++++++++++++++++-------------- JavaToCSharpGui/App.axaml | 6 +-- 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/JavaToCSharpCli/Program.cs b/JavaToCSharpCli/Program.cs index 43208e69..5c831389 100644 --- a/JavaToCSharpCli/Program.cs +++ b/JavaToCSharpCli/Program.cs @@ -13,63 +13,75 @@ public class Program private static readonly ILoggerFactory _loggerFactory; private static readonly ILogger _logger; - private static readonly Option _includeSubdirectoriesOption = new("--include-subdirectories") { + private static readonly Option _includeSubdirectoriesOption = new("--include-subdirectories") + { Description = "When the command is dir, converts files in all subdirectories", DefaultValueFactory = _ => true, }; - private static readonly Option _includeUsingsOption = new("--include-usings") { + private static readonly Option _includeUsingsOption = new("--include-usings") + { Description = "Include using directives in output", - DefaultValueFactory = _ => true, + DefaultValueFactory = _ => true, }; - private static readonly Option _includeNamespaceOption = new("--include-namespace") { - Description = "Include namespace in output", - DefaultValueFactory = _ => true + private static readonly Option _includeNamespaceOption = new("--include-namespace") + { + Description = "Include namespace in output", + DefaultValueFactory = _ => true, }; - private static readonly Option _includeCommentsOption = new("--include-comments") { - Description = "Include comments in output", - DefaultValueFactory = _ => true + private static readonly Option _includeCommentsOption = new("--include-comments") + { + Description = "Include comments in output", + DefaultValueFactory = _ => true, }; - private static readonly Option _useDebugAssertOption = new("--use-debug-assert") { + private static readonly Option _useDebugAssertOption = new("--use-debug-assert") + { Description = "Use Debug.Assert for asserts", - DefaultValueFactory = _ => false + DefaultValueFactory = _ => false, }; - private static readonly Option _startInterfaceNamesWithIOption = new("--start-interface-names-with-i") { + private static readonly Option _startInterfaceNamesWithIOption = new("--start-interface-names-with-i") + { Description = "Prefix interface names with the letter I", - DefaultValueFactory = _ => true + DefaultValueFactory = _ => true, }; - private static readonly Option _commentUnrecognizedCodeOption = new("--comment-unrecognized-code") { + private static readonly Option _commentUnrecognizedCodeOption = new("--comment-unrecognized-code") + { Description = "Include unrecognized code in output as commented-out code", - DefaultValueFactory = _ => true + DefaultValueFactory = _ => true, }; - private static readonly Option _systemOutToConsoleOption = new("--system-out-to-console") { + private static readonly Option _systemOutToConsoleOption = new("--system-out-to-console") + { Description = "Convert System.out calls to Console", - DefaultValueFactory = _ => false + DefaultValueFactory = _ => false, }; - private static readonly Option _fileScopedNamespacesOption = new("--file-scoped-namespaces") { + private static readonly Option _fileScopedNamespacesOption = new("--file-scoped-namespaces") + { Description = "Use file-scoped namespaces in C# output", - DefaultValueFactory = _ => false + DefaultValueFactory = _ => false, }; - private static readonly Option _clearDefaultUsingsOption = new("--clear-usings") { + private static readonly Option _clearDefaultUsingsOption = new("--clear-usings") + { Description = "Remove all default usings provided by this app", - DefaultValueFactory = _ => false + DefaultValueFactory = _ => false, }; - private static readonly Option> _addUsingsOption = new("--add-using") { + private static readonly Option> _addUsingsOption = new("--add-using") + { Description = "Adds a using directive to the collection of usings", - HelpName = "namespace" + HelpName = "namespace", }; - private static readonly Option _mappingsFileNameOption = new("--mappings-file") { - Description = "A yaml file with syntax mappings from imports, methods and annotations" + private static readonly Option _mappingsFileNameOption = new("--mappings-file") + { + Description = "A yaml file with syntax mappings from imports, methods and annotations", }; static Program() @@ -83,7 +95,7 @@ public static async Task Main(string[] args) { var rootCommand = new RootCommand("Java to C# Converter") { - Description = "A syntactic transformer of source code from Java to C#." + Description = "A syntactic transformer of source code from Java to C#.", }; rootCommand.Subcommands.Add(CreateFileCommand()); @@ -110,13 +122,15 @@ public static async Task Main(string[] args) private static Command CreateFileCommand() { - var inputArgument = new Argument("input") { - Description = "A Java source code file to convert" + var inputArgument = new Argument("input") + { + Description = "A Java source code file to convert", }; - var outputArgument = new Argument("output") { + var outputArgument = new Argument("output") + { Description = "Path to place the C# output file, or stdout if omitted", - DefaultValueFactory = _ => null + DefaultValueFactory = _ => null, }; var fileCommand = new Command("file", "Convert a Java file to C#"); @@ -187,11 +201,13 @@ private static SyntaxMapping ReadMappingsFile(string mappingsFile) private static Command CreateDirectoryCommand() { - var inputArgument = new Argument("input") { + var inputArgument = new Argument("input") + { Description = "A directory containing Java source code files to convert" }; - var outputArgument = new Argument("output") { + var outputArgument = new Argument("output") + { Description = "Path to place the C# output files" }; @@ -237,13 +253,17 @@ private static void ConvertToCSharpDir(DirectoryInfo inputDirectory, DirectoryIn } } else + { _logger.LogError("Java input folder {path} doesn't exist!", inputDirectory); + } } private static void ConvertToCSharpFile(FileSystemInfo inputFile, FileSystemInfo? outputFile, JavaConversionOptions options, bool overwrite = true) { if (!overwrite && outputFile is { Exists: true }) + { _logger.LogInformation("{outputFilePath} exists, skip to next.", outputFile); + } else if (inputFile.Exists) { try @@ -281,7 +301,9 @@ private static void ConvertToCSharpFile(FileSystemInfo inputFile, FileSystemInfo } } else + { _logger.LogError("Java input file {filePath} doesn't exist!", inputFile.FullName); + } } private static void OutputFileOrPrint(string? fileName, string contents) diff --git a/JavaToCSharpGui/App.axaml b/JavaToCSharpGui/App.axaml index 7445ef17..3128bd0d 100644 --- a/JavaToCSharpGui/App.axaml +++ b/JavaToCSharpGui/App.axaml @@ -1,6 +1,6 @@  @@ -10,7 +10,7 @@ - - + +