|
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Collections.Immutable
Imports System.Composition
Imports System.Diagnostics.CodeAnalysis
Imports System.Threading
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.CodeFixes.GenerateMember
Imports Microsoft.CodeAnalysis.CodeGeneration
Imports Microsoft.CodeAnalysis.GenerateMember.GenerateEnumMember
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEnumMember
<ExportCodeFixProvider(LanguageNames.VisualBasic, Name:=PredefinedCodeFixProviderNames.GenerateEnumMember), [Shared]>
<ExtensionOrder(After:=PredefinedCodeFixProviderNames.GenerateConstructor)>
Friend NotInheritable Class GenerateEnumMemberCodeFixProvider
Inherits AbstractGenerateMemberCodeFixProvider
Friend Const BC30456 As String = "BC30456" ' error BC30456: 'Red' is not a member of 'Color'.
<ImportingConstructor>
<SuppressMessage("RoslynDiagnosticsReliability", "RS0033:Importing constructor should be [Obsolete]", Justification:="Used in test code: https://github.com/dotnet/roslyn/issues/42814")>
Public Sub New()
End Sub
Public Overrides ReadOnly Property FixableDiagnosticIds As ImmutableArray(Of String)
Get
Return ImmutableArray.Create(BC30456)
End Get
End Property
Protected Overrides Function GetCodeActionsAsync(document As Document, node As SyntaxNode, cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of CodeAction))
Dim service = document.GetLanguageService(Of IGenerateEnumMemberService)()
Return service.GenerateEnumMemberAsync(document, node, cancellationToken)
End Function
Protected Overrides Function IsCandidate(node As SyntaxNode, token As SyntaxToken, diagnostic As Diagnostic) As Boolean
Return TypeOf node Is MemberAccessExpressionSyntax
End Function
Protected Overrides Function GetTargetNode(node As SyntaxNode) As SyntaxNode
Return DirectCast(node, MemberAccessExpressionSyntax).Name
End Function
End Class
End Namespace
|