blob: 4db9c211a7728e058ea699363d7fc079b497cda5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis;
using MonoDevelop.CSharp.CodeFixes.GenerateConstructor;
using Microsoft.CodeAnalysis.CSharp;
using ICSharpCode.NRefactory6.CSharp;
using ICSharpCode.NRefactory6.CSharp.GenerateMember.GenerateParameterizedMember;
namespace MonoDevelop.CSharp.CodeFixes.GenerateMethod
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = PredefinedCodeFixProviderNames.GenerateConversion), Shared]
[ExtensionOrder(After = PredefinedCodeFixProviderNames.GenerateEnumMember)]
internal class GenerateConversionCodeFixProvider : AbstractGenerateMemberCodeFixProvider
{
private const string CS0029 = "CS0029"; // error CS0029: Cannot implicitly convert type 'type' to 'type'
private const string CS0030 = "CS0030"; // error CS0030: Cannot convert type 'type' to 'type'
public override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(CS0029, CS0030); }
}
protected override bool IsCandidate(SyntaxNode node)
{
return node.IsKind(SyntaxKind.IdentifierName) ||
node.IsKind(SyntaxKind.MethodDeclaration) ||
node.IsKind(SyntaxKind.InvocationExpression) ||
node.IsKind(SyntaxKind.CastExpression) ||
node is LiteralExpressionSyntax ||
node is SimpleNameSyntax ||
node is ExpressionSyntax;
}
protected override SyntaxNode GetTargetNode(SyntaxNode node)
{
var invocation = node as InvocationExpressionSyntax;
if (invocation != null)
{
return invocation.Expression.GetRightmostName();
}
var memberBindingExpression = node as MemberBindingExpressionSyntax;
if (memberBindingExpression != null)
{
return memberBindingExpression.Name;
}
return node;
}
static CSharpGenerateConversionService service = new CSharpGenerateConversionService ();
protected override Task<IEnumerable<CodeAction>> GetCodeActionsAsync(Document document, SyntaxNode node, CancellationToken cancellationToken)
{
return service.GenerateConversionAsync(document, node, cancellationToken);
}
}
}
|