@@ -13,63 +13,75 @@ public class Program
1313 private static readonly ILoggerFactory _loggerFactory ;
1414 private static readonly ILogger _logger ;
1515
16- private static readonly Option < bool > _includeSubdirectoriesOption = new ( "--include-subdirectories" ) {
16+ private static readonly Option < bool > _includeSubdirectoriesOption = new ( "--include-subdirectories" )
17+ {
1718 Description = "When the command is dir, converts files in all subdirectories" ,
1819 DefaultValueFactory = _ => true ,
1920 } ;
2021
21- private static readonly Option < bool > _includeUsingsOption = new ( "--include-usings" ) {
22+ private static readonly Option < bool > _includeUsingsOption = new ( "--include-usings" )
23+ {
2224 Description = "Include using directives in output" ,
23- DefaultValueFactory = _ => true ,
25+ DefaultValueFactory = _ => true ,
2426 } ;
2527
26- private static readonly Option < bool > _includeNamespaceOption = new ( "--include-namespace" ) {
27- Description = "Include namespace in output" ,
28- DefaultValueFactory = _ => true
28+ private static readonly Option < bool > _includeNamespaceOption = new ( "--include-namespace" )
29+ {
30+ Description = "Include namespace in output" ,
31+ DefaultValueFactory = _ => true ,
2932 } ;
3033
31- private static readonly Option < bool > _includeCommentsOption = new ( "--include-comments" ) {
32- Description = "Include comments in output" ,
33- DefaultValueFactory = _ => true
34+ private static readonly Option < bool > _includeCommentsOption = new ( "--include-comments" )
35+ {
36+ Description = "Include comments in output" ,
37+ DefaultValueFactory = _ => true ,
3438 } ;
3539
36- private static readonly Option < bool > _useDebugAssertOption = new ( "--use-debug-assert" ) {
40+ private static readonly Option < bool > _useDebugAssertOption = new ( "--use-debug-assert" )
41+ {
3742 Description = "Use Debug.Assert for asserts" ,
38- DefaultValueFactory = _ => false
43+ DefaultValueFactory = _ => false ,
3944 } ;
4045
41- private static readonly Option < bool > _startInterfaceNamesWithIOption = new ( "--start-interface-names-with-i" ) {
46+ private static readonly Option < bool > _startInterfaceNamesWithIOption = new ( "--start-interface-names-with-i" )
47+ {
4248 Description = "Prefix interface names with the letter I" ,
43- DefaultValueFactory = _ => true
49+ DefaultValueFactory = _ => true ,
4450 } ;
4551
46- private static readonly Option < bool > _commentUnrecognizedCodeOption = new ( "--comment-unrecognized-code" ) {
52+ private static readonly Option < bool > _commentUnrecognizedCodeOption = new ( "--comment-unrecognized-code" )
53+ {
4754 Description = "Include unrecognized code in output as commented-out code" ,
48- DefaultValueFactory = _ => true
55+ DefaultValueFactory = _ => true ,
4956 } ;
5057
51- private static readonly Option < bool > _systemOutToConsoleOption = new ( "--system-out-to-console" ) {
58+ private static readonly Option < bool > _systemOutToConsoleOption = new ( "--system-out-to-console" )
59+ {
5260 Description = "Convert System.out calls to Console" ,
53- DefaultValueFactory = _ => false
61+ DefaultValueFactory = _ => false ,
5462 } ;
5563
56- private static readonly Option < bool > _fileScopedNamespacesOption = new ( "--file-scoped-namespaces" ) {
64+ private static readonly Option < bool > _fileScopedNamespacesOption = new ( "--file-scoped-namespaces" )
65+ {
5766 Description = "Use file-scoped namespaces in C# output" ,
58- DefaultValueFactory = _ => false
67+ DefaultValueFactory = _ => false ,
5968 } ;
6069
61- private static readonly Option < bool > _clearDefaultUsingsOption = new ( "--clear-usings" ) {
70+ private static readonly Option < bool > _clearDefaultUsingsOption = new ( "--clear-usings" )
71+ {
6272 Description = "Remove all default usings provided by this app" ,
63- DefaultValueFactory = _ => false
73+ DefaultValueFactory = _ => false ,
6474 } ;
6575
66- private static readonly Option < List < string > > _addUsingsOption = new ( "--add-using" ) {
76+ private static readonly Option < List < string > > _addUsingsOption = new ( "--add-using" )
77+ {
6778 Description = "Adds a using directive to the collection of usings" ,
68- HelpName = "namespace"
79+ HelpName = "namespace" ,
6980 } ;
7081
71- private static readonly Option < string > _mappingsFileNameOption = new ( "--mappings-file" ) {
72- Description = "A yaml file with syntax mappings from imports, methods and annotations"
82+ private static readonly Option < string > _mappingsFileNameOption = new ( "--mappings-file" )
83+ {
84+ Description = "A yaml file with syntax mappings from imports, methods and annotations" ,
7385 } ;
7486
7587 static Program ( )
@@ -83,7 +95,7 @@ public static async Task Main(string[] args)
8395 {
8496 var rootCommand = new RootCommand ( "Java to C# Converter" )
8597 {
86- Description = "A syntactic transformer of source code from Java to C#."
98+ Description = "A syntactic transformer of source code from Java to C#." ,
8799 } ;
88100
89101 rootCommand . Subcommands . Add ( CreateFileCommand ( ) ) ;
@@ -110,13 +122,15 @@ public static async Task Main(string[] args)
110122
111123 private static Command CreateFileCommand ( )
112124 {
113- var inputArgument = new Argument < FileInfo > ( "input" ) {
114- Description = "A Java source code file to convert"
125+ var inputArgument = new Argument < FileInfo > ( "input" )
126+ {
127+ Description = "A Java source code file to convert" ,
115128 } ;
116129
117- var outputArgument = new Argument < FileInfo ? > ( "output" ) {
130+ var outputArgument = new Argument < FileInfo ? > ( "output" )
131+ {
118132 Description = "Path to place the C# output file, or stdout if omitted" ,
119- DefaultValueFactory = _ => null
133+ DefaultValueFactory = _ => null ,
120134 } ;
121135
122136 var fileCommand = new Command ( "file" , "Convert a Java file to C#" ) ;
@@ -187,11 +201,13 @@ private static SyntaxMapping ReadMappingsFile(string mappingsFile)
187201
188202 private static Command CreateDirectoryCommand ( )
189203 {
190- var inputArgument = new Argument < DirectoryInfo > ( "input" ) {
204+ var inputArgument = new Argument < DirectoryInfo > ( "input" )
205+ {
191206 Description = "A directory containing Java source code files to convert"
192207 } ;
193208
194- var outputArgument = new Argument < DirectoryInfo > ( "output" ) {
209+ var outputArgument = new Argument < DirectoryInfo > ( "output" )
210+ {
195211 Description = "Path to place the C# output files"
196212 } ;
197213
@@ -237,13 +253,17 @@ private static void ConvertToCSharpDir(DirectoryInfo inputDirectory, DirectoryIn
237253 }
238254 }
239255 else
256+ {
240257 _logger . LogError ( "Java input folder {path} doesn't exist!" , inputDirectory ) ;
258+ }
241259 }
242260
243261 private static void ConvertToCSharpFile ( FileSystemInfo inputFile , FileSystemInfo ? outputFile , JavaConversionOptions options , bool overwrite = true )
244262 {
245263 if ( ! overwrite && outputFile is { Exists : true } )
264+ {
246265 _logger . LogInformation ( "{outputFilePath} exists, skip to next." , outputFile ) ;
266+ }
247267 else if ( inputFile . Exists )
248268 {
249269 try
@@ -281,7 +301,9 @@ private static void ConvertToCSharpFile(FileSystemInfo inputFile, FileSystemInfo
281301 }
282302 }
283303 else
304+ {
284305 _logger . LogError ( "Java input file {filePath} doesn't exist!" , inputFile . FullName ) ;
306+ }
285307 }
286308
287309 private static void OutputFileOrPrint ( string ? fileName , string contents )
0 commit comments