Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
5872fe96
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,发现更多精彩内容 >>
提交
5872fe96
编写于
11月 19, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
11月 19, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15398 from CyrusNajmabadi/shareGenerationCode
Move helpers to common layer.
上级
bafc06cc
983fcca1
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
114 addition
and
188 deletion
+114
-188
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
...rp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
+3
-109
src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationHelpers.cs
...ces/Core/Portable/CodeGeneration/CodeGenerationHelpers.cs
+109
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationHelpers.vb
...rtable/CodeGeneration/VisualBasicCodeGenerationHelpers.vb
+2
-79
未找到文件。
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
浏览文件 @
5872fe96
...
...
@@ -172,7 +172,9 @@ public static MemberDeclarationSyntax LastOperator(SyntaxList<MemberDeclarationS
Func
<
SyntaxList
<
TDeclaration
>,
TDeclaration
>
before
=
null
)
where
TDeclaration
:
SyntaxNode
{
var
index
=
GetInsertionIndex
(
declarationList
,
declaration
,
options
,
availableIndices
,
after
,
before
);
var
index
=
GetInsertionIndex
(
declarationList
,
declaration
,
options
,
availableIndices
,
CSharpDeclarationComparer
.
Instance
,
after
,
before
);
if
(
availableIndices
!=
null
)
{
availableIndices
.
Insert
(
index
,
true
);
...
...
@@ -191,114 +193,6 @@ public static MemberDeclarationSyntax LastOperator(SyntaxList<MemberDeclarationS
return
declaration
.
ChildTokens
().
Where
(
t
=>
t
.
IsKind
(
SyntaxKind
.
OpenBraceToken
,
SyntaxKind
.
CloseBraceToken
)
&&
t
.
IsMissing
).
Any
();
}
public
static
int
GetInsertionIndex
<
TDeclaration
>(
SyntaxList
<
TDeclaration
>
declarationList
,
TDeclaration
declaration
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
,
Func
<
SyntaxList
<
TDeclaration
>,
TDeclaration
>
after
=
null
,
Func
<
SyntaxList
<
TDeclaration
>,
TDeclaration
>
before
=
null
)
where
TDeclaration
:
SyntaxNode
{
Contract
.
ThrowIfTrue
(
availableIndices
!=
null
&&
availableIndices
.
Count
!=
declarationList
.
Count
+
1
);
if
(
options
!=
null
)
{
// Try to strictly obey the after option by inserting immediately after the member containing the location
if
(
options
.
AfterThisLocation
!=
null
)
{
var
afterMember
=
declarationList
.
LastOrDefault
(
m
=>
m
.
SpanStart
<=
options
.
AfterThisLocation
.
SourceSpan
.
Start
);
if
(
afterMember
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
afterMember
);
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
// Try to strictly obey the before option by inserting immediately before the member containing the location
if
(
options
.
BeforeThisLocation
!=
null
)
{
var
beforeMember
=
declarationList
.
FirstOrDefault
(
m
=>
m
.
Span
.
End
>=
options
.
BeforeThisLocation
.
SourceSpan
.
End
);
if
(
beforeMember
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
beforeMember
);
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
if
(
options
.
AutoInsertionLocation
)
{
if
(
declarationList
.
IsEmpty
())
{
return
0
;
}
else
if
(
declarationList
.
IsSorted
(
CSharpDeclarationComparer
.
Instance
))
{
var
result
=
Array
.
BinarySearch
(
declarationList
.
ToArray
(),
declaration
,
CSharpDeclarationComparer
.
Instance
);
var
index
=
GetPreferredIndex
(
result
<
0
?
~
result
:
result
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
if
(
after
!=
null
)
{
var
member
=
after
(
declarationList
);
if
(
member
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
member
);
if
(
index
>=
0
)
{
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
}
if
(
before
!=
null
)
{
var
member
=
before
(
declarationList
);
if
(
member
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
member
);
if
(
index
>=
0
)
{
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
}
}
}
// Otherwise, add the declaration to the end.
{
var
index
=
GetPreferredIndex
(
declarationList
.
Count
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
return
declarationList
.
Count
;
}
public
static
SyntaxNode
GetContextNode
(
Location
location
,
CancellationToken
cancellationToken
)
{
...
...
src/Workspaces/Core/Portable/CodeGeneration/CodeGenerationHelpers.cs
浏览文件 @
5872fe96
...
...
@@ -228,5 +228,114 @@ public static T GetReuseableSyntaxNodeForAttribute<T>(AttributeData attribute, C
attribute
.
ApplicationSyntaxReference
.
GetSyntax
()
as
T
:
null
;
}
public
static
int
GetInsertionIndex
<
TDeclaration
>(
SyntaxList
<
TDeclaration
>
declarationList
,
TDeclaration
declaration
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
,
IComparer
<
TDeclaration
>
comparer
,
Func
<
SyntaxList
<
TDeclaration
>,
TDeclaration
>
after
=
null
,
Func
<
SyntaxList
<
TDeclaration
>,
TDeclaration
>
before
=
null
)
where
TDeclaration
:
SyntaxNode
{
Contract
.
ThrowIfTrue
(
availableIndices
!=
null
&&
availableIndices
.
Count
!=
declarationList
.
Count
+
1
);
if
(
options
!=
null
)
{
// Try to strictly obey the after option by inserting immediately after the member containing the location
if
(
options
.
AfterThisLocation
!=
null
)
{
var
afterMember
=
declarationList
.
LastOrDefault
(
m
=>
m
.
SpanStart
<=
options
.
AfterThisLocation
.
SourceSpan
.
Start
);
if
(
afterMember
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
afterMember
);
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
// Try to strictly obey the before option by inserting immediately before the member containing the location
if
(
options
.
BeforeThisLocation
!=
null
)
{
var
beforeMember
=
declarationList
.
FirstOrDefault
(
m
=>
m
.
Span
.
End
>=
options
.
BeforeThisLocation
.
SourceSpan
.
End
);
if
(
beforeMember
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
beforeMember
);
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
if
(
options
.
AutoInsertionLocation
)
{
if
(
declarationList
.
IsEmpty
())
{
return
0
;
}
else
if
(
declarationList
.
IsSorted
(
comparer
))
{
var
result
=
Array
.
BinarySearch
(
declarationList
.
ToArray
(),
declaration
,
comparer
);
var
index
=
GetPreferredIndex
(
result
<
0
?
~
result
:
result
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
if
(
after
!=
null
)
{
var
member
=
after
(
declarationList
);
if
(
member
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
member
);
if
(
index
>=
0
)
{
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
true
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
}
if
(
before
!=
null
)
{
var
member
=
before
(
declarationList
);
if
(
member
!=
null
)
{
var
index
=
declarationList
.
IndexOf
(
member
);
if
(
index
>=
0
)
{
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
}
}
}
}
// Otherwise, add the declaration to the end.
{
var
index
=
GetPreferredIndex
(
declarationList
.
Count
,
availableIndices
,
forward
:
false
);
if
(
index
!=
-
1
)
{
return
index
;
}
}
return
declarationList
.
Count
;
}
}
}
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicCodeGenerationHelpers.vb
浏览文件 @
5872fe96
...
...
@@ -149,7 +149,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
before
=
BeforeDeclaration
(
declarationList
,
options
,
before
)
Dim
index
=
GetInsertionIndex
(
declarationList
,
declaration
,
options
,
availableIndices
,
after
,
before
)
declarationList
,
declaration
,
options
,
availableIndices
,
VisualBasicDeclarationComparer
.
Instance
,
after
,
before
)
If
availableIndices
IsNot
Nothing
Then
availableIndices
.
Insert
(
index
,
True
)
...
...
@@ -158,84 +159,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return
declarationList
.
Insert
(
index
,
declaration
)
End
Function
Private
Function
GetInsertionIndex
(
Of
TDeclaration
As
SyntaxNode
)(
declarationList
As
SyntaxList
(
Of
TDeclaration
),
declaration
As
TDeclaration
,
options
As
CodeGenerationOptions
,
availableIndices
As
IList
(
Of
Boolean
),
after
As
Func
(
Of
SyntaxList
(
Of
TDeclaration
),
TDeclaration
),
before
As
Func
(
Of
SyntaxList
(
Of
TDeclaration
),
TDeclaration
))
As
Integer
If
options
IsNot
Nothing
Then
' Try to use AfterThisLocation
If
options
.
AfterThisLocation
IsNot
Nothing
Then
Dim
afterMember
=
declarationList
.
LastOrDefault
(
Function
(
m
)
m
.
SpanStart
<=
options
.
AfterThisLocation
.
SourceSpan
.
Start
)
If
afterMember
IsNot
Nothing
Then
Dim
index
=
declarationList
.
IndexOf
(
afterMember
)
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
=
True
)
If
index
<>
-
1
Then
Return
index
End
If
End
If
End
If
' Try to use BeforeThisLocation
If
options
.
BeforeThisLocation
IsNot
Nothing
Then
Dim
beforeMember
=
declarationList
.
FirstOrDefault
(
Function
(
m
)
m
.
Span
.
End
>=
options
.
BeforeThisLocation
.
SourceSpan
.
End
)
If
beforeMember
IsNot
Nothing
Then
Dim
index
=
declarationList
.
IndexOf
(
beforeMember
)
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
=
False
)
If
index
<>
-
1
Then
Return
index
End
If
End
If
End
If
If
options
.
AutoInsertionLocation
Then
Dim
declarations
=
declarationList
.
ToArray
()
If
(
declarations
.
Length
=
0
)
Then
Return
0
ElseIf
declarations
.
IsSorted
(
VisualBasicDeclarationComparer
.
Instance
)
Then
Dim
result
=
Array
.
BinarySearch
(
Of
TDeclaration
)(
declarations
,
declaration
,
VisualBasicDeclarationComparer
.
Instance
)
Dim
index
=
GetPreferredIndex
(
If
(
result
<
0
,
Not
result
,
result
),
availableIndices
,
forward
:
=
True
)
If
index
<>
-
1
Then
Return
index
End
If
End
If
If
after
IsNot
Nothing
Then
Dim
member
=
after
(
declarationList
)
If
member
IsNot
Nothing
Then
Dim
index
=
declarationList
.
IndexOf
(
member
)
index
=
GetPreferredIndex
(
index
+
1
,
availableIndices
,
forward
:
=
True
)
If
index
<>
-
1
Then
Return
index
End
If
End
If
End
If
If
before
IsNot
Nothing
Then
Dim
member
=
before
(
declarationList
)
If
member
IsNot
Nothing
Then
Dim
index
=
declarationList
.
IndexOf
(
member
)
index
=
GetPreferredIndex
(
index
,
availableIndices
,
forward
:
=
False
)
If
index
<>
-
1
Then
Return
index
End
If
End
If
End
If
End
If
End
If
' Otherwise, add the method to the end.
Dim
index1
=
GetPreferredIndex
(
declarationList
.
Count
,
availableIndices
,
forward
:
=
False
)
If
index1
<>
-
1
Then
Return
index1
End
If
Return
declarationList
.
Count
End
Function
Public
Function
GetDestination
(
destination
As
SyntaxNode
)
As
CodeGenerationDestination
If
destination
IsNot
Nothing
Then
Select
Case
destination
.
Kind
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录