-
Notifications
You must be signed in to change notification settings - Fork 457
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 crash and record diagnostic location in preview feature analyzer #5809
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5809 +/- ##
=======================================
Coverage 95.58% 95.58%
=======================================
Files 1284 1284
Lines 296834 296805 -29
Branches 18101 18090 -11
=======================================
- Hits 283725 283714 -11
+ Misses 10670 10655 -15
+ Partials 2439 2436 -3 |
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/DetectPreviewFeatureAnalyzer.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @Youssef1313 overall LGTM , could you add similar logic into VB code? Looks at least this method could benefit fom using TypeStatementSyntax
and TypeBlockSyntax
instead
Lines 124 to 176 in f471d33
Protected Overrides Function GetPreviewInterfaceNodeForTypeImplementingPreviewInterface(typeSymbol As ISymbol, previewInterfaceSymbol As ISymbol) As SyntaxNode | |
Dim typeSymbolDeclaringReferences = typeSymbol.DeclaringSyntaxReferences | |
For Each syntaxReference In typeSymbolDeclaringReferences | |
Dim typeSymbolDefinition = syntaxReference.GetSyntax() | |
Dim classStatement = TryCast(typeSymbolDefinition, ClassStatementSyntax) | |
If classStatement IsNot Nothing Then | |
Dim classBlock = TryCast(classStatement.Parent, ClassBlockSyntax) | |
If classBlock IsNot Nothing Then | |
Dim syntaxNode As SyntaxNode = Nothing | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(classBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
Else | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(classBlock.Implements, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
End If | |
End If | |
End If | |
End If | |
Dim structStatement = TryCast(typeSymbolDefinition, StructureStatementSyntax) | |
If structStatement IsNot Nothing Then | |
Dim structBlock = TryCast(structStatement.Parent, StructureBlockSyntax) | |
If structBlock IsNot Nothing Then | |
Dim syntaxNode As SyntaxNode = Nothing | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(structBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
Else | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(structBlock.Implements, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
End If | |
End If | |
End If | |
End If | |
Dim interfaceStatement = TryCast(typeSymbolDefinition, InterfaceStatementSyntax) | |
If interfaceStatement IsNot Nothing Then | |
Dim interfaceBlock = TryCast(interfaceStatement.Parent, InterfaceBlockSyntax) | |
If interfaceBlock IsNot Nothing Then | |
Dim syntaxNode As SyntaxNode = Nothing | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(interfaceBlock.Implements, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
Else | |
If TryGetPreviewInterfaceNodeForClassOrStructImplementingPreviewInterface(interfaceBlock.Inherits, previewInterfaceSymbol, syntaxNode) Then | |
Return syntaxNode | |
End If | |
End If | |
End If | |
End If | |
Next | |
Return Nothing | |
End Function |
...Analyzers/UnitTests/Microsoft.NetCore.Analyzers/Runtime/DetectPreviewFeatureTests.Classes.cs
Show resolved
Hide resolved
…/roslyn-analyzers into preview-features-nre
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Youssef1313 looks great. The perf failures unrelated and reported in #5790, merging
…otnet#5809) * Fix crash and record diagnostic location in preview feature analyzer
@jeffhandley Can you take a look?
Fixes #5802