Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1a4d95ea
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,发现更多精彩内容 >>
提交
1a4d95ea
编写于
3月 21, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish VB support.
上级
f99769df
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
71 addition
and
38 deletion
+71
-38
src/EditorFeatures/VisualBasicTest/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.vb
...omMembers/GenerateEqualsAndGetHashCodeFromMembersTests.vb
+21
-19
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
...HashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
+24
-1
src/Workspaces/CSharp/Portable/CodeGeneration/UsingDirectivesAdder.cs
...es/CSharp/Portable/CodeGeneration/UsingDirectivesAdder.cs
+3
-3
src/Workspaces/Core/Portable/CodeGeneration/AbstractCodeGenerationService.cs
.../Portable/CodeGeneration/AbstractCodeGenerationService.cs
+10
-2
src/Workspaces/Core/Portable/CodeGeneration/AbstractImportsAdder.cs
...aces/Core/Portable/CodeGeneration/AbstractImportsAdder.cs
+5
-8
src/Workspaces/Core/Portable/CodeGeneration/ICodeGenerationService.cs
...es/Core/Portable/CodeGeneration/ICodeGenerationService.cs
+2
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/ImportsStatementsAdder.vb
...alBasic/Portable/CodeGeneration/ImportsStatementsAdder.vb
+6
-5
未找到文件。
src/EditorFeatures/VisualBasicTest/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.vb
浏览文件 @
1a4d95ea
...
...
@@ -209,28 +209,29 @@ ignoreTrivia:=False)
Public
Async
Function
TestImplementIEquatable1
()
As
Task
Await
TestWithPickMembersDialogAsync
(
"
i
mports System.Collections.Generic
I
mports System.Collections.Generic
structure Program
public s as s
tring
Public s As S
tring
[||]
e
nd structure"
,
E
nd structure"
,
"
imports System.Collections.Generic
Imports System
Imports System.Collections.Generic
s
tructure Program
Implements
System.
IEquatable(Of Program)
S
tructure Program
Implements IEquatable(Of Program)
public s as s
tring
Public s As S
tring
Public Overrides Function Equals(obj As Object) As Boolean
Return (TypeOf obj Is Program) AndAlso Equals(DirectCast(obj, Program))
End Function
Public Function Equals(other As Program) As Boolean Implements
System.
IEquatable(Of Program).Equals
Public Function Equals(other As Program) As Boolean Implements IEquatable(Of Program).Equals
Return s = other.s
End Function
end s
tructure"
,
End S
tructure"
,
chosenSymbols
:
=
Nothing
,
optionsCallback
:
=
Sub
(
Options
)
EnableOption
(
Options
,
ImplementIEquatableId
),
ignoreTrivia
:
=
False
)
...
...
@@ -240,29 +241,30 @@ ignoreTrivia:=False)
Public
Async
Function
TestImplementIEquatable2
()
As
Task
Await
TestWithPickMembersDialogAsync
(
"
i
mports System.Collections.Generic
I
mports System.Collections.Generic
c
lass Program
public s as s
tring
C
lass Program
Public s As S
tring
[||]
end c
lass"
,
End C
lass"
,
"
imports System.Collections.Generic
Imports System
Imports System.Collections.Generic
c
lass Program
Implements
System.
IEquatable(Of Program)
C
lass Program
Implements IEquatable(Of Program)
public s as s
tring
Public s As S
tring
Public Overrides Function Equals(obj As Object) As Boolean
Return Equals(TryCast(obj, Program))
End Function
Public Function Equals(other As Program) As Boolean Implements
System.
IEquatable(Of Program).Equals
Public Function Equals(other As Program) As Boolean Implements IEquatable(Of Program).Equals
Return other IsNot Nothing AndAlso
s = other.s
End Function
end c
lass"
,
End C
lass"
,
chosenSymbols
:
=
Nothing
,
optionsCallback
:
=
Sub
(
Options
)
EnableOption
(
Options
,
ImplementIEquatableId
),
ignoreTrivia
:
=
False
)
...
...
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
浏览文件 @
1a4d95ea
...
...
@@ -93,17 +93,40 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
generator
.
TypeExpression
(
constructed
));
}
var
newDocument
=
await
UpdateDocumentAndAddImportsAsync
(
oldType
,
newType
,
cancellationToken
).
ConfigureAwait
(
false
);
var
formattedDocument
=
await
FormatDocumentAsync
(
newDocument
,
cancellationToken
).
ConfigureAwait
(
false
);
return
formattedDocument
;
}
private
async
Task
<
Document
>
UpdateDocumentAndAddImportsAsync
(
SyntaxNode
oldType
,
SyntaxNode
newType
,
CancellationToken
cancellationToken
)
{
var
oldRoot
=
await
_document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
newDocument
=
_document
.
WithSyntaxRoot
(
oldRoot
.
ReplaceNode
(
oldType
,
newType
));
var
options
=
await
_document
.
GetOptionsAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
placeSystemNamespaceFirst
=
options
.
GetOption
(
GenerationOptions
.
PlaceSystemNamespaceFirst
);
var
codeGenService
=
_document
.
GetLanguageService
<
ICodeGenerationService
>();
newDocument
=
await
codeGenService
.
AddImportsAsync
(
newDocument
,
new
CodeGenerationOptions
(
placeSystemNamespaceFirst
:
placeSystemNamespaceFirst
),
cancellationToken
).
ConfigureAwait
(
false
);
return
newDocument
;
}
private
async
Task
<
Document
>
FormatDocumentAsync
(
Document
newDocument
,
CancellationToken
cancellationToken
)
{
var
rules
=
new
List
<
IFormattingRule
>
{
new
FormatLargeBinaryExpressionRule
(
_document
.
GetLanguageService
<
ISyntaxFactsService
>())
};
rules
.
AddRange
(
Formatter
.
GetDefaultFormattingRules
(
_document
));
var
formattedDocument
=
await
Formatter
.
FormatAsync
(
newDocument
,
s_specializedFormattingAnnotation
,
options
:
null
,
rules
:
rules
,
cancellationToken
:
cancellationToken
).
ConfigureAwait
(
false
);
return
formattedDocument
;
}
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/UsingDirectivesAdder.cs
浏览文件 @
1a4d95ea
...
...
@@ -73,12 +73,12 @@ protected override SyntaxNode GetInnermostNamespaceScope(SyntaxNodeOrToken nodeO
}
public
override
async
Task
<
Document
>
AddAsync
(
IEnumerable
<
ISymbol
>
members
,
bool
placeSystemNamespaceFirst
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
{
var
importsContainerToMissingNamespaces
=
await
DetermineNamespaceToImportAsync
(
members
,
options
,
cancellationToken
).
ConfigureAwait
(
false
);
var
importsContainerToMissingNamespaces
=
await
DetermineNamespaceToImportAsync
(
options
,
cancellationToken
).
ConfigureAwait
(
false
);
if
(
importsContainerToMissingNamespaces
.
Count
==
0
)
{
return
this
.
Document
;
...
...
@@ -91,4 +91,4 @@ protected override SyntaxNode GetInnermostNamespaceScope(SyntaxNodeOrToken nodeO
return
this
.
Document
.
WithSyntaxRoot
(
newRoot
);
}
}
}
}
\ No newline at end of file
src/Workspaces/Core/Portable/CodeGeneration/AbstractCodeGenerationService.cs
浏览文件 @
1a4d95ea
...
...
@@ -198,13 +198,21 @@ protected static T Cast<T>(object value)
if
(
options
.
AddImports
)
{
var
adder
=
this
.
CreateImportsAdder
(
newDocument
);
newDocument
=
await
adder
.
AddAsync
(
members
,
options
.
PlaceSystemNamespaceFirs
t
,
options
,
cancellationToken
).
ConfigureAwait
(
false
);
newDocument
=
await
AddImportsAsync
(
newDocumen
t
,
options
,
cancellationToken
).
ConfigureAwait
(
false
);
}
return
newDocument
;
}
public
async
Task
<
Document
>
AddImportsAsync
(
Document
document
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
{
options
=
options
??
CodeGenerationOptions
.
Default
;
var
adder
=
this
.
CreateImportsAdder
(
document
);
var
newDocument
=
await
adder
.
AddAsync
(
options
.
PlaceSystemNamespaceFirst
,
options
,
cancellationToken
).
ConfigureAwait
(
false
);
return
newDocument
;
}
protected
TDeclarationNode
AddMembers
<
TDeclarationNode
>(
TDeclarationNode
destination
,
IEnumerable
<
ISymbol
>
members
,
...
...
src/Workspaces/Core/Portable/CodeGeneration/AbstractImportsAdder.cs
浏览文件 @
1a4d95ea
...
...
@@ -27,12 +27,10 @@ protected AbstractImportsAdder(Document document)
protected
abstract
SyntaxNode
GetImportsContainer
(
SyntaxNode
node
);
protected
abstract
SyntaxNode
GetInnermostNamespaceScope
(
SyntaxNodeOrToken
node
);
public
abstract
Task
<
Document
>
AddAsync
(
IEnumerable
<
ISymbol
>
members
,
bool
placeSystemNamespaceFirst
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
);
public
abstract
Task
<
Document
>
AddAsync
(
bool
placeSystemNamespaceFirst
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
);
protected
async
Task
<
IDictionary
<
SyntaxNode
,
ISet
<
INamedTypeSymbol
>>>
GetAllReferencedDefinitionsAsync
(
Compilation
compilation
,
IEnumerable
<
ISymbol
>
members
,
CancellationToken
cancellationToken
)
Compilation
compilation
,
CancellationToken
cancellationToken
)
{
var
namespaceScopeToReferencedDefinitions
=
new
Dictionary
<
SyntaxNode
,
ISet
<
INamedTypeSymbol
>>();
var
root
=
await
Document
.
GetSyntaxRootAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -99,15 +97,14 @@ private bool IsBuiltIn(INamedTypeSymbol type)
}
protected
async
Task
<
IDictionary
<
SyntaxNode
,
IList
<
INamespaceSymbol
>>>
DetermineNamespaceToImportAsync
(
IEnumerable
<
ISymbol
>
members
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
{
var
semanticModel
=
await
this
.
Document
.
GetSemanticModelAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
compilation
=
semanticModel
.
Compilation
;
// First, find all the named types referenced by code that we are trying to generated.
var
namespaceScopeToReferencedDefinitions
=
await
GetAllReferencedDefinitionsAsync
(
compilation
,
members
,
cancellationToken
).
ConfigureAwait
(
false
);
var
namespaceScopeToReferencedDefinitions
=
await
GetAllReferencedDefinitionsAsync
(
compilation
,
cancellationToken
).
ConfigureAwait
(
false
);
var
importsContainerToMissingImports
=
new
Dictionary
<
SyntaxNode
,
IList
<
INamespaceSymbol
>>();
...
...
src/Workspaces/Core/Portable/CodeGeneration/ICodeGenerationService.cs
浏览文件 @
1a4d95ea
...
...
@@ -119,6 +119,8 @@ internal interface ICodeGenerationService : ILanguageService
/// </summary>
TDeclarationNode
AddStatements
<
TDeclarationNode
>(
TDeclarationNode
destination
,
IEnumerable
<
SyntaxNode
>
statements
,
CodeGenerationOptions
options
=
null
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
where
TDeclarationNode
:
SyntaxNode
;
Task
<
Document
>
AddImportsAsync
(
Document
document
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
);
/// <summary>
/// Adds a field with the provided signature into destination.
/// </summary>
...
...
src/Workspaces/VisualBasic/Portable/CodeGeneration/ImportsStatementsAdder.vb
浏览文件 @
1a4d95ea
...
...
@@ -66,12 +66,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
ToList
()
End
Function
Public
Overrides
Async
Function
AddAsync
(
members
As
IEnumerable
(
Of
ISymbol
),
placeSystemNamespaceFirst
As
Boolean
,
options
As
CodeGenerationOptions
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
Document
)
Public
Overrides
Async
Function
AddAsync
(
placeSystemNamespaceFirst
As
Boolean
,
options
As
CodeGenerationOptions
,
cancellationToken
As
CancellationToken
)
As
Task
(
Of
Document
)
Dim
importsContainerToMissingNamespaces
=
Await
DetermineNamespaceToImportAsync
(
members
,
options
,
cancellationToken
).
ConfigureAwait
(
False
)
Dim
importsContainerToMissingNamespaces
=
Await
DetermineNamespaceToImportAsync
(
options
,
cancellationToken
).
ConfigureAwait
(
False
)
If
importsContainerToMissingNamespaces
.
Count
=
0
Then
Return
Me
.
Document
End
If
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录