diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs new file mode 100644 index 0000000000..4db9c211a7 --- /dev/null +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeFixes/GenerateMethod/GenerateConversionCodeFixProvider.cs @@ -0,0 +1,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); + } + } +} |