未验证 提交 4b4ce21d 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #40316 from jasonmalinowski/remove-nullable-helper-methods

Remove some nullable helper methods
......@@ -62,7 +62,7 @@ public override bool ContainingScopeHasAsyncKeyword()
var variableDeclExpression = node.GetAncestorOrThis<VariableDeclarationSyntax>();
if (variableDeclExpression != null)
{
return model.GetTypeInfo(variableDeclExpression.Type).GetTypeWithAnnotatedNullability();
return model.GetTypeInfo(variableDeclExpression.Type).Type;
}
}
......@@ -81,7 +81,7 @@ public override bool ContainingScopeHasAsyncKeyword()
if (node.Parent is CastExpressionSyntax castExpression)
{
return model.GetTypeInfo(castExpression).GetTypeWithFlowNullability();
return model.GetTypeInfo(castExpression).Type;
}
}
......
......@@ -171,7 +171,7 @@ protected override ImmutableArray<ITypeSymbol> DetermineTypeArguments(Cancellati
foreach (var typeArgument in ((GenericNameSyntax)State.SimpleNameOpt).TypeArgumentList.Arguments)
{
var typeInfo = this.Document.SemanticModel.GetTypeInfo(typeArgument, cancellationToken);
result.Add(typeInfo.GetTypeWithAnnotatedNullability());
result.Add(typeInfo.Type);
}
}
......
......@@ -90,7 +90,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
if (parensDesignation is null)
{
var typeSymbol = semanticModel.GetTypeInfo(typeSyntax.StripRefIfNeeded()).GetConvertedTypeWithAnnotatedNullability();
var typeSymbol = semanticModel.GetTypeInfo(typeSyntax.StripRefIfNeeded()).ConvertedType;
// We're going to be passed through the simplifier. Tell it to not just convert
// this back to var (as that would defeat the purpose of this refactoring entirely).
......
......@@ -402,17 +402,17 @@ static bool IsInstanceMemberReference(IOperation operation)
if (typeInfo.Type?.SpecialType == SpecialType.System_String &&
typeInfo.ConvertedType?.IsFormattableString() == true)
{
return typeInfo.GetConvertedTypeWithFlowNullability();
return typeInfo.ConvertedType;
}
if (typeInfo.Type != null)
{
return typeInfo.GetTypeWithFlowNullability();
return typeInfo.Type;
}
if (typeInfo.ConvertedType != null)
{
return typeInfo.GetConvertedTypeWithFlowNullability();
return typeInfo.ConvertedType;
}
if (objectAsDefault)
......
......@@ -97,7 +97,7 @@ private IEnumerable<TypeInferenceInfo> GetTypesSimple(SyntaxNode node)
if (symbolInfo.CandidateReason != CandidateReason.WrongArity)
{
var typeInferenceInfo = new TypeInferenceInfo(typeInfo.GetTypeWithFlowNullability());
var typeInferenceInfo = new TypeInferenceInfo(typeInfo.Type);
// If it bound to a method, try to get the Action/Func form of that method.
if (typeInferenceInfo.InferredType == null)
......@@ -1194,7 +1194,7 @@ private IEnumerable<TypeInferenceInfo> InferTypeInPropertyDeclaration(PropertyDe
Debug.Assert(propertyDeclaration?.Type != null, "Property type should never be null");
var typeInfo = SemanticModel.GetTypeInfo(propertyDeclaration.Type);
return CreateResult(typeInfo.GetTypeWithAnnotatedNullability());
return CreateResult(typeInfo.Type);
}
private IEnumerable<TypeInferenceInfo> InferTypeInExpressionStatement(ExpressionStatementSyntax expressionStatement, SyntaxToken? previousToken = null)
......
......@@ -80,7 +80,7 @@ public static ISymbol GetEnclosingNamedTypeOrAssembly(this SemanticModel semanti
if (typeInfo.Type != null)
{
return typeInfo.GetTypeWithFlowNullability()!;
return typeInfo.Type;
}
var symbolInfo = semanticModel.GetSymbolInfo(expression, cancellationToken);
......
......@@ -8,31 +8,9 @@ namespace Microsoft.CodeAnalysis
{
internal static partial class NullableExtensions
{
public static T WithNullability<T>(this T typeSymbol, NullableFlowState flowState) where T : class, ITypeSymbol
{
// TODO: call the compiler API once it's available
switch (flowState)
{
case NullableFlowState.None:
return (T)typeSymbol.WithNullableAnnotation(NullableAnnotation.None);
case NullableFlowState.NotNull:
return (T)typeSymbol.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
case NullableFlowState.MaybeNull:
return (T)typeSymbol.WithNullableAnnotation(NullableAnnotation.Annotated);
default:
throw ExceptionUtilities.UnexpectedValue(typeSymbol);
}
}
public static ITypeSymbol? GetConvertedTypeWithFlowNullability(this TypeInfo typeInfo)
=> typeInfo.ConvertedType?.WithNullability(typeInfo.ConvertedNullability.FlowState);
public static ITypeSymbol? GetConvertedTypeWithAnnotatedNullability(this TypeInfo typeInfo)
=> typeInfo.ConvertedType?.WithNullableAnnotation(typeInfo.ConvertedNullability.Annotation);
public static ITypeSymbol? GetTypeWithFlowNullability(this TypeInfo typeInfo)
=> typeInfo.Type?.WithNullability(typeInfo.Nullability.FlowState);
public static ITypeSymbol? GetTypeWithAnnotatedNullability(this TypeInfo typeInfo)
=> typeInfo.Type?.WithNullableAnnotation(typeInfo.Nullability.Annotation);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册