Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
02348ab6
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,发现更多精彩内容 >>
提交
02348ab6
编写于
7月 18, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move checking logic into the generators.
上级
f1ec9ba8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
94 addition
and
104 deletion
+94
-104
src/Features/CSharp/Portable/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
...iers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
+4
-35
src/Features/VisualBasic/Portable/AddAccessibilityModifiers/VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
...VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
+47
-50
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+26
-16
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
+2
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
...sic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
+15
-3
未找到文件。
src/Features/CSharp/Portable/AddAccessibilityModifiers/CSharpAddAccessibilityModifiersDiagnosticAnalyzer.cs
浏览文件 @
02348ab6
...
...
@@ -70,46 +70,15 @@ public CSharpAddAccessibilityModifiersDiagnosticAnalyzer()
return
;
}
// If they already have accessibility, no need to report anything.
var
accessibility
=
generator
.
GetAccessibility
(
member
);
if
(
accessibility
!=
Accessibility
.
NotApplicable
)
{
return
;
}
// Certain members never have accessibility. Don't bother reporting on them.
if
(
member
.
IsKind
(
SyntaxKind
.
DestructorDeclaration
))
if
(!
generator
.
CanHaveAccessibility
(
member
))
{
return
;
}
if
(
member
.
IsKind
(
SyntaxKind
.
ConstructorDeclaration
,
out
ConstructorDeclarationSyntax
constructor
)
&&
constructor
.
Modifiers
.
Any
(
SyntaxKind
.
StaticKeyword
))
{
return
;
}
if
(
member
.
IsKind
(
SyntaxKind
.
MethodDeclaration
,
out
MethodDeclarationSyntax
method
)
&&
method
.
ExplicitInterfaceSpecifier
!=
null
)
{
return
;
}
if
(
member
.
IsKind
(
SyntaxKind
.
PropertyDeclaration
,
out
PropertyDeclarationSyntax
property
)
&&
property
.
ExplicitInterfaceSpecifier
!=
null
)
{
return
;
}
if
(
member
.
IsKind
(
SyntaxKind
.
EventDeclaration
,
out
EventDeclarationSyntax
ev
)
&&
ev
.
ExplicitInterfaceSpecifier
!=
null
)
{
return
;
}
if
(
member
.
IsKind
(
SyntaxKind
.
IndexerDeclaration
,
out
IndexerDeclarationSyntax
indexer
)
&&
indexer
.
ExplicitInterfaceSpecifier
!=
null
)
// If they already have accessibility, no need to report anything.
var
accessibility
=
generator
.
GetAccessibility
(
member
);
if
(
accessibility
!=
Accessibility
.
NotApplicable
)
{
return
;
}
...
...
src/Features/VisualBasic/Portable/AddAccessibilityModifiers/VisualBasicAddAccessibilityModifiersDiagnosticAnalyzer.vb
浏览文件 @
02348ab6
...
...
@@ -21,55 +21,52 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.AddAccessibilityModifiers
Private
Sub
ProcessMembers
(
context
As
SyntaxTreeAnalysisContext
,
generator
As
SyntaxGenerator
,
[
option
]
As
CodeStyleOption
(
Of
AccessibilityModifiersRequired
),
members
As
SyntaxList
(
Of
StatementSyntax
))
For
Each
member
In
members
ProcessMember
(
context
,
generator
,
[
option
]
,
member
)
Next
End
Sub
Private
Sub
ProcessMember
(
context
As
SyntaxTreeAnalysisContext
,
generator
As
SyntaxGenerator
,
[
option
]
As
CodeStyleOption
(
Of
AccessibilityModifiersRequired
),
member
As
StatementSyntax
)
If
member
.
Kind
()
=
SyntaxKind
.
NamespaceBlock
Then
Dim
namespaceBlock
=
DirectCast
(
member
,
NamespaceBlockSyntax
)
ProcessMembers
(
context
,
generator
,
[
option
]
,
namespaceBlock
.
Members
)
End
If
' If we have a class or struct or module, recurse inwards.
If
member
.
IsKind
(
SyntaxKind
.
ClassBlock
)
OrElse
member
.
IsKind
(
SyntaxKind
.
StructureBlock
)
OrElse
member
.
IsKind
(
SyntaxKind
.
ModuleBlock
)
Then
Dim
typeBlock
=
DirectCast
(
member
,
TypeBlockSyntax
)
ProcessMembers
(
context
,
generator
,
[
option
]
,
typeBlock
.
Members
)
End
If
' Have to have a name to report the issue on.
Dim
name
=
member
.
GetNameToken
()
If
name
.
Kind
()
=
SyntaxKind
.
None
Then
Return
End
If
' If they already have accessibility, no need to report anything.
Dim
Accessibility
=
generator
.
GetAccessibility
(
member
)
If
Accessibility
<>
Accessibility
.
NotApplicable
Then
Return
End
If
' Certain members never have accessibility. Don't bother reporting on them.
If
member
.
IsKind
(
SyntaxKind
.
ConstructorBlock
)
AndAlso
member
.
GetModifiers
().
Any
(
SyntaxKind
.
SharedKeyword
)
Then
Return
End
If
For
Each
member
In
members
ProcessMember
(
context
,
generator
,
[
option
]
,
member
)
Next
End
Sub
' Missing accessibility. Report issue to user.
Dim
additionalLocations
=
ImmutableArray
.
Create
(
member
.
GetLocation
())
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
[
option
]
.
Notification
.
Value
),
name
.
GetLocation
(),
additionalLocations
:
=
additionalLocations
))
End
Sub
End
Class
Private
Sub
ProcessMember
(
context
As
SyntaxTreeAnalysisContext
,
generator
As
SyntaxGenerator
,
[
option
]
As
CodeStyleOption
(
Of
AccessibilityModifiersRequired
),
member
As
StatementSyntax
)
If
member
.
Kind
()
=
SyntaxKind
.
NamespaceBlock
Then
Dim
namespaceBlock
=
DirectCast
(
member
,
NamespaceBlockSyntax
)
ProcessMembers
(
context
,
generator
,
[
option
]
,
namespaceBlock
.
Members
)
End
If
' If we have a class or struct or module, recurse inwards.
If
member
.
IsKind
(
SyntaxKind
.
ClassBlock
)
OrElse
member
.
IsKind
(
SyntaxKind
.
StructureBlock
)
OrElse
member
.
IsKind
(
SyntaxKind
.
ModuleBlock
)
Then
Dim
typeBlock
=
DirectCast
(
member
,
TypeBlockSyntax
)
ProcessMembers
(
context
,
generator
,
[
option
]
,
typeBlock
.
Members
)
End
If
' Have to have a name to report the issue on.
Dim
name
=
member
.
GetNameToken
()
If
name
.
Kind
()
=
SyntaxKind
.
None
Then
Return
End
If
' Certain members never have accessibility. Don't bother reporting on them.
If
Not
generator
.
CanHaveAccessibility
(
member
)
Then
Return
End
If
' If they already have accessibility, no need to report anything.
Dim
Accessibility
=
generator
.
GetAccessibility
(
member
)
If
Accessibility
<>
Accessibility
.
NotApplicable
Then
Return
End
If
' Missing accessibility. Report issue to user.
Dim
additionalLocations
=
ImmutableArray
.
Create
(
member
.
GetLocation
())
context
.
ReportDiagnostic
(
Diagnostic
.
Create
(
CreateDescriptorWithSeverity
(
[
option
]
.
Notification
.
Value
),
name
.
GetLocation
(),
additionalLocations
:
=
additionalLocations
))
End
Sub
End
Class
End
Namespace
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
02348ab6
...
...
@@ -1408,7 +1408,7 @@ private SyntaxNode AsMemberOf(SyntaxNode declaration, SyntaxNode member)
}
}
privat
e
bool
CanHaveAccessibility
(
SyntaxNode
declaration
)
internal
overrid
e
bool
CanHaveAccessibility
(
SyntaxNode
declaration
)
{
switch
(
declaration
.
Kind
())
{
...
...
@@ -1417,27 +1417,37 @@ private bool CanHaveAccessibility(SyntaxNode declaration)
case
SyntaxKind
.
InterfaceDeclaration
:
case
SyntaxKind
.
EnumDeclaration
:
case
SyntaxKind
.
DelegateDeclaration
:
case
SyntaxKind
.
MethodDeclaration
:
case
SyntaxKind
.
OperatorDeclaration
:
case
SyntaxKind
.
ConversionOperatorDeclaration
:
case
SyntaxKind
.
ConstructorDeclaration
:
case
SyntaxKind
.
FieldDeclaration
:
case
SyntaxKind
.
PropertyDeclaration
:
case
SyntaxKind
.
IndexerDeclaration
:
case
SyntaxKind
.
EventFieldDeclaration
:
case
SyntaxKind
.
EventDeclaration
:
case
SyntaxKind
.
GetAccessorDeclaration
:
case
SyntaxKind
.
SetAccessorDeclaration
:
case
SyntaxKind
.
AddAccessorDeclaration
:
case
SyntaxKind
.
RemoveAccessorDeclaration
:
return
true
;
case
SyntaxKind
.
VariableDeclaration
:
case
SyntaxKind
.
VariableDeclarator
:
return
this
.
GetDeclarationKind
(
declaration
)
==
DeclarationKind
.
Field
;
case
SyntaxKind
.
EnumMemberDeclaration
:
case
SyntaxKind
.
Parameter
:
case
SyntaxKind
.
LocalDeclarationStatement
:
case
SyntaxKind
.
DestructorDeclaration
:
var
declarationKind
=
this
.
GetDeclarationKind
(
declaration
);
return
declarationKind
==
DeclarationKind
.
Field
||
declarationKind
==
DeclarationKind
.
Event
;
case
SyntaxKind
.
ConstructorDeclaration
:
// Static constructor can't have accessibility
return
!((
ConstructorDeclarationSyntax
)
declaration
).
Modifiers
.
Any
(
SyntaxKind
.
StaticKeyword
);
case
SyntaxKind
.
PropertyDeclaration
:
return
((
PropertyDeclarationSyntax
)
declaration
).
ExplicitInterfaceSpecifier
==
null
;
case
SyntaxKind
.
IndexerDeclaration
:
return
((
IndexerDeclarationSyntax
)
declaration
).
ExplicitInterfaceSpecifier
==
null
;
case
SyntaxKind
.
MethodDeclaration
:
return
((
MethodDeclarationSyntax
)
declaration
).
ExplicitInterfaceSpecifier
==
null
;
case
SyntaxKind
.
EventDeclaration
:
return
((
EventDeclarationSyntax
)
declaration
).
ExplicitInterfaceSpecifier
==
null
;
default
:
return
false
;
}
...
...
@@ -3122,9 +3132,9 @@ private static SyntaxNode WithBaseList(SyntaxNode declaration, BaseListSyntax ba
}
}
#
endregion
#endregion
#
region
Remove
,
Replace
,
Insert
#region Remove, Replace, Insert
public
override
SyntaxNode
ReplaceNode
(
SyntaxNode
root
,
SyntaxNode
declaration
,
SyntaxNode
newDeclaration
)
{
...
...
@@ -3461,9 +3471,9 @@ private static SyntaxNode ShiftTrivia(SyntaxNode root, SyntaxNode node)
internal
override
bool
IsRegularOrDocComment
(
SyntaxTrivia
trivia
)
=>
trivia
.
IsRegularOrDocComment
();
#
endregion
#endregion
#
region
Statements
and
Expressions
#region Statements and Expressions
public
override
SyntaxNode
AddEventHandler
(
SyntaxNode
@event
,
SyntaxNode
handler
)
{
...
...
@@ -4152,6 +4162,6 @@ internal override SyntaxNode RefExpression(SyntaxNode expression)
public
override
SyntaxNode
TupleExpression
(
IEnumerable
<
SyntaxNode
>
arguments
)
=>
SyntaxFactory
.
TupleExpression
(
SyntaxFactory
.
SeparatedList
(
arguments
.
Select
(
AsArgument
)));
#
endregion
#endregion
}
}
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
浏览文件 @
02348ab6
...
...
@@ -1023,6 +1023,8 @@ public SyntaxNode AddMembers(SyntaxNode declaration, params SyntaxNode[] members
/// </summary>
public
abstract
SyntaxNode
WithAccessibility
(
SyntaxNode
declaration
,
Accessibility
accessibility
);
internal
abstract
bool
CanHaveAccessibility
(
SyntaxNode
declaration
);
/// <summary>
/// Gets the <see cref="DeclarationModifiers"/> for the declaration.
/// </summary>
...
...
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
浏览文件 @
02348ab6
...
...
@@ -2669,6 +2669,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
End
Function
Public
Overrides
Function
GetAccessibility
(
declaration
As
SyntaxNode
)
As
Accessibility
If
Not
CanHaveAccessibility
(
declaration
)
Then
Return
Accessibility
.
NotApplicable
End
If
Dim
tokens
=
GetModifierTokens
(
declaration
)
Dim
acc
As
Accessibility
Dim
mods
As
DeclarationModifiers
...
...
@@ -2678,6 +2682,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
End
Function
Public
Overrides
Function
WithAccessibility
(
declaration
As
SyntaxNode
,
accessibility
As
Accessibility
)
As
SyntaxNode
If
Not
CanHaveAccessibility
(
declaration
)
Then
Return
declaration
End
If
Return
Isolate
(
declaration
,
Function
(
d
)
Me
.
WithAccessibilityInternal
(
d
,
accessibility
))
End
Function
...
...
@@ -2700,7 +2708,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return
WithModifierTokens
(
declaration
,
Merge
(
tokens
,
newTokens
))
End
Function
Private
Function
CanHaveAccessibility
(
declaration
As
SyntaxNode
)
As
Boolean
Friend
Overrides
Function
CanHaveAccessibility
(
declaration
As
SyntaxNode
)
As
Boolean
Select
Case
declaration
.
Kind
Case
SyntaxKind
.
ClassBlock
,
SyntaxKind
.
ClassStatement
,
...
...
@@ -2717,10 +2725,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
SyntaxKind
.
FieldDeclaration
,
SyntaxKind
.
FunctionBlock
,
SyntaxKind
.
SubBlock
,
SyntaxKind
.
ConstructorBlock
,
SyntaxKind
.
FunctionStatement
,
SyntaxKind
.
SubStatement
,
SyntaxKind
.
SubNewStatement
,
SyntaxKind
.
PropertyBlock
,
SyntaxKind
.
PropertyStatement
,
SyntaxKind
.
OperatorBlock
,
...
...
@@ -2738,6 +2744,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
SyntaxKind
.
RaiseEventAccessorBlock
,
SyntaxKind
.
RaiseEventAccessorStatement
Return
True
Case
SyntaxKind
.
ConstructorBlock
,
SyntaxKind
.
SubNewStatement
' Shared constructor cannot have modifiers in VB.
Return
Not
declaration
.
GetModifiers
().
Any
(
SyntaxKind
.
SharedKeyword
)
Case
Else
Return
False
End
Select
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录