提交 72ffd3f1 编写于 作者: M Manish Vasani

Address feedback

上级 ad24a9cb
......@@ -55,7 +55,7 @@ protected sealed override void InitializeWorker(AnalysisContext context)
/// <summary>
/// Override this method to register custom language specific actions to find symbol usages.
/// </summary>
protected virtual void RegisterCustomSymbolReferenceActions(SymbolStartAnalysisContext context, Action<ISymbol, ValueUsageInfo> onSymbolUsageFound)
protected virtual void HandleNamedTypeSymbolStart(SymbolStartAnalysisContext context, Action<ISymbol, ValueUsageInfo> onSymbolUsageFound)
{
}
......@@ -103,6 +103,7 @@ private void RegisterActions(CompilationStartAnalysisContext compilationStartCon
compilationStartContext.RegisterSymbolAction(AnalyzeSymbolDeclaration, SymbolKind.Method, SymbolKind.Field, SymbolKind.Property, SymbolKind.Event);
Action<ISymbol, ValueUsageInfo> onSymbolUsageFound = OnSymbolUsage;
compilationStartContext.RegisterSymbolStartAction(symbolStartContext =>
{
if (symbolStartContext.Symbol.GetAttributes().Any(a => a.AttributeClass == _structLayoutAttributeType))
......@@ -121,7 +122,7 @@ private void RegisterActions(CompilationStartAnalysisContext compilationStartCon
symbolStartContext.RegisterSymbolEndAction(symbolEndContext => OnSymbolEnd(symbolEndContext, hasInvalidOperation));
// Register custom language-specific actions, if any.
_analyzer.RegisterCustomSymbolReferenceActions(symbolStartContext, OnSymbolUsage);
_analyzer.HandleNamedTypeSymbolStart(symbolStartContext, onSymbolUsageFound);
}, SymbolKind.NamedType);
}
......
......@@ -10,9 +10,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnusedMembers
Friend NotInheritable Class VisualBasicRemoveUnusedMembersDiagnosticAnalyzer
Inherits AbstractRemoveUnusedMembersDiagnosticAnalyzer(Of DocumentationCommentTriviaSyntax, IdentifierNameSyntax)
Protected Overrides Sub RegisterCustomSymbolReferenceActions(context As SymbolStartAnalysisContext, onSymbolUsageFound As Action(Of ISymbol, ValueUsageInfo))
Protected Overrides Sub HandleNamedTypeSymbolStart(context As SymbolStartAnalysisContext, onSymbolUsageFound As Action(Of ISymbol, ValueUsageInfo))
' Mark all methods with handles clause as having a read reference
' to ensure that we consider the method as "used".
' Such methods are essentially event handlers and are normally
' not referenced directly.
For Each method In DirectCast(context.Symbol, INamedTypeSymbol).GetMembers().OfType(Of IMethodSymbol)
If Not method.HandledEvents.IsEmpty Then
onSymbolUsageFound(method, ValueUsageInfo.Read)
......@@ -20,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.RemoveUnusedMembers
Next
' Register syntax node action for HandlesClause
' This is a temporary workaround for following bugs:
' This is a workaround for following bugs:
' 1. https://github.com/dotnet/roslyn/issues/30978
' 2. https://github.com/dotnet/roslyn/issues/30979
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册