Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a3d791de
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,发现更多精彩内容 >>
提交
a3d791de
编写于
1月 18, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge
上级
56e9b44e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
20 addition
and
27 deletion
+20
-27
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/AbstractCSharpSimplifier.cs
...le/Simplification/Simplifiers/AbstractCSharpSimplifier.cs
+3
-2
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/ExpressionSimplifier.cs
...rtable/Simplification/Simplifiers/ExpressionSimplifier.cs
+1
-1
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/NameSimplifier.cs
...arp/Portable/Simplification/Simplifiers/NameSimplifier.cs
+9
-17
src/Workspaces/VisualBasic/Portable/Simplification/Reducers/VisualBasicVariableDeclaratorReducer.vb
...fication/Reducers/VisualBasicVariableDeclaratorReducer.vb
+1
-1
src/Workspaces/VisualBasic/Portable/Simplification/Simplifiers/NameSimplifier.vb
...sic/Portable/Simplification/Simplifiers/NameSimplifier.vb
+6
-6
未找到文件。
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/AbstractCSharpSimplifier.cs
浏览文件 @
a3d791de
...
...
@@ -391,9 +391,10 @@ protected static bool InsideNameOfExpression(ExpressionSyntax expression, Semant
var
nameOfInvocationExpr
=
expression
.
FirstAncestorOrSelf
<
InvocationExpressionSyntax
>(
invocationExpr
=>
{
return
(
invocationExpr
.
Expression
is
IdentifierNameSyntax
identifierName
)
&&
(
identifierName
.
Identifier
.
Text
==
"nameof"
)
&&
return
invocationExpr
.
Expression
is
IdentifierNameSyntax
identifierName
&&
identifierName
.
Identifier
.
Text
==
"nameof"
&&
semanticModel
.
GetConstantValue
(
invocationExpr
).
HasValue
&&
(
semanticModel
.
GetTypeInfo
(
invocationExpr
).
Type
.
SpecialType
==
SpecialType
.
System_String
)
;
semanticModel
.
GetTypeInfo
(
invocationExpr
).
Type
.
SpecialType
==
SpecialType
.
System_String
;
});
return
nameOfInvocationExpr
!=
null
;
...
...
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/ExpressionSimplifier.cs
浏览文件 @
a3d791de
...
...
@@ -418,7 +418,7 @@ private static bool AccessMethodWithDynamicArgumentInsideStructConstructor(Membe
if
(
left
!=
null
&&
right
!=
null
)
{
var
leftSymbol
=
SimplificationHelpers
.
GetOriginalSymbolInfo
(
semanticModel
,
left
);
if
(
leftSymbol
!=
null
&&
(
leftSymbol
.
Kind
==
SymbolKind
.
NamedType
)
)
if
(
leftSymbol
!=
null
&&
leftSymbol
.
Kind
==
SymbolKind
.
NamedType
)
{
var
rightSymbol
=
SimplificationHelpers
.
GetOriginalSymbolInfo
(
semanticModel
,
right
);
if
(
rightSymbol
!=
null
&&
(
rightSymbol
.
IsStatic
||
rightSymbol
.
Kind
==
SymbolKind
.
NamedType
))
...
...
src/Workspaces/CSharp/Portable/Simplification/Simplifiers/NameSimplifier.cs
浏览文件 @
a3d791de
...
...
@@ -272,7 +272,7 @@ private NameSimplifier()
// Nullable rewrite: Nullable<int> -> int?
// Don't rewrite in the case where Nullable<int> is part of some qualified name like Nullable<int>.Something
if
(!
name
.
IsVar
&&
(
symbol
.
Kind
==
SymbolKind
.
NamedType
)
&&
!
name
.
IsLeftSideOfQualifiedName
())
if
(!
name
.
IsVar
&&
symbol
.
Kind
==
SymbolKind
.
NamedType
&&
!
name
.
IsLeftSideOfQualifiedName
())
{
var
type
=
(
INamedTypeSymbol
)
symbol
;
if
(
aliasInfo
==
null
&&
CanSimplifyNullable
(
type
,
name
,
semanticModel
))
...
...
@@ -567,7 +567,7 @@ private static bool IsPartOfNamespaceDeclarationName(SyntaxNode node)
IsAmbiguousCast
(
name
,
reducedName
)
||
IsNullableTypeInPointerExpression
(
reducedName
)
||
IsNotNullableReplaceable
(
name
,
reducedName
)
||
IsNonReducableQualifiedNameInUsingDirective
(
semanticModel
,
name
,
reducedName
))
IsNonReducableQualifiedNameInUsingDirective
(
semanticModel
,
name
))
{
return
false
;
}
...
...
@@ -604,23 +604,15 @@ private static bool CanReplaceWithReducedName(NameSyntax name, TypeSyntax reduce
private
static
bool
IsNotNullableReplaceable
(
NameSyntax
name
,
TypeSyntax
reducedName
)
{
var
isNotNullableReplaceable
=
false
;
var
isLeftSideOfDot
=
name
.
IsLeftSideOfDot
();
var
isRightSideOfDot
=
name
.
IsRightSideOfDot
();
if
(
reducedName
.
Kind
()
==
SyntaxKind
.
NullableType
)
if
(
reducedName
.
IsKind
(
SyntaxKind
.
NullableType
,
out
NullableTypeSyntax
nullableType
))
{
if
(((
NullableTypeSyntax
)
reducedName
).
ElementType
.
Kind
()
==
SyntaxKind
.
OmittedTypeArgument
)
{
isNotNullableReplaceable
=
true
;
}
else
{
isNotNullableReplaceable
=
name
.
IsLeftSideOfDot
()
||
name
.
IsRightSideOfDot
();
}
if
(
nullableType
.
ElementType
.
Kind
()
==
SyntaxKind
.
OmittedTypeArgument
)
return
true
;
return
name
.
IsLeftSideOfDot
()
||
name
.
IsRightSideOfDot
();
}
return
isNotNullableReplaceabl
e
;
return
fals
e
;
}
private
static
bool
IsNullableTypeInPointerExpression
(
ExpressionSyntax
simplifiedNode
)
...
...
@@ -665,7 +657,7 @@ private static bool IsAmbiguousCast(ExpressionSyntax expression, ExpressionSynta
return
false
;
}
private
static
bool
IsNonReducableQualifiedNameInUsingDirective
(
SemanticModel
model
,
NameSyntax
name
,
TypeSyntax
reducedName
)
private
static
bool
IsNonReducableQualifiedNameInUsingDirective
(
SemanticModel
model
,
NameSyntax
name
)
{
// Whereas most of the time we do not want to reduce namespace names, We will
// make an exception for namespaces with the global:: alias.
...
...
src/Workspaces/VisualBasic/Portable/Simplification/Reducers/VisualBasicVariableDeclaratorReducer.vb
浏览文件 @
a3d791de
...
...
@@ -82,7 +82,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification
Return
False
End
If
Dim
initializerType
As
ITypeSymbol
=
Nothing
Dim
initializerType
As
ITypeSymbol
If
declaredSymbolType
.
IsArrayType
()
AndAlso
variableDeclarator
.
Initializer
.
Value
.
Kind
()
=
SyntaxKind
.
CollectionInitializer
Then
' Get type of the array literal in context without the target type
...
...
src/Workspaces/VisualBasic/Portable/Simplification/Simplifiers/NameSimplifier.vb
浏览文件 @
a3d791de
...
...
@@ -65,7 +65,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification.Simplifiers
issueSpan
=
name
.
Span
Return
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
,
semanticModel
,
cancellationToken
)
Return
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
)
Else
If
Not
name
.
IsRightSideOfDot
()
Then
...
...
@@ -114,7 +114,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification.Simplifiers
End
If
End
If
If
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
,
semanticModel
,
cancellationToken
)
Then
If
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
)
Then
' check if the alias name ends with an Attribute suffix that can be omitted.
Dim
replacementNodeWithoutAttributeSuffix
As
ExpressionSyntax
=
Nothing
...
...
@@ -179,7 +179,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification.Simplifiers
replacementNode
=
SyntaxFactory
.
PredefinedType
(
token
)
issueSpan
=
name
.
Span
Dim
canReplace
=
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
,
semanticModel
,
cancellationToken
)
Dim
canReplace
=
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
)
If
canReplace
Then
replacementNode
=
replacementNode
.
WithAdditionalAnnotations
(
New
SyntaxAnnotation
(
codeStyleOptionName
))
End
If
...
...
@@ -207,7 +207,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification.Simplifiers
issueSpan
=
name
.
Span
If
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
,
semanticModel
,
cancellationToken
)
Then
If
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
)
Then
Return
True
End
If
End
If
...
...
@@ -295,10 +295,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Simplification.Simplifiers
Return
False
End
If
Return
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
,
semanticModel
,
cancellationToken
)
Return
CanReplaceWithReducedNameInContext
(
name
,
replacementNode
)
End
Function
Private
Function
CanReplaceWithReducedNameInContext
(
name
As
NameSyntax
,
replacementNode
As
ExpressionSyntax
,
semanticModel
As
SemanticModel
,
cancellationToken
As
CancellationToken
)
As
Boolean
Private
Function
CanReplaceWithReducedNameInContext
(
name
As
NameSyntax
,
replacementNode
As
ExpressionSyntax
)
As
Boolean
' Special case. if this new minimal name parses out to a predefined type, then we
' have to make sure that we're not in a using alias. That's the one place where the
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录