Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
8c419a11
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,发现更多精彩内容 >>
提交
8c419a11
编写于
2月 23, 2017
作者:
J
Jonathon Marolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify string concatination logic
上级
6a10ecfd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
16 deletion
+23
-16
src/Features/Core/Portable/ConvertToInterpolatedString/AbstractConvertConcatenationToInterpolatedStringRefactoringProvider.cs
...rtConcatenationToInterpolatedStringRefactoringProvider.cs
+23
-16
未找到文件。
src/Features/Core/Portable/ConvertToInterpolatedString/AbstractConvertConcatenationToInterpolatedStringRefactoringProvider.cs
浏览文件 @
8c419a11
...
...
@@ -105,22 +105,20 @@ private Task<Document> UpdateDocumentAsync(Document document, SyntaxNode root, S
{
var
syntaxFacts
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
var
generator
=
SyntaxGenerator
.
GetGenerator
(
document
);
var
startToken
=
CreateInterpolatedStringStartToken
(
isVerbatimStringLiteral
)
.
WithLeadingTrivia
(
pieces
.
First
().
GetLeadingTrivia
());
var
endToken
=
CreateInterpolatedStringEndToken
()
.
WithTrailingTrivia
(
pieces
.
Last
().
GetTrailingTrivia
());
var
content
=
new
List
<
SyntaxNode
>(
pieces
.
Count
);
var
previousIndex
=
-
2
;
var
insertionIndex
=
-
1
;
for
(
var
i
=
0
;
i
<
pieces
.
Count
;
i
++)
var
previousContentWasStringLiteralExpression
=
false
;
foreach
(
var
piece
in
pieces
)
{
if
(
syntaxFacts
.
IsStringLiteralExpression
(
piece
s
[
i
]
))
if
(
syntaxFacts
.
IsStringLiteralExpression
(
piece
))
{
var
text
=
piece
s
[
i
]
.
GetFirstToken
().
Text
;
var
text
=
piece
.
GetFirstToken
().
Text
;
var
textWithoutQuotes
=
GetTextWithoutQuotes
(
text
,
isVerbatimStringLiteral
);
if
(
i
-
1
==
previousIndex
)
if
(
previousContentWasStringLiteralExpression
)
{
// Last part we added to the content list was also an interpolated-string-text-node.
// We need to combine these as the API for creating an interpolated strings
...
...
@@ -129,30 +127,39 @@ private Task<Document> UpdateDocumentAsync(Document document, SyntaxNode root, S
// {InterpolatedStringText}{Interpolation}{InterpolatedStringText}
// not:
// {InterpolatedStringText}{Interpolation}{InterpolatedStringText}{InterpolatedStringText}
var
interpolatedStringTextNode
=
content
[
insertionIndex
];
var
existingText
=
interpolatedStringTextNode
.
GetFirstToken
().
Text
;
var
newText
=
existingText
+
textWithoutQuotes
;
content
[
insertionIndex
]
=
generator
.
InterpolatedStringText
(
generator
.
InterpolatedStringTextToken
(
newText
));
var
existingingInterpolatedStringTextNode
=
content
.
Last
();
var
newText
=
ConcatinateTextToTextNode
(
generator
,
existingingInterpolatedStringTextNode
,
textWithoutQuotes
);
content
[
content
.
Count
-
1
]
=
newText
;
}
else
{
// This is either the first string literal we have encountered or it is the most recent one we've seen
// after adding an interpolation. Add a new interpolated-string-text-node to the list.
content
.
Add
(
generator
.
InterpolatedStringText
(
generator
.
InterpolatedStringTextToken
(
textWithoutQuotes
)));
//
Update the insertion index incase the next piece is also a interpolated-string-text-node
.
insertionIndex
=
i
;
// Update this variable to be true every time we encounter a new string literal expression
//
so we know to concatinate future string literals together if we encounter them
.
previousContentWasStringLiteralExpression
=
true
;
}
previousIndex
=
i
;
}
else
{
content
.
Add
(
generator
.
Interpolation
(
pieces
[
i
].
WithoutTrivia
()));
content
.
Add
(
generator
.
Interpolation
(
piece
.
WithoutTrivia
()));
// Update this variable to be false every time we encounter an interpolation
// so we know when we've encountered a new string literal expression later.
previousContentWasStringLiteralExpression
=
false
;
}
}
return
generator
.
InterpolatedStringExpression
(
startToken
,
content
,
endToken
);
}
private
static
SyntaxNode
ConcatinateTextToTextNode
(
SyntaxGenerator
generator
,
SyntaxNode
interpolatedStringTextNode
,
string
textWithoutQuotes
)
{
var
existingText
=
interpolatedStringTextNode
.
GetFirstToken
().
Text
;
var
newText
=
existingText
+
textWithoutQuotes
;
return
generator
.
InterpolatedStringText
(
generator
.
InterpolatedStringTextToken
(
newText
));
}
protected
abstract
string
GetTextWithoutQuotes
(
string
text
,
bool
isVerbatimStringLiteral
);
protected
abstract
SyntaxToken
CreateInterpolatedStringStartToken
(
bool
isVerbatimStringLiteral
);
protected
abstract
SyntaxToken
CreateInterpolatedStringEndToken
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录