Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET
Roslyn
提交
4d7418b0
R
Roslyn
项目概览
dotNET
/
Roslyn
通知
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,发现更多精彩内容 >>
提交
4d7418b0
编写于
6月 02, 2017
作者:
S
Sam Harwell
提交者:
GitHub
6月 02, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19812 from RobSiklos/issue17711
Fix IDE0009 false positive on expressions qualified with 'base.'
上级
70e858b2
ee1f5532
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
188 addition
and
0 deletion
+188
-0
src/EditorFeatures/CSharpTest/QualifyMemberAccess/QualifyMemberAccessTests.cs
...SharpTest/QualifyMemberAccess/QualifyMemberAccessTests.cs
+68
-0
src/EditorFeatures/VisualBasicTest/QualifyMemberAccess/QualifyMemberAccessTests.vb
...BasicTest/QualifyMemberAccess/QualifyMemberAccessTests.vb
+97
-0
src/Features/CSharp/Portable/QualifyMemberAccess/CSharpQualifyMemberAccessDiagnosticAnalyzer.cs
...mberAccess/CSharpQualifyMemberAccessDiagnosticAnalyzer.cs
+4
-0
src/Features/Core/Portable/QualifyMemberAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
...erAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
+14
-0
src/Features/VisualBasic/Portable/Diagnostics/Analyzers/VisualBasicQualifyMemberAccessDiagnosticAnalyzer.vb
...yzers/VisualBasicQualifyMemberAccessDiagnosticAnalyzer.vb
+5
-0
未找到文件。
src/EditorFeatures/CSharpTest/QualifyMemberAccess/QualifyMemberAccessTests.cs
浏览文件 @
4d7418b0
...
...
@@ -1028,5 +1028,73 @@ void Error()
}"
,
CodeStyleOptions
.
QualifyMethodAccess
);
}
[
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)]
public
async
Task
DoNotReportToQualify_IfBaseQualificationOnField
()
{
await
TestMissingAsyncWithOption
(
@"class Base
{
protected int field;
}
class Derived : Base
{
void M() { [|base.field|] = 0; }
}"
,
CodeStyleOptions
.
QualifyFieldAccess
);
}
[
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)]
public
async
Task
DoNotReportToQualify_IfBaseQualificationOnProperty
()
{
await
TestMissingAsyncWithOption
(
@"class Base
{
protected virtual int Property { get; }
}
class Derived : Base
{
protected override int Property { get { return [|base.Property|]; } }
}"
,
CodeStyleOptions
.
QualifyPropertyAccess
);
}
[
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)]
public
async
Task
DoNotReportToQualify_IfBaseQualificationOnMethod
()
{
await
TestMissingAsyncWithOption
(
@"class Base
{
protected virtual void M() { }
}
class Derived : Base
{
protected override void M() { [|base.M()|]; }
}"
,
CodeStyleOptions
.
QualifyMethodAccess
);
}
[
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)]
public
async
Task
DoNotReportToQualify_IfBaseQualificationOnEvent
()
{
await
TestMissingAsyncWithOption
(
@"class Base
{
protected virtual event EventHandler Event;
}
class Derived : Base
{
protected override event EventHandler Event
{
add { [|base.Event|] += value; }
remove { }
}
}"
,
CodeStyleOptions
.
QualifyEventAccess
);
}
}
}
\ No newline at end of file
src/EditorFeatures/VisualBasicTest/QualifyMemberAccess/QualifyMemberAccessTests.vb
浏览文件 @
4d7418b0
...
...
@@ -464,5 +464,102 @@ CodeStyleOptions.QualifyPropertyAccess, NotificationOption.Warning)
CodeStyleOptions
.
QualifyPropertyAccess
,
NotificationOption
.
Error
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyBaseQualificationOnField
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class Base
Protected Field As Integer
End Class
Class Derived
Inherits Base
Sub M()
[|MyBase.Field|] = 0
End Sub
End Class
"
,
CodeStyleOptions
.
QualifyFieldAccess
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyClassQualificationOnField
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class C
Private ReadOnly Field As Integer
Sub M()
[|MyClass.Field|] = 0
End Sub
End Class
"
,
CodeStyleOptions
.
QualifyFieldAccess
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyBaseQualificationOnProperty
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class Base
Protected Overridable ReadOnly Property P As Integer
End Class
Class Derived
Inherits Base
Protected Overrides ReadOnly Property P As Integer
Get
Return [|MyBase.P|]
End Get
End Class
"
,
CodeStyleOptions
.
QualifyPropertyAccess
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyClassQualificationOnProperty
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class C
Dim i As Integer
Protected Overridable ReadOnly Property P As Integer
Sub M()
Me.i = [|MyClass.P|]
End Sub
End Class
"
,
CodeStyleOptions
.
QualifyPropertyAccess
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyBaseQualificationOnMethod
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class Base
Protected Overridable Sub M
End Sub
End Class
Class Derived
Inherits Base
Protected Overrides Sub M()
Get
Return [|MyBase.M|]()
End Get
End Class
"
,
CodeStyleOptions
.
QualifyMethodAccess
)
End
Function
<
WorkItem
(
17711
,
"https://github.com/dotnet/roslyn/issues/17711"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsQualifyMemberAccess
)
>
Public
Async
Function
DoNotReportToQualify_IfMyClassQualificationOnMethod
()
As
Task
Await
TestMissingAsyncWithOption
(
"
Class C
Protected Overridable Sub M()
End Sub
Sub M2()
[|MyClass.M|]()
End Sub
End Class
"
,
CodeStyleOptions
.
QualifyMethodAccess
)
End
Function
End
Class
End
Namespace
\ No newline at end of file
src/Features/CSharp/Portable/QualifyMemberAccess/CSharpQualifyMemberAccessDiagnosticAnalyzer.cs
浏览文件 @
4d7418b0
...
...
@@ -13,5 +13,9 @@ protected override string GetLanguageName()
protected
override
bool
IsAlreadyQualifiedMemberAccess
(
SyntaxNode
node
)
=>
node
.
IsKind
(
SyntaxKind
.
ThisExpression
);
// If the member is already qualified with `base.`, it cannot be further qualified.
protected
override
bool
CanMemberAccessBeQualified
(
SyntaxNode
node
)
=>
!
node
.
IsKind
(
SyntaxKind
.
BaseExpression
);
}
}
\ No newline at end of file
src/Features/Core/Portable/QualifyMemberAccess/AbstractQualifyMemberAccessDiagnosticAnalyzer.cs
浏览文件 @
4d7418b0
...
...
@@ -37,6 +37,14 @@ public override bool OpenFileOnly(Workspace workspace)
protected
abstract
string
GetLanguageName
();
/// <summary>
/// Reports on whether the specified member is suitable for qualification. Some member
/// access expressions cannot be qualified; for instance if they begin with <c>base.</c>,
/// <c>MyBase.</c>, or <c>MyClass.</c>.
/// </summary>
/// <returns>True if the member access can be qualified; otherwise, False.</returns>
protected
abstract
bool
CanMemberAccessBeQualified
(
SyntaxNode
node
);
protected
abstract
bool
IsAlreadyQualifiedMemberAccess
(
SyntaxNode
node
);
private
static
MethodInfo
s_registerMethod
=
typeof
(
AnalysisContext
).
GetTypeInfo
().
GetDeclaredMethod
(
"RegisterOperationActionImmutableArrayInternal"
);
...
...
@@ -66,6 +74,12 @@ private void AnalyzeOperation(OperationAnalysisContext context)
return
;
}
// If we can't be qualified (e.g., because we're already qualified with `base.`), we're done.
if
(!
CanMemberAccessBeQualified
(
memberReference
.
Instance
.
Syntax
))
{
return
;
}
// if we can't find a member then we can't do anything. Also, we shouldn't qualify
// accesses to static members.
if
(
memberReference
.
Member
==
null
||
...
...
src/Features/VisualBasic/Portable/Diagnostics/Analyzers/VisualBasicQualifyMemberAccessDiagnosticAnalyzer.vb
浏览文件 @
4d7418b0
...
...
@@ -15,5 +15,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.QualifyMemberAccess
Protected
Overrides
Function
IsAlreadyQualifiedMemberAccess
(
node
As
SyntaxNode
)
As
Boolean
Return
node
.
IsKind
(
SyntaxKind
.
MeExpression
)
End
Function
Protected
Overrides
Function
CanMemberAccessBeQualified
(
node
As
SyntaxNode
)
As
Boolean
' If the member is already qualified with `MyBase.`, or `MyClass.`, it cannot be further qualified.
Return
Not
(
node
.
IsKind
(
SyntaxKind
.
MyBaseExpression
)
OrElse
node
.
IsKind
(
SyntaxKind
.
MyClassExpression
))
End
Function
End
Class
End
Namespace
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录