Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue in attribute line with attribute class name #8897

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ private void BuildType(List<ReviewLine> reviewLines, INamedTypeSymbol namedType,
{
typeToken.NavigationDisplayName = namedType.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
typeToken.RenderClasses.Add(namedType.TypeKind.ToString().ToLowerInvariant());
typeToken.HasSuffixSpace = true;
}

if (namedType.TypeKind == TypeKind.Delegate)
{
reviewLine.Tokens.Last().HasSuffixSpace = false;
Expand All @@ -309,6 +307,7 @@ private void BuildType(List<ReviewLine> reviewLines, INamedTypeSymbol namedType,
return;
}

reviewLine.Tokens.Last().HasSuffixSpace = true;
BuildBaseType(reviewLine, namedType);
reviewLine.Tokens.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBraceToken));
foreach (var namedTypeSymbol in SymbolOrderProvider.OrderTypes(namedType.GetTypeMembers()))
Expand Down Expand Up @@ -517,8 +516,10 @@ private void BuildAttributes(List<ReviewLine> reviewLines, ImmutableArray<Attrib
attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.EqualsToken));
BuildTypedConstant(attributeLine, argument.Value);
}
attributeLine.Tokens.Last().HasSuffixSpace = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@christothes are there any other cases where there needs to be special considerations for attributes?

attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseParenToken));
}
attributeLine.Tokens.Last().HasSuffixSpace = false;
attributeLine.AddToken(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseBracketToken));
attributeLine.RelatedToLine = relatedTo;
//Add current attribute line to review lines
Expand Down Expand Up @@ -573,7 +574,7 @@ private void BuildTypedConstant(ReviewLine reviewLine, TypedConstant typedConsta
}
else if (typedConstant.Kind == TypedConstantKind.Array)
{
tokenList.Add(ReviewToken.CreateKeywordToken(SyntaxKind.NewKeyword, false));
tokenList.Add(ReviewToken.CreateKeywordToken(SyntaxKind.NewKeyword));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBracketToken, false));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.CloseBracketToken));
tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.OpenBraceToken));
Expand Down Expand Up @@ -826,14 +827,16 @@ protected override void AddSpace()

protected override void AddBitwiseOr()
{
if(_tokenList.Count > 0)
_tokenList.Last().HasSuffixSpace = true;
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.BarToken));
}

public override void VisitField(IFieldSymbol symbol)
{
_tokenList.Add(ReviewToken.CreateTypeNameToken(symbol.Type.Name));
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.DotToken));
_tokenList.Add(ReviewToken.CreateMemberNameToken(symbol.Name));
_tokenList.Add(ReviewToken.CreateTypeNameToken(symbol.Type.Name, false));
_tokenList.Add(ReviewToken.CreatePunctuationToken(SyntaxKind.DotToken, false));
_tokenList.Add(ReviewToken.CreateMemberNameToken(symbol.Name, false));
}

public void Format(ITypeSymbol? type, object? typedConstantValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.42.0" />
<PackageReference Include="Azure.Core.Expressions.DataFactory" Version="1.0.0" />
<PackageReference Include="Azure.Security.Attestation" Version="1.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Azure.Template" Version="1.0.3-beta.4055065" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,25 @@ public void VerifyObsoleteMemberIsHidden()
Assert.True(relatedLine?.IsHidden);
}
}

[Fact]
public void VerifyTemplateClassLine()
praveenkuttappan marked this conversation as resolved.
Show resolved Hide resolved
{
var coreExprAssembly = Assembly.Load("Azure.Core.Expressions.DataFactory");
var dllStream = coreExprAssembly.GetFile("Azure.Core.Expressions.DataFactory.dll");
var assemblySymbol = CompilationFactory.GetCompilation(dllStream, null);
var codeFile = new CSharpAPIParser.TreeToken.CodeFileBuilder().Build(assemblySymbol, true, null);

var lines = codeFile.ReviewLines;
var namespaceLine = lines.Where(lines => lines.LineId == "Azure.Core.Expressions.DataFactory").FirstOrDefault();
Assert.NotNull(namespaceLine);
var classLine = namespaceLine.Children.Where(lines => lines.LineId.StartsWith("Azure.Core.Expressions.DataFactory.DataFactoryElement")).FirstOrDefault();
Assert.NotNull(classLine);
Assert.Equal("public sealed class DataFactoryElement<T> {", classLine.ToString().Trim());

var methodLine = classLine.Children.Where(lines => lines.LineId == "Azure.Core.Expressions.DataFactory.DataFactoryElement<T>.FromKeyVaultSecret(Azure.Core.Expressions.DataFactory.DataFactoryKeyVaultSecret)").FirstOrDefault();
Assert.NotNull(methodLine);
Assert.Equal("public static DataFactoryElement<string?> FromKeyVaultSecret(DataFactoryKeyVaultSecret secret);", methodLine.ToString().Trim());
}
}
}