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 handling of records in RCS1223 #1051

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix ([RCS1235](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1235.md)) ([#1047](https://github.com/JosefPihrt/Roslynator/pull/1047)).
- Fix ([RCS1206](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1206.md)) ([#1049](https://github.com/JosefPihrt/Roslynator/pull/1049)).
- Prevent possible recursion in ([RCS1235](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1235.md)) ([#1054](https://github.com/JosefPihrt/Roslynator/pull/1054)).
- Fix ([RCS1223](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1223.md)) ([#1051](https://github.com/JosefPihrt/Roslynator/pull/1051)).

## [4.2.0] - 2022-11-27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,12 @@ public static void AnalyzerNamedTypeSymbol(SymbolAnalysisContext context, INamed

if (typeSymbol.OriginalDefinition.HasAttribute(debuggerDisplayAttributeSymbol, includeBaseTypes: true))
return;

SyntaxToken identifier;

if (typeKind == TypeKind.Class)
{
var classDeclaration = (ClassDeclarationSyntax)typeSymbol.GetSyntax(context.CancellationToken);

identifier = classDeclaration.Identifier;
}
else
{
var structDeclaration = (StructDeclarationSyntax)typeSymbol.GetSyntax(context.CancellationToken);

identifier = structDeclaration.Identifier;
}


if(typeSymbol.GetSyntax(context.CancellationToken) is not TypeDeclarationSyntax typeDeclaration)
return;

var identifier = typeDeclaration.Identifier;

DiagnosticHelpers.ReportDiagnostic(context, DiagnosticRules.MarkTypeWithDebuggerDisplayAttribute, identifier, identifier.ValueText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,32 @@ public abstract class C
}
");
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.MarkTypeWithDebuggerDisplayAttribute)]
public async Task Test_PublicRecord()
{
await VerifyDiagnosticAndFixAsync(@"
using System.Diagnostics;

public record [|R|]
{
}
", @"
using System.Diagnostics;

[DebuggerDisplay(""{DebuggerDisplay,nq}"")]
public record R
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get
{
return ToString();
}
}
}
");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,7 @@ public static async Task<Document> RefactorAsync(

PropertyDeclarationSyntax propertyDeclaration = DebuggerDisplayPropertyDeclaration(propertyName, InvocationExpression(IdentifierName("ToString")));

TypeDeclarationSyntax newTypeDeclaration;

if (typeDeclaration is ClassDeclarationSyntax classDeclaration)
{
newTypeDeclaration = SyntaxRefactorings.AddAttributeLists(classDeclaration, keepDocumentationCommentOnTop: true, attributeList);
}
else
{
var structDeclaration = (StructDeclarationSyntax)typeDeclaration;

newTypeDeclaration = SyntaxRefactorings.AddAttributeLists(structDeclaration, keepDocumentationCommentOnTop: true, attributeList);
}
TypeDeclarationSyntax newTypeDeclaration = SyntaxRefactorings.AddAttributeLists(typeDeclaration, keepDocumentationCommentOnTop: true, attributeList);

newTypeDeclaration = MemberDeclarationInserter.Default.Insert(newTypeDeclaration, propertyDeclaration);

Expand Down