Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
aa2e439d
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,发现更多精彩内容 >>
提交
aa2e439d
编写于
2月 25, 2015
作者:
M
Matt Warren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for accessors and WriteOnly to SyntaxGenerator
上级
c29dc68a
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
687 addition
and
126 deletion
+687
-126
src/Compilers/CSharp/Portable/Syntax/SyntaxFormatter.cs
src/Compilers/CSharp/Portable/Syntax/SyntaxFormatter.cs
+28
-7
src/Compilers/VisualBasic/Portable/Syntax/SyntaxFormatter.vb
src/Compilers/VisualBasic/Portable/Syntax/SyntaxFormatter.vb
+17
-8
src/Diagnostics/FxCop/System.Runtime.Analyzers/Test/Design/DefineAccessorsForAttributeArgumentsTests.Fixer.cs
...Design/DefineAccessorsForAttributeArgumentsTests.Fixer.cs
+2
-2
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+194
-46
src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
...kspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
+79
-1
src/Workspaces/Core/Portable/Editing/DeclarationKind.cs
src/Workspaces/Core/Portable/Editing/DeclarationKind.cs
+6
-1
src/Workspaces/Core/Portable/Editing/DeclarationModifiers.cs
src/Workspaces/Core/Portable/Editing/DeclarationModifiers.cs
+15
-2
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
+26
-0
src/Workspaces/Core/Portable/PublicAPI.txt
src/Workspaces/Core/Portable/PublicAPI.txt
+12
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
...sic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
+221
-57
src/Workspaces/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
...es/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
+87
-2
未找到文件。
src/Compilers/CSharp/Portable/Syntax/SyntaxFormatter.cs
浏览文件 @
aa2e439d
...
...
@@ -11,6 +11,8 @@ namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
internal
class
SyntaxFormatter
:
CSharpSyntaxRewriter
{
private
readonly
TextSpan
_consideredSpan
;
private
readonly
int
_initialDepth
;
private
readonly
string
_indentWhitespace
;
private
readonly
bool
_useElasticTrivia
;
...
...
@@ -26,19 +28,20 @@ internal class SyntaxFormatter : CSharpSyntaxRewriter
// of the values between indentations[0] and indentations[initialDepth] (exclusive).
private
ArrayBuilder
<
SyntaxTrivia
>
_indentations
;
private
SyntaxFormatter
(
string
indentWhitespace
,
bool
useElasticTrivia
)
private
SyntaxFormatter
(
TextSpan
consideredSpan
,
int
initialDepth
,
string
indentWhitespace
,
bool
useElasticTrivia
)
:
base
(
visitIntoStructuredTrivia
:
true
)
{
_consideredSpan
=
consideredSpan
;
_initialDepth
=
initialDepth
;
_indentWhitespace
=
indentWhitespace
;
_useElasticTrivia
=
useElasticTrivia
;
_afterLineBreak
=
true
;
}
internal
static
TNode
Format
<
TNode
>(
TNode
node
,
string
indentWhitespace
,
bool
useElasticTrivia
=
false
)
where
TNode
:
SyntaxNode
{
var
formatter
=
new
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
);
var
formatter
=
new
SyntaxFormatter
(
node
.
FullSpan
,
GetDeclarationDepth
(
node
),
indentWhitespace
,
useElasticTrivia
);
var
result
=
(
TNode
)
formatter
.
Visit
(
node
);
formatter
.
Free
();
return
result
;
...
...
@@ -46,7 +49,7 @@ internal static TNode Format<TNode>(TNode node, string indentWhitespace, bool us
internal
static
SyntaxToken
Format
(
SyntaxToken
token
,
string
indentWhitespace
,
bool
useElasticTrivia
=
false
)
{
var
formatter
=
new
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
);
var
formatter
=
new
SyntaxFormatter
(
token
.
FullSpan
,
GetDeclarationDepth
(
token
),
indentWhitespace
,
useElasticTrivia
);
var
result
=
formatter
.
VisitToken
(
token
);
formatter
.
Free
();
return
result
;
...
...
@@ -54,7 +57,7 @@ internal static SyntaxToken Format(SyntaxToken token, string indentWhitespace, b
internal
static
SyntaxTriviaList
Format
(
SyntaxTriviaList
trivia
,
string
indentWhitespace
,
bool
useElasticTrivia
=
false
)
{
var
formatter
=
new
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
);
var
formatter
=
new
SyntaxFormatter
(
trivia
.
FullSpan
,
GetDeclarationDepth
(
trivia
.
Token
),
indentWhitespace
,
useElasticTrivia
);
var
result
=
formatter
.
RewriteTrivia
(
trivia
,
GetDeclarationDepth
((
SyntaxToken
)
trivia
.
ElementAt
(
0
).
Token
),
...
...
@@ -98,8 +101,7 @@ public override SyntaxToken VisitToken(SyntaxToken token)
mustHaveSeparator
:
false
,
lineBreaksAfter
:
lineBreaksAfter
));
// get next token, skipping zero width tokens except for end-of-directive tokens
var
nextToken
=
token
.
GetNextToken
(
t
=>
SyntaxToken
.
NonZeroWidth
(
t
)
||
t
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
,
t
=>
t
.
Kind
()
==
SyntaxKind
.
SkippedTokensTrivia
);
var
nextToken
=
this
.
GetNextRelevantToken
(
token
);
_afterLineBreak
=
EndsInLineBreak
(
token
);
_afterIndentation
=
false
;
...
...
@@ -127,8 +129,27 @@ public override SyntaxToken VisitToken(SyntaxToken token)
}
}
private
SyntaxToken
GetNextRelevantToken
(
SyntaxToken
token
)
{
// get next token, skipping zero width tokens except for end-of-directive tokens
var
nextToken
=
token
.
GetNextToken
(
t
=>
SyntaxToken
.
NonZeroWidth
(
t
)
||
t
.
Kind
()
==
SyntaxKind
.
EndOfDirectiveToken
,
t
=>
t
.
Kind
()
==
SyntaxKind
.
SkippedTokensTrivia
);
if
(
_consideredSpan
.
Contains
(
nextToken
.
FullSpan
))
{
return
nextToken
;
}
else
{
return
default
(
SyntaxToken
);
}
}
private
SyntaxTrivia
GetIndentation
(
int
count
)
{
count
=
Math
.
Max
(
count
-
_initialDepth
,
0
);
int
capacity
=
count
+
1
;
if
(
_indentations
==
null
)
{
...
...
src/Compilers/VisualBasic/Portable/Syntax/SyntaxFormatter.vb
浏览文件 @
aa2e439d
...
...
@@ -10,6 +10,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
Friend
Class
SyntaxFormatter
Inherits
VisualBasicSyntaxRewriter
Private
ReadOnly
consideredSpan
As
TextSpan
Private
ReadOnly
indentWhitespace
As
String
Private
ReadOnly
useElasticTrivia
As
Boolean
Private
ReadOnly
useDefaultCasing
As
Boolean
...
...
@@ -35,9 +36,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
''' <param name="useElasticTrivia">Whether to use elastic trivia or not</param>
''' <param name="useDefaultCasing">Whether to rewrite keywords in default casing or not</param>
''' <remarks></remarks>
Private
Sub
New
(
indentWhitespace
As
String
,
Optional
useElasticTrivia
As
Boolean
=
False
,
Optional
useDefaultCasing
As
Boolean
=
False
)
:
MyBase
.
New
(
V
isitIntoStructuredTrivia
:
=
True
)
Private
Sub
New
(
consideredSpan
As
TextSpan
,
indentWhitespace
As
String
,
Optional
useElasticTrivia
As
Boolean
=
False
,
Optional
useDefaultCasing
As
Boolean
=
False
)
MyBase
.
New
(
v
isitIntoStructuredTrivia
:
=
True
)
Me
.
consideredSpan
=
consideredSpan
Me
.
indentWhitespace
=
indentWhitespace
Me
.
useElasticTrivia
=
useElasticTrivia
Me
.
useDefaultCasing
=
useDefaultCasing
...
...
@@ -46,21 +48,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
End
Sub
Friend
Shared
Function
Format
(
Of
TNode
As
SyntaxNode
)(
node
As
TNode
,
indentWhitespace
As
String
,
Optional
useElasticTrivia
As
Boolean
=
False
,
Optional
useDefaultCasing
As
Boolean
=
False
)
As
SyntaxNode
Dim
formatter
As
New
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
formatter
As
New
SyntaxFormatter
(
node
.
FullSpan
,
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
result
As
TNode
=
CType
(
formatter
.
Visit
(
node
),
TNode
)
formatter
.
Free
()
Return
result
End
Function
Friend
Shared
Function
Format
(
token
As
SyntaxToken
,
indentWhitespace
As
String
,
Optional
useElasticTrivia
As
Boolean
=
False
,
Optional
useDefaultCasing
As
Boolean
=
False
)
As
SyntaxToken
Dim
formatter
As
New
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
formatter
As
New
SyntaxFormatter
(
token
.
FullSpan
,
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
result
As
SyntaxToken
=
formatter
.
VisitToken
(
token
)
formatter
.
Free
()
Return
result
End
Function
Friend
Shared
Function
Format
(
trivia
As
SyntaxTriviaList
,
indentWhitespace
As
String
,
Optional
useElasticTrivia
As
Boolean
=
False
,
Optional
useDefaultCasing
As
Boolean
=
False
)
As
SyntaxTriviaList
Dim
formatter
=
New
SyntaxFormatter
(
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
formatter
=
New
SyntaxFormatter
(
trivia
.
FullSpan
,
indentWhitespace
,
useElasticTrivia
,
useDefaultCasing
)
Dim
result
As
SyntaxTriviaList
=
formatter
.
RewriteTrivia
(
trivia
,
formatter
.
GetIndentationDepth
(),
isTrailing
:
=
False
,
...
...
@@ -659,9 +661,16 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
End
Function
Private
Function
GetNextRelevantToken
(
token
As
SyntaxToken
)
As
SyntaxToken
Return
token
.
GetNextToken
(
Function
(
t
As
SyntaxToken
)
Return
t
.
Kind
<>
SyntaxKind
.
None
End
Function
,
Function
(
t
As
SyntaxTrivia
)
False
)
Dim
nextToken
=
token
.
GetNextToken
(
Function
(
t
As
SyntaxToken
)
Return
t
.
Kind
<>
SyntaxKind
.
None
End
Function
,
Function
(
t
As
SyntaxTrivia
)
False
)
If
consideredSpan
.
Contains
(
nextToken
.
FullSpan
)
Then
Return
nextToken
Else
Return
Nothing
End
If
End
Function
Private
Sub
AddLinebreaksAfterElementsIfNeeded
(
Of
TNode
As
SyntaxNode
)(
...
...
src/Diagnostics/FxCop/System.Runtime.Analyzers/Test/Design/DefineAccessorsForAttributeArgumentsTests.Fixer.cs
浏览文件 @
aa2e439d
...
...
@@ -86,8 +86,8 @@ public SetterOnlyTestAttribute(string name)
}
public string Name
{
set { m_name = value }
{
internal
set { m_name = value }
get;
}
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
aa2e439d
此差异已折叠。
点击以展开。
src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
浏览文件 @
aa2e439d
...
...
@@ -647,10 +647,18 @@ public void TestPropertyDeclarations()
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
|
DeclarationModifiers
.
ReadOnly
),
"abstract x p\r\n{\r\n get;\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
|
DeclarationModifiers
.
WriteOnly
),
"abstract x p\r\n{\r\n set;\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
ReadOnly
),
"x p\r\n{\r\n get\r\n {\r\n }\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
WriteOnly
),
"x p\r\n{\r\n set\r\n {\r\n }\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
),
"abstract x p\r\n{\r\n get;\r\n set;\r\n}"
);
...
...
@@ -659,6 +667,10 @@ public void TestPropertyDeclarations()
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
ReadOnly
,
getAccessorStatements
:
new
[]
{
_g
.
IdentifierName
(
"y"
)
}),
"x p\r\n{\r\n get\r\n {\r\n y;\r\n }\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
WriteOnly
,
setAccessorStatements
:
new
[]
{
_g
.
IdentifierName
(
"y"
)
}),
"x p\r\n{\r\n set\r\n {\r\n y;\r\n }\r\n}"
);
VerifySyntax
<
PropertyDeclarationSyntax
>(
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"x"
),
setAccessorStatements
:
new
[]
{
_g
.
IdentifierName
(
"y"
)
}),
"x p\r\n{\r\n get\r\n {\r\n }\r\n\r\n set\r\n {\r\n y;\r\n }\r\n}"
);
...
...
@@ -671,6 +683,10 @@ public void TestIndexerDeclarations()
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
|
DeclarationModifiers
.
ReadOnly
),
"abstract x this[y z]\r\n{\r\n get;\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
|
DeclarationModifiers
.
WriteOnly
),
"abstract x this[y z]\r\n{\r\n set;\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
Abstract
),
"abstract x this[y z]\r\n{\r\n get;\r\n set;\r\n}"
);
...
...
@@ -679,11 +695,20 @@ public void TestIndexerDeclarations()
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
ReadOnly
),
"x this[y z]\r\n{\r\n get\r\n {\r\n }\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
WriteOnly
),
"x this[y z]\r\n{\r\n set\r\n {\r\n }\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
ReadOnly
,
getAccessorStatements
:
new
[]
{
_g
.
IdentifierName
(
"a"
)
}),
"x this[y z]\r\n{\r\n get\r\n {\r\n a;\r\n }\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
),
modifiers
:
DeclarationModifiers
.
WriteOnly
,
setAccessorStatements
:
new
[]
{
_g
.
IdentifierName
(
"a"
)
}),
"x this[y z]\r\n{\r\n set\r\n {\r\n a;\r\n }\r\n}"
);
VerifySyntax
<
IndexerDeclarationSyntax
>(
_g
.
IndexerDeclaration
(
new
[]
{
_g
.
ParameterDeclaration
(
"z"
,
_g
.
IdentifierName
(
"y"
))
},
_g
.
IdentifierName
(
"x"
)),
"x this[y z]\r\n{\r\n get\r\n {\r\n }\r\n\r\n set\r\n {\r\n }\r\n}"
);
...
...
@@ -1179,7 +1204,7 @@ public class C { } // end").Members[0];
VerifySyntax
<
ClassDeclarationSyntax
>(
removed
,
"// comment\r\npublic class C\r\n{\r\n} // end\r\n"
);
var
attrWithComment
=
_g
.
GetAttributes
(
added
).
First
();
VerifySyntax
<
AttributeListSyntax
>(
attrWithComment
,
"// comment\r\n[a]
\r\n
"
);
VerifySyntax
<
AttributeListSyntax
>(
attrWithComment
,
"// comment\r\n[a]"
);
// added attributes are stripped of trivia
var
added2
=
_g
.
AddAttributes
(
cls
,
attrWithComment
);
...
...
@@ -1740,6 +1765,59 @@ public void TestWithExpression()
Assert
.
Null
(
_g
.
GetExpression
(
_g
.
WithExpression
(
_g
.
IdentifierName
(
"e"
),
_g
.
IdentifierName
(
"x"
))));
}
[
Fact
]
public
void
TestAccessorDeclarations
()
{
var
prop
=
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"T"
));
Assert
.
Equal
(
2
,
_g
.
GetAccessors
(
prop
).
Count
);
// get accessors from property
var
getAccessor
=
_g
.
GetAccessor
(
prop
,
DeclarationKind
.
GetAccessor
);
Assert
.
NotNull
(
getAccessor
);
VerifySyntax
<
AccessorDeclarationSyntax
>(
getAccessor
,
@"get
{
}"
);
Assert
.
NotNull
(
getAccessor
);
Assert
.
Equal
(
Accessibility
.
NotApplicable
,
_g
.
GetAccessibility
(
getAccessor
));
// get accessors from property
var
setAccessor
=
_g
.
GetAccessor
(
prop
,
DeclarationKind
.
SetAccessor
);
Assert
.
NotNull
(
setAccessor
);
Assert
.
Equal
(
Accessibility
.
NotApplicable
,
_g
.
GetAccessibility
(
setAccessor
));
// remove accessors
Assert
.
Null
(
_g
.
GetAccessor
(
_g
.
RemoveNode
(
prop
,
getAccessor
),
DeclarationKind
.
GetAccessor
));
Assert
.
Null
(
_g
.
GetAccessor
(
_g
.
RemoveNode
(
prop
,
setAccessor
),
DeclarationKind
.
SetAccessor
));
// change accessor accessibility
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
WithAccessibility
(
getAccessor
,
Accessibility
.
Public
)));
Assert
.
Equal
(
Accessibility
.
Private
,
_g
.
GetAccessibility
(
_g
.
WithAccessibility
(
setAccessor
,
Accessibility
.
Private
)));
// change accessor statements
Assert
.
Equal
(
0
,
_g
.
GetStatements
(
getAccessor
).
Count
);
Assert
.
Equal
(
0
,
_g
.
GetStatements
(
setAccessor
).
Count
);
var
newGetAccessor
=
_g
.
WithStatements
(
getAccessor
,
null
);
VerifySyntax
<
AccessorDeclarationSyntax
>(
newGetAccessor
,
@"get;"
);
var
newNewGetAccessor
=
_g
.
WithStatements
(
newGetAccessor
,
new
SyntaxNode
[]
{
});
VerifySyntax
<
AccessorDeclarationSyntax
>(
newNewGetAccessor
,
@"get
{
}"
);
// change accessors
var
newProp
=
_g
.
ReplaceNode
(
prop
,
getAccessor
,
_g
.
WithAccessibility
(
getAccessor
,
Accessibility
.
Public
));
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
GetAccessor
(
newProp
,
DeclarationKind
.
GetAccessor
)));
newProp
=
_g
.
ReplaceNode
(
prop
,
setAccessor
,
_g
.
WithAccessibility
(
setAccessor
,
Accessibility
.
Public
));
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
GetAccessor
(
newProp
,
DeclarationKind
.
SetAccessor
)));
}
[
Fact
]
public
void
TestGetStatements
()
{
...
...
src/Workspaces/Core/Portable/Editing/DeclarationKind.cs
浏览文件 @
aa2e439d
...
...
@@ -30,6 +30,11 @@ public enum DeclarationKind
Parameter
,
Variable
,
Attribute
,
LambdaExpression
LambdaExpression
,
GetAccessor
,
SetAccessor
,
AddAccessor
,
RemoveAccessor
,
RaiseAccessor
}
}
src/Workspaces/Core/Portable/Editing/DeclarationModifiers.cs
浏览文件 @
aa2e439d
...
...
@@ -26,7 +26,8 @@ private DeclarationModifiers(Modifiers modifiers)
bool
isConst
=
false
,
bool
isWithEvents
=
false
,
bool
isPartial
=
false
,
bool
isAsync
=
false
)
bool
isAsync
=
false
,
bool
isWriteOnly
=
false
)
:
this
(
(
isStatic
?
Modifiers
.
Static
:
Modifiers
.
None
)
|
(
isAbstract
?
Modifiers
.
Abstract
:
Modifiers
.
None
)
|
...
...
@@ -120,6 +121,11 @@ public bool IsAsync
get
{
return
(
_modifiers
&
Modifiers
.
Async
)
!=
0
;
}
}
public
bool
IsWriteOnly
{
get
{
return
(
_modifiers
&
Modifiers
.
WriteOnly
)
!=
0
;
}
}
public
DeclarationModifiers
WithIsStatic
(
bool
isStatic
)
{
return
new
DeclarationModifiers
(
SetFlag
(
_modifiers
,
Modifiers
.
Static
,
isStatic
));
...
...
@@ -180,6 +186,11 @@ public DeclarationModifiers WithAsync(bool isAsync)
return
new
DeclarationModifiers
(
SetFlag
(
_modifiers
,
Modifiers
.
Async
,
isAsync
));
}
public
DeclarationModifiers
WithIsWriteOnly
(
bool
isWriteOnly
)
{
return
new
DeclarationModifiers
(
SetFlag
(
_modifiers
,
Modifiers
.
WriteOnly
,
isWriteOnly
));
}
private
static
Modifiers
SetFlag
(
Modifiers
existing
,
Modifiers
modifier
,
bool
isSet
)
{
return
isSet
?
(
existing
|
modifier
)
:
(
existing
&
~
modifier
);
...
...
@@ -200,7 +211,8 @@ private enum Modifiers
Const
=
0x0100
,
WithEvents
=
0x0200
,
Partial
=
0x0400
,
Async
=
0x0800
Async
=
0x0800
,
WriteOnly
=
0x1000
}
public
static
readonly
DeclarationModifiers
None
=
default
(
DeclarationModifiers
);
...
...
@@ -217,6 +229,7 @@ private enum Modifiers
public
static
readonly
DeclarationModifiers
WithEvents
=
new
DeclarationModifiers
(
Modifiers
.
WithEvents
);
public
static
readonly
DeclarationModifiers
Partial
=
new
DeclarationModifiers
(
Modifiers
.
Partial
);
public
static
readonly
DeclarationModifiers
Async
=
new
DeclarationModifiers
(
Modifiers
.
Async
);
public
static
readonly
DeclarationModifiers
WriteOnly
=
new
DeclarationModifiers
(
Modifiers
.
WriteOnly
);
public
static
DeclarationModifiers
operator
|(
DeclarationModifiers
left
,
DeclarationModifiers
right
)
{
...
...
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
浏览文件 @
aa2e439d
...
...
@@ -901,6 +901,32 @@ public SyntaxNode AddParameters(SyntaxNode declaration, IEnumerable<SyntaxNode>
/// </summary>
public
abstract
SyntaxNode
WithStatements
(
SyntaxNode
declaration
,
IEnumerable
<
SyntaxNode
>
statements
);
/// <summary>
/// Gets the accessors for the declaration.
/// </summary>
public
abstract
IReadOnlyList
<
SyntaxNode
>
GetAccessors
(
SyntaxNode
declaration
);
/// <summary>
/// Gets the accessor of the specified kind for the declaration.
/// </summary>
public
SyntaxNode
GetAccessor
(
SyntaxNode
declaration
,
DeclarationKind
kind
)
{
return
this
.
GetAccessors
(
declaration
).
FirstOrDefault
(
a
=>
GetDeclarationKind
(
a
)
==
kind
);
}
/// <summary>
/// Creates a new instance of the declaration with the accessors inserted.
/// </summary>
public
abstract
SyntaxNode
InsertAccessors
(
SyntaxNode
declaration
,
int
index
,
IEnumerable
<
SyntaxNode
>
accessors
);
/// <summary>
/// Creates a new instance of the declaration with the accessors added.
/// </summary>
public
SyntaxNode
AddAccessors
(
SyntaxNode
declaration
,
IEnumerable
<
SyntaxNode
>
accessors
)
{
return
this
.
InsertAccessors
(
declaration
,
this
.
GetAccessors
(
declaration
).
Count
,
accessors
);
}
/// <summary>
/// Gets the statements for the body of the get-accessor of the declaration.
/// </summary>
...
...
src/Workspaces/Core/Portable/PublicAPI.txt
浏览文件 @
aa2e439d
...
...
@@ -170,6 +170,7 @@ Microsoft.CodeAnalysis.DocumentInfo.WithName(string name)
Microsoft.CodeAnalysis.DocumentInfo.WithSourceCodeKind(Microsoft.CodeAnalysis.SourceCodeKind kind)
Microsoft.CodeAnalysis.DocumentInfo.WithTextLoader(Microsoft.CodeAnalysis.TextLoader loader)
Microsoft.CodeAnalysis.Editing.DeclarationKind
Microsoft.CodeAnalysis.Editing.DeclarationKind.AddAccessor = 26
Microsoft.CodeAnalysis.Editing.DeclarationKind.Attribute = 22
Microsoft.CodeAnalysis.Editing.DeclarationKind.Class = 2
Microsoft.CodeAnalysis.Editing.DeclarationKind.CompilationUnit = 1
...
...
@@ -182,6 +183,7 @@ Microsoft.CodeAnalysis.Editing.DeclarationKind.Enum = 5
Microsoft.CodeAnalysis.Editing.DeclarationKind.EnumMember = 15
Microsoft.CodeAnalysis.Editing.DeclarationKind.Event = 16
Microsoft.CodeAnalysis.Editing.DeclarationKind.Field = 12
Microsoft.CodeAnalysis.Editing.DeclarationKind.GetAccessor = 24
Microsoft.CodeAnalysis.Editing.DeclarationKind.Indexer = 14
Microsoft.CodeAnalysis.Editing.DeclarationKind.Interface = 4
Microsoft.CodeAnalysis.Editing.DeclarationKind.LambdaExpression = 23
...
...
@@ -192,6 +194,9 @@ Microsoft.CodeAnalysis.Editing.DeclarationKind.None = 0
Microsoft.CodeAnalysis.Editing.DeclarationKind.Operator = 8
Microsoft.CodeAnalysis.Editing.DeclarationKind.Parameter = 20
Microsoft.CodeAnalysis.Editing.DeclarationKind.Property = 13
Microsoft.CodeAnalysis.Editing.DeclarationKind.RaiseAccessor = 28
Microsoft.CodeAnalysis.Editing.DeclarationKind.RemoveAccessor = 27
Microsoft.CodeAnalysis.Editing.DeclarationKind.SetAccessor = 25
Microsoft.CodeAnalysis.Editing.DeclarationKind.Struct = 3
Microsoft.CodeAnalysis.Editing.DeclarationKind.Variable = 21
Microsoft.CodeAnalysis.Editing.DeclarationModifiers
...
...
@@ -208,6 +213,7 @@ Microsoft.CodeAnalysis.Editing.DeclarationModifiers.IsStatic.get
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.IsUnsafe.get
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.IsVirtual.get
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.IsWithEvents.get
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.IsWriteOnly.get
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithAsync(bool isAsync)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsAbstract(bool isAbstract)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsConst(bool isConst)
...
...
@@ -218,6 +224,7 @@ Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsSealed(bool isSealed)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsStatic(bool isStatic)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsUnsafe(bool isUnsafe)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsVirtual(bool isVirtual)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithIsWriteOnly(bool isWriteOnly)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithPartial(bool isPartial)
Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithWithEvents(bool withEvents)
Microsoft.CodeAnalysis.Editing.DocumentEditor
...
...
@@ -266,6 +273,7 @@ Microsoft.CodeAnalysis.Editing.SyntaxEditor.SyntaxEditor(Microsoft.CodeAnalysis.
Microsoft.CodeAnalysis.Editing.SyntaxEditor.TrackNode(Microsoft.CodeAnalysis.SyntaxNode node)
Microsoft.CodeAnalysis.Editing.SyntaxEditorExtensions
Microsoft.CodeAnalysis.Editing.SyntaxGenerator
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AddAccessors(Microsoft.CodeAnalysis.SyntaxNode declaration, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> accessors)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AddAttributeArguments(Microsoft.CodeAnalysis.SyntaxNode attributeDeclaration, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> attributeArguments)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AddAttributes(Microsoft.CodeAnalysis.SyntaxNode declaration, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> attributes)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.AddAttributes(Microsoft.CodeAnalysis.SyntaxNode declaration, params Microsoft.CodeAnalysis.SyntaxNode[] attributes)
...
...
@@ -299,6 +307,7 @@ Microsoft.CodeAnalysis.Editing.SyntaxGenerator.FieldDeclaration(Microsoft.CodeAn
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GenericName(string identifier, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.ITypeSymbol> typeArguments)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GenericName(string identifier, params Microsoft.CodeAnalysis.ITypeSymbol[] typeArguments)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GenericName(string identifier, params Microsoft.CodeAnalysis.SyntaxNode[] typeArguments)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetAccessor(Microsoft.CodeAnalysis.SyntaxNode declaration, Microsoft.CodeAnalysis.Editing.DeclarationKind kind)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetDeclaration(Microsoft.CodeAnalysis.SyntaxNode node)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetDeclaration(Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.Editing.DeclarationKind kind)
Microsoft.CodeAnalysis.Editing.SyntaxGenerator.IfStatement(Microsoft.CodeAnalysis.SyntaxNode condition, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> trueStatements, Microsoft.CodeAnalysis.SyntaxNode falseStatement)
...
...
@@ -873,6 +882,7 @@ abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.ExpressionStatement(Micr
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.FieldDeclaration(string name, Microsoft.CodeAnalysis.SyntaxNode type, Microsoft.CodeAnalysis.Accessibility accessibility = Microsoft.CodeAnalysis.Accessibility.NotApplicable, Microsoft.CodeAnalysis.Editing.DeclarationModifiers modifiers = default(Microsoft.CodeAnalysis.Editing.DeclarationModifiers), Microsoft.CodeAnalysis.SyntaxNode initializer = null)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GenericName(string identifier, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> typeArguments)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetAccessibility(Microsoft.CodeAnalysis.SyntaxNode declaration)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetAccessors(Microsoft.CodeAnalysis.SyntaxNode declaration)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetAttributeArguments(Microsoft.CodeAnalysis.SyntaxNode attributeDeclaration)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetAttributes(Microsoft.CodeAnalysis.SyntaxNode declaration)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetBaseAndInterfaceTypes(Microsoft.CodeAnalysis.SyntaxNode declaration)
...
...
@@ -893,6 +903,7 @@ abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GreaterThanOrEqualExpres
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.IdentifierName(string identifier)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.IfStatement(Microsoft.CodeAnalysis.SyntaxNode condition, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> trueStatements, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> falseStatements = null)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.IndexerDeclaration(System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> parameters, Microsoft.CodeAnalysis.SyntaxNode type, Microsoft.CodeAnalysis.Accessibility accessibility = Microsoft.CodeAnalysis.Accessibility.NotApplicable, Microsoft.CodeAnalysis.Editing.DeclarationModifiers modifiers = default(Microsoft.CodeAnalysis.Editing.DeclarationModifiers), System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> getAccessorStatements = null, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> setAccessorStatements = null)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.InsertAccessors(Microsoft.CodeAnalysis.SyntaxNode declaration, int index, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> accessors)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.InsertAttributeArguments(Microsoft.CodeAnalysis.SyntaxNode attributeDeclaration, int index, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> attributeArguments)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.InsertAttributes(Microsoft.CodeAnalysis.SyntaxNode declaration, int index, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> attributes)
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.InsertMembers(Microsoft.CodeAnalysis.SyntaxNode declaration, int index, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> members)
...
...
@@ -1193,6 +1204,7 @@ static readonly Microsoft.CodeAnalysis.Editing.DeclarationModifiers.Static
static readonly Microsoft.CodeAnalysis.Editing.DeclarationModifiers.Unsafe
static readonly Microsoft.CodeAnalysis.Editing.DeclarationModifiers.Virtual
static readonly Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WithEvents
static readonly Microsoft.CodeAnalysis.Editing.DeclarationModifiers.WriteOnly
static readonly Microsoft.CodeAnalysis.Formatting.Formatter.Annotation
static readonly Microsoft.CodeAnalysis.Formatting.FormattingOptions.IndentationSize
static readonly Microsoft.CodeAnalysis.Formatting.FormattingOptions.NewLine
...
...
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
浏览文件 @
aa2e439d
此差异已折叠。
点击以展开。
src/Workspaces/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
浏览文件 @
aa2e439d
...
...
@@ -688,6 +688,10 @@ End Function</x>.Value)
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
+
DeclarationModifiers
.
ReadOnly
),
<
x
>
MustInherit
ReadOnly
Property
p
As
x
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyStatementSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
+
DeclarationModifiers
.
WriteOnly
),
<
x
>
MustInherit
WriteOnly
Property
p
As
x
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
ReadOnly
),
<
x
>
ReadOnly
Property
p
As
x
...
...
@@ -695,6 +699,13 @@ End Function</x>.Value)
End
Get
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
WriteOnly
),
<
x
>
WriteOnly
Property
p
As
x
Set
(
value
As
x
)
End
Set
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyStatementSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
),
<
x
>
MustInherit
Property
p
As
x
</
x
>
.
Value
)
...
...
@@ -707,6 +718,14 @@ End Property</x>.Value)
End
Get
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
WriteOnly
,
setAccessorStatements
:
=
{
g
.
IdentifierName
(
"y"
)}),
<
x
>
WriteOnly
Property
p
As
x
Set
(
value
As
x
)
y
End
Set
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
PropertyDeclaration
(
"p"
,
g
.
IdentifierName
(
"x"
),
setAccessorStatements
:
=
{
g
.
IdentifierName
(
"y"
)}),
<
x
>
Property
p
As
x
...
...
@@ -725,6 +744,10 @@ End Property</x>.Value)
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
+
DeclarationModifiers
.
ReadOnly
),
<
x
>
Default
MustInherit
ReadOnly
Property
Item
(
z
As
y
)
As
x
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyStatementSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
+
DeclarationModifiers
.
WriteOnly
),
<
x
>
Default
MustInherit
WriteOnly
Property
Item
(
z
As
y
)
As
x
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyStatementSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
Abstract
),
<
x
>
Default
MustInherit
Property
Item
(
z
As
y
)
As
x
</
x
>
.
Value
)
...
...
@@ -736,6 +759,13 @@ End Property</x>.Value)
End
Get
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
WriteOnly
),
<
x
>
Default
WriteOnly
Property
Item
(
z
As
y
)
As
x
Set
(
value
As
x
)
End
Set
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
ReadOnly
,
getAccessorStatements
:
=
{
g
.
IdentifierName
(
"a"
)}),
...
...
@@ -745,6 +775,15 @@ End Property</x>.Value)
End
Get
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
WriteOnly
,
setAccessorStatements
:
=
{
g
.
IdentifierName
(
"a"
)}),
<
x
>
Default
WriteOnly
Property
Item
(
z
As
y
)
As
x
Set
(
value
As
x
)
a
End
Set
End
Property
</
x
>
.
Value
)
VerifySyntax
(
Of
PropertyBlockSyntax
)(
g
.
IndexerDeclaration
({
g
.
ParameterDeclaration
(
"z"
,
g
.
IdentifierName
(
"y"
))},
g
.
IdentifierName
(
"x"
),
modifiers
:
=
DeclarationModifiers
.
None
),
<
x
>
Default
Property
Item
(
z
As
y
)
As
x
...
...
@@ -1682,8 +1721,7 @@ End Class ' end</x>.Value)
VerifySyntax
(
Of
AttributeListSyntax
)(
attrWithComment
,
<
x
>
' comment
&
lt
;
a>
;
</
x
>
.
Value
)
&
lt
;
a>
;
</
x
>
.
Value
)
' added attributes are stripped of trivia
Dim
added2
=
g
.
AddAttributes
(
cls
,
attrWithComment
)
...
...
@@ -2151,6 +2189,53 @@ End Sub</x>.Value)
End
Function
</
x
>
.
Value
)
End
Sub
<
Fact
>
Public
Sub
TestAccessorDeclarations
()
Dim
_g
=
g
Dim
prop
=
_g
.
PropertyDeclaration
(
"p"
,
_g
.
IdentifierName
(
"T"
))
Assert
.
Equal
(
2
,
_g
.
GetAccessors
(
prop
).
Count
)
' get accessors from property
Dim
getAccessor
=
_g
.
GetAccessor
(
prop
,
DeclarationKind
.
GetAccessor
)
Assert
.
NotNull
(
getAccessor
)
VerifySyntax
(
Of
AccessorBlockSyntax
)(
getAccessor
,
<
x
>
Get
End
Get
</
x
>
.
Value
)
Assert
.
NotNull
(
getAccessor
)
Assert
.
Equal
(
Accessibility
.
NotApplicable
,
_g
.
GetAccessibility
(
getAccessor
))
' get accessors from property
Dim
setAccessor
=
_g
.
GetAccessor
(
prop
,
DeclarationKind
.
SetAccessor
)
Assert
.
NotNull
(
setAccessor
)
Assert
.
Equal
(
Accessibility
.
NotApplicable
,
_g
.
GetAccessibility
(
setAccessor
))
' remove accessors
Assert
.
Null
(
_g
.
GetAccessor
(
_g
.
RemoveNode
(
prop
,
getAccessor
),
DeclarationKind
.
GetAccessor
))
Assert
.
Null
(
_g
.
GetAccessor
(
_g
.
RemoveNode
(
prop
,
setAccessor
),
DeclarationKind
.
SetAccessor
))
' change accessor accessibility
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
WithAccessibility
(
getAccessor
,
Accessibility
.
Public
)))
Assert
.
Equal
(
Accessibility
.
Private
,
_g
.
GetAccessibility
(
_g
.
WithAccessibility
(
setAccessor
,
Accessibility
.
Private
)))
' change accessor statements
Assert
.
Equal
(
0
,
_g
.
GetStatements
(
getAccessor
).
Count
)
Assert
.
Equal
(
0
,
_g
.
GetStatements
(
setAccessor
).
Count
)
Dim
newGetAccessor
=
_g
.
WithStatements
(
getAccessor
,
Nothing
)
VerifySyntax
(
Of
AccessorBlockSyntax
)(
newGetAccessor
,
<
x
>
Get
End
Get
</
x
>
.
Value
)
' change accessors
Dim
newProp
=
_g
.
ReplaceNode
(
prop
,
getAccessor
,
_g
.
WithAccessibility
(
getAccessor
,
Accessibility
.
Public
))
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
GetAccessor
(
newProp
,
DeclarationKind
.
GetAccessor
)))
newProp
=
_g
.
ReplaceNode
(
prop
,
setAccessor
,
_g
.
WithAccessibility
(
setAccessor
,
Accessibility
.
Public
))
Assert
.
Equal
(
Accessibility
.
Public
,
_g
.
GetAccessibility
(
_g
.
GetAccessor
(
newProp
,
DeclarationKind
.
SetAccessor
)))
End
Sub
<
Fact
>
Public
Sub
TestGetAccessorStatements
()
Dim
stmts
=
{
g
.
ExpressionStatement
(
g
.
AssignmentStatement
(
g
.
IdentifierName
(
"x"
),
g
.
IdentifierName
(
"y"
))),
g
.
ExpressionStatement
(
g
.
InvocationExpression
(
g
.
IdentifierName
(
"fn"
),
g
.
IdentifierName
(
"arg"
)))}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录