Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
38db5289
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,发现更多精彩内容 >>
提交
38db5289
编写于
2月 23, 2018
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement code review feedback (code style and additional tests)
上级
1491c335
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
169 addition
and
25 deletion
+169
-25
src/EditorFeatures/CSharpTest/MakeFieldReadonly/MakeFieldReadonlyTests.cs
...es/CSharpTest/MakeFieldReadonly/MakeFieldReadonlyTests.cs
+9
-0
src/EditorFeatures/VisualBasicTest/MakeFieldReadonly/MakeFieldReadonlyTests.vb
...sualBasicTest/MakeFieldReadonly/MakeFieldReadonlyTests.vb
+138
-0
src/Features/CSharp/Portable/MakeFieldReadonly/CSharpMakeFieldReadonlyDiagnosticAnalyzer.cs
...ieldReadonly/CSharpMakeFieldReadonlyDiagnosticAnalyzer.cs
+2
-2
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs
...FieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs
+4
-5
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
...ldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
+11
-12
src/Workspaces/CSharp/Portable/LanguageServices/CSharpSyntaxFactsService.cs
...arp/Portable/LanguageServices/CSharpSyntaxFactsService.cs
+2
-3
src/Workspaces/Core/Portable/LanguageServices/SyntaxFactsService/ISyntaxFactsService.cs
...anguageServices/SyntaxFactsService/ISyntaxFactsService.cs
+1
-1
src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicSyntaxFactsService.vb
...ortable/LanguageServices/VisualBasicSyntaxFactsService.vb
+2
-2
未找到文件。
src/EditorFeatures/CSharpTest/MakeFieldReadonly/MakeFieldReadonlyTests.cs
浏览文件 @
38db5289
...
...
@@ -20,6 +20,7 @@ internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProvider
[
InlineData
(
"internal"
)]
[
InlineData
(
"protected"
)]
[
InlineData
(
"protected internal"
)]
[
InlineData
(
"private protected"
)]
public
async
Task
NonPrivateField
(
string
accessibility
)
{
await
TestMissingInRegularAndScriptAsync
(
...
...
@@ -696,12 +697,20 @@ public async Task FixAll()
@"class MyClass
{
private int {|FixAllInDocument:_goo|} = 0, _bar = 0;
private int _x = 0, _y = 0, _z = 0;
private int _fizz = 0;
void Method() { _z = 1; }
}"
,
@"class MyClass
{
private readonly int _goo = 0, _bar = 0;
private readonly int _x = 0;
private readonly int _y = 0;
private int _z = 0;
private readonly int _fizz = 0;
void Method() { _z = 1; }
}"
);
}
...
...
src/EditorFeatures/VisualBasicTest/MakeFieldReadonly/MakeFieldReadonlyTests.vb
浏览文件 @
38db5289
...
...
@@ -143,6 +143,142 @@ End Class",
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms01
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim [|x|] As Integer, y As String
End Class"
,
"Class C
Private ReadOnly x As Integer
Private y As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms02
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x As Integer, [|y|] As String
End Class"
,
"Class C
Private x As Integer
Private ReadOnly y As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms03
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim [|x|], y As Integer, z, w As String
End Class"
,
"Class C
Private ReadOnly x As Integer
Private y As Integer
Private z As String
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms04
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, [|y|] As Integer, z, w As String
End Class"
,
"Class C
Private x As Integer
Private ReadOnly y As Integer
Private z As String
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms05
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, y As Integer, [|z|], w As String
End Class"
,
"Class C
Private x As Integer
Private y As Integer
Private ReadOnly z As String
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms06
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, y As Integer, z, [|w|] As String
End Class"
,
"Class C
Private x As Integer
Private y As Integer
Private z As String
Private ReadOnly w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms07
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim [|x|], y() As Integer, z(), w As String
End Class"
,
"Class C
Private ReadOnly x As Integer
Private y As Integer()
Private z As String()
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms08
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, [|y|]() As Integer, z(), w As String
End Class"
,
"Class C
Private x As Integer
Private ReadOnly y As Integer()
Private z As String()
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms09
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, y() As Integer, [|z|](), w As String
End Class"
,
"Class C
Private x As Integer
Private y As Integer()
Private ReadOnly z As String()
Private w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_VBSpecialForms10
()
As
Task
Await
TestInRegularAndScriptAsync
(
"Class C
Dim x, y() As Integer, z(), [|w|] As String
End Class"
,
"Class C
Private x As Integer
Private y As Integer()
Private z As String()
Private ReadOnly w As String
End Class"
)
End
Function
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMakeFieldReadonly
)
>
Public
Async
Function
MultipleFieldsAssignedInline_OneAssignedInMethod
()
As
Task
Await
TestInRegularAndScriptAsync
(
...
...
@@ -502,10 +638,12 @@ End Class")
Await
TestInRegularAndScriptAsync
(
"Class C
Private {|FixAllInDocument:_goo|} As Integer = 0, _bar As Integer = 0
Dim a, b(), c As Integer, x, y As String
Private _fizz As Integer = 0
End Class"
,
"Class C
Private ReadOnly _goo As Integer = 0, _bar As Integer = 0
ReadOnly a, b(), c As Integer, x, y As String
Private ReadOnly _fizz As Integer = 0
End Class"
)
End
Function
...
...
src/Features/CSharp/Portable/MakeFieldReadonly/CSharpMakeFieldReadonlyDiagnosticAnalyzer.cs
浏览文件 @
38db5289
...
...
@@ -16,8 +16,8 @@ internal class CSharpMakeFieldReadonlyDiagnosticAnalyzer :
protected
override
void
InitializeWorker
(
AnalysisContext
context
)
=>
context
.
RegisterSyntaxNodeAction
(
AnalyzeType
,
SyntaxKind
.
ClassDeclaration
,
SyntaxKind
.
StructDeclaration
);
protected
override
ISyntaxFactsService
GetSyntaxFactsService
()
=>
CSharpSyntaxFactsService
.
Instance
;
protected
override
ISyntaxFactsService
GetSyntaxFactsService
()
=>
CSharpSyntaxFactsService
.
Instance
;
protected
override
bool
IsWrittenTo
(
IdentifierNameSyntax
name
,
SemanticModel
model
,
CancellationToken
cancellationToken
)
=>
name
.
IsWrittenTo
();
...
...
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyCodeFixProvider.cs
浏览文件 @
38db5289
...
...
@@ -15,8 +15,7 @@
namespace
Microsoft.CodeAnalysis.MakeFieldReadonly
{
internal
abstract
class
AbstractMakeFieldReadonlyCodeFixProvider
<
TSymbolSyntax
,
TFieldDeclarationSyntax
>
internal
abstract
class
AbstractMakeFieldReadonlyCodeFixProvider
<
TSymbolSyntax
,
TFieldDeclarationSyntax
>
:
SyntaxEditorBasedCodeFixProvider
where
TSymbolSyntax
:
SyntaxNode
where
TFieldDeclarationSyntax
:
SyntaxNode
...
...
@@ -24,6 +23,9 @@ internal abstract class AbstractMakeFieldReadonlyCodeFixProvider
public
override
ImmutableArray
<
string
>
FixableDiagnosticIds
=>
ImmutableArray
.
Create
(
IDEDiagnosticIds
.
MakeFieldReadonlyDiagnosticId
);
protected
abstract
SyntaxNode
GetInitializerNode
(
TSymbolSyntax
declaration
);
protected
abstract
ImmutableList
<
TSymbolSyntax
>
GetVariableDeclarators
(
TFieldDeclarationSyntax
declaration
);
public
override
Task
RegisterCodeFixesAsync
(
CodeFixContext
context
)
{
context
.
RegisterCodeFix
(
new
MyCodeAction
(
...
...
@@ -87,9 +89,6 @@ private async void MakeFieldReadonly(Document document, SyntaxEditor editor, Lis
}
}
}
protected
abstract
SyntaxNode
GetInitializerNode
(
TSymbolSyntax
declaration
);
protected
abstract
ImmutableList
<
TSymbolSyntax
>
GetVariableDeclarators
(
TFieldDeclarationSyntax
declaration
);
protected
override
Task
FixAllAsync
(
Document
document
,
...
...
src/Features/Core/Portable/MakeFieldReadonly/AbstractMakeFieldReadonlyDiagnosticAnalyzer.cs
浏览文件 @
38db5289
...
...
@@ -13,20 +13,23 @@ internal abstract class AbstractMakeFieldReadonlyDiagnosticAnalyzer<TIdentifierN
where
TIdentifierNameSyntax
:
SyntaxNode
where
TConstructorDeclarationSyntax
:
SyntaxNode
{
private
static
readonly
LocalizableString
s_localizableTitle
=
new
LocalizableResourceString
(
nameof
(
FeaturesResources
.
Add_readonly_modifier
),
FeaturesResources
.
ResourceManager
,
typeof
(
FeaturesResources
));
private
static
readonly
LocalizableString
s_localizableMessage
=
new
LocalizableResourceString
(
nameof
(
FeaturesResources
.
Make_field_readonly
),
WorkspacesResources
.
ResourceManager
,
typeof
(
WorkspacesResources
));
public
AbstractMakeFieldReadonlyDiagnosticAnalyzer
()
:
base
(
IDEDiagnosticIds
.
MakeFieldReadonlyDiagnosticId
,
s_localizableTitle
,
s_localizableMessage
)
protected
AbstractMakeFieldReadonlyDiagnosticAnalyzer
()
:
base
(
IDEDiagnosticIds
.
MakeFieldReadonlyDiagnosticId
,
new
LocalizableResourceString
(
nameof
(
FeaturesResources
.
Add_readonly_modifier
),
FeaturesResources
.
ResourceManager
,
typeof
(
FeaturesResources
)),
new
LocalizableResourceString
(
nameof
(
FeaturesResources
.
Make_field_readonly
),
WorkspacesResources
.
ResourceManager
,
typeof
(
WorkspacesResources
)))
{
}
protected
abstract
ISyntaxFactsService
GetSyntaxFactsService
();
protected
abstract
bool
IsWrittenTo
(
TIdentifierNameSyntax
node
,
SemanticModel
model
,
CancellationToken
cancellationToken
);
protected
abstract
bool
IsMemberOfThisInstance
(
SyntaxNode
node
);
public
override
bool
OpenFileOnly
(
Workspace
workspace
)
=>
false
;
public
override
DiagnosticAnalyzerCategory
GetAnalyzerCategory
()
=>
DiagnosticAnalyzerCategory
.
SemanticDocumentAnalysis
;
internal
void
AnalyzeType
(
SyntaxNodeAnalysisContext
context
)
protected
void
AnalyzeType
(
SyntaxNodeAnalysisContext
context
)
{
var
optionSet
=
context
.
Options
.
GetDocumentOptionSetAsync
(
context
.
Node
.
SyntaxTree
,
context
.
CancellationToken
).
GetAwaiter
().
GetResult
();
if
(
optionSet
==
null
)
...
...
@@ -126,7 +129,7 @@ private void RemoveAssignedSymbols(SemanticModel model, ISyntaxFactsService synt
var
isInAnonymousOrLocalFunction
=
false
;
for
(
var
current
=
descendant
.
Parent
;
current
!=
ctorNode
;
current
=
current
.
Parent
)
{
if
(
syntaxFactsService
.
IsAnonymous
Or
LocalFunction
(
current
))
if
(
syntaxFactsService
.
IsAnonymous
Function
(
current
)
||
syntaxFactsService
.
Is
LocalFunction
(
current
))
{
isInAnonymousOrLocalFunction
=
true
;
break
;
...
...
@@ -186,9 +189,5 @@ private bool IsMutableValueType(ITypeSymbol type)
return
false
;
}
protected
abstract
ISyntaxFactsService
GetSyntaxFactsService
();
protected
abstract
bool
IsWrittenTo
(
TIdentifierNameSyntax
node
,
SemanticModel
model
,
CancellationToken
cancellationToken
);
protected
abstract
bool
IsMemberOfThisInstance
(
SyntaxNode
node
);
}
}
src/Workspaces/CSharp/Portable/LanguageServices/CSharpSyntaxFactsService.cs
浏览文件 @
38db5289
...
...
@@ -201,10 +201,9 @@ public bool IsAnonymousFunction(SyntaxNode node)
node
is
AnonymousMethodExpressionSyntax
;
}
public
bool
Is
AnonymousOr
LocalFunction
(
SyntaxNode
node
)
public
bool
IsLocalFunction
(
SyntaxNode
node
)
{
return
IsAnonymousFunction
(
node
)
||
node
is
LocalFunctionStatementSyntax
;
return
node
is
LocalFunctionStatementSyntax
;
}
public
bool
IsGenericName
(
SyntaxNode
node
)
...
...
src/Workspaces/Core/Portable/LanguageServices/SyntaxFactsService/ISyntaxFactsService.cs
浏览文件 @
38db5289
...
...
@@ -250,7 +250,7 @@ internal interface ISyntaxFactsService : ILanguageService
bool
IsAnonymousFunction
(
SyntaxNode
n
);
bool
Is
AnonymousOr
LocalFunction
(
SyntaxNode
n
);
bool
IsLocalFunction
(
SyntaxNode
n
);
bool
IsInConstantContext
(
SyntaxNode
node
);
bool
IsInConstructor
(
SyntaxNode
node
);
...
...
src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicSyntaxFactsService.vb
浏览文件 @
38db5289
...
...
@@ -201,8 +201,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return
TypeOf
node
Is
LambdaExpressionSyntax
End
Function
Public
Function
Is
AnonymousOrLocalFunction
(
node
As
SyntaxNode
)
As
Boolean
Implements
ISyntaxFactsService
.
IsAnonymousOr
LocalFunction
Return
IsAnonymousFunction
(
node
)
Public
Function
Is
LocalFunction
(
node
As
SyntaxNode
)
As
Boolean
Implements
ISyntaxFactsService
.
Is
LocalFunction
Return
False
End
Function
Public
Function
IsGenericName
(
node
As
SyntaxNode
)
As
Boolean
Implements
ISyntaxFactsService
.
IsGenericName
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录