Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
4e83ff3b
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,发现更多精彩内容 >>
提交
4e83ff3b
编写于
3月 07, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up comments.
上级
cf25e543
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
24 deletion
+50
-24
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
...rtable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
+50
-24
未找到文件。
src/Workspaces/Core/Portable/CodeFixes/FixAllOccurrences/BatchFixAllProvider.cs
浏览文件 @
4e83ff3b
...
...
@@ -453,45 +453,68 @@ public virtual string GetFixAllTitle(FixAllState fixAllState)
ArrayBuilder
<
TextChange
>
overlappingSpans
,
ArrayBuilder
<
TextChange
>
intersectingSpans
)
{
// Pure insertions (i.e. changes with empty spans) are complex to evaluate.
// We have to make sure that
return
change
.
Span
.
IsEmpty
?
InsertionChangeCanBeApplied
(
change
,
overlappingSpans
,
intersectingSpans
)
// We distinguish two types of changes that can happen. 'Pure Insertions'
// and 'Overwrites'. Pure-Insertions are those that are just inserting
// text into a specific *position*. They do not replace any existing text.
// 'Overwrites' end up replacing existing text with some other piece of
// (possibly-empty) text.
//
// Overwrites of text tend to be easy to understand and merge. It is very
// clear what code is being overwritten and how it should interact with
// other changes. Pure-insertions are more ambiguous to deal with. For
// example, say there are two pure-insertions at some position. There is
// no way for us to know what to do with this. For example, we could take
// one insertion then the other, or vice versa. Because of this ambiguity
// we conservatively disallow cases like this.
return
IsPureInsertion
(
change
)
?
PureInsertionChangeCanBeApplied
(
change
,
overlappingSpans
,
intersectingSpans
)
:
OverwriteChangeCanBeApplied
(
change
,
overlappingSpans
,
intersectingSpans
);
}
private
static
bool
InsertionChangeCanBeApplied
(
private
static
bool
IsPureInsertion
(
TextChange
change
)
=>
change
.
Span
.
IsEmpty
;
private
static
bool
PureInsertionChangeCanBeApplied
(
TextChange
change
,
ArrayBuilder
<
TextChange
>
overlappingSpans
,
ArrayBuilder
<
TextChange
>
intersectingSpans
)
{
// Empty spans can't ever overlap anything.
Debug
.
Assert
(
change
.
Span
.
IsEmpty
);
// Pure insertions can't ever overlap anything. (They're just an insertion at a
// single position, and overlaps can't occur with single-positions).
Debug
.
Assert
(
IsPureInsertion
(
change
));
Debug
.
Assert
(
overlappingSpans
.
Count
==
0
);
if
(
intersectingSpans
.
Count
==
0
)
{
// Our insertion didn't hit any other changes. This is safe to apply.
// Our
pure-
insertion didn't hit any other changes. This is safe to apply.
return
true
;
}
if
(
intersectingSpans
.
Count
==
1
)
{
// Our insertion hit another change. Thats safe when:
// Our
pure-
insertion hit another change. Thats safe when:
// 1) if both changes are the same.
// 2) the change we're hitting is
not empty and we're at the end of the other change
.
// 2) the change we're hitting is
an overwrite-change and we're at the end of it
.
// Specifically, it is not safe for us to insert somewhere in start-to-middle of an
// existing
non-empty change. And if we have another *empty*
change, then it's
// existing
overwrite-change. And if we have another pure-insertion
change, then it's
// not safe for both of us to be inserting at the same point (except when the
// change is identical).
// Note: you may wonder why we don't support hitting an overwriting change at the
// start of the overwrite. This is because it's now ambiguous as to which of these
// changes should be applied first.
var
otherChange
=
intersectingSpans
[
0
];
if
(
otherChange
==
change
)
{
// We're both inserting the same text at the same position. This is safe.
// We're both pure-inserting the same text at the same position.
// We assume this is a case of some provider making the same changes and
// we allow this.
return
true
;
}
return
!
otherChange
.
Span
.
IsEmpty
&&
return
!
IsPureInsertion
(
otherChange
)
&&
otherChange
.
Span
.
End
==
change
.
Span
.
Start
;
}
...
...
@@ -504,7 +527,7 @@ public virtual string GetFixAllTitle(FixAllState fixAllState)
ArrayBuilder
<
TextChange
>
overlappingSpans
,
ArrayBuilder
<
TextChange
>
intersectingSpans
)
{
Debug
.
Assert
(!
change
.
Span
.
IsEmpty
);
Debug
.
Assert
(!
IsPureInsertion
(
change
)
);
return
!
OverwriteChangeConflictsWithOverlappingSpans
(
change
,
overlappingSpans
)
&&
!
OverwriteChangeConflictsWithIntersectingSpans
(
change
,
intersectingSpans
);
...
...
@@ -514,39 +537,42 @@ public virtual string GetFixAllTitle(FixAllState fixAllState)
TextChange
change
,
ArrayBuilder
<
TextChange
>
overlappingSpans
)
{
Debug
.
Assert
(!
change
.
Span
.
IsEmpty
);
Debug
.
Assert
(!
IsPureInsertion
(
change
)
);
if
(
overlappingSpans
.
Count
==
0
)
{
// This
chang
e didn't overlap with any other changes. This change is safe to make.
// This
overwrit
e didn't overlap with any other changes. This change is safe to make.
return
false
;
}
// The change we want to make overlapped an existing change we're making. Only allow
// this if there was a single overlap and we are exactly the same change as it.
// Otherwise, this is a conflict.
return
overlappingSpans
.
Count
>
1
||
overlappingSpans
[
0
]
!=
change
;
var
isSafe
=
overlappingSpans
.
Count
==
1
&&
overlappingSpans
[
0
]
==
change
;
return
!
isSafe
;
}
private
static
bool
OverwriteChangeConflictsWithIntersectingSpans
(
TextChange
change
,
ArrayBuilder
<
TextChange
>
intersectingSpans
)
{
Debug
.
Assert
(!
change
.
Span
.
IsEmpty
);
Debug
.
Assert
(!
IsPureInsertion
(
change
)
);
// We care about our intersections with
*empty-span* changes. Non-empty
changes that
// We care about our intersections with
pure-insertion changes. Overwrite-
changes that
// we overlap are already handled in OverwriteChangeConflictsWithOverlappingSpans.
// And
non-empty
spans that we abut (i.e. which we're adjacent to) are totally safe
// And
overwrite
spans that we abut (i.e. which we're adjacent to) are totally safe
// for both to be applied.
//
// However,
empty-spa
n changes are extremely ambiguous. It is not possible to tell which
// change should be applied first. So if we get any
empty spa
ns we have to bail
// However,
pure-insertio
n changes are extremely ambiguous. It is not possible to tell which
// change should be applied first. So if we get any
pure-insertio
ns we have to bail
// on applying this span.
foreach
(
var
otherSpan
in
intersectingSpans
)
{
if
(
otherSpan
.
Span
.
IsEmpty
)
if
(
IsPureInsertion
(
otherSpan
)
)
{
// If the other span is empty, then we definitely conflict with it.
// Intersecting with a pure-insertion is too ambiguous, so we just consider
// this a conflict.
return
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录