Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2a027e26
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,发现更多精彩内容 >>
提交
2a027e26
编写于
7月 08, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests
上级
47427bf2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
276 addition
and
15 deletion
+276
-15
src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj
...EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj
+1
-0
src/EditorFeatures/CSharpTest/UsePatternMatching/CSharpIsAndCastCheckCodeRefactoringProviderTests.cs
...ching/CSharpIsAndCastCheckCodeRefactoringProviderTests.cs
+268
-0
src/EditorFeatures/CSharpTest/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzerTests_FixAllTests.cs
...SharpIsAndCastCheckDiagnosticAnalyzerTests_FixAllTests.cs
+1
-1
src/Features/CSharp/Portable/CSharpFeatures.csproj
src/Features/CSharp/Portable/CSharpFeatures.csproj
+1
-1
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCheckCodeRefactoringProvider.cs
...rnMatching/CSharpIsAndCastCheckCodeRefactoringProvider.cs
+5
-13
未找到文件。
src/EditorFeatures/CSharpTest/CSharpEditorServicesTest.csproj
浏览文件 @
2a027e26
...
...
@@ -384,6 +384,7 @@
<Compile
Include=
"UseExpressionBody\Refactoring\UseExpressionBodyForOperatorsRefactoringTests.cs"
/>
<Compile
Include=
"UseExpressionBody\Refactoring\UseExpressionBodyForMethodsRefactoringTests.cs"
/>
<Compile
Include=
"UseNullPropagation\UseNullPropagationTests.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpIsAndCastCheckCodeRefactoringProviderTests.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpIsAndCastCheckDiagnosticAnalyzerTests_FixAllTests.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpIsAndCastCheckDiagnosticAnalyzerTests.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpAsAndNullCheckTests.cs"
/>
...
...
src/EditorFeatures/CSharpTest/UsePatternMatching/CSharpIsAndCastCheckCodeRefactoringProviderTests.cs
0 → 100644
浏览文件 @
2a027e26
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeRefactorings
;
using
Microsoft.CodeAnalysis.CSharp.UsePatternMatching
;
using
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UsePatternMatching
{
public
partial
class
CSharpIsAndCastCheckCodeRefactoringProviderTests
:
AbstractCSharpCodeActionTest
{
protected
override
CodeRefactoringProvider
CreateCodeRefactoringProvider
(
Workspace
workspace
,
TestParameters
parameters
)
=>
new
CSharpIsAndCastCheckCodeRefactoringProvider
();
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestBinaryExpression
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
{
return [||]obj is TestFile && ((TestFile)obj).i > 0;
}
}"
,
@"class TestFile
{
int i;
bool M(object obj)
{
return obj is TestFile {|Rename:file|} && file.i > 0;
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestExpressionBody
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
=> [||]obj is TestFile && ((TestFile)obj).i > 0;
}"
,
@"class TestFile
{
int i;
bool M(object obj)
=> obj is TestFile {|Rename:file|} && file.i > 0;
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestField
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
static object obj;
bool M = [||]obj is TestFile && ((TestFile)obj).i > 0;
}"
,
@"class TestFile
{
int i;
static object obj;
bool M = obj is TestFile {|Rename:file|} && file.i > 0;
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestLambdaBody
()
{
await
TestInRegularAndScript1Async
(
@"
using System;
class TestFile
{
int i;
void Foo(Func<bool> f) { }
bool M(object obj)
=> Foo(() => [||]obj is TestFile && ((TestFile)obj).i > 0, () => obj is TestFile && ((TestFile)obj).i > 0);
}"
,
@"
using System;
class TestFile
{
int i;
void Foo(Func<bool> f) { }
bool M(object obj)
=> Foo(() => obj is TestFile {|Rename:file|} && file.i > 0, () => obj is TestFile && ((TestFile)obj).i > 0);
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestDefiniteAssignment1
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
{
if ([||]obj is TestFile)
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
else
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
}
}"
,
@"class TestFile
{
int i;
bool M(object obj)
{
if (obj is TestFile {|Rename:file|})
{
M(file.i);
M(file.i);
}
else
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestDefiniteAssignment2
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
{
if (!([||]obj is TestFile))
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
else
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
}
}"
,
@"class TestFile
{
int i;
bool M(object obj)
{
if (!(obj is TestFile {|Rename:file|}))
{
M(((TestFile)obj).i);
M(((TestFile)obj).i);
}
else
{
M(file.i);
M(file.i);
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestNotOnAnalyzerMatch
()
{
await
TestMissingAsync
(
@"class TestFile
{
bool M(object obj)
{
if ([||]obj is TestFile)
{
var file = (TestFile)obj;
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestNotOnNullable
()
{
await
TestMissingAsync
(
@"struct TestFile
{
bool M(object obj)
{
if ([||]obj is TestFile?)
{
var i = ((TestFile?)obj).Value;
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestComplexMatch
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
{
return [||]M(null) is TestFile && ((TestFile)M(null)).i > 0;
}
}"
,
@"class TestFile
{
int i;
bool M(object obj)
{
return M(null) is TestFile {|Rename:file|} && file.i > 0;
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
TestTrivia
()
{
await
TestInRegularAndScript1Async
(
@"class TestFile
{
int i;
bool M(object obj)
{
return [||]obj is TestFile && /*before*/ ((TestFile)obj) /*after*/.i > 0;
}
}"
,
@"class TestFile
{
int i;
bool M(object obj)
{
return obj is TestFile {|Rename:file|} && /*before*/ file /*after*/.i > 0;
}
}"
,
ignoreTrivia
:
false
);
}
}
}
src/EditorFeatures/CSharpTest/UsePatternMatching/CSharpIsAndCastCheckDiagnosticAnalyzerTests_FixAllTests.cs
浏览文件 @
2a027e26
...
...
@@ -6,7 +6,7 @@
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UsePatternMatching
{
public
partial
class
CSharpIsAndCastCheckTests
public
partial
class
CSharpIsAndCastCheck
DiagnosticAnalyzer
Tests
{
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsInlineTypeCheck
)]
public
async
Task
FixAllInDocument1
()
...
...
src/Features/CSharp/Portable/CSharpFeatures.csproj
浏览文件 @
2a027e26
...
...
@@ -414,7 +414,7 @@
<Compile
Include=
"UseExpressionBody\Helpers\UseExpressionBodyHelper`1.cs"
/>
<Compile
Include=
"UseObjectInitializer\CSharpUseObjectInitializerCodeFixProvider.cs"
/>
<Compile
Include=
"SignatureHelp\TupleConstructionSignatureHelpProvider.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpIsAndCastCodeRefactoringProvider.cs"
/>
<Compile
Include=
"UsePatternMatching\CSharpIsAndCastC
heckC
odeRefactoringProvider.cs"
/>
<Compile
Include=
"UseThrowExpression\CSharpUseThrowExpressionDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"Structure\CSharpBlockStructureProvider.cs"
/>
<Compile
Include=
"Structure\CSharpStructureHelpers.cs"
/>
...
...
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastCodeRefactoringProvider.cs
→
src/Features/CSharp/Portable/UsePatternMatching/CSharpIsAndCastC
heckC
odeRefactoringProvider.cs
浏览文件 @
2a027e26
...
...
@@ -17,7 +17,7 @@
namespace
Microsoft.CodeAnalysis.CSharp.UsePatternMatching
{
[
ExportCodeRefactoringProvider
(
LanguageNames
.
CSharp
),
Shared
]
internal
class
CSharpIsAndCastCodeRefactoringProvider
:
CodeRefactoringProvider
internal
class
CSharpIsAndCastC
heckC
odeRefactoringProvider
:
CodeRefactoringProvider
{
private
const
string
CS0165
=
nameof
(
CS0165
);
// Use of unassigned local variable 's'
private
static
readonly
SyntaxAnnotation
s_referenceAnnotation
=
new
SyntaxAnnotation
();
...
...
@@ -70,16 +70,6 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var
matches
=
new
HashSet
<
CastExpressionSyntax
>();
AddMatches
(
container
,
expr
,
type
,
matches
);
//if (container is StatementSyntax containingStatement &&
// containingStatement.Parent is BlockSyntax block)
//{
// var statementIndex = block.Statements.IndexOf(containingStatement);
// for (int i = statementIndex + 1, n = block.Statements.Count; i < n; i++)
// {
// AddMatches(block.Statements[i], expr, type, matches);
// }
//}
if
(
matches
.
Count
==
0
)
{
return
;
...
...
@@ -153,9 +143,11 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var
localReference
=
SyntaxFactory
.
IdentifierName
(
localName
);
foreach
(
var
castExpression
in
matches
)
{
var
castRoot
=
castExpression
.
WalkUpParentheses
();
editor
.
ReplaceNode
(
cast
Expression
.
WalkUpParentheses
()
,
localReference
.
WithTriviaFrom
(
cast
Expression
)
cast
Root
,
localReference
.
WithTriviaFrom
(
cast
Root
)
.
WithAdditionalAnnotations
(
s_referenceAnnotation
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录