Skip to content

Commit

Permalink
change the type of OriginalParentAccessorKind from string to MethodKi…
Browse files Browse the repository at this point in the history
…nd (enum)
  • Loading branch information
Timur Kelman authored and Timur Kelman committed Jul 26, 2024
1 parent 4dc283c commit c51479a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CodeConverter/CSharp/ExpressionNodeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ public override async Task<CSharpSyntaxNode> VisitIdentifierName(VBasic.Syntax.I
var sym = GetSymbolInfoInDocument<ISymbol>(node);
if (sym is ILocalSymbol) {
if (sym.IsStatic && sym.ContainingSymbol is IMethodSymbol m && m.AssociatedSymbol is IPropertySymbol) {
qualifiedIdentifier = qualifiedIdentifier.WithParentPropertyAccessorKind(m.MethodKind.ToString());
qualifiedIdentifier = qualifiedIdentifier.WithParentPropertyAccessorKind(m.MethodKind);
}

var vbMethodBlock = node.Ancestors().OfType<VBasic.Syntax.MethodBlockBaseSyntax>().FirstOrDefault();
Expand Down
6 changes: 3 additions & 3 deletions CodeConverter/CSharp/HoistedFieldFromVbStaticVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ internal class HoistedFieldFromVbStaticVariable : IHoistedNode
{
public string OriginalMethodName { get; }
public string OriginalVariableName { get; }
public string OriginalParentAccessorKind { get; }
public MethodKind OriginalParentAccessorKind { get; }
public ExpressionSyntax Initializer { get; }
public TypeSyntax Type { get; }
public bool IsStatic { get; }

public HoistedFieldFromVbStaticVariable(string originalMethodName, string originalVariableName, string originalParentAccessorKind, ExpressionSyntax initializer, TypeSyntax type, bool isStatic)
public HoistedFieldFromVbStaticVariable(string originalMethodName, string originalVariableName, MethodKind originalParentAccessorKind, ExpressionSyntax initializer, TypeSyntax type, bool isStatic)
{
OriginalMethodName = originalMethodName;
OriginalVariableName = originalVariableName;
Expand All @@ -22,5 +22,5 @@ public HoistedFieldFromVbStaticVariable(string originalMethodName, string origin
}

public string FieldName => OriginalMethodName != null ? $"_{OriginalMethodName}_{OriginalVariableName}" : $"_{OriginalVariableName}";
public string PrefixedOriginalVariableName => PerScopeState.GetPrefixedName(OriginalParentAccessorKind, OriginalVariableName);
public string PrefixedOriginalVariableName => PerScopeState.GetPrefixedName(OriginalParentAccessorKind.ToString(), OriginalVariableName);
}
4 changes: 2 additions & 2 deletions CodeConverter/CSharp/MethodBodyExecutableStatementVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public override async Task<SyntaxList<StatementSyntax>> VisitLocalDeclarationSta
string methodName;
SyntaxTokenList methodModifiers;

string parentAccessorKind = null;
MethodKind parentAccessorKind = MethodKind.Ordinary;
if (_methodNode is VBSyntax.MethodBlockSyntax methodBlock) {
var methodStatement = methodBlock.BlockStatement as VBSyntax.MethodStatementSyntax;
methodModifiers = methodStatement.Modifiers;
Expand All @@ -121,7 +121,7 @@ public override async Task<SyntaxList<StatementSyntax>> VisitLocalDeclarationSta
} else if (_methodNode is VBSyntax.AccessorBlockSyntax accessorBlock) {
var propertyBlock = accessorBlock.Parent as VBSyntax.PropertyBlockSyntax;
methodName = propertyBlock.PropertyStatement.Identifier.Text;
parentAccessorKind = accessorBlock.IsKind(VBasic.SyntaxKind.GetAccessorBlock) ? "PropertyGet" : "PropertySet";
parentAccessorKind = accessorBlock.IsKind(VBasic.SyntaxKind.GetAccessorBlock) ? MethodKind.PropertyGet : MethodKind.PropertySet;
methodModifiers = propertyBlock.PropertyStatement.Modifiers;
} else {
throw new NotImplementedException(_methodNode.GetType() + " not implemented!");
Expand Down
2 changes: 1 addition & 1 deletion CodeConverter/CSharp/PerScopeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async Task<SyntaxList<MemberDeclarationSyntax>> CreateVbStaticFieldsAsync
modifiers.Add(CS.SyntaxFactory.Token(SyntaxKind.StaticKeyword));
}
var fieldDecl = CS.SyntaxFactory.FieldDeclaration(CS.SyntaxFactory.List<AttributeListSyntax>(), CS.SyntaxFactory.TokenList(modifiers), decl);
if (!string.IsNullOrEmpty(field.OriginalParentAccessorKind)) {
if (field.OriginalParentAccessorKind != MethodKind.Ordinary) {
fieldDecl = fieldDecl.WithParentPropertyAccessorKind(field.OriginalParentAccessorKind);
}
declarations.Add(fieldDecl);
Expand Down
4 changes: 2 additions & 2 deletions CodeConverter/Util/SyntaxNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ private static T WithoutSourceMappingNonRecursive<T>(this T node) where T : Synt
return node.WithoutAnnotations(AnnotationConstants.SourceStartLineAnnotationKind).WithoutAnnotations(AnnotationConstants.SourceEndLineAnnotationKind);
}

public static T WithParentPropertyAccessorKind<T>(this T node, string accessorKind) where T : SyntaxNode
public static T WithParentPropertyAccessorKind<T>(this T node, MethodKind accessorKind) where T : SyntaxNode
{
return node.WithAdditionalAnnotations(AnnotationConstants.ParentPropertyAccessorKind(accessorKind));
return node.WithAdditionalAnnotations(AnnotationConstants.ParentPropertyAccessorKind(accessorKind.ToString()));
}

private static bool IsBlockParent(SyntaxNode converted, SyntaxToken lastCsConvertedToken)
Expand Down

0 comments on commit c51479a

Please sign in to comment.