Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
750e1eb7
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,发现更多精彩内容 >>
提交
750e1eb7
编写于
3月 30, 2020
作者:
M
Manish Vasani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move certain syntax generator internal methods down to shared layer
上级
74c510f2
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
162 addition
and
112 deletion
+162
-112
src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs
src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs
+1
-1
src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs
...Style/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs
+1
-1
src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb
...le/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb
+1
-1
src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb
...alBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb
+1
-1
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+1
-13
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
+7
-4
src/Workspaces/Core/Portable/Formatting/Formatter.cs
src/Workspaces/Core/Portable/Formatting/Formatter.cs
+1
-67
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs
...mpiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs
+4
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs
...tensions/Compiler/Core/Formatting/FormattingExtensions.cs
+67
-0
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpSyntaxGeneratorInternal.cs
.../CSharp/LanguageServices/CSharpSyntaxGeneratorInternal.cs
+21
-0
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/Extensions/SyntaxGeneratorExtensions_Negate.cs
...space/Core/Extensions/SyntaxGeneratorExtensions_Negate.cs
+11
-8
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/SyntaxGeneratorInternalExtensions/SyntaxGeneratorInternal.cs
...taxGeneratorInternalExtensions/SyntaxGeneratorInternal.cs
+16
-0
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems
...ndExtensions/Workspace/Core/WorkspaceExtensions.projitems
+1
-0
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb
...ic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb
+24
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
...sic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
+1
-15
src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb
...Portable/Formatting/VisualBasicSyntaxFormattingService.vb
+4
-0
未找到文件。
src/CodeStyle/CSharp/Analyzers/CSharpFormattingAnalyzer.cs
浏览文件 @
750e1eb7
...
...
@@ -12,6 +12,6 @@ namespace Microsoft.CodeAnalysis.CodeStyle
internal
class
CSharpFormattingAnalyzer
:
AbstractFormattingAnalyzer
{
protected
override
ISyntaxFormattingService
SyntaxFormattingService
=>
new
CSharpSyntaxFormattingService
()
;
=>
CSharpSyntaxFormattingService
.
Instance
;
}
}
src/CodeStyle/CSharp/CodeFixes/CSharpFormattingCodeFixProvider.cs
浏览文件 @
750e1eb7
...
...
@@ -21,6 +21,6 @@ public CSharpFormattingCodeFixProvider()
{
}
protected
override
ISyntaxFormattingService
SyntaxFormattingService
=>
new
CSharpSyntaxFormattingService
()
;
protected
override
ISyntaxFormattingService
SyntaxFormattingService
=>
CSharpSyntaxFormattingService
.
Instance
;
}
}
src/CodeStyle/VisualBasic/Analyzers/VisualBasicFormattingAnalyzer.vb
浏览文件 @
750e1eb7
...
...
@@ -13,7 +13,7 @@ Namespace Microsoft.CodeAnalysis.CodeStyle
Protected
Overrides
ReadOnly
Property
SyntaxFormattingService
As
ISyntaxFormattingService
Get
Return
New
VisualBasicSyntaxFormattingService
()
Return
VisualBasicSyntaxFormattingService
.
Instance
End
Get
End
Property
End
Class
...
...
src/CodeStyle/VisualBasic/CodeFixes/VisualBasicFormattingCodeFixProvider.vb
浏览文件 @
750e1eb7
...
...
@@ -21,7 +21,7 @@ Namespace Microsoft.CodeAnalysis.CodeStyle
Protected
Overrides
ReadOnly
Property
SyntaxFormattingService
As
ISyntaxFormattingService
Get
Return
New
VisualBasicSyntaxFormattingService
()
Return
VisualBasicSyntaxFormattingService
.
Instance
End
Get
End
Property
End
Class
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
750e1eb7
...
...
@@ -15,7 +15,6 @@
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServices
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Simplification
;
...
...
@@ -43,8 +42,6 @@ public CSharpSyntaxGenerator()
internal
override
bool
RequiresExplicitImplementationForInterfaceMembers
=>
false
;
internal
override
ISyntaxFacts
SyntaxFacts
=>
CSharpSyntaxFacts
.
Instance
;
internal
override
SyntaxGeneratorInternal
SyntaxGeneratorInternal
=>
CSharpSyntaxGeneratorInternal
.
Instance
;
internal
override
SyntaxTrivia
EndOfLine
(
string
text
)
...
...
@@ -2940,9 +2937,6 @@ public override SyntaxNode NameOfExpression(SyntaxNode expression)
public
override
SyntaxNode
ReturnStatement
(
SyntaxNode
expressionOpt
=
null
)
=>
SyntaxFactory
.
ReturnStatement
((
ExpressionSyntax
)
expressionOpt
);
internal
override
SyntaxNode
YieldReturnStatement
(
SyntaxNode
expressionOpt
=
null
)
=>
SyntaxFactory
.
YieldStatement
(
SyntaxKind
.
YieldReturnStatement
,
(
ExpressionSyntax
)
expressionOpt
);
public
override
SyntaxNode
ThrowStatement
(
SyntaxNode
expressionOpt
=
null
)
=>
SyntaxFactory
.
ThrowStatement
((
ExpressionSyntax
)
expressionOpt
);
...
...
@@ -3134,11 +3128,8 @@ public override SyntaxNode DefaultExpression(ITypeSymbol type)
return
DefaultExpression
(
type
.
GenerateTypeSyntax
());
}
internal
override
SyntaxNode
AddParentheses
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
)
=>
Parenthesize
(
expression
,
includeElasticTrivia
,
addSimplifierAnnotation
);
private
static
ExpressionSyntax
Parenthesize
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
)
=>
((
ExpressionSyntax
)
expression
).
Parenthesize
(
includeElasticTrivia
,
addSimplifierAnnotation
);
=>
CSharpSyntaxGeneratorInternal
.
Parenthesize
(
expression
,
includeElasticTrivia
,
addSimplifierAnnotation
);
public
override
SyntaxNode
IsTypeExpression
(
SyntaxNode
expression
,
SyntaxNode
type
)
=>
SyntaxFactory
.
BinaryExpression
(
SyntaxKind
.
IsExpression
,
Parenthesize
(
expression
),
(
TypeSyntax
)
type
);
...
...
@@ -3479,9 +3470,6 @@ internal override SyntaxNode NamedAnonymousObjectMemberDeclarator(SyntaxNode ide
(
ExpressionSyntax
)
expression
);
}
internal
override
SyntaxNode
RefExpression
(
SyntaxNode
expression
)
=>
SyntaxFactory
.
RefExpression
((
ExpressionSyntax
)
expression
);
public
override
SyntaxNode
TupleExpression
(
IEnumerable
<
SyntaxNode
>
arguments
)
=>
SyntaxFactory
.
TupleExpression
(
SyntaxFactory
.
SeparatedList
(
arguments
.
Select
(
AsArgument
)));
...
...
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
浏览文件 @
750e1eb7
...
...
@@ -36,7 +36,7 @@ public abstract class SyntaxGenerator : ILanguageService
internal
abstract
SyntaxTrivia
CarriageReturnLineFeed
{
get
;
}
internal
abstract
SyntaxTrivia
ElasticCarriageReturnLineFeed
{
get
;
}
internal
abstract
bool
RequiresExplicitImplementationForInterfaceMembers
{
get
;
}
internal
abstract
ISyntaxFacts
SyntaxFacts
{
get
;
}
internal
ISyntaxFacts
SyntaxFacts
=>
SyntaxGeneratorInternal
.
SyntaxFacts
;
internal
abstract
SyntaxGeneratorInternal
SyntaxGeneratorInternal
{
get
;
}
internal
abstract
SyntaxTrivia
EndOfLine
(
string
text
);
...
...
@@ -1353,7 +1353,8 @@ protected static SyntaxList<TNode> RemoveRange<TNode>(SyntaxList<TNode> list, in
/// Creates a statement that can be used to yield a value from an iterator method.
/// </summary>
/// <param name="expression">An expression that can be yielded.</param>
internal
abstract
SyntaxNode
YieldReturnStatement
(
SyntaxNode
expression
);
internal
SyntaxNode
YieldReturnStatement
(
SyntaxNode
expression
)
=>
SyntaxGeneratorInternal
.
YieldReturnStatement
(
expression
);
/// <summary>
/// Creates a statement that can be used to throw an exception.
...
...
@@ -1924,7 +1925,8 @@ public virtual SyntaxNode MemberAccessExpression(SyntaxNode expression, SyntaxNo
internal
abstract
SyntaxNode
MemberAccessExpressionWorker
(
SyntaxNode
expression
,
SyntaxNode
memberName
);
internal
abstract
SyntaxNode
RefExpression
(
SyntaxNode
expression
);
internal
SyntaxNode
RefExpression
(
SyntaxNode
expression
)
=>
SyntaxGeneratorInternal
.
RefExpression
(
expression
);
/// <summary>
/// Creates a member access expression.
...
...
@@ -2140,7 +2142,8 @@ public SyntaxNode LambdaParameter(string identifier, ITypeSymbol type)
/// <summary>
/// Wraps with parens.
/// </summary>
internal
abstract
SyntaxNode
AddParentheses
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
);
internal
SyntaxNode
AddParentheses
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
)
=>
SyntaxGeneratorInternal
.
AddParentheses
(
expression
,
includeElasticTrivia
,
addSimplifierAnnotation
);
/// <summary>
/// Creates an nameof expression.
...
...
src/Workspaces/Core/Portable/Formatting/Formatter.cs
浏览文件 @
750e1eb7
...
...
@@ -14,6 +14,7 @@
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Text
;
using
Roslyn.Utilities
;
using
static
Microsoft
.
CodeAnalysis
.
Formatting
.
FormattingExtensions
;
namespace
Microsoft.CodeAnalysis.Formatting
{
...
...
@@ -298,73 +299,6 @@ internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnum
:
formattingResult
.
GetTextChanges
(
cancellationToken
);
}
private
static
IEnumerable
<
TextSpan
>
GetAnnotatedSpans
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
)
{
foreach
(
var
nodeOrToken
in
node
.
GetAnnotatedNodesAndTokens
(
annotation
))
{
var
firstToken
=
nodeOrToken
.
IsNode
?
nodeOrToken
.
AsNode
().
GetFirstToken
(
includeZeroWidth
:
true
)
:
nodeOrToken
.
AsToken
();
var
lastToken
=
nodeOrToken
.
IsNode
?
nodeOrToken
.
AsNode
().
GetLastToken
(
includeZeroWidth
:
true
)
:
nodeOrToken
.
AsToken
();
yield
return
GetSpan
(
firstToken
,
lastToken
);
}
}
private
static
TextSpan
GetSpan
(
SyntaxToken
firstToken
,
SyntaxToken
lastToken
)
{
var
previousToken
=
firstToken
.
GetPreviousToken
();
var
nextToken
=
lastToken
.
GetNextToken
();
if
(
previousToken
.
RawKind
!=
0
)
{
firstToken
=
previousToken
;
}
if
(
nextToken
.
RawKind
!=
0
)
{
lastToken
=
nextToken
;
}
return
TextSpan
.
FromBounds
(
firstToken
.
SpanStart
,
lastToken
.
Span
.
End
);
}
private
static
IEnumerable
<
TextSpan
>
GetElasticSpans
(
SyntaxNode
root
)
{
var
tokens
=
root
.
GetAnnotatedTrivia
(
SyntaxAnnotation
.
ElasticAnnotation
).
Select
(
tr
=>
tr
.
Token
).
Distinct
();
return
AggregateSpans
(
tokens
.
Select
(
t
=>
GetElasticSpan
(
t
)));
}
private
static
TextSpan
GetElasticSpan
(
SyntaxToken
token
)
=>
GetSpan
(
token
,
token
);
private
static
IEnumerable
<
TextSpan
>
AggregateSpans
(
IEnumerable
<
TextSpan
>
spans
)
{
var
aggregateSpans
=
new
List
<
TextSpan
>();
var
last
=
default
(
TextSpan
);
foreach
(
var
span
in
spans
)
{
if
(
last
==
default
)
{
last
=
span
;
}
else
if
(
span
.
IntersectsWith
(
last
))
{
last
=
TextSpan
.
FromBounds
(
last
.
Start
,
span
.
End
);
}
else
{
aggregateSpans
.
Add
(
last
);
last
=
span
;
}
}
if
(
last
!=
default
)
{
aggregateSpans
.
Add
(
last
);
}
return
aggregateSpans
;
}
/// <summary>
/// Organizes the imports in the document.
/// </summary>
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Formatting/CSharpSyntaxFormattingService.cs
浏览文件 @
750e1eb7
...
...
@@ -26,7 +26,10 @@ internal class CSharpSyntaxFormattingService : AbstractSyntaxFormattingService
{
private
readonly
ImmutableList
<
AbstractFormattingRule
>
_rules
;
#if !CODE_STYLE
#if CODE_STYLE
public
static
readonly
CSharpSyntaxFormattingService
Instance
=
new
CSharpSyntaxFormattingService
();
#else
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
#endif
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Formatting/FormattingExtensions.cs
浏览文件 @
750e1eb7
...
...
@@ -279,5 +279,72 @@ public static TextChange SimpleDiff(this TextChange textChange, string text)
return
new
TextChange
(
span
,
newText
);
}
internal
static
IEnumerable
<
TextSpan
>
GetAnnotatedSpans
(
SyntaxNode
node
,
SyntaxAnnotation
annotation
)
{
foreach
(
var
nodeOrToken
in
node
.
GetAnnotatedNodesAndTokens
(
annotation
))
{
var
firstToken
=
nodeOrToken
.
IsNode
?
nodeOrToken
.
AsNode
().
GetFirstToken
(
includeZeroWidth
:
true
)
:
nodeOrToken
.
AsToken
();
var
lastToken
=
nodeOrToken
.
IsNode
?
nodeOrToken
.
AsNode
().
GetLastToken
(
includeZeroWidth
:
true
)
:
nodeOrToken
.
AsToken
();
yield
return
GetSpan
(
firstToken
,
lastToken
);
}
}
internal
static
TextSpan
GetSpan
(
SyntaxToken
firstToken
,
SyntaxToken
lastToken
)
{
var
previousToken
=
firstToken
.
GetPreviousToken
();
var
nextToken
=
lastToken
.
GetNextToken
();
if
(
previousToken
.
RawKind
!=
0
)
{
firstToken
=
previousToken
;
}
if
(
nextToken
.
RawKind
!=
0
)
{
lastToken
=
nextToken
;
}
return
TextSpan
.
FromBounds
(
firstToken
.
SpanStart
,
lastToken
.
Span
.
End
);
}
internal
static
IEnumerable
<
TextSpan
>
GetElasticSpans
(
SyntaxNode
root
)
{
var
tokens
=
root
.
GetAnnotatedTrivia
(
SyntaxAnnotation
.
ElasticAnnotation
).
Select
(
tr
=>
tr
.
Token
).
Distinct
();
return
AggregateSpans
(
tokens
.
Select
(
t
=>
GetElasticSpan
(
t
)));
}
internal
static
TextSpan
GetElasticSpan
(
SyntaxToken
token
)
=>
GetSpan
(
token
,
token
);
private
static
IEnumerable
<
TextSpan
>
AggregateSpans
(
IEnumerable
<
TextSpan
>
spans
)
{
var
aggregateSpans
=
new
List
<
TextSpan
>();
var
last
=
default
(
TextSpan
);
foreach
(
var
span
in
spans
)
{
if
(
last
==
default
)
{
last
=
span
;
}
else
if
(
span
.
IntersectsWith
(
last
))
{
last
=
TextSpan
.
FromBounds
(
last
.
Start
,
span
.
End
);
}
else
{
aggregateSpans
.
Add
(
last
);
last
=
span
;
}
}
if
(
last
!=
default
)
{
aggregateSpans
.
Add
(
last
);
}
return
aggregateSpans
;
}
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/CSharp/LanguageServices/CSharpSyntaxGeneratorInternal.cs
浏览文件 @
750e1eb7
...
...
@@ -4,9 +4,12 @@
using
System.Composition
;
using
System.Diagnostics.CodeAnalysis
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.LanguageServices
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.LanguageServices
;
namespace
Microsoft.CodeAnalysis.CSharp.CodeGeneration
{
...
...
@@ -21,6 +24,8 @@ public CSharpSyntaxGeneratorInternal()
public
static
readonly
SyntaxGeneratorInternal
Instance
=
new
CSharpSyntaxGeneratorInternal
();
internal
override
ISyntaxFacts
SyntaxFacts
=>
CSharpSyntaxFacts
.
Instance
;
internal
override
SyntaxNode
LocalDeclarationStatement
(
SyntaxNode
type
,
SyntaxToken
name
,
SyntaxNode
initializer
,
bool
isConst
)
{
return
SyntaxFactory
.
LocalDeclarationStatement
(
...
...
@@ -52,5 +57,21 @@ internal override SyntaxNode ConditionalAccessExpression(SyntaxNode expression,
internal
override
SyntaxNode
MemberBindingExpression
(
SyntaxNode
name
)
=>
SyntaxFactory
.
MemberBindingExpression
((
SimpleNameSyntax
)
name
);
internal
override
SyntaxNode
RefExpression
(
SyntaxNode
expression
)
=>
SyntaxFactory
.
RefExpression
((
ExpressionSyntax
)
expression
);
internal
override
SyntaxNode
AddParentheses
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
)
{
return
Parenthesize
(
expression
,
includeElasticTrivia
,
addSimplifierAnnotation
);
}
internal
static
ExpressionSyntax
Parenthesize
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
)
{
return
((
ExpressionSyntax
)
expression
).
Parenthesize
(
includeElasticTrivia
,
addSimplifierAnnotation
);
}
internal
override
SyntaxNode
YieldReturnStatement
(
SyntaxNode
expressionOpt
=
null
)
=>
SyntaxFactory
.
YieldStatement
(
SyntaxKind
.
YieldReturnStatement
,
(
ExpressionSyntax
)
expressionOpt
);
}
}
src/Workspaces/
Core/Portable/Shared
/Extensions/SyntaxGeneratorExtensions_Negate.cs
→
src/Workspaces/
SharedUtilitiesAndExtensions/Workspace/Core
/Extensions/SyntaxGeneratorExtensions_Negate.cs
浏览文件 @
750e1eb7
...
...
@@ -33,25 +33,28 @@ internal static partial class SyntaxGeneratorExtensions
public
static
SyntaxNode
Negate
(
this
SyntaxGenerator
generator
,
SyntaxGeneratorInternal
generatorInternal
,
SyntaxNode
expression
,
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
{
return
Negate
(
generator
,
expression
,
semanticModel
,
negateBinary
:
true
,
cancellationToken
);
return
Negate
(
generator
,
generatorInternal
,
expression
,
semanticModel
,
negateBinary
:
true
,
cancellationToken
);
}
public
static
SyntaxNode
Negate
(
this
SyntaxGenerator
generator
,
SyntaxGeneratorInternal
generatorInternal
,
SyntaxNode
expression
,
SemanticModel
semanticModel
,
bool
negateBinary
,
CancellationToken
cancellationToken
)
{
var
syntaxFacts
=
generator
.
SyntaxFacts
;
var
syntaxFacts
=
generator
Internal
.
SyntaxFacts
;
if
(
syntaxFacts
.
IsParenthesizedExpression
(
expression
))
{
return
generator
.
AddParentheses
(
return
generator
Internal
.
AddParentheses
(
generator
.
Negate
(
generatorInternal
,
syntaxFacts
.
GetExpressionOfParenthesizedExpression
(
expression
),
semanticModel
,
negateBinary
,
...
...
@@ -60,7 +63,7 @@ internal static partial class SyntaxGeneratorExtensions
}
if
(
negateBinary
&&
syntaxFacts
.
IsBinaryExpression
(
expression
))
{
return
GetNegationOfBinaryExpression
(
expression
,
generator
,
semanticModel
,
cancellationToken
);
return
GetNegationOfBinaryExpression
(
expression
,
generator
,
generatorInternal
,
semanticModel
,
cancellationToken
);
}
else
if
(
syntaxFacts
.
IsLiteralExpression
(
expression
))
{
...
...
@@ -77,10 +80,11 @@ internal static partial class SyntaxGeneratorExtensions
private
static
SyntaxNode
GetNegationOfBinaryExpression
(
SyntaxNode
expressionNode
,
SyntaxGenerator
generator
,
SyntaxGeneratorInternal
generatorInternal
,
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
{
var
syntaxFacts
=
generator
.
SyntaxFacts
;
var
syntaxFacts
=
generator
Internal
.
SyntaxFacts
;
syntaxFacts
.
GetPartsOfBinaryExpression
(
expressionNode
,
out
var
leftOperand
,
out
var
operatorToken
,
out
var
rightOperand
);
var
binaryOperation
=
semanticModel
.
GetOperation
(
expressionNode
,
cancellationToken
)
as
IBinaryOperation
;
...
...
@@ -122,8 +126,8 @@ internal static partial class SyntaxGeneratorExtensions
var
newRightOperand
=
rightOperand
;
if
(
negateOperands
)
{
newLeftOperand
=
generator
.
Negate
(
leftOperand
,
semanticModel
,
cancellationToken
);
newRightOperand
=
generator
.
Negate
(
rightOperand
,
semanticModel
,
cancellationToken
);
newLeftOperand
=
generator
.
Negate
(
generatorInternal
,
leftOperand
,
semanticModel
,
cancellationToken
);
newRightOperand
=
generator
.
Negate
(
generatorInternal
,
rightOperand
,
semanticModel
,
cancellationToken
);
}
var
newBinaryExpressionSyntax
=
NewBinaryOperation
(
binaryOperation
,
newLeftOperand
,
negatedKind
,
newRightOperand
,
generator
,
cancellationToken
)
...
...
@@ -135,7 +139,6 @@ internal static partial class SyntaxGeneratorExtensions
}
}
private
static
SyntaxNode
NewBinaryOperation
(
IBinaryOperation
binaryOperation
,
SyntaxNode
leftOperand
,
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/LanguageServices/SyntaxGeneratorInternalExtensions/SyntaxGeneratorInternal.cs
浏览文件 @
750e1eb7
...
...
@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using
Microsoft.CodeAnalysis.Host
;
using
Microsoft.CodeAnalysis.LanguageServices
;
namespace
Microsoft.CodeAnalysis.Editing
{
...
...
@@ -15,6 +16,8 @@ namespace Microsoft.CodeAnalysis.Editing
/// </summary>
internal
abstract
class
SyntaxGeneratorInternal
:
ILanguageService
{
internal
abstract
ISyntaxFacts
SyntaxFacts
{
get
;
}
/// <summary>
/// Creates a statement that declares a single local variable with an optional initializer.
/// </summary>
...
...
@@ -36,5 +39,18 @@ internal SyntaxNode LocalDeclarationStatement(SyntaxToken name, SyntaxNode initi
internal
abstract
SyntaxNode
ConditionalAccessExpression
(
SyntaxNode
expression
,
SyntaxNode
whenNotNull
);
internal
abstract
SyntaxNode
MemberBindingExpression
(
SyntaxNode
name
);
internal
abstract
SyntaxNode
RefExpression
(
SyntaxNode
expression
);
/// <summary>
/// Wraps with parens.
/// </summary>
internal
abstract
SyntaxNode
AddParentheses
(
SyntaxNode
expression
,
bool
includeElasticTrivia
=
true
,
bool
addSimplifierAnnotation
=
true
);
/// <summary>
/// Creates a statement that can be used to yield a value from an iterator method.
/// </summary>
/// <param name="expression">An expression that can be yielded.</param>
internal
abstract
SyntaxNode
YieldReturnStatement
(
SyntaxNode
expression
);
}
}
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/WorkspaceExtensions.projitems
浏览文件 @
750e1eb7
...
...
@@ -12,6 +12,7 @@
<Compile
Include=
"$(MSBuildThisFileDirectory)Extensions\ContextQuery\SyntaxContext.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Extensions\HostWorkspaceServicesExtensions.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Extensions\SyntaxGeneratorExtensions.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Extensions\SyntaxGeneratorExtensions_Negate.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)Helpers\SimplificationHelpers.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)LanguageServices\AddImports\AbstractAddImportsService.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)LanguageServices\AddImports\AddImportHelpers.cs"
/>
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/VisualBasic/LanguageServices/VisualBasicSyntaxGeneratorInternal.vb
浏览文件 @
750e1eb7
...
...
@@ -6,6 +6,8 @@ Imports System.Composition
Imports
System.Diagnostics.CodeAnalysis
Imports
Microsoft.CodeAnalysis.Editing
Imports
Microsoft.CodeAnalysis.Host.Mef
Imports
Microsoft.CodeAnalysis.LanguageServices
Imports
Microsoft.CodeAnalysis.VisualBasic.LanguageServices
Imports
Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace
Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
...
...
@@ -20,6 +22,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Public
Sub
New
()
End
Sub
Friend
Overrides
ReadOnly
Property
SyntaxFacts
As
ISyntaxFacts
Get
Return
VisualBasicSyntaxFacts
.
Instance
End
Get
End
Property
Friend
Overloads
Overrides
Function
LocalDeclarationStatement
(
type
As
SyntaxNode
,
identifier
As
SyntaxToken
,
Optional
initializer
As
SyntaxNode
=
Nothing
,
Optional
isConst
As
Boolean
=
False
)
As
SyntaxNode
Return
SyntaxFactory
.
LocalDeclarationStatement
(
SyntaxFactory
.
TokenList
(
SyntaxFactory
.
Token
(
If
(
isConst
,
SyntaxKind
.
ConstKeyword
,
SyntaxKind
.
DimKeyword
))),
...
...
@@ -56,5 +64,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Friend
Overrides
Function
MemberBindingExpression
(
name
As
SyntaxNode
)
As
SyntaxNode
Return
SyntaxFactory
.
SimpleMemberAccessExpression
(
DirectCast
(
name
,
SimpleNameSyntax
))
End
Function
Friend
Overrides
Function
RefExpression
(
expression
As
SyntaxNode
)
As
SyntaxNode
Return
expression
End
Function
Friend
Overrides
Function
AddParentheses
(
expression
As
SyntaxNode
,
Optional
includeElasticTrivia
As
Boolean
=
True
,
Optional
addSimplifierAnnotation
As
Boolean
=
True
)
As
SyntaxNode
Return
Parenthesize
(
expression
,
addSimplifierAnnotation
)
End
Function
Friend
Shared
Function
Parenthesize
(
expression
As
SyntaxNode
,
Optional
addSimplifierAnnotation
As
Boolean
=
True
)
As
ParenthesizedExpressionSyntax
Return
DirectCast
(
expression
,
ExpressionSyntax
).
Parenthesize
(
addSimplifierAnnotation
)
End
Function
Friend
Overrides
Function
YieldReturnStatement
(
expression
As
SyntaxNode
)
As
SyntaxNode
Return
SyntaxFactory
.
YieldStatement
(
DirectCast
(
expression
,
ExpressionSyntax
))
End
Function
End
Class
End
Namespace
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
浏览文件 @
750e1eb7
...
...
@@ -31,8 +31,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Friend
Overrides
ReadOnly
Property
RequiresExplicitImplementationForInterfaceMembers
As
Boolean
=
True
Friend
Overrides
ReadOnly
Property
SyntaxFacts
As
ISyntaxFacts
=
VisualBasicSyntaxFacts
.
Instance
Friend
Overrides
ReadOnly
Property
SyntaxGeneratorInternal
As
SyntaxGeneratorInternal
=
VisualBasicSyntaxGeneratorInternal
.
Instance
Friend
Overrides
Function
EndOfLine
(
text
As
String
)
As
SyntaxTrivia
...
...
@@ -73,12 +71,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return
SyntaxFactory
.
TupleExpression
(
SyntaxFactory
.
SeparatedList
(
arguments
.
Select
(
AddressOf
AsSimpleArgument
)))
End
Function
Friend
Overrides
Function
AddParentheses
(
expression
As
SyntaxNode
,
Optional
includeElasticTrivia
As
Boolean
=
True
,
Optional
addSimplifierAnnotation
As
Boolean
=
True
)
As
SyntaxNode
Return
Parenthesize
(
expression
,
addSimplifierAnnotation
)
End
Function
Private
Function
Parenthesize
(
expression
As
SyntaxNode
,
Optional
addSimplifierAnnotation
As
Boolean
=
True
)
As
ParenthesizedExpressionSyntax
Return
DirectCast
(
expression
,
ExpressionSyntax
).
Parenthesize
(
addSimplifierAnnotation
)
Return
VisualBasicSyntaxGeneratorInternal
.
Parenthesize
(
expression
,
addSimplifierAnnotation
)
End
Function
Public
Overrides
Function
AddExpression
(
left
As
SyntaxNode
,
right
As
SyntaxNode
)
As
SyntaxNode
...
...
@@ -377,10 +371,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return
SyntaxFactory
.
ReturnStatement
(
DirectCast
(
expressionOpt
,
ExpressionSyntax
))
End
Function
Friend
Overrides
Function
YieldReturnStatement
(
expression
As
SyntaxNode
)
As
SyntaxNode
Return
SyntaxFactory
.
YieldStatement
(
DirectCast
(
expression
,
ExpressionSyntax
))
End
Function
Public
Overrides
Function
ThisExpression
()
As
SyntaxNode
Return
SyntaxFactory
.
MeExpression
()
End
Function
...
...
@@ -679,10 +669,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Throw
New
NotSupportedException
()
End
Function
Friend
Overrides
Function
RefExpression
(
expression
As
SyntaxNode
)
As
SyntaxNode
Return
expression
End
Function
#End Region
#Region "Declarations"
...
...
src/Workspaces/VisualBasic/Portable/Formatting/VisualBasicSyntaxFormattingService.vb
浏览文件 @
750e1eb7
...
...
@@ -26,6 +26,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Formatting
Private
ReadOnly
_rules
As
ImmutableList
(
Of
AbstractFormattingRule
)
#If CODE_STYLE Then
Public
Shared
ReadOnly
Instance
As
New
VisualBasicSyntaxFormattingService
#End If
#If Not CODE_STYLE Then
<
ImportingConstructor
>
<
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
True
)
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录