Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a64937b0
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,发现更多精彩内容 >>
提交
a64937b0
编写于
3月 19, 2015
作者:
W
Wonseok Chae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[EnC] Make it a rude edit to change the value of a constant field
上级
84d8c5aa
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
99 addition
and
8 deletion
+99
-8
src/EditorFeatures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
...atures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
+2
-2
src/EditorFeatures/CSharpTest/EditAndContinue/RudeEditTopLevelTests.cs
...tures/CSharpTest/EditAndContinue/RudeEditTopLevelTests.cs
+43
-0
src/EditorFeatures/VisualBasicTest/EditAndContinue/ActiveStatementTests.vb
...s/VisualBasicTest/EditAndContinue/ActiveStatementTests.vb
+2
-2
src/EditorFeatures/VisualBasicTest/EditAndContinue/RudeEditTopLevelTests.vb
.../VisualBasicTest/EditAndContinue/RudeEditTopLevelTests.vb
+31
-0
src/Features/CSharp/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
...s/CSharp/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
+10
-1
src/Features/VisualBasic/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb
...sic/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb
+11
-3
未找到文件。
src/EditorFeatures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
浏览文件 @
a64937b0
...
...
@@ -1804,7 +1804,7 @@ class C
var
active
=
GetActiveStatements
(
src1
,
src2
);
edits
.
VerifyRudeDiagnostics
(
active
,
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"const int a = 1"
,
"field"
));
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"const int a = 1"
,
"
const
field"
));
}
[
Fact
]
...
...
@@ -1854,7 +1854,7 @@ class C
var
active
=
GetActiveStatements
(
src1
,
src2
);
edits
.
VerifyRudeDiagnostics
(
active
,
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"const int a = 1, b = 2"
,
"field"
));
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"const int a = 1, b = 2"
,
"
const
field"
));
}
[
Fact
]
...
...
src/EditorFeatures/CSharpTest/EditAndContinue/RudeEditTopLevelTests.cs
浏览文件 @
a64937b0
...
...
@@ -5777,6 +5777,49 @@ class SampleCollection<T>
Diagnostic
(
RudeEditKind
.
Delete
,
"public T this[int i]"
,
"indexer setter"
));
}
[
WorkItem
(
1120407
)]
[
Fact
]
public
void
ConstField_Update
()
{
var
src1
=
"class C { const int x = 0; }"
;
var
src2
=
"class C { const int x = 1; }"
;
var
edits
=
GetTopEdits
(
src1
,
src2
);
edits
.
VerifyEdits
(
"Update [x = 0]@20 -> [x = 1]@20"
);
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
Update
,
"x = 1"
,
"const field"
));
}
[
Fact
]
public
void
ConstField_Delete
()
{
var
src1
=
"class C { const int x = 0; }"
;
var
src2
=
"class C { int x = 0; }"
;
var
edits
=
GetTopEdits
(
src1
,
src2
);
edits
.
VerifyEdits
(
"Update [const int x = 0;]@10 -> [int x = 0;]@10"
);
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"int x = 0"
,
"field"
));
}
[
Fact
]
public
void
ConstField_Add
()
{
var
src1
=
"class C { int x = 0; }"
;
var
src2
=
"class C { const int x = 0; }"
;
var
edits
=
GetTopEdits
(
src1
,
src2
);
edits
.
VerifyEdits
(
"Update [int x = 0;]@10 -> [const int x = 0;]@10"
);
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"const int x = 0"
,
"const field"
));
}
#
endregion
#
region
Events
...
...
src/EditorFeatures/VisualBasicTest/EditAndContinue/ActiveStatementTests.vb
浏览文件 @
a64937b0
...
...
@@ -1893,7 +1893,7 @@ End Class
Dim
active
=
GetActiveStatements
(
src1
,
src2
)
edits
.
VerifyRudeDiagnostics
(
active
,
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Private Const a As Integer = 1"
,
"field"
))
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Private Const a As Integer = 1"
,
"
const
field"
))
End
Sub
<
Fact
>
...
...
@@ -1938,7 +1938,7 @@ End Class
Dim
active
=
GetActiveStatements
(
src1
,
src2
)
edits
.
VerifyRudeDiagnostics
(
active
,
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Private Const a As Integer = 1, b As Integer = 2"
,
"field"
))
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Private Const a As Integer = 1, b As Integer = 2"
,
"
const
field"
))
End
Sub
<
Fact
>
...
...
src/EditorFeatures/VisualBasicTest/EditAndContinue/RudeEditTopLevelTests.vb
浏览文件 @
a64937b0
...
...
@@ -4698,6 +4698,37 @@ End Class
edits
.
VerifyRudeDiagnostics
()
End
Sub
<
Fact
>
Public
Sub
ConstField_Update
()
Dim
src1
=
"Class C : Const x = 0 : End Class"
Dim
src2
=
"Class C : Const x = 1 : End Class"
Dim
edits
=
GetTopEdits
(
src1
,
src2
)
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
Update
,
"x = 1"
,
"const field"
))
End
Sub
<
Fact
>
Public
Sub
ConstField_Delete
()
Dim
src1
=
"Class C : Const x = 0 : End Class"
Dim
src2
=
"Class C : Dim x = 0 : End Class"
Dim
edits
=
GetTopEdits
(
src1
,
src2
)
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Dim x = 0"
,
"field"
))
End
Sub
<
Fact
>
Public
Sub
ConstField_Add
()
Dim
src1
=
"Class C : Dim x = 0 : End Class"
Dim
src2
=
"Class C : Const x = 0 : End Class"
Dim
edits
=
GetTopEdits
(
src1
,
src2
)
edits
.
VerifyRudeDiagnostics
(
Diagnostic
(
RudeEditKind
.
ModifiersUpdate
,
"Const x = 0"
,
"const field"
))
End
Sub
#End Region
#Region "Events"
...
...
src/Features/CSharp/EditAndContinue/CSharpEditAndContinueAnalyzer.cs
浏览文件 @
a64937b0
...
...
@@ -1250,7 +1250,8 @@ internal static string GetTopLevelDisplayNameImpl(SyntaxNode node, EditKind edit
return
"delegate"
;
case
SyntaxKind
.
FieldDeclaration
:
return
"field"
;
var
declaration
=
(
FieldDeclarationSyntax
)
node
;
return
declaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
)
?
"const field"
:
"field"
;
case
SyntaxKind
.
EventFieldDeclaration
:
return
"event field"
;
...
...
@@ -2108,6 +2109,14 @@ private void ClassifyUpdate(VariableDeclaratorSyntax oldNode, VariableDeclarator
return
;
}
// Check if a constant field is updated:
var
fieldDeclaration
=
oldNode
.
Parent
.
Parent
as
FieldDeclarationSyntax
;
if
(
fieldDeclaration
!=
null
&&
fieldDeclaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
))
{
ReportError
(
RudeEditKind
.
Update
);
return
;
}
// TODO (#749): handle lambdas in initializers & constructors
ClassifyDeclarationBodyRudeUpdates
(
newNode
,
allowLambdas
:
false
);
}
...
...
src/Features/VisualBasic/EditAndContinue/VisualBasicEditAndContinueAnalyzer.vb
浏览文件 @
a64937b0
...
...
@@ -1341,7 +1341,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
Case
SyntaxKind
.
FieldDeclaration
Dim
declaration
=
DirectCast
(
node
,
FieldDeclarationSyntax
)
Return
If
(
declaration
.
Modifiers
.
Any
(
SyntaxKind
.
WithEventsKeyword
),
"WithEvents field"
,
"field"
)
Return
If
(
declaration
.
Modifiers
.
Any
(
SyntaxKind
.
WithEventsKeyword
),
"WithEvents field"
,
If
(
declaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
),
"const field"
,
"field"
))
Case
SyntaxKind
.
VariableDeclarator
,
SyntaxKind
.
ModifiedIdentifier
...
...
@@ -2269,10 +2270,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EditAndContinue
Return
End
If
ClassifyTypeAndInitializerUpdates
(
oldNode
.
Initializer
,
If
ClassifyTypeAndInitializerUpdates
(
oldNode
.
Initializer
,
oldNode
.
AsClause
,
newNode
.
Initializer
,
newNode
.
AsClause
)
newNode
.
AsClause
)
Then
' Check if a constant field is updated:
Dim
fieldDeclaration
=
TryCast
(
oldNode
.
Parent
,
FieldDeclarationSyntax
)
If
fieldDeclaration
IsNot
Nothing
AndAlso
fieldDeclaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
)
Then
ReportError
(
RudeEditKind
.
Update
)
Return
End
If
End
If
End
Sub
Private
Sub
ClassifyUpdate
(
oldNode
As
PropertyStatementSyntax
,
newNode
As
PropertyStatementSyntax
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录