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

Add netcoreapp3.1 target for the features layer

上级 7c63d34b
......@@ -108,7 +108,7 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
// actually looking at something Nullable (and not some type that uses a similar
// syntactic pattern).
var semanticModel = context.SemanticModel;
var nullableType = semanticModel.Compilation.GetTypeByMetadataName(typeof(Nullable<>).FullName);
var nullableType = semanticModel.Compilation.GetTypeByMetadataName(typeof(Nullable<>).FullName!);
if (nullableType == null)
{
return;
......
......@@ -49,7 +49,7 @@ protected override void InitializeWorker(AnalysisContext context)
private void OnCompilationStart(CompilationStartAnalysisContext context)
{
var ienumerableType = context.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName);
var ienumerableType = context.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName!);
if (ienumerableType != null)
{
var syntaxKinds = GetSyntaxFacts().SyntaxKinds;
......
......@@ -30,7 +30,7 @@ namespace Microsoft.CodeAnalysis.CSharp.CodeFixes.AddExplicitCast
///
/// 'Derived1' is less specific than 'Derived2' compared to 'Base'
/// </summary>
internal sealed class InheritanceDistanceComparer : IComparer<ITypeSymbol>
internal sealed class InheritanceDistanceComparer : IComparer<ITypeSymbol?>
{
private readonly ITypeSymbol _baseType;
private readonly SemanticModel _semanticModel;
......@@ -41,8 +41,13 @@ public InheritanceDistanceComparer(SemanticModel semanticModel, ITypeSymbol base
_baseType = baseType;
}
public int Compare(ITypeSymbol x, ITypeSymbol y)
public int Compare(ITypeSymbol? x, ITypeSymbol? y)
{
if (x is null)
return y is null ? 0 : -1;
else if (y is null)
return 1;
var xDist = GetInheritanceDistance(x);
var yDist = GetInheritanceDistance(y);
return xDist.CompareTo(yDist);
......
......@@ -117,10 +117,10 @@ public override ImmutableArray<string> FixableDiagnosticIds
private bool IsCorrectTypeForYieldReturn(ITypeSymbol typeArgument, ITypeSymbol returnExpressionType, ITypeSymbol methodReturnType, SemanticModel model)
{
var ienumerableSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName);
var ienumeratorSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator).FullName);
var ienumerableGenericSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable<>).FullName);
var ienumeratorGenericSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator<>).FullName);
var ienumerableSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName!);
var ienumeratorSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator).FullName!);
var ienumerableGenericSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable<>).FullName!);
var ienumeratorGenericSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator<>).FullName!);
if (ienumerableGenericSymbol == null ||
ienumerableSymbol == null ||
......@@ -190,8 +190,8 @@ private bool CanConvertTypes(ITypeSymbol typeArgument, ITypeSymbol returnExpress
private bool IsCorrectTypeForYieldReturn(ITypeSymbol methodReturnType, SemanticModel model)
{
var ienumerableSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName);
var ienumeratorSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator).FullName);
var ienumerableSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerable).FullName!);
var ienumeratorSymbol = model.Compilation.GetTypeByMetadataName(typeof(IEnumerator).FullName!);
if (ienumerableSymbol == null ||
ienumeratorSymbol == null)
......
......@@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<ApplyNgenOptimization>partial</ApplyNgenOptimization>
<!-- NuGet -->
......
......@@ -274,7 +274,7 @@ private async Task<Solution> ConfigureAsync()
// Otherwise, add analyzer config document to all applicable projects for the current project's solution.
AnalyzerConfigDocument? analyzerConfigDocument = null;
var analyzerConfigDirectory = PathUtilities.GetDirectoryName(analyzerConfigPath);
var analyzerConfigDirectory = PathUtilities.GetDirectoryName(analyzerConfigPath) ?? throw ExceptionUtilities.Unreachable;
var currentSolution = _project.Solution;
foreach (var projectId in _project.Solution.ProjectIds)
{
......
......@@ -287,7 +287,7 @@ private ImmutableArray<CodeRefactoringProvider> CreateRefactorings(string langua
attribute.Languages.Length == 0 ||
attribute.Languages.Contains(language))
{
builder.Add((CodeRefactoringProvider)Activator.CreateInstance(typeInfo.AsType()));
builder.Add((CodeRefactoringProvider)Activator.CreateInstance(typeInfo.AsType())!);
}
}
}
......
......@@ -35,7 +35,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
return new ImportCompletionCacheService(_peItemsCache, _projectItemsCache);
}
private void OnCacheFlushRequested(object sender, EventArgs e)
private void OnCacheFlushRequested(object? sender, EventArgs e)
{
_peItemsCache.Clear();
_projectItemsCache.Clear();
......
......@@ -215,6 +215,7 @@ static bool HasGlobalAlias(MetadataReference? metadataReference)
bool forceCacheCreation,
IDictionary<TKey, CacheEntry> cache,
CancellationToken cancellationToken)
where TKey : notnull
{
var language = syntaxContext.SemanticModel.Language;
......
......@@ -91,7 +91,7 @@ public static (string analyzerId, VersionStamp version) GetAnalyzerIdAndVersion(
}
public static string GetAnalyzerAssemblyName(this DiagnosticAnalyzer analyzer)
=> analyzer.GetType().Assembly.GetName().Name;
=> analyzer.GetType().Assembly.GetName().Name ?? throw ExceptionUtilities.Unreachable;
public static OptionSet GetAnalyzerOptionSet(this AnalyzerOptions analyzerOptions, SyntaxTree syntaxTree, CancellationToken cancellationToken)
{
......
......@@ -6,6 +6,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -125,10 +126,10 @@ public bool IsActiveFile(DocumentId documentId)
public bool FromBuild(ProjectId projectId)
=> _projectStates.TryGetValue(projectId, out var projectState) && projectState.FromBuild;
public bool TryGetActiveFileState(DocumentId documentId, out ActiveFileState state)
public bool TryGetActiveFileState(DocumentId documentId, [NotNullWhen(true)] out ActiveFileState? state)
=> _activeFileStates.TryGetValue(documentId, out state);
public bool TryGetProjectState(ProjectId projectId, out ProjectState state)
public bool TryGetProjectState(ProjectId projectId, [NotNullWhen(true)] out ProjectState? state)
=> _projectStates.TryGetValue(projectId, out state);
public ActiveFileState GetOrCreateActiveFileState(DocumentId documentId)
......
......@@ -100,7 +100,7 @@ public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs
#pragma warning restore CS0618 // Type or member is obsolete
}
private void OnProjectAnalyzerReferenceChanged(object sender, ProjectAnalyzerReferenceChangedEventArgs e)
private void OnProjectAnalyzerReferenceChanged(object? sender, ProjectAnalyzerReferenceChangedEventArgs e)
{
if (e.Removed.Length == 0)
{
......
......@@ -440,15 +440,27 @@ internal static bool AreEquivalent(Diagnostic[] diagnosticsA, Diagnostic[] diagn
return set.SetEquals(diagnosticsB);
}
private sealed class DiagnosticComparer : IEqualityComparer<Diagnostic>
private sealed class DiagnosticComparer : IEqualityComparer<Diagnostic?>
{
internal static readonly DiagnosticComparer Instance = new DiagnosticComparer();
public bool Equals(Diagnostic x, Diagnostic y)
=> x.Id == y.Id && x.Location == y.Location;
public bool Equals(Diagnostic? x, Diagnostic? y)
{
if (x is null)
return y is null;
else if (y is null)
return false;
return x.Id == y.Id && x.Location == y.Location;
}
public int GetHashCode(Diagnostic obj)
=> Hash.Combine(obj.Id.GetHashCode(), obj.Location.GetHashCode());
public int GetHashCode(Diagnostic? obj)
{
if (obj is null)
return 0;
return Hash.Combine(obj.Id.GetHashCode(), obj.Location.GetHashCode());
}
}
#endif
}
......
......@@ -322,7 +322,7 @@ public HostAnalyzerReferenceDiagnosticReporter(AbstractHostDiagnosticUpdateSourc
_primaryWorkspace = primaryWorkspace;
}
public void OnAnalyzerLoadFailed(object sender, AnalyzerLoadFailureEventArgs e)
public void OnAnalyzerLoadFailed(object? sender, AnalyzerLoadFailureEventArgs e)
{
if (!(sender is AnalyzerFileReference reference))
{
......
......@@ -2108,11 +2108,11 @@ private static int CompareLineChanges(LineChange x, LineChange y)
#region Semantic Analysis
private sealed class AssemblyEqualityComparer : IEqualityComparer<IAssemblySymbol>
private sealed class AssemblyEqualityComparer : IEqualityComparer<IAssemblySymbol?>
{
public static readonly IEqualityComparer<IAssemblySymbol> Instance = new AssemblyEqualityComparer();
public static readonly IEqualityComparer<IAssemblySymbol?> Instance = new AssemblyEqualityComparer();
public bool Equals(IAssemblySymbol x, IAssemblySymbol y)
public bool Equals(IAssemblySymbol? x, IAssemblySymbol? y)
{
// Types defined in old source assembly need to be treated as equivalent to types in the new source assembly,
// provided that they only differ in their containing assemblies.
......@@ -2123,11 +2123,11 @@ public bool Equals(IAssemblySymbol x, IAssemblySymbol y)
// a single PE symbol. Thus comparing assemblies by identity partitions them so that each partition
// contains assemblies that originated from the same Gen0 assembly.
return x.Identity.Equals(y.Identity);
return Equals(x?.Identity, y?.Identity);
}
public int GetHashCode(IAssemblySymbol obj)
=> obj.Identity.GetHashCode();
public int GetHashCode(IAssemblySymbol? obj)
=> obj?.Identity.GetHashCode() ?? 0;
}
protected static readonly SymbolEquivalenceComparer s_assemblyEqualityComparer = new SymbolEquivalenceComparer(
......@@ -2727,7 +2727,7 @@ private static bool HasBackingField(IEventSymbol @event)
return false;
}
lazyLayoutAttribute ??= model.Compilation.GetTypeByMetadataName(typeof(StructLayoutAttribute).FullName);
lazyLayoutAttribute ??= model.Compilation.GetTypeByMetadataName(typeof(StructLayoutAttribute).FullName!);
if (lazyLayoutAttribute == null)
{
return false;
......@@ -3397,6 +3397,7 @@ private static void MarkVariables(ref BitVector mask, ImmutableArray<ISymbol> va
}
private static void BuildIndex<TKey>(Dictionary<TKey, int> index, ImmutableArray<TKey> array)
where TKey : notnull
{
for (var i = 0; i < array.Length; i++)
{
......
......@@ -248,7 +248,7 @@ public async Task<(Guid Mvid, Diagnostic? Error)> GetProjectModuleIdAsync(Projec
{
Debug.Assert(Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA, "SymReader requires MTA");
EmitBaseline baseline;
EmitBaseline? baseline;
lock (_projectEmitBaselinesGuard)
{
if (_projectEmitBaselines.TryGetValue(projectId, out baseline))
......
......@@ -628,7 +628,7 @@ private bool WellKnownFrameworkValueType(Compilation compilation, ITypeSymbol ty
return false;
}
var cancellationTokenType = compilation.GetTypeByMetadataName(typeof(CancellationToken).FullName);
var cancellationTokenType = compilation.GetTypeByMetadataName(typeof(CancellationToken).FullName!);
if (cancellationTokenType != null && cancellationTokenType.Equals(type))
{
return true;
......
......@@ -111,7 +111,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
return null;
var semanticModel = await _document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var equatableType = semanticModel.Compilation.GetTypeByMetadataName(typeof(IEquatable<>).FullName);
var equatableType = semanticModel.Compilation.GetTypeByMetadataName(typeof(IEquatable<>).FullName!);
if (equatableType == null)
return null;
......
......@@ -292,7 +292,7 @@ public override string Title
statements.Add(g.ExpressionStatement(
g.InvocationExpression(
g.MemberAccessExpression(
g.TypeExpression(compilation.GetTypeByMetadataName(typeof(GC).FullName)),
g.TypeExpression(compilation.GetTypeByMetadataName(typeof(GC).FullName!)),
nameof(GC.SuppressFinalize)),
g.ThisExpression())));
......
......@@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<ApplyNgenOptimization>partial</ApplyNgenOptimization>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
......
......@@ -77,7 +77,7 @@ private static IOperation Unwrap(IOperation expression)
{
if (invocation.Arguments.Length == 1 &&
invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal &&
invocation.SemanticModel.Compilation.GetTypeByMetadataName(typeof(System.IFormattable).FullName) is { } systemIFormattable &&
invocation.SemanticModel.Compilation.GetTypeByMetadataName(typeof(System.IFormattable).FullName!) is { } systemIFormattable &&
invocation.Instance.Type.Implements(systemIFormattable))
{
unwrapped = invocation.Instance;
......
......@@ -41,7 +41,7 @@ public static bool TryGetAnalyzer(Compilation compilation, [NotNullWhen(true)] o
// This may not find anything. However, CanAnalyze checks for this. So
// we represent the value as non-nullable for all future code.
var objectGetHashCodeMethod = objectType?.GetMembers(nameof(GetHashCode)).FirstOrDefault() as IMethodSymbol;
var equalityComparerType = compilation.GetTypeByMetadataName(typeof(EqualityComparer<>).FullName);
var equalityComparerType = compilation.GetTypeByMetadataName(typeof(EqualityComparer<>).FullName!);
var systemHashCodeType = compilation.GetTypeByMetadataName("System.HashCode");
if (systemHashCodeType == null || objectGetHashCodeMethod == null)
......
......@@ -71,7 +71,7 @@ public override void Initialize(AnalysisContext context)
context.RegisterCompilationStartAction(startContext =>
{
var formatProviderType = startContext.Compilation.GetTypeByMetadataName(typeof(System.IFormatProvider).FullName);
var formatProviderType = startContext.Compilation.GetTypeByMetadataName(typeof(System.IFormatProvider).FullName!);
if (formatProviderType == null)
{
return;
......@@ -343,8 +343,10 @@ private bool FormatCallWorksAtRuntime(string formatString, int numberOfPlacehold
var formatStringWithEscapedBracketsChangedToSpaces = RemoveEscapedBrackets(formatString);
var matches = s_extractPlaceholdersRegex.Matches(formatStringWithEscapedBracketsChangedToSpaces);
foreach (Match match in matches)
foreach (Match? match in matches)
{
RoslynDebug.AssertNotNull(match);
var textInsideBrackets = match.Groups[1].Value;
if (!PlaceholderIndexIsValid(textInsideBrackets, numberOfPlaceholderArguments))
......
......@@ -3,7 +3,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<RootNamespace></RootNamespace>
<ApplyNgenOptimization>partial</ApplyNgenOptimization>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册