Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5e0be57a
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,发现更多精彩内容 >>
提交
5e0be57a
编写于
9月 16, 2018
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add invert conditional code.
上级
dce1f89a
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
169 addition
and
0 deletion
+169
-0
src/Features/CSharp/Portable/InvertConditional/CSharpInvertConditionalCodeRefactoringProvider.cs
...itional/CSharpInvertConditionalCodeRefactoringProvider.cs
+92
-0
src/Features/Core/Portable/FeaturesResources.Designer.cs
src/Features/Core/Portable/FeaturesResources.Designer.cs
+9
-0
src/Features/Core/Portable/FeaturesResources.resx
src/Features/Core/Portable/FeaturesResources.resx
+3
-0
src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf
src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.de.xlf
src/Features/Core/Portable/xlf/FeaturesResources.de.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.es.xlf
src/Features/Core/Portable/xlf/FeaturesResources.es.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf
src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.it.xlf
src/Features/Core/Portable/xlf/FeaturesResources.it.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf
src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf
src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf
src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf
src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf
src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf
src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf
+5
-0
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf
+5
-0
未找到文件。
src/Features/CSharp/Portable/InvertConditional/CSharpInvertConditionalCodeRefactoringProvider.cs
0 → 100644
浏览文件 @
5e0be57a
// 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
;
using
System.Composition
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeActions
;
using
Microsoft.CodeAnalysis.CodeRefactorings
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
namespace
Microsoft.CodeAnalysis.CSharp.InvertConditional
{
[
ExportCodeRefactoringProvider
(
LanguageNames
.
CSharp
),
Shared
]
internal
class
CSharpInvertConditionalCodeRefactoringProvider
:
CodeRefactoringProvider
{
public
override
async
Task
ComputeRefactoringsAsync
(
CodeRefactoringContext
context
)
{
var
document
=
context
.
Document
;
var
span
=
context
.
Span
;
var
cancellationToken
=
context
.
CancellationToken
;
if
(
span
.
Length
>
0
)
{
return
;
}
var
position
=
span
.
Start
;
var
conditional
=
await
FindConditionalAsync
(
document
,
position
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
conditional
==
null
)
{
return
;
}
if
(
position
<
conditional
.
Span
.
Start
||
position
>
conditional
.
QuestionToken
.
Span
.
End
)
{
return
;
}
if
(
conditional
.
ColonToken
.
IsMissing
)
{
return
;
}
context
.
RegisterRefactoring
(
new
MyCodeAction
(
FeaturesResources
.
Invert_conditional
,
c
=>
InvertConditionalAsync
(
document
,
position
,
c
)));
}
private
static
async
Task
<
ConditionalExpressionSyntax
>
FindConditionalAsync
(
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
{
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
token
=
root
.
FindToken
(
position
);
return
token
.
Parent
.
FirstAncestorOrSelf
<
ConditionalExpressionSyntax
>();
}
private
async
Task
<
Document
>
InvertConditionalAsync
(
Document
document
,
int
position
,
CancellationToken
cancellationToken
)
{
var
conditional
=
await
FindConditionalAsync
(
document
,
position
,
cancellationToken
).
ConfigureAwait
(
false
);
var
semanticModel
=
await
document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
root
=
await
document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
editor
=
new
SyntaxEditor
(
root
,
document
.
Project
.
Solution
.
Workspace
);
var
generator
=
editor
.
Generator
;
var
condition
=
conditional
.
Condition
;
var
whenTrue
=
conditional
.
WhenTrue
;
var
whenFalse
=
conditional
.
WhenFalse
;
editor
.
ReplaceNode
(
condition
,
generator
.
Negate
(
condition
,
semanticModel
,
cancellationToken
));
editor
.
ReplaceNode
(
whenTrue
,
whenFalse
.
WithTriviaFrom
(
whenTrue
));
editor
.
ReplaceNode
(
whenFalse
,
whenTrue
.
WithTriviaFrom
(
whenFalse
));
return
document
.
WithSyntaxRoot
(
editor
.
GetChangedRoot
());
}
private
class
MyCodeAction
:
CodeAction
.
DocumentChangeAction
{
public
MyCodeAction
(
string
title
,
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
title
,
createChangedDocument
)
{
}
}
}
}
src/Features/Core/Portable/FeaturesResources.Designer.cs
浏览文件 @
5e0be57a
...
...
@@ -2008,6 +2008,15 @@ internal class FeaturesResources {
}
}
/// <summary>
/// Looks up a localized string similar to Invert conditional.
/// </summary>
internal
static
string
Invert_conditional
{
get
{
return
ResourceManager
.
GetString
(
"Invert_conditional"
,
resourceCulture
);
}
}
/// <summary>
/// Looks up a localized string similar to is.
/// </summary>
...
...
src/Features/Core/Portable/FeaturesResources.resx
浏览文件 @
5e0be57a
...
...
@@ -1430,4 +1430,7 @@ This version used in: {2}</value>
<data
name=
"Type_0_has_a_private_member_1_that_can_be_removed_as_the_value_assigned_to_it_is_never_read"
xml:space=
"preserve"
>
<value>
Type '{0}' has a private member '{1}' that can be removed as the value assigned to it is never read.
</value>
</data>
<data
name=
"Invert_conditional"
xml:space=
"preserve"
>
<value>
Invert conditional
</value>
</data>
</root>
\ No newline at end of file
src/Features/Core/Portable/xlf/FeaturesResources.cs.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Formátuje se dokument.
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Podpisy souvisejících metod nalezené v metadatech se nebudou aktualizovat.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.de.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Dokument wird formatiert
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
In Metadaten gefundene ähnliche Methodensignaturen werden nicht aktualisiert.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.es.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Aplicando formato al documento
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Las signaturas de método relacionadas encontradas en los metadatos no se actualizarán.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.fr.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Mise en forme du document
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Les signatures de méthode associées trouvées dans les métadonnées ne seront pas mises à jour.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.it.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Formattazione del documento
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Le firme del metodo correlate trovate nei metadati non verranno aggiornate.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.ja.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
ドキュメントの書式設定
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
メタデータ内に検出される関連するメソッド シグネチャは更新されません。
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.ko.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
문서 서식 지정
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
메타데이터에서 찾은 관련 메서드 시그니처가 업데이트되지 않습니다.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.pl.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Formatowanie dokumentu
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Sygnatury powiązanych metod znalezione w metadanych nie zostaną zaktualizowane.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.pt-BR.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Formatando documento
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
As assinaturas de método relacionadas encontradas nos metadados não serão atualizadas.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.ru.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Форматирование документа
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Связанные сигнатуры методов, найденные в метаданных, не будут обновлены.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.tr.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
Belge biçimlendiriliyor
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
Meta verilerde bulunan ilgili metot imzaları güncelleştirilmez.
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hans.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
设置文档格式
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
不更新在元数据中发现的相关方法签名。
</target>
...
...
src/Features/Core/Portable/xlf/FeaturesResources.zh-Hant.xlf
浏览文件 @
5e0be57a
...
...
@@ -67,6 +67,11 @@
<target
state=
"translated"
>
正在將文件格式化
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Invert_conditional"
>
<source>
Invert conditional
</source>
<target
state=
"new"
>
Invert conditional
</target>
<note
/>
</trans-unit>
<trans-unit
id=
"Related_method_signatures_found_in_metadata_will_not_be_updated"
>
<source>
Related method signatures found in metadata will not be updated.
</source>
<target
state=
"translated"
>
將不會更新中繼資料中所找到的相關方法簽章。
</target>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录