Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
3facb050
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3facb050
编写于
3月 13, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Infer base type better when generating a type
上级
4faf4ad5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
89 addition
and
33 deletion
+89
-33
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
.../CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
+34
-18
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeWithUnboundAnalyzerTests.cs
...tics/GenerateType/GenerateTypeWithUnboundAnalyzerTests.cs
+46
-0
src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs
...ortable/GenerateType/AbstractGenerateTypeService.State.cs
+9
-15
未找到文件。
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
浏览文件 @
3facb050
...
@@ -7,9 +7,7 @@
...
@@ -7,9 +7,7 @@
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType
;
using
Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType
;
using
Microsoft.CodeAnalysis.CSharp.Diagnostics
;
using
Microsoft.CodeAnalysis.CSharp.Test.Utilities
;
using
Microsoft.CodeAnalysis.CSharp.Test.Utilities
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
...
@@ -5355,32 +5353,50 @@ public Class(global::System.Object method)
...
@@ -5355,32 +5353,50 @@ public Class(global::System.Object method)
}}
"
,
}}
"
,
index
:
1
);
index
:
1
);
}
}
}
public
partial
class
GenerateTypeWithUnboundAnalyzerTests
:
AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal
override
(
DiagnosticAnalyzer
,
CodeFixProvider
)
CreateDiagnosticProviderAndFixer
(
Workspace
workspace
)
=>
(
new
CSharpUnboundIdentifiersDiagnosticAnalyzer
(),
new
GenerateTypeCodeFixProvider
());
protected
override
ImmutableArray
<
CodeAction
>
MassageActions
(
ImmutableArray
<
CodeAction
>
codeActions
)
=>
FlattenActions
(
codeActions
);
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)]
[
WorkItem
(
13211
,
"https://github.com/dotnet/roslyn/issues/13211
"
)]
[
WorkItem
(
270
,
"https://github.com/dotnet/roslyn/issues/270
"
)]
public
async
Task
TestGenerate
OffOfIncompleteMember
()
public
async
Task
TestGenerate
InIsExpression
()
{
{
await
TestInRegularAndScriptAsync
(
await
TestInRegularAndScriptAsync
(
@"class Class
@"using System;
class Program
{
{
public [|Goo|]
static void Main(Exception p)
{
bool result = p is [|SampleType|];
}
}"
,
}"
,
@"class Class
@"using System;
using System.Runtime.Serialization;
class Program
{
{
public Goo
static void Main(Exception p)
{
bool result = p is SampleType;
}
}
}
internal class Goo
[Serializable]
internal class SampleType : Exception
{
{
public SampleType()
{
}
public SampleType(string message) : base(message)
{
}
public SampleType(string message, Exception innerException) : base(message, innerException)
{
}
protected SampleType(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}"
,
}"
,
index
:
1
);
index
:
1
);
}
}
...
...
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeWithUnboundAnalyzerTests.cs
0 → 100644
浏览文件 @
3facb050
// 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.
using
System.Collections.Immutable
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType
;
using
Microsoft.CodeAnalysis.CSharp.Diagnostics
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics.GenerateTypeTests
{
public
partial
class
GenerateTypeWithUnboundAnalyzerTests
:
AbstractCSharpDiagnosticProviderBasedUserDiagnosticTest
{
internal
override
(
DiagnosticAnalyzer
,
CodeFixProvider
)
CreateDiagnosticProviderAndFixer
(
Workspace
workspace
)
=>
(
new
CSharpUnboundIdentifiersDiagnosticAnalyzer
(),
new
GenerateTypeCodeFixProvider
());
protected
override
ImmutableArray
<
CodeAction
>
MassageActions
(
ImmutableArray
<
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
TestInRegularAndScriptAsync
(
@"class Class
{
public [|Goo|]
}"
,
@"class Class
{
public Goo
}
internal class Goo
{
}"
,
index
:
1
);
}
}
}
src/Features/Core/Portable/GenerateType/AbstractGenerateTypeService.State.cs
浏览文件 @
3facb050
...
@@ -210,42 +210,36 @@ private State(Compilation compilation)
...
@@ -210,42 +210,36 @@ private State(Compilation compilation)
var
syntaxFacts
=
document
.
Document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
syntaxFacts
=
document
.
Document
.
GetLanguageService
<
ISyntaxFactsService
>();
if
(
service
.
IsInCatchDeclaration
(
NameOrMemberAccessExpression
))
if
(
service
.
IsInCatchDeclaration
(
NameOrMemberAccessExpression
))
{
{
BaseTypeOrInterfaceOpt
=
document
.
SemanticModel
.
Compilation
.
ExceptionType
(
);
SetBaseType
(
document
.
SemanticModel
.
Compilation
.
ExceptionType
()
);
}
}
else
if
(
syntaxFacts
.
IsAttributeName
(
NameOrMemberAccessExpression
))
else
if
(
syntaxFacts
.
IsAttributeName
(
NameOrMemberAccessExpression
))
{
{
BaseTypeOrInterfaceOpt
=
document
.
SemanticModel
.
Compilation
.
AttributeType
(
);
SetBaseType
(
document
.
SemanticModel
.
Compilation
.
AttributeType
()
);
}
}
else
if
(
else
service
.
IsArrayElementType
(
NameOrMemberAccessExpression
)
||
service
.
IsInVariableTypeContext
(
NameOrMemberAccessExpression
)
||
ObjectCreationExpressionOpt
!=
null
)
{
{
var
expr
=
ObjectCreationExpressionOpt
??
NameOrMemberAccessExpression
;
var
expr
=
ObjectCreationExpressionOpt
??
NameOrMemberAccessExpression
;
if
(
expr
!=
null
)
{
var
typeInference
=
document
.
Document
.
GetLanguageService
<
ITypeInferenceService
>();
var
typeInference
=
document
.
Document
.
GetLanguageService
<
ITypeInferenceService
>();
var
baseType
=
typeInference
.
InferType
(
document
.
SemanticModel
,
expr
,
objectAsDefault
:
true
,
cancellationToken
:
cancellationToken
)
as
INamedTypeSymbol
;
var
baseType
=
typeInference
.
InferType
(
document
.
SemanticModel
,
expr
,
objectAsDefault
:
true
,
cancellationToken
:
cancellationToken
)
as
INamedTypeSymbol
;
SetBaseType
(
baseType
);
SetBaseType
(
baseType
);
}
}
}
}
}
private
void
SetBaseType
(
INamedTypeSymbol
baseType
)
private
void
SetBaseType
(
INamedTypeSymbol
baseType
)
{
{
if
(
baseType
==
null
)
if
(
baseType
==
null
)
{
return
;
return
;
}
// A base type need to be non class or interface type. Also, being 'object' is
// A base type need to be non class or interface type. Also, being 'object' is
// redundant as the base type.
// redundant as the base type.
if
(
baseType
.
IsSealed
||
baseType
.
IsStatic
||
baseType
.
SpecialType
==
SpecialType
.
System_Object
)
if
(
baseType
.
IsSealed
||
baseType
.
IsStatic
||
baseType
.
SpecialType
==
SpecialType
.
System_Object
)
{
return
;
return
;
}
if
(
baseType
.
TypeKind
!=
TypeKind
.
Class
&&
baseType
.
TypeKind
!=
TypeKind
.
Interface
)
if
(
baseType
.
TypeKind
!=
TypeKind
.
Class
&&
baseType
.
TypeKind
!=
TypeKind
.
Interface
)
{
return
;
return
;
}
// Strip off top-level nullability since we can't put top-level nullability into the base list. We will still include nested nullability
// Strip off top-level nullability since we can't put top-level nullability into the base list. We will still include nested nullability
// if you're deriving some interface like IEnumerable<string?>.
// if you're deriving some interface like IEnumerable<string?>.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录