Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
9f202244
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,发现更多精彩内容 >>
提交
9f202244
编写于
11月 19, 2019
作者:
A
Allison Chou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change name generating implementation
上级
1ea92fa2
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
18 addition
and
16 deletion
+18
-16
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
...dExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
+1
-1
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
...or.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
+8
-1
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
...actor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
+8
-1
src/Features/Core/Portable/ExtractMethod/UniqueNameGenerator.cs
...atures/Core/Portable/ExtractMethod/UniqueNameGenerator.cs
+1
-13
未找到文件。
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
浏览文件 @
9f202244
...
...
@@ -41,7 +41,7 @@ protected override SyntaxToken CreateMethodName(bool localFunction)
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
nameGenerator
=
new
UniqueNameGenerator
(
semanticModel
);
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
containingScope
,
methodName
,
localFunction
));
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
containingScope
,
methodName
));
}
private
static
string
GetMethodNameBasedOnExpression
(
string
methodName
,
SyntaxNode
expression
)
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
浏览文件 @
9f202244
...
...
@@ -47,7 +47,14 @@ protected override SyntaxToken CreateMethodName(bool localFunction)
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
nameGenerator
=
new
UniqueNameGenerator
(
semanticModel
);
var
scope
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
scope
,
"NewMethod"
,
localFunction
));
// If extracting a local function, we want to ensure all local variables are considered when generating a unique name.
if
(
localFunction
)
{
scope
=
this
.
CSharpSelectionResult
.
GetFirstTokenInSelection
().
Parent
;
}
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
scope
,
"NewMethod"
));
}
protected
override
IEnumerable
<
StatementSyntax
>
GetInitialStatementsForMethodDefinitions
()
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.SingleStatementCodeGenerator.cs
浏览文件 @
9f202244
...
...
@@ -39,7 +39,14 @@ protected override SyntaxToken CreateMethodName(bool localFunction)
var
semanticModel
=
this
.
SemanticDocument
.
SemanticModel
;
var
nameGenerator
=
new
UniqueNameGenerator
(
semanticModel
);
var
scope
=
this
.
CSharpSelectionResult
.
GetContainingScope
();
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
scope
,
"NewMethod"
,
localFunction
));
// If extracting a local function, we want to ensure all local variables are considered when generating a unique name.
if
(
localFunction
)
{
scope
=
this
.
CSharpSelectionResult
.
GetFirstTokenInSelection
().
Parent
;
}
return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
scope
,
"NewMethod"
));
}
protected
override
IEnumerable
<
StatementSyntax
>
GetInitialStatementsForMethodDefinitions
()
...
...
src/Features/Core/Portable/ExtractMethod/UniqueNameGenerator.cs
浏览文件 @
9f202244
...
...
@@ -16,23 +16,11 @@ public UniqueNameGenerator(SemanticModel semanticModel)
_semanticModel
=
semanticModel
;
}
public
string
CreateUniqueMethodName
(
SyntaxNode
contextNode
,
string
baseName
,
bool
localFunction
=
false
)
public
string
CreateUniqueMethodName
(
SyntaxNode
contextNode
,
string
baseName
)
{
Contract
.
ThrowIfNull
(
contextNode
);
Contract
.
ThrowIfNull
(
baseName
);
if
(
localFunction
)
{
// When generating local functions, we also want to take into account the names of local variables.
var
childNodes
=
contextNode
.
ChildNodes
().
AsArray
();
if
(
childNodes
.
Length
>
0
)
{
// If we take the first child node, we may end up with part of the method header.
// To be safe, we use the last child node, which is guaranteed to be part of the context method's body.
contextNode
=
(
SyntaxNode
)
childNodes
.
GetValue
(
childNodes
.
Length
-
1
);
}
}
return
NameGenerator
.
GenerateUniqueName
(
baseName
,
string
.
Empty
,
n
=>
_semanticModel
.
LookupSymbols
(
contextNode
.
SpanStart
,
container
:
null
,
n
).
Length
==
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录