Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d3012c79
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,发现更多精彩内容 >>
提交
d3012c79
编写于
12月 06, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Other direction
上级
ee442592
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
12 deletion
+87
-12
src/EditorFeatures/CSharpTest/ReverseForStatement/ReverseForStatementTests.cs
...SharpTest/ReverseForStatement/ReverseForStatementTests.cs
+60
-0
src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs
...ement/CSharpReverseForStatementCodeRefactoringProvider.cs
+27
-12
未找到文件。
src/EditorFeatures/CSharpTest/ReverseForStatement/ReverseForStatementTests.cs
浏览文件 @
d3012c79
...
...
@@ -569,6 +569,66 @@ void M(string[] args)
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMoveDeclarationNearReference
)]
public
async
Task
TestByteMax
()
{
await
TestMissingAsync
(
@"class C
{
void M(string[] args)
{
[||]for (byte x = byte.MaxValue; x >= 10; x--)
{
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMoveDeclarationNearReference
)]
public
async
Task
TestUInt16Max
()
{
await
TestMissingAsync
(
@"class C
{
void M(string[] args)
{
[||]for (ushort x = ushort.MaxValue; x >= 10; x--)
{
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMoveDeclarationNearReference
)]
public
async
Task
TestUInt32Max
()
{
await
TestMissingAsync
(
@"class C
{
void M(string[] args)
{
[||]for (uint x = uint.MaxValue; x >= 10; x--)
{
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMoveDeclarationNearReference
)]
public
async
Task
TestUInt64Max
()
{
await
TestMissingAsync
(
@"class C
{
void M(string[] args)
{
[||]for (ulong x = ulong.MaxValue; x >= 10; x--)
{
}
}
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsMoveDeclarationNearReference
)]
public
async
Task
TestByteZeroMinReverse
()
{
...
...
src/Features/CSharp/Portable/ReverseForStatement/CSharpReverseForStatementCodeRefactoringProvider.cs
浏览文件 @
d3012c79
...
...
@@ -58,7 +58,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
MatchesDecrementPattern
(
variable
,
condition
,
after
,
out
end
,
out
start
))
{
var
semanticModel
=
await
document
.
RequireSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
if
(
IsUnsignedBoundary
(
semanticModel
,
variable
,
start
,
cancellationToken
))
if
(
IsUnsignedBoundary
(
semanticModel
,
variable
,
start
,
end
,
cancellationToken
))
{
// Don't allow reversing when you have unsigned types and are on the start/end
// of the legal values for that type. i.e. `for (byte i = 0; i < 10; i++)` it's
...
...
@@ -73,20 +73,35 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
private
bool
IsUnsignedBoundary
(
SemanticModel
semanticModel
,
VariableDeclaratorSyntax
variable
,
ExpressionSyntax
start
,
CancellationToken
cancellationToken
)
ExpressionSyntax
start
,
ExpressionSyntax
end
,
CancellationToken
cancellationToken
)
{
var
local
=
semanticModel
.
GetDeclaredSymbol
(
variable
,
cancellationToken
)
as
ILocalSymbol
;
if
(
local
!=
null
)
var
startValue
=
semanticModel
.
GetConstantValue
(
start
,
cancellationToken
);
var
endValue
=
semanticModel
.
GetConstantValue
(
end
,
cancellationToken
);
return
local
?.
Type
.
SpecialType
switch
{
switch
(
local
.
Type
.
SpecialType
)
{
case
SpecialType
.
System_Byte
:
case
SpecialType
.
System_UInt16
:
case
SpecialType
.
System_UInt32
:
case
SpecialType
.
System_UInt64
:
var
startValue
=
semanticModel
.
GetConstantValue
(
start
,
cancellationToken
);
return
startValue
.
HasValue
&&
IsIntegral
(
startValue
.
Value
)
&&
ToUInt64
(
startValue
.
Value
)
==
0
;
}
SpecialType
.
System_Byte
=>
IsUnsignedBoundary
(
startValue
,
endValue
,
byte
.
MaxValue
),
SpecialType
.
System_UInt16
=>
IsUnsignedBoundary
(
startValue
,
endValue
,
ushort
.
MaxValue
),
SpecialType
.
System_UInt32
=>
IsUnsignedBoundary
(
startValue
,
endValue
,
uint
.
MaxValue
),
SpecialType
.
System_UInt64
=>
IsUnsignedBoundary
(
startValue
,
endValue
,
ulong
.
MaxValue
),
_
=>
false
,
};
}
private
bool
IsUnsignedBoundary
<
TValue
>(
Optional
<
object
>
startValue
,
Optional
<
object
>
endValue
,
TValue
maxValue
)
where
TValue
:
struct
{
if
(
startValue
.
HasValue
&&
IsIntegral
(
startValue
.
Value
)
&&
ToUInt64
(
startValue
.
Value
)
==
0
)
{
return
true
;
}
if
(
endValue
.
HasValue
&&
IsIntegral
(
endValue
.
Value
)
&&
ToUInt64
(
endValue
.
Value
)
==
ToUInt64
(
maxValue
))
{
return
true
;
}
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录