提交 a8c08249 编写于 作者: S Sam Harwell

Fix issues with nullable annotations found during review

上级 e3d80ac0
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -35,14 +37,14 @@ protected AbstractAddImportsService()
public bool HasExistingImport(
Compilation compilation, SyntaxNode root,
SyntaxNode contextLocation, SyntaxNode import)
SyntaxNode? contextLocation, SyntaxNode import)
{
var globalImports = GetGlobalImports(compilation);
var containers = GetAllContainers(root, contextLocation);
return HasExistingImport(import, containers, globalImports);
}
private static ImmutableArray<SyntaxNode> GetAllContainers(SyntaxNode root, SyntaxNode contextLocation)
private static ImmutableArray<SyntaxNode> GetAllContainers(SyntaxNode root, SyntaxNode? contextLocation)
{
contextLocation ??= root;
......@@ -77,7 +79,7 @@ private static ImmutableArray<SyntaxNode> GetAllContainers(SyntaxNode root, Synt
return false;
}
public SyntaxNode GetImportContainer(SyntaxNode root, SyntaxNode contextLocation, SyntaxNode import)
public SyntaxNode GetImportContainer(SyntaxNode root, SyntaxNode? contextLocation, SyntaxNode import)
{
contextLocation ??= root;
GetContainers(root, contextLocation,
......@@ -106,7 +108,7 @@ public SyntaxNode GetImportContainer(SyntaxNode root, SyntaxNode contextLocation
public SyntaxNode AddImports(
Compilation compilation,
SyntaxNode root,
SyntaxNode contextLocation,
SyntaxNode? contextLocation,
IEnumerable<SyntaxNode> newImports,
bool placeSystemNamespaceFirst)
{
......
......@@ -15,16 +15,16 @@ internal interface IAddImportsService : ILanguageService
/// <paramref name="import"/> in scope at <paramref name="contextLocation"/>. This includes
/// global imports for VB.
/// </summary>
bool HasExistingImport(Compilation compilation, SyntaxNode root, SyntaxNode contextLocation, SyntaxNode import);
bool HasExistingImport(Compilation compilation, SyntaxNode root, SyntaxNode? contextLocation, SyntaxNode import);
/// <summary>
/// Given a context location in a provided syntax tree, returns the appropriate container
/// that <paramref name="import"/> should be added to.
/// </summary>
SyntaxNode GetImportContainer(SyntaxNode root, SyntaxNode contextLocation, SyntaxNode import);
SyntaxNode GetImportContainer(SyntaxNode root, SyntaxNode? contextLocation, SyntaxNode import);
SyntaxNode AddImports(
Compilation compilation, SyntaxNode root, SyntaxNode contextLocation,
Compilation compilation, SyntaxNode root, SyntaxNode? contextLocation,
IEnumerable<SyntaxNode> newImports, bool placeSystemNamespaceFirst);
}
......
......@@ -46,7 +46,7 @@ public static IPropertySymbol RenameParameters(this IPropertySymbol property, IL
}
bool shouldRemoveAttribute(AttributeData a) =>
attributesToRemove.Where(attr => attr != null).Any(attr => attr!.Equals(a.AttributeClass));
attributesToRemove.Any(attr => attr?.Equals(a.AttributeClass) ?? false);
var someParameterHasAttribute = property.Parameters
.Any(p => p.GetAttributes().Any(shouldRemoveAttribute));
......
......@@ -81,7 +81,7 @@ public static bool IsAnonymousType([NotNullWhen(returnValue: true)] this INamedT
}
[return: NotNullIfNotNull(parameterName: "symbol")]
public static ITypeSymbol? RemoveNullableIfPresent([NotNullWhen(returnValue: true)] this ITypeSymbol? symbol)
public static ITypeSymbol? RemoveNullableIfPresent(this ITypeSymbol? symbol)
{
if (symbol.IsNullable())
{
......@@ -255,7 +255,7 @@ public static bool IsAnonymousType([NotNullWhen(returnValue: true)] this INamedT
return null;
}
private static ISymbol FindImplementations<TSymbol>(
private static ISymbol? FindImplementations<TSymbol>(
this ITypeSymbol typeSymbol,
TSymbol constructedInterfaceMember,
Workspace workspace) where TSymbol : class, ISymbol
......@@ -436,6 +436,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
&& symbol.ContainingNamespace.ContainingNamespace?.IsGlobalNamespace == true;
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? RemoveUnavailableTypeParameters(
this ITypeSymbol? type,
Compilation compilation,
......@@ -444,6 +445,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return type?.RemoveUnavailableTypeParameters(compilation, availableTypeParameters.Select(t => t.Name).ToSet());
}
[return: NotNullIfNotNull(parameterName: "type")]
private static ITypeSymbol? RemoveUnavailableTypeParameters(
this ITypeSymbol? type,
Compilation compilation,
......@@ -452,6 +454,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return type?.Accept(new UnavailableTypeParameterRemover(compilation, availableTypeParameterNames));
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? RemoveAnonymousTypes(
this ITypeSymbol? type,
Compilation compilation)
......@@ -459,6 +462,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return type?.Accept(new AnonymousTypeRemover(compilation));
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? ReplaceTypeParametersBasedOnTypeConstraints(
this ITypeSymbol? type,
Compilation compilation,
......@@ -469,6 +473,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return type?.Accept(new ReplaceTypeParameterBasedOnTypeConstraintVisitor(compilation, availableTypeParameters.Select(t => t.Name).ToSet(), solution, cancellationToken));
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? RemoveUnnamedErrorTypes(
this ITypeSymbol? type,
Compilation compilation)
......@@ -492,6 +497,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return result;
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
this ITypeSymbol? type,
IDictionary<TType1, TType2> mapping,
......@@ -502,6 +508,7 @@ public static bool IsFormattableString([NotNullWhen(returnValue: true)] this ITy
return type.SubstituteTypes(mapping, new CompilationTypeGenerator(compilation));
}
[return: NotNullIfNotNull(parameterName: "type")]
public static ITypeSymbol? SubstituteTypes<TType1, TType2>(
this ITypeSymbol? type,
IDictionary<TType1, TType2> mapping,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册