Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a072b62b
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,发现更多精彩内容 >>
提交
a072b62b
编写于
12月 11, 2019
作者:
A
Allison Chou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Addressed feedback
上级
1a6846be
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
87 addition
and
257 deletion
+87
-257
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
...st/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
+43
-158
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractMethodTests.cs
...SharpTest/CodeActions/ExtractMethod/ExtractMethodTests.cs
+21
-64
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
...dExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
+2
-4
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
...xtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
+9
-3
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
+1
-1
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
...actor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
+2
-2
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
...rp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
+5
-10
src/Workspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
...kspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
+4
-15
未找到文件。
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractLocalFunctionTests.cs
浏览文件 @
a072b62b
...
...
@@ -22,6 +22,39 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
private
int
CodeActionIndex
=>
1
;
private
const
string
EditorConfigNaming_CamelCase
=
@"[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case"
;
private
const
string
EditorConfigNaming_PascalCase
=
@"[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.capitalization = pascal_case"
;
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractLocalFunction
)]
public
async
Task
TestPartialSelection_StaticOptionTrue
()
{
...
...
@@ -4001,22 +4034,7 @@ static void Main()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4039,22 +4057,7 @@ static bool newMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4077,22 +4080,7 @@ void TestMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4114,22 +4102,7 @@ static int getA()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4153,22 +4126,7 @@ static void Main()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.capitalization = pascal_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_PascalCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4191,22 +4149,7 @@ static bool NewMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.capitalization = pascal_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_PascalCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4229,22 +4172,7 @@ void TestMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.capitalization = pascal_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_PascalCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4266,22 +4194,7 @@ static int GetA()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = pascal_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.pascal_case.capitalization = pascal_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_PascalCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4305,22 +4218,8 @@ static void Main()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
dotnet_naming_symbols.local_functions.required_modifiers = static
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -4343,22 +4242,8 @@ bool NewMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_CamelCase
+
@"
dotnet_naming_symbols.local_functions.required_modifiers = static
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
src/EditorFeatures/CSharpTest/CodeActions/ExtractMethod/ExtractMethodTests.cs
浏览文件 @
a072b62b
...
...
@@ -17,6 +17,23 @@ public class ExtractMethodTests : AbstractCSharpCodeActionTest
protected
override
CodeRefactoringProvider
CreateCodeRefactoringProvider
(
Workspace
workspace
,
TestParameters
parameters
)
=>
new
ExtractMethodCodeRefactoringProvider
();
private
const
string
EditorConfigNaming_LocalFunctions_CamelCase
=
@"[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case"
;
[
WorkItem
(
540799
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540799"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsExtractMethod
)]
public
async
Task
TestPartialSelection
()
...
...
@@ -3699,22 +3716,7 @@ static void Main()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_LocalFunctions_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -3737,22 +3739,7 @@ private static bool NewMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_LocalFunctions_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -3775,22 +3762,7 @@ void TestMethod()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_LocalFunctions_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
@@ -3812,22 +3784,7 @@ private static int GetA()
}
}
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">[*]
# Naming rules
dotnet_naming_rule.local_functions_should_be_camel_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_camel_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_camel_case.style = camel_case
# Symbol specifications
dotnet_naming_symbols.local_functions.applicable_kinds = local_function
dotnet_naming_symbols.local_functions.applicable_accessibilities = *
dotnet_naming_symbols.local_functions.required_modifiers =
# Naming styles
dotnet_naming_style.camel_case.capitalization = camel_case
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">"
+
EditorConfigNaming_LocalFunctions_CamelCase
+
@"
</AnalyzerConfigDocument>
</Project>
</Workspace>"
;
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.ExpressionCodeGenerator.cs
浏览文件 @
a072b62b
...
...
@@ -53,15 +53,13 @@ protected override SyntaxToken CreateMethodName()
private
string
GetMethodNameBasedOnExpression
(
string
methodName
,
SyntaxNode
expression
)
{
var
preferLocalFunctionCamelCaseName
=
methodName
.
Equals
(
"newMethod"
);
if
(
expression
.
Parent
!=
null
&&
expression
.
Parent
.
Kind
()
==
SyntaxKind
.
EqualsValueClause
&&
expression
.
Parent
.
Parent
!=
null
&&
expression
.
Parent
.
Parent
.
Kind
()
==
SyntaxKind
.
VariableDeclarator
)
{
var
name
=
((
VariableDeclaratorSyntax
)
expression
.
Parent
.
Parent
).
Identifier
.
ValueText
;
return
(
name
!=
null
&&
name
.
Length
>
0
)
?
MakeMethodName
(
"Get"
,
name
,
LocalFunction
,
preferLocalFunctionCamelCaseName
)
:
methodName
;
return
(
name
!=
null
&&
name
.
Length
>
0
)
?
MakeMethodName
(
"Get"
,
name
,
methodName
.
Equals
(
NewMethodCamelCaseStr
)
)
:
methodName
;
}
if
(
expression
is
MemberAccessExpressionSyntax
memberAccess
)
...
...
@@ -91,7 +89,7 @@ private string GetMethodNameBasedOnExpression(string methodName, SyntaxNode expr
var
unqualifiedNameIdentifierValueText
=
unqualifiedName
.
Identifier
.
ValueText
;
return
(
unqualifiedNameIdentifierValueText
!=
null
&&
unqualifiedNameIdentifierValueText
.
Length
>
0
)
?
MakeMethodName
(
"Get"
,
unqualifiedNameIdentifierValueText
,
LocalFunction
,
preferLocalFunctionCamelCaseName
)
:
methodName
;
MakeMethodName
(
"Get"
,
unqualifiedNameIdentifierValueText
,
methodName
.
Equals
(
NewMethodCamelCaseStr
)
)
:
methodName
;
}
return
methodName
;
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.cs
浏览文件 @
a072b62b
...
...
@@ -31,6 +31,9 @@ private abstract partial class CSharpCodeGenerator : CodeGenerator<StatementSynt
{
private
readonly
SyntaxToken
_methodName
;
private
const
string
NewMethodPascalCaseStr
=
"NewMethod"
;
private
const
string
NewMethodCamelCaseStr
=
"newMethod"
;
public
static
Task
<
GeneratedCode
>
GenerateAsync
(
InsertionPoint
insertionPoint
,
SelectionResult
selectionResult
,
...
...
@@ -217,7 +220,10 @@ private DeclarationModifiers CreateMethodModifiers()
var
isStatic
=
!
this
.
AnalyzerResult
.
UseInstanceMember
;
var
isReadOnly
=
this
.
AnalyzerResult
.
ShouldBeReadOnly
;
if
(
LocalFunction
&&
!
this
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferStaticLocalFunction
).
Value
)
// Static local functions are only supported in C# 8.0 and later
var
languageVersion
=
((
CSharpParseOptions
)
this
.
SemanticDocument
.
SyntaxTree
.
Options
).
LanguageVersion
;
if
(
LocalFunction
&&
(!
this
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferStaticLocalFunction
).
Value
||
languageVersion
<
LanguageVersion
.
CSharp8
))
{
isStatic
=
false
;
}
...
...
@@ -806,7 +812,7 @@ protected SyntaxToken GenerateMethodNameForStatementGenerators()
protected
string
GenerateMethodNameFromUserPreference
()
{
var
methodName
=
"NewMethod"
;
var
methodName
=
NewMethodPascalCaseStr
;
if
(!
LocalFunction
)
{
return
methodName
;
...
...
@@ -822,7 +828,7 @@ protected string GenerateMethodNameFromUserPreference()
{
if
(
namingRules
.
Any
(
rule
=>
rule
.
NamingStyle
.
CapitalizationScheme
.
Equals
(
Capitalization
.
CamelCase
)
&&
rule
.
SymbolSpecification
.
AppliesTo
(
localFunctionKind
,
CreateMethodModifiers
(),
null
)))
{
methodName
=
"newMethod"
;
methodName
=
NewMethodCamelCaseStr
;
}
}
...
...
src/Features/Core/Portable/ExtractMethod/MethodExtractor.cs
浏览文件 @
a072b62b
...
...
@@ -176,7 +176,7 @@ public async Task<ExtractMethodResult> ExtractMethodAsync(CancellationToken canc
return
Tuple
.
Create
(
true
,
status
);
}
internal
static
string
MakeMethodName
(
string
prefix
,
string
originalName
,
bool
localFunction
=
false
,
bool
camelCase
=
fal
se
)
internal
static
string
MakeMethodName
(
string
prefix
,
string
originalName
,
bool
localFunction
,
bool
camelCa
se
)
{
var
startingWithLetter
=
originalName
.
ToCharArray
().
SkipWhile
(
c
=>
!
char
.
IsLetter
(
c
)).
ToArray
();
var
name
=
startingWithLetter
.
Length
==
0
?
originalName
:
new
string
(
startingWithLetter
);
...
...
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
浏览文件 @
a072b62b
...
...
@@ -48,7 +48,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
End
If
Dim
name
=
identifierNode
.
Identifier
.
ValueText
Return
If
(
name
IsNot
Nothing
AndAlso
name
.
Length
>
0
,
MakeMethodName
(
"Get"
,
name
),
methodName
)
Return
If
(
name
IsNot
Nothing
AndAlso
name
.
Length
>
0
,
MakeMethodName
(
"Get"
,
name
,
localFunction
:
=
False
,
camelCase
:
=
False
),
methodName
)
End
If
If
TypeOf
expression
Is
MemberAccessExpressionSyntax
Then
...
...
@@ -58,7 +58,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
If
TypeOf
expression
Is
NameSyntax
Then
Dim
lastDottedName
=
CType
(
expression
,
NameSyntax
).
GetLastDottedName
()
Dim
plainName
=
CType
(
lastDottedName
,
SimpleNameSyntax
).
Identifier
.
ValueText
Return
If
(
plainName
IsNot
Nothing
AndAlso
plainName
.
Length
>
0
,
MakeMethodName
(
"Get"
,
plainName
),
methodName
)
Return
If
(
plainName
IsNot
Nothing
AndAlso
plainName
.
Length
>
0
,
MakeMethodName
(
"Get"
,
plainName
,
localFunction
:
=
False
,
camelCase
:
=
False
),
methodName
)
End
If
Return
methodName
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
浏览文件 @
a072b62b
...
...
@@ -113,10 +113,7 @@ protected override TDeclarationNode AddMethod<TDeclarationNode>(TDeclarationNode
{
CheckDeclarationNode
<
TypeDeclarationSyntax
,
CompilationUnitSyntax
,
NamespaceDeclarationSyntax
>(
destination
);
if
(
options
.
Options
==
null
)
{
options
=
options
.
With
(
options
:
Workspace
.
Options
);
}
options
=
options
.
Options
==
null
?
options
.
With
(
options
:
Workspace
.
Options
)
:
options
;
// Synthesized methods for properties/events are not things we actually generate
// declarations for.
...
...
@@ -578,20 +575,18 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
}
}
if
(
options
.
Options
==
null
)
if
(
method
.
IsDestructor
()
)
{
options
=
options
.
With
(
options
:
Workspace
.
O
ptions
);
return
DestructorGenerator
.
GenerateDestructorDeclaration
(
method
,
destination
,
o
ptions
);
}
options
=
options
.
Options
==
null
?
options
.
With
(
options
:
Workspace
.
Options
)
:
options
;
if
(
method
.
IsConstructor
())
{
return
ConstructorGenerator
.
GenerateConstructorDeclaration
(
method
,
destination
,
Workspace
,
options
,
options
.
ParseOptions
);
}
else
if
(
method
.
IsDestructor
())
{
return
DestructorGenerator
.
GenerateDestructorDeclaration
(
method
,
destination
,
options
);
}
else
if
(
method
.
IsUserDefinedOperator
())
{
return
OperatorGenerator
.
GenerateOperatorDeclaration
(
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
浏览文件 @
a072b62b
...
...
@@ -111,7 +111,7 @@ internal static class MethodGenerator
var
methodDeclaration
=
SyntaxFactory
.
MethodDeclaration
(
attributeLists
:
GenerateAttributes
(
method
,
options
,
explicitInterfaceSpecifier
!=
null
),
modifiers
:
GenerateModifiers
(
method
,
destination
,
options
,
localFunction
:
false
),
modifiers
:
GenerateModifiers
(
method
,
destination
,
options
),
returnType
:
method
.
GenerateReturnTypeSyntax
(),
explicitInterfaceSpecifier
:
explicitInterfaceSpecifier
,
identifier
:
method
.
Name
.
ToIdentifierToken
(),
...
...
@@ -131,7 +131,7 @@ internal static class MethodGenerator
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
{
var
localFunctionDeclaration
=
SyntaxFactory
.
LocalFunctionStatement
(
modifiers
:
GenerateModifiers
(
method
,
destination
,
options
,
localFunction
:
true
,
((
CSharpParseOptions
)
parseOptions
).
LanguageVersion
),
modifiers
:
GenerateModifiers
(
method
,
destination
,
options
),
returnType
:
method
.
GenerateReturnTypeSyntax
(),
identifier
:
method
.
Name
.
ToIdentifierToken
(),
typeParameterList
:
GenerateTypeParameterList
(
method
,
options
),
...
...
@@ -212,7 +212,7 @@ internal static class MethodGenerator
}
private
static
SyntaxTokenList
GenerateModifiers
(
IMethodSymbol
method
,
CodeGenerationDestination
destination
,
CodeGenerationOptions
options
,
bool
localFunction
,
LanguageVersion
languageVersion
=
LanguageVersion
.
Latest
)
IMethodSymbol
method
,
CodeGenerationDestination
destination
,
CodeGenerationOptions
options
)
{
var
tokens
=
ArrayBuilder
<
SyntaxToken
>.
GetInstance
();
...
...
@@ -245,18 +245,7 @@ internal static class MethodGenerator
if
(
method
.
IsStatic
)
{
if
(
localFunction
)
{
// Static local functions are only supported in C# 8.0 and later.
if
(
languageVersion
>=
LanguageVersion
.
CSharp8
)
{
tokens
.
Add
(
SyntaxFactory
.
Token
(
SyntaxKind
.
StaticKeyword
));
}
}
else
{
tokens
.
Add
(
SyntaxFactory
.
Token
(
SyntaxKind
.
StaticKeyword
));
}
tokens
.
Add
(
SyntaxFactory
.
Token
(
SyntaxKind
.
StaticKeyword
));
}
// Don't show the readonly modifier if the containing type is already readonly
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录