提交 659689bf 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14778 from CyrusNajmabadi/generateTypeIncompleteMember

Make GenerateType work off of an Incomplete-Member.

Fixes #13211
......@@ -195,6 +195,9 @@ public static bool IsInTypeOnlyContext(ExpressionSyntax node)
case TypedVariableComponent:
return ((TypedVariableComponentSyntax)parent).Type == node;
case IncompleteMember:
return ((IncompleteMemberSyntax)parent).Type == node;
}
}
......
......@@ -15178,5 +15178,39 @@ where true
var infoSymbol2 = semanticModel.GetSymbolInfo(qe.Body.SelectOrGroup).Symbol;
Assert.Equal(expectedNames[i++], infoSymbol2.Name);
}
[Fact]
public void TestIncompleteMember()
{
// Note: binding information in an incomplete member is not available.
// When https://github.com/dotnet/roslyn/issues/7536 is fixed this test
// will have to be updated.
string sourceCode = @"
using System;
class Program
{
public /*<bind>*/K/*</bind>*/
}
class K
{ }
";
var semanticInfo = GetSemanticInfoForTest(sourceCode);
Assert.Equal("K", semanticInfo.Type.ToTestDisplayString());
Assert.Equal(TypeKind.Class, semanticInfo.Type.TypeKind);
Assert.Equal("K", semanticInfo.ConvertedType.ToTestDisplayString());
Assert.Equal(TypeKind.Class, semanticInfo.ConvertedType.TypeKind);
Assert.Equal(ConversionKind.Identity, semanticInfo.ImplicitConversion.Kind);
Assert.Equal("K", semanticInfo.Symbol.ToTestDisplayString());
Assert.Equal(SymbolKind.NamedType, semanticInfo.Symbol.Kind);
Assert.Equal(0, semanticInfo.CandidateSymbols.Length);
Assert.Equal(0, semanticInfo.MethodGroup.Length);
Assert.False(semanticInfo.IsCompileTimeConstant);
}
}
}
......@@ -7,9 +7,8 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType;
using Microsoft.CodeAnalysis.CSharp.Diagnostics;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Simplification;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -2018,4 +2017,26 @@ public async Task TestAccessibilityForPublicFields6()
index: 2);
}
}
public partial class GenerateTypeWithUnboundAnalyzerTests : AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal override Tuple<DiagnosticAnalyzer, CodeFixProvider> CreateDiagnosticProviderAndFixer(Workspace workspace)
{
return new Tuple<DiagnosticAnalyzer, CodeFixProvider>(
new CSharpUnboundIdentifiersDiagnosticAnalyzer(), new GenerateTypeCodeFixProvider());
}
protected override IList<CodeAction> MassageActions(IList<CodeAction> codeActions)
=> FlattenActions(codeActions);
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
[WorkItem(13211, "https://github.com/dotnet/roslyn/issues/13211")]
public async Task TestGenerateOffOfIncompleteMember()
{
await TestAsync(
@"class Class { public [|Foo|] }",
@"class Class { public Foo } internal class Foo { }",
index: 1);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册