Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6156724f
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,发现更多精彩内容 >>
提交
6156724f
编写于
11月 16, 2017
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update tests.
上级
be92d952
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
75 addition
and
98 deletion
+75
-98
src/EditorFeatures/CSharp/UseAutoProperty/UseAutoPropertyAnalyzer.cs
...eatures/CSharp/UseAutoProperty/UseAutoPropertyAnalyzer.cs
+1
-2
src/EditorFeatures/CSharp/UseAutoProperty/UseAutoPropertyCodeFixProvider.cs
.../CSharp/UseAutoProperty/UseAutoPropertyCodeFixProvider.cs
+1
-5
src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs
...pTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs
+55
-62
src/EditorFeatures/VisualBasic/UseAutoProperty/UseAutoPropertyAnalyzer.vb
...es/VisualBasic/UseAutoProperty/UseAutoPropertyAnalyzer.vb
+1
-2
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
...rtable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
+13
-20
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs
...UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs
+4
-7
未找到文件。
src/EditorFeatures/CSharp/UseAutoProperty/UseAutoPropertyAnalyzer.cs
浏览文件 @
6156724f
...
...
@@ -56,8 +56,7 @@ protected override bool SupportsPropertyInitializer(Compilation compilation)
if
(
member
is
PropertyDeclarationSyntax
propertyDeclaration
)
{
var
property
=
(
IPropertySymbol
)
context
.
SemanticModel
.
GetDeclaredSymbol
(
propertyDeclaration
,
context
.
CancellationToken
);
AnalyzeProperty
(
context
,
property
,
analysisResults
);
AnalyzeProperty
(
context
,
propertyDeclaration
,
analysisResults
);
}
}
...
...
src/EditorFeatures/CSharp/UseAutoProperty/UseAutoPropertyCodeFixProvider.cs
浏览文件 @
6156724f
...
...
@@ -36,7 +36,6 @@ protected override SyntaxNode GetNodeToRemove(VariableDeclaratorSyntax declarato
var
sourceText
=
await
propertyDocument
.
GetTextAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
getAccessor
=
propertyDeclaration
.
AccessorList
.
Accessors
.
First
(
d
=>
d
.
IsKind
(
SyntaxKind
.
GetAccessorDeclaration
));
var
isSingleLine
=
sourceText
.
AreOnSameLine
(
getAccessor
.
GetFirstToken
(),
getAccessor
.
GetLastToken
());
var
updatedProperty
=
propertyDeclaration
.
WithAccessorList
(
UpdateAccessorList
(
propertyDeclaration
.
AccessorList
));
...
...
@@ -63,10 +62,7 @@ protected override SyntaxNode GetNodeToRemove(VariableDeclaratorSyntax declarato
.
WithSemicolonToken
(
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
}
if
(
isSingleLine
)
{
updatedProperty
=
updatedProperty
.
WithAdditionalAnnotations
(
SpecializedFormattingAnnotation
);
}
return
updatedProperty
;
}
...
...
src/EditorFeatures/CSharpTest/Diagnostics/UseAutoProperty/UseAutoPropertyTests.cs
浏览文件 @
6156724f
...
...
@@ -35,9 +35,7 @@ int P
@"class Class
{
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -60,9 +58,7 @@ public int P
@"class Class
{
public int P
{
get; private set; }
public int P { get; private set; }
}"
,
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
));
}
...
...
@@ -104,9 +100,7 @@ int P
@"class Class
{
int P
{
get; } = 1;
int P { get; } = 1;
}"
);
}
...
...
@@ -147,9 +141,7 @@ public async Task TestSingleGetterFromProperty()
@"class Class
{
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -195,9 +187,7 @@ int P
@"class Class
{
int P
{
get; set; }
int P { get; set; }
}"
);
}
...
...
@@ -220,9 +210,7 @@ int P
@"class Class
{
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -268,9 +256,7 @@ int P
@"class Class
{
int P
{
get; set; }
int P { get; set; }
}"
);
}
...
...
@@ -503,9 +489,7 @@ int P
{
int j, k;
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -529,9 +513,7 @@ int P
{
int i, k;
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -555,9 +537,7 @@ int P
{
int i, j;
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -586,9 +566,7 @@ int P
partial class Class
{
int P
{
get; }
int P { get; }
}"
);
}
...
...
@@ -635,9 +613,7 @@ public Class()
@"class Class
{
int P
{
get; }
int P { get; }
public Class()
{
...
...
@@ -670,9 +646,7 @@ public Class(int P)
@"class Class
{
int P
{
get; }
int P { get; }
public Class(int P)
{
...
...
@@ -705,9 +679,7 @@ public Class()
@"class Class
{
int P
{
get; }
int P { get; }
public Class()
{
...
...
@@ -740,9 +712,7 @@ public void Goo()
@"class Class
{
int P
{
get; set; }
int P { get; set; }
public void Goo()
{
...
...
@@ -775,9 +745,7 @@ public void Goo()
@"class Class
{
public int P
{
get; private set; }
public int P { get; private set; }
public void Goo()
{
...
...
@@ -877,9 +845,7 @@ public async Task Tuple_SingleGetterFromField()
@"class Class
{
(int, string) P
{
get; }
(int, string) P { get; }
}"
);
}
...
...
@@ -902,9 +868,7 @@ public async Task TupleWithNames_SingleGetterFromField()
@"class Class
{
(int a, string b) P
{
get; }
(int a, string b) P { get; }
}"
);
}
...
...
@@ -945,9 +909,7 @@ public async Task TupleWithOneName_SingleGetterFromField()
@"class Class
{
(int a, string) P
{
get; }
(int a, string) P { get; }
}"
);
}
...
...
@@ -970,9 +932,7 @@ public async Task Tuple_Initializer()
@"class Class
{
(int, string) P
{
get; } = (1, ""hello"");
(int, string) P { get; } = (1, ""hello"");
}"
);
}
...
...
@@ -1000,9 +960,42 @@ public async Task Tuple_GetterAndSetter()
@"class Class
{
(int, string) P
(int, string) P { get; set; }
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseAutoProperty
)]
public
async
Task
TestFixAllInDocument
()
{
await
TestInRegularAndScriptAsync
(
@"class Class
{
{|FixAllInDocument:int i|};
int P
{
get
{
get; set; }
return i;
}
}
int j;
int Q
{
get
{
return j;
}
}
}"
,
@"class Class
{
int P { get; }
int Q { get; }
}"
);
}
}
...
...
src/EditorFeatures/VisualBasic/UseAutoProperty/UseAutoPropertyAnalyzer.vb
浏览文件 @
6156724f
...
...
@@ -53,8 +53,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UseAutoProperty
Dim
propertyDeclaration
=
TryCast
(
member
,
PropertyBlockSyntax
)
If
propertyDeclaration
IsNot
Nothing
Then
Dim
[
property
]
=
context
.
SemanticModel
.
GetDeclaredSymbol
(
propertyDeclaration
,
context
.
CancellationToken
)
AnalyzeProperty
(
context
,
[
property
]
,
analysisResults
)
AnalyzeProperty
(
context
,
propertyDeclaration
,
analysisResults
)
End
If
End
Sub
...
...
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyAnalyzer.cs
浏览文件 @
6156724f
...
...
@@ -10,11 +10,6 @@
namespace
Microsoft.CodeAnalysis.UseAutoProperty
{
internal
static
class
Constants
{
public
const
string
SymbolEquivalenceKey
=
nameof
(
SymbolEquivalenceKey
);
}
internal
abstract
class
AbstractUseAutoPropertyAnalyzer
<
TPropertyDeclaration
,
TFieldDeclaration
,
TVariableDeclarator
,
TExpression
>
:
AbstractCodeStyleDiagnosticAnalyzer
where
TPropertyDeclaration
:
SyntaxNode
...
...
@@ -31,7 +26,7 @@ protected AbstractUseAutoPropertyAnalyzer()
}
public
override
bool
OpenFileOnly
(
Workspace
workspace
)
=>
false
;
public
override
DiagnosticAnalyzerCategory
GetAnalyzerCategory
()
=>
DiagnosticAnalyzerCategory
.
Project
Analysis
;
public
override
DiagnosticAnalyzerCategory
GetAnalyzerCategory
()
=>
DiagnosticAnalyzerCategory
.
SemanticSpan
Analysis
;
protected
abstract
void
RegisterIneligibleFieldsAction
(
List
<
AnalysisResult
>
analysisResults
,
HashSet
<
IFieldSymbol
>
ineligibleFields
,
...
...
@@ -62,8 +57,17 @@ private void AnalyzeSemanticModel(SemanticModelAnalysisContext context)
protected
abstract
void
AnalyzeCompilationUnit
(
SemanticModelAnalysisContext
context
,
SyntaxNode
root
,
List
<
AnalysisResult
>
analysisResults
);
protected
void
AnalyzeProperty
(
SemanticModelAnalysisContext
context
,
IPropertySymbol
property
,
List
<
AnalysisResult
>
analysisResults
)
protected
void
AnalyzeProperty
(
SemanticModelAnalysisContext
context
,
TPropertyDeclaration
propertyDeclaration
,
List
<
AnalysisResult
>
analysisResults
)
{
var
cancellationToken
=
context
.
CancellationToken
;
var
semanticModel
=
context
.
SemanticModel
;
var
property
=
semanticModel
.
GetDeclaredSymbol
(
propertyDeclaration
,
cancellationToken
)
as
IPropertySymbol
;
if
(
property
==
null
)
{
return
;
}
if
(
property
.
IsIndexer
)
{
return
;
...
...
@@ -104,14 +108,6 @@ protected void AnalyzeProperty(SemanticModelAnalysisContext context, IPropertySy
return
;
}
var
cancellationToken
=
context
.
CancellationToken
;
var
propertyDeclaration
=
property
.
DeclaringSyntaxReferences
[
0
].
GetSyntax
(
cancellationToken
).
FirstAncestorOrSelf
<
TPropertyDeclaration
>();
if
(
propertyDeclaration
==
null
)
{
return
;
}
var
semanticModel
=
context
.
SemanticModel
;
var
getterField
=
GetGetterField
(
semanticModel
,
property
.
GetMethod
,
cancellationToken
);
if
(
getterField
==
null
)
{
...
...
@@ -272,9 +268,6 @@ private void Process(AnalysisResult result, SemanticModelAnalysisContext context
var
variableDeclarator
=
result
.
VariableDeclarator
;
var
nodeToFade
=
GetNodeToFade
(
result
.
FieldDeclaration
,
variableDeclarator
);
var
properties
=
ImmutableDictionary
<
string
,
string
>.
Empty
.
Add
(
Constants
.
SymbolEquivalenceKey
,
result
.
SymbolEquivalenceKey
);
// Fade out the field/variable we are going to remove.
var
diagnostic1
=
Diagnostic
.
Create
(
UnnecessaryWithoutSuggestionDescriptor
,
nodeToFade
.
GetLocation
());
context
.
ReportDiagnostic
(
diagnostic1
);
...
...
@@ -284,10 +277,10 @@ private void Process(AnalysisResult result, SemanticModelAnalysisContext context
// them when performing the code fix.
IEnumerable
<
Location
>
additionalLocations
=
new
Location
[]
{
propertyDeclaration
.
GetLocation
(),
variableDeclarator
.
GetLocation
()
};
var
diagnostic2
=
Diagnostic
.
Create
(
HiddenDescriptor
,
propertyDeclaration
.
GetLocation
(),
additionalLocations
,
properties
);
var
diagnostic2
=
Diagnostic
.
Create
(
HiddenDescriptor
,
propertyDeclaration
.
GetLocation
(),
additionalLocations
);
context
.
ReportDiagnostic
(
diagnostic2
);
var
diagnostic3
=
Diagnostic
.
Create
(
HiddenDescriptor
,
nodeToFade
.
GetLocation
(),
additionalLocations
,
properties
);
var
diagnostic3
=
Diagnostic
.
Create
(
HiddenDescriptor
,
nodeToFade
.
GetLocation
(),
additionalLocations
);
context
.
ReportDiagnostic
(
diagnostic3
);
}
...
...
src/Features/Core/Portable/UseAutoProperty/AbstractUseAutoPropertyCodeFixProvider.cs
浏览文件 @
6156724f
...
...
@@ -46,20 +46,17 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
{
foreach
(
var
diagnostic
in
context
.
Diagnostics
)
{
var
equivalenceKey
=
diagnostic
.
Properties
[
Constants
.
SymbolEquivalenceKey
];
context
.
RegisterCodeFix
(
new
UseAutoPropertyCodeAction
(
FeaturesResources
.
Use_auto_property
,
c
=>
ProcessResult
(
context
,
diagnostic
,
c
),
equivalenceKey
),
c
=>
ProcessResultAsync
(
context
,
diagnostic
,
c
)),
diagnostic
);
}
return
SpecializedTasks
.
EmptyTask
;
}
private
async
Task
<
Solution
>
ProcessResult
(
CodeFixContext
context
,
Diagnostic
diagnostic
,
CancellationToken
cancellationToken
)
private
async
Task
<
Solution
>
ProcessResult
Async
(
CodeFixContext
context
,
Diagnostic
diagnostic
,
CancellationToken
cancellationToken
)
{
var
locations
=
diagnostic
.
AdditionalLocations
;
var
propertyLocation
=
locations
[
0
];
...
...
@@ -238,8 +235,8 @@ private async Task<SyntaxNode> FormatAsync(SyntaxNode newRoot, Document document
private
class
UseAutoPropertyCodeAction
:
CodeAction
.
SolutionChangeAction
{
public
UseAutoPropertyCodeAction
(
string
title
,
Func
<
CancellationToken
,
Task
<
Solution
>>
createChangedSolution
,
string
equivalenceKey
)
:
base
(
title
,
createChangedSolution
,
equivalenceKey
)
public
UseAutoPropertyCodeAction
(
string
title
,
Func
<
CancellationToken
,
Task
<
Solution
>>
createChangedSolution
)
:
base
(
title
,
createChangedSolution
,
title
)
{
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录