@@ -14,6 +14,8 @@ namespace Flow.Launcher.Localization.Analyzers.Localize
1414 [ ExportCodeFixProvider ( LanguageNames . CSharp , Name = nameof ( OldGetTranslateAnalyzerCodeFixProvider ) ) , Shared ]
1515 public class OldGetTranslateAnalyzerCodeFixProvider : CodeFixProvider
1616 {
17+ #region CodeFixProvider
18+
1719 public sealed override ImmutableArray < string > FixableDiagnosticIds => ImmutableArray . Create (
1820 AnalyzerDiagnostics . OldLocalizationApiUsed . Id
1921 ) ;
@@ -39,6 +41,10 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
3941 ) ;
4042 }
4143
44+ #endregion
45+
46+ #region Fix Methods
47+
4248 private static Document FixOldTranslation ( CodeFixContext context , SyntaxNode root , Diagnostic diagnostic )
4349 {
4450 var diagnosticSpan = diagnostic . Location . SourceSpan ;
@@ -63,20 +69,19 @@ private static Document FixOldTranslation(CodeFixContext context, SyntaxNode roo
6369 return context . Document ;
6470 }
6571
72+ #region Utils
6673
6774 private static string GetTranslationKey ( ExpressionSyntax syntax )
6875 {
69- if (
70- syntax is LiteralExpressionSyntax literalExpressionSyntax &&
71- literalExpressionSyntax . Token . Value is string translationKey
72- )
76+ if ( syntax is LiteralExpressionSyntax literalExpressionSyntax &&
77+ literalExpressionSyntax . Token . Value is string translationKey )
7378 return translationKey ;
7479 return null ;
7580 }
7681
7782 private static Document FixOldTranslationWithoutStringFormat (
78- CodeFixContext context , string translationKey , SyntaxNode root , InvocationExpressionSyntax invocationExpr
79- ) {
83+ CodeFixContext context , string translationKey , SyntaxNode root , InvocationExpressionSyntax invocationExpr )
84+ {
8085 var newInvocationExpr = SyntaxFactory . ParseExpression (
8186 $ "{ Constants . ClassName } .{ translationKey } ()"
8287 ) ;
@@ -88,10 +93,8 @@ private static Document FixOldTranslationWithoutStringFormat(
8893
8994 private static string GetTranslationKeyFromInnerInvocation ( ExpressionSyntax syntax )
9095 {
91- if (
92- syntax is InvocationExpressionSyntax invocationExpressionSyntax &&
93- invocationExpressionSyntax . ArgumentList . Arguments . Count is 1
94- )
96+ if ( syntax is InvocationExpressionSyntax invocationExpressionSyntax &&
97+ invocationExpressionSyntax . ArgumentList . Arguments . Count is 1 )
9598 {
9699 var firstArgument = invocationExpressionSyntax . ArgumentList . Arguments . First ( ) . Expression ;
97100 return GetTranslationKey ( firstArgument ) ;
@@ -104,13 +107,17 @@ private static Document FixOldTranslationWithStringFormat(
104107 SeparatedSyntaxList < ArgumentSyntax > argumentList ,
105108 string translationKey2 ,
106109 SyntaxNode root ,
107- InvocationExpressionSyntax invocationExpr
108- ) {
110+ InvocationExpressionSyntax invocationExpr )
111+ {
109112 var newArguments = string . Join ( ", " , argumentList . Skip ( 1 ) . Select ( a => a . Expression ) ) ;
110113 var newInnerInvocationExpr = SyntaxFactory . ParseExpression ( $ "{ Constants . ClassName } .{ translationKey2 } ({ newArguments } )") ;
111114
112115 var newRoot = root . ReplaceNode ( invocationExpr , newInnerInvocationExpr ) ;
113116 return context . Document . WithSyntaxRoot ( newRoot ) ;
114117 }
118+
119+ #endregion
120+
121+ #endregion
115122 }
116123}
0 commit comments