99using static ICSharpCode . CodeConverter . CSharp . SemanticModelExtensions ;
1010
1111namespace ICSharpCode . CodeConverter . CSharp ;
12- internal class NameExpressionNodeVisitor : VBasic . VisualBasicSyntaxVisitor < Task < CSharpSyntaxNode > >
12+
13+
14+ internal class NameExpressionNodeVisitor
1315{
1416 private readonly SemanticModel _semanticModel ;
1517 private readonly HashSet < string > _generatedNames ;
1618 private readonly ITypeContext _typeContext ;
1719 private readonly HashSet < string > _extraUsingDirectives ;
1820 private readonly Dictionary < string , Stack < ( SyntaxNode Scope , string TempName ) > > _tempNameForAnonymousScope ;
1921 private readonly Stack < ExpressionSyntax > _withBlockLhs ;
22+ private readonly ArgumentConverter _argumentConverter ;
2023
2124 public CommonConversions CommonConversions { get ; }
2225 public CommentConvertingVisitorWrapper TriviaConvertingExpressionVisitor { get ; }
2326
2427 public NameExpressionNodeVisitor ( SemanticModel semanticModel , HashSet < string > generatedNames , ITypeContext typeContext , HashSet < string > extraUsingDirectives ,
2528 Dictionary < string , Stack < ( SyntaxNode Scope , string TempName ) > > tempNameForAnonymousScope , Stack < ExpressionSyntax > withBlockLhs , CommonConversions commonConversions ,
29+ ArgumentConverter argumentConverter ,
2630 CommentConvertingVisitorWrapper triviaConvertingExpressionVisitor )
2731 {
2832 _semanticModel = semanticModel ;
@@ -31,11 +35,12 @@ public NameExpressionNodeVisitor(SemanticModel semanticModel, HashSet<string> ge
3135 _extraUsingDirectives = extraUsingDirectives ;
3236 _tempNameForAnonymousScope = tempNameForAnonymousScope ;
3337 _withBlockLhs = withBlockLhs ;
38+ _argumentConverter = argumentConverter ;
3439 CommonConversions = commonConversions ;
3540 TriviaConvertingExpressionVisitor = triviaConvertingExpressionVisitor ;
3641 }
3742
38- public override async Task < CSharpSyntaxNode > VisitMemberAccessExpression ( VBasic . Syntax . MemberAccessExpressionSyntax node )
43+ public async Task < CSharpSyntaxNode > ConvertMemberAccessExpressionAsync ( VBasic . Syntax . MemberAccessExpressionSyntax node )
3944 {
4045 var nodeSymbol = _semanticModel . GetSymbolInfoInDocument < ISymbol > ( node . Name ) ;
4146
@@ -106,28 +111,28 @@ public override async Task<CSharpSyntaxNode> VisitMemberAccessExpression(VBasic.
106111 return await AdjustForImplicitInvocationAsync ( node , memberAccessExpressionSyntax ) ;
107112 }
108113
109- public override async Task < CSharpSyntaxNode > VisitGlobalName ( VBasic . Syntax . GlobalNameSyntax node )
114+ public async Task < CSharpSyntaxNode > ConvertGlobalNameAsync ( VBasic . Syntax . GlobalNameSyntax node )
110115 {
111116 return ValidSyntaxFactory . IdentifierName ( SyntaxFactory . Token ( SyntaxKind . GlobalKeyword ) ) ;
112117 }
113118
114- public override async Task < CSharpSyntaxNode > VisitMeExpression ( VBasic . Syntax . MeExpressionSyntax node )
119+ public async Task < CSharpSyntaxNode > ConvertMeExpressionAsync ( VBasic . Syntax . MeExpressionSyntax node )
115120 {
116121 return SyntaxFactory . ThisExpression ( ) ;
117122 }
118123
119- public override async Task < CSharpSyntaxNode > VisitMyBaseExpression ( VBasic . Syntax . MyBaseExpressionSyntax node )
124+ public async Task < CSharpSyntaxNode > ConvertMyBaseExpressionAsync ( VBasic . Syntax . MyBaseExpressionSyntax node )
120125 {
121126 return SyntaxFactory . BaseExpression ( ) ;
122127 }
123128
124- public override async Task < CSharpSyntaxNode > VisitGenericName ( VBasic . Syntax . GenericNameSyntax node )
129+ public async Task < CSharpSyntaxNode > ConvertGenericNameAsync ( VBasic . Syntax . GenericNameSyntax node )
125130 {
126131 var symbol = _semanticModel . GetSymbolInfoInDocument < ISymbol > ( node ) ;
127132 var genericNameSyntax = await GenericNameAccountingForReducedParametersAsync ( node , symbol ) ;
128133 return await AdjustForImplicitInvocationAsync ( node , genericNameSyntax ) ;
129134 }
130- public override async Task < CSharpSyntaxNode > VisitQualifiedName ( VBasic . Syntax . QualifiedNameSyntax node )
135+ public async Task < CSharpSyntaxNode > ConvertQualifiedNameAsync ( VBasic . Syntax . QualifiedNameSyntax node )
131136 {
132137 var symbol = _semanticModel . GetSymbolInfoInDocument < ITypeSymbol > ( node ) ;
133138 if ( symbol != null ) {
@@ -155,7 +160,7 @@ public override async Task<CSharpSyntaxNode> VisitQualifiedName(VBasic.Syntax.Qu
155160 }
156161
157162 /// <remarks>PERF: This is a hot code path, try to avoid using things like GetOperation except where needed.</remarks>
158- public override async Task < CSharpSyntaxNode > VisitIdentifierName ( VBasic . Syntax . IdentifierNameSyntax node )
163+ public async Task < CSharpSyntaxNode > ConvertIdentifierNameAsync ( VBasic . Syntax . IdentifierNameSyntax node )
159164 {
160165 var identifier = SyntaxFactory . IdentifierName ( CommonConversions . ConvertIdentifier ( node . Identifier , node . GetAncestor < VBasic . Syntax . AttributeSyntax > ( ) != null ) ) ;
161166
@@ -189,7 +194,7 @@ public override async Task<CSharpSyntaxNode> VisitIdentifierName(VBasic.Syntax.I
189194
190195
191196
192- public override async Task < CSharpSyntaxNode > VisitInvocationExpression (
197+ public async Task < CSharpSyntaxNode > ConvertInvocationExpressionAsync (
193198 VBasic . Syntax . InvocationExpressionSyntax node )
194199 {
195200 var invocationSymbol = _semanticModel . GetSymbolInfo ( node ) . ExtractBestMatch < ISymbol > ( ) ;
@@ -201,7 +206,7 @@ public override async Task<CSharpSyntaxNode> VisitInvocationExpression(
201206 try {
202207
203208 if ( node . Expression is null ) {
204- var convertArgumentListOrEmptyAsync = await ConvertArgumentsAsync ( node . ArgumentList ) ;
209+ var convertArgumentListOrEmptyAsync = await _argumentConverter . ConvertArgumentsAsync ( node . ArgumentList ) ;
205210 return SyntaxFactory . ElementBindingExpression ( SyntaxFactory . BracketedArgumentList ( SyntaxFactory . SeparatedList ( convertArgumentListOrEmptyAsync ) ) ) ;
206211 }
207212
@@ -273,7 +278,7 @@ private async Task<ExpressionSyntax> ConvertInvocationAsync(VBSyntax.InvocationE
273278 return convertedExpression ; //Parameterless property access
274279 }
275280
276- var convertedArgumentList = await ConvertArgumentListOrEmptyAsync ( node , node . ArgumentList ) ;
281+ var convertedArgumentList = await _argumentConverter . ConvertArgumentListOrEmptyAsync ( node , node . ArgumentList ) ;
277282
278283 if ( IsElementAtOrDefaultInvocation ( invocationSymbol , expressionSymbol ) ) {
279284 convertedExpression = GetElementAtOrDefaultExpression ( expressionType , convertedExpression ) ;
@@ -315,7 +320,7 @@ private async Task<ExpressionSyntax> CreateElementAccessAsync(VBSyntax.Invocatio
315320 var bracketedArgumentListSyntax = SyntaxFactory . BracketedArgumentList ( args ) ;
316321 if ( expression is ElementBindingExpressionSyntax binding &&
317322 ! binding . ArgumentList . Arguments . Any ( ) ) {
318- // Special case where structure changes due to conditional access (See VisitMemberAccessExpression )
323+ // Special case where structure changes due to conditional access (See ConvertMemberAccessExpression )
319324 return binding . WithArgumentList ( bracketedArgumentListSyntax ) ;
320325 }
321326
@@ -360,7 +365,7 @@ private async Task<InvocationExpressionSyntax> TryConvertParameterizedPropertyAs
360365 var idToken = expr . DescendantTokens ( ) . Last ( t => t . IsKind ( SyntaxKind . IdentifierToken ) ) ;
361366 expr = ReplaceRightmostIdentifierText ( expr , idToken , overrideIdentifier ) ;
362367
363- var args = await ConvertArgumentListOrEmptyAsync ( node , optionalArgumentList ) ;
368+ var args = await _argumentConverter . ConvertArgumentListOrEmptyAsync ( node , optionalArgumentList ) ;
364369 if ( extraArg != null ) {
365370 var extraArgSyntax = SyntaxFactory . Argument ( extraArg ) ;
366371 var propertySymbol = ( ( IPropertyReferenceOperation ) operation ) . Property ;
@@ -620,8 +625,8 @@ private CSharpSyntaxNode AddEmptyArgumentListIfImplicit(SyntaxNode node, Express
620625 {
621626 if ( _semanticModel . SyntaxTree != node . SyntaxTree ) return id ;
622627 return _semanticModel . GetOperation ( node ) switch {
623- IInvocationOperation invocation => SyntaxFactory . InvocationExpression ( id , CreateArgList ( invocation . TargetMethod ) ) ,
624- IPropertyReferenceOperation propReference when propReference . Property . Parameters . Any ( ) => SyntaxFactory . InvocationExpression ( id , CreateArgList ( propReference . Property ) ) ,
628+ IInvocationOperation invocation => SyntaxFactory . InvocationExpression ( id , _argumentConverter . CreateArgList ( invocation . TargetMethod ) ) ,
629+ IPropertyReferenceOperation propReference when propReference . Property . Parameters . Any ( ) => SyntaxFactory . InvocationExpression ( id , _argumentConverter . CreateArgList ( propReference . Property ) ) ,
625630 _ => id
626631 } ;
627632 }
@@ -645,7 +650,7 @@ private async Task<CSharpSyntaxNode> SubstituteVisualBasicMethodOrNullAsync(VBSy
645650 }
646651
647652 if ( SimpleMethodReplacement . TryGet ( symbol , out var methodReplacement ) &&
648- methodReplacement . ReplaceIfMatches ( symbol , await ConvertArgumentsAsync ( node . ArgumentList ) , false ) is { } csExpression ) {
653+ methodReplacement . ReplaceIfMatches ( symbol , await _argumentConverter . ConvertArgumentsAsync ( node . ArgumentList ) , false ) is { } csExpression ) {
649654 cSharpSyntaxNode = csExpression ;
650655 }
651656
0 commit comments