Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
307bc88b
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,发现更多精彩内容 >>
提交
307bc88b
编写于
8月 19, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check for specific node shapes to walk to the right extract method parent.
上级
78a997e9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
16 deletion
+48
-16
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
...e/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
+17
-3
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
...actor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
+2
-2
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb
...asic/Portable/ExtractMethod/VisualBasicSelectionResult.vb
+29
-11
未找到文件。
src/Features/CSharp/Portable/ExtractMethod/CSharpSelectionResult.ExpressionResult.cs
浏览文件 @
307bc88b
...
...
@@ -6,6 +6,7 @@
using
System.Linq
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.LanguageServices
;
using
Microsoft.CodeAnalysis.CSharp.Symbols
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.ExtractMethod
;
...
...
@@ -44,9 +45,22 @@ public override bool ContainingScopeHasAsyncKeyword()
var
firstToken
=
GetFirstTokenInSelection
();
var
lastToken
=
GetLastTokenInSelection
();
var
scope
=
firstToken
.
GetCommonRoot
(
lastToken
).
GetAncestorOrThis
<
ExpressionSyntax
>();
return
scope
.
IsRightSideOfDotOrArrowOrColonColon
()
?
scope
.
Parent
:
scope
;
if
(
scope
==
null
)
return
null
;
// If the selection ends up mapping to the name on the right in `x.y` or `x?.y`, then grab
// the full expr `x.y` or `x?.y` as the part to extract.
if
(
scope
.
Parent
is
MemberAccessExpressionSyntax
memberAccess
&&
memberAccess
.
Name
==
scope
)
scope
=
(
ExpressionSyntax
)
scope
.
Parent
;
if
(
scope
.
Parent
is
MemberBindingExpressionSyntax
memberBinding
&&
memberBinding
.
Name
==
scope
)
scope
=
(
ExpressionSyntax
)
scope
.
Parent
;
if
(
scope
is
MemberBindingExpressionSyntax
||
scope
is
ElementBindingExpressionSyntax
)
scope
=
scope
.
GetParentConditionalAccessExpression
();
return
scope
;
}
public
override
ITypeSymbol
?
GetContainingScopeType
()
...
...
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicMethodExtractor.VisualBasicCodeGenerator.ExpressionCodeGenerator.vb
浏览文件 @
307bc88b
...
...
@@ -25,11 +25,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
Protected
Overrides
Function
CreateMethodName
()
As
SyntaxToken
Dim
methodName
=
"NewMethod"
Dim
containingScope
=
CType
(
VBSelectionResult
.
GetContainingScope
(),
SyntaxNode
)
Dim
containingScope
=
VBSelectionResult
.
GetContainingScope
(
)
methodName
=
GetMethodNameBasedOnExpression
(
methodName
,
containingScope
)
Dim
semanticModel
=
CType
(
SemanticDocument
.
SemanticModel
,
SemanticModel
)
Dim
semanticModel
=
SemanticDocument
.
SemanticModel
Dim
nameGenerator
=
New
UniqueNameGenerator
(
semanticModel
)
Return
SyntaxFactory
.
Identifier
(
nameGenerator
.
CreateUniqueMethodName
(
containingScope
,
methodName
))
...
...
src/Features/VisualBasic/Portable/ExtractMethod/VisualBasicSelectionResult.vb
浏览文件 @
307bc88b
...
...
@@ -8,6 +8,7 @@ Imports Microsoft.CodeAnalysis.ExtractMethod
Imports
Microsoft.CodeAnalysis.Options
Imports
Microsoft.CodeAnalysis.Text
Imports
Microsoft.CodeAnalysis.VisualBasic
Imports
Microsoft.CodeAnalysis.VisualBasic.LanguageServices
Imports
Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
...
...
@@ -94,7 +95,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
Return
False
End
If
Dim
node
=
CType
(
Me
.
GetContainingScope
(),
SyntaxNode
)
Dim
node
=
Me
.
GetContainingScope
(
)
If
TypeOf
node
Is
MethodBlockBaseSyntax
Then
Dim
methodBlock
=
DirectCast
(
node
,
MethodBlockBaseSyntax
)
If
methodBlock
.
BlockStatement
IsNot
Nothing
Then
...
...
@@ -120,18 +121,35 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
If
SelectionInExpression
Then
Dim
last
=
GetLastTokenInSelection
()
Dim
expression
=
first
.
GetCommonRoot
(
last
).
GetAncestorOrThis
(
Of
ExpressionSyntax
)()
Return
If
(
expression
.
IsRightSideOfDotOrBang
(),
expression
.
Parent
,
expression
)
End
If
Dim
scope
=
first
.
GetCommonRoot
(
last
).
GetAncestorOrThis
(
Of
ExpressionSyntax
)()
Contract
.
ThrowIfNull
(
scope
,
"Should always find an expression given that SelectionInExpression was true"
)
' If the selection ends up mapping to the name on the right in `x.y` Or `x?.y`, then grab
' the full expr `x.y` Or `x?.y` as the part to extract.
Dim
memberAccess
=
TryCast
(
scope
.
Parent
,
MemberAccessExpressionSyntax
)
If
memberAccess
?
.
Name
Is
scope
Then
If
memberAccess
.
Expression
Is
Nothing
Then
' .y or
' x?.y
scope
=
If
(
memberAccess
.
GetParentConditionalAccessExpression
(),
DirectCast
(
memberAccess
,
ExpressionSyntax
))
End
If
End
If
' it contains statements
Return
first
.
GetAncestors
(
Of
SyntaxNode
).
FirstOrDefault
(
Function
(
n
)
TypeOf
n
Is
MethodBlockBaseSyntax
OrElse
TypeOf
n
Is
LambdaExpressionSyntax
)
Dim
invocation
=
TryCast
(
scope
,
InvocationExpressionSyntax
)
If
invocation
IsNot
Nothing
AndAlso
invocation
.
Expression
Is
Nothing
Then
' x?(y)
scope
=
invocation
.
GetParentConditionalAccessExpression
()
End
If
Return
scope
Else
' it contains statements
Return
first
.
GetAncestors
(
Of
SyntaxNode
).
FirstOrDefault
(
Function
(
n
)
TypeOf
n
Is
MethodBlockBaseSyntax
OrElse
TypeOf
n
Is
LambdaExpressionSyntax
)
End
If
End
Function
Public
Overrides
Function
GetContainingScopeType
()
As
ITypeSymbol
Dim
node
=
CType
(
Me
.
GetContainingScope
(),
SyntaxNode
)
Dim
node
=
Me
.
GetContainingScope
(
)
Dim
semanticModel
=
Me
.
SemanticDocument
.
SemanticModel
' special case for collection initializer and explicit cast
...
...
@@ -289,11 +307,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExtractMethod
' Contract.ThrowIfFalse(last.IsParentKind(SyntaxKind.GlobalStatement))
' Contract.ThrowIfFalse(last.Parent.IsParentKind(SyntaxKind.CompilationUnit))
' Return last.Parent.Parent
t
hrow
ExceptionUtilities
.
Unreachable
T
hrow
ExceptionUtilities
.
Unreachable
End
Function
Public
Function
IsUnderModuleBlock
()
As
Boolean
Dim
currentScope
=
CType
(
GetContainingScope
(),
SyntaxNode
)
Dim
currentScope
=
GetContainingScope
(
)
Dim
types
=
currentScope
.
GetAncestors
(
Of
TypeBlockSyntax
)()
Return
types
.
Any
(
Function
(
t
)
t
.
BlockStatement
.
Kind
=
SyntaxKind
.
ModuleStatement
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录