1- using System ;
2- using System . IO ;
3- using System . Threading ;
4- using JavaToCSharp ;
1+ using JavaToCSharp ;
52using Microsoft . Extensions . Logging ;
63
74namespace JavaToCSharpCli ;
@@ -21,7 +18,7 @@ public static void Main(string[] args)
2118 {
2219 try
2320 {
24- if ( args == null || args . Length < 3 )
21+ if ( args . Length < 3 )
2522 ShowHelp ( ) ;
2623 else
2724 switch ( args [ 0 ] )
@@ -39,7 +36,7 @@ public static void Main(string[] args)
3936 }
4037 catch ( Exception ex )
4138 {
42- _logger . LogError ( ex . Message , ex ) ;
39+ _logger . LogError ( ex , "Error: { Message}" , ex . Message ) ;
4340 }
4441
4542 // allow logger background thread to flush
@@ -53,13 +50,13 @@ private static void ConvertToCSharpDir(string folderPath, string outputFolderPat
5350 var input = new DirectoryInfo ( folderPath ) ;
5451 foreach ( var f in input . GetFiles ( "*.java" , SearchOption . AllDirectories ) )
5552 {
56- string directoryName = f . DirectoryName ;
57- if ( String . IsNullOrWhiteSpace ( directoryName ) )
53+ string ? directoryName = f . DirectoryName ;
54+ if ( string . IsNullOrWhiteSpace ( directoryName ) )
5855 {
5956 continue ;
6057 }
6158
62- var newFolderPath = directoryName . Replace ( folderPath , outputFolderPath , StringComparison . OrdinalIgnoreCase ) ;
59+ string newFolderPath = directoryName . Replace ( folderPath , outputFolderPath , StringComparison . OrdinalIgnoreCase ) ;
6360 if ( ! Directory . Exists ( newFolderPath ) )
6461 {
6562 Directory . CreateDirectory ( newFolderPath ) ;
@@ -82,17 +79,16 @@ private static void ConvertToCSharpFile(string filePath, string outputFilePath,
8279 {
8380 try
8481 {
85- var javaText = File . ReadAllText ( filePath ) ;
82+ string javaText = File . ReadAllText ( filePath ) ;
8683 var options = new JavaConversionOptions ( ) ;
8784
8885 options . WarningEncountered += ( _ , eventArgs ) =>
8986 {
90- var message = $ "Line { eventArgs . JavaLineNumber } : { eventArgs . Message } ";
91- _logger . LogWarning ( message ) ;
92- File . AppendAllText ( Path . ChangeExtension ( outputFilePath , ".warning" ) , message + Environment . NewLine ) ;
87+ _logger . LogWarning ( "Line {JavaLineNumber}: {Message}" , eventArgs . JavaLineNumber , eventArgs . Message ) ;
88+ File . AppendAllText ( Path . ChangeExtension ( outputFilePath , ".warning" ) , eventArgs . Message + Environment . NewLine ) ;
9389 } ;
9490
95- var parsed = JavaToCSharpConverter . ConvertText ( javaText , options ) ;
91+ string ? parsed = JavaToCSharpConverter . ConvertText ( javaText , options ) ;
9692 File . WriteAllText ( outputFilePath , parsed ) ;
9793 _logger . LogInformation ( "{filePath} converted!" , filePath ) ;
9894 }
0 commit comments