提交 a3d791de 编写于 作者: C Cyrus Najmabadi

merge

上级 56e9b44e
......@@ -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;
......
......@@ -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))
......
......@@ -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 isNotNullableReplaceable;
return false;
}
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.
......
......@@ -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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册