Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
52037991
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,发现更多精彩内容 >>
提交
52037991
编写于
11月 07, 2018
作者:
M
Manish Vasani
浏览文件
操作
浏览文件
下载
差异文件
Merge latest changes and resolve conflicts
上级
27585698
151e59e6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
21 deletion
+49
-21
build/Targets/Packages.props
build/Targets/Packages.props
+1
-1
src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs
...SharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs
+21
-1
src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs
...dMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs
+27
-19
未找到文件。
build/Targets/Packages.props
浏览文件 @
52037991
...
...
@@ -11,7 +11,7 @@
-->
<PropertyGroup>
<VersionPrefix>
2.11.0
</VersionPrefix>
<PreReleaseVersionLabel>
beta
1
</PreReleaseVersionLabel>
<PreReleaseVersionLabel>
beta
2
</PreReleaseVersionLabel>
<SemanticVersioningV1>
true
</SemanticVersioningV1>
<!--
...
...
src/EditorFeatures/CSharpTest/RemoveUnusedMembers/RemoveUnusedMembersTests.cs
浏览文件 @
52037991
...
...
@@ -433,7 +433,7 @@ public async Task MethodIsUnused_Abstract()
await
TestDiagnosticMissingAsync
(
@"class C
{
pr
ivate
abstract void [|M|]();
pr
otected
abstract void [|M|]();
}"
);
}
...
...
@@ -477,6 +477,26 @@ class C : I
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsRemoveUnusedMembers
)]
[
WorkItem
(
30965
,
"https://github.com/dotnet/roslyn/issues/30965"
)]
public
async
Task
EventIsUnused_ExplicitInterfaceImplementation
()
{
await
TestDiagnosticMissingAsync
(
@"interface I
{
event System.Action E;
}
class C : I
{
event System.Action [|I.E|]
{
add { }
remove { }
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsRemoveUnusedMembers
)]
[
WorkItem
(
30894
,
"https://github.com/dotnet/roslyn/issues/30894"
)]
public
async
Task
WriteOnlyProperty_NotWritten
()
...
...
src/Features/Core/Portable/RemoveUnusedMembers/AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs
浏览文件 @
52037991
...
...
@@ -415,6 +415,22 @@ void AddDebuggerDisplayAttributeArgumentsCore(ISymbol symbol, ArrayBuilder<strin
}
}
/// <summary>
/// Returns true if the given symbol meets the following criteria to be
/// a candidate for dead code analysis:
/// 1. It is marked as "private".
/// 2. It is not an implicitly declared symbol.
/// 3. It is either a method, field, property or an event.
/// 4. If method, then one of the following must be true:
/// a. It is a constructor with non-zero parameters OR
/// b. It is a method with <see cref="MethodKind.Ordinary"/>,
/// such that it is not an accessor, not an entry point method,
/// not an extern method and is not an explicit interface method implementation.
/// 5. If field, then it must not be a backing field for an auto property.
/// Backing fields have a non-null <see cref="IFieldSymbol.AssociatedSymbol"/>.
/// 6. If property, then it must not be an explicit interface property implementation.
/// 7. If event, then it must not be an explicit interface event implementation.
/// </summary>
private
bool
IsCandidateSymbol
(
ISymbol
memberSymbol
)
{
Debug
.
Assert
(
memberSymbol
==
memberSymbol
.
OriginalDefinition
);
...
...
@@ -422,36 +438,28 @@ private bool IsCandidateSymbol(ISymbol memberSymbol)
if
(
memberSymbol
.
DeclaredAccessibility
==
Accessibility
.
Private
&&
!
memberSymbol
.
IsImplicitlyDeclared
)
{
// Do not track accessors, as we will track the associated symbol.
switch
(
memberSymbol
.
Kind
)
{
case
SymbolKind
.
Method
:
// Skip following methods:
// 1. Entry point (Main) method
// 2. Abstract/Virtual/Override methods
// 3. Extern methods
// 4. Interface implementation methods
// 5. Constructors with no parameters.
// 6. Static constructors.
// 7. Destructors.
var
methodSymbol
=
(
IMethodSymbol
)
memberSymbol
;
switch
(
methodSymbol
.
MethodKind
)
{
case
MethodKind
.
Constructor
:
// It is fine to have an unused private constructor
// without parameters.
// This is commonly used for static holder types
// that want to block instantiation of the type.
return
methodSymbol
.
Parameters
.
Length
>
0
;
case
MethodKind
.
StaticConstructor
:
case
MethodKind
.
Destructor
:
return
false
;
default
:
case
MethodKind
.
Ordinary
:
// Do not flag accessors, as we will track the associated symbol.
return
methodSymbol
.
AssociatedSymbol
==
null
&&
!
IsEntryPoint
(
methodSymbol
)
&&
!
methodSymbol
.
IsAbstract
&&
!
methodSymbol
.
IsVirtual
&&
!
methodSymbol
.
IsOverride
&&
!
methodSymbol
.
IsExtern
&&
methodSymbol
.
ExplicitInterfaceImplementations
.
IsEmpty
;
default
:
return
false
;
}
case
SymbolKind
.
Field
:
...
...
@@ -460,8 +468,8 @@ private bool IsCandidateSymbol(ISymbol memberSymbol)
case
SymbolKind
.
Property
:
return
((
IPropertySymbol
)
memberSymbol
).
ExplicitInterfaceImplementations
.
IsEmpty
;
defaul
t
:
return
true
;
case
SymbolKind
.
Even
t
:
return
((
IEventSymbol
)
memberSymbol
).
ExplicitInterfaceImplementations
.
IsEmpty
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录