未验证 提交 c112e5eb 编写于 作者: J Julien Couvreur 提交者: GitHub

Annotate even more CodeAnalysis public APIs (#42329)

上级 5b99da82
......@@ -263,7 +263,7 @@ public PEAssemblySymbol CreatePEAssemblyForAssemblyMetadata(AssemblyMetadata met
}
var assembly = metadata.GetAssembly();
Debug.Assert(assembly is object);
var peReferences = assembly.AssemblyReferences.SelectAsArray(MapAssemblyIdentityToResolvedSymbol, referencedAssembliesByIdentity);
assemblyReferenceIdentityMap = GetAssemblyReferenceIdentityBaselineMap(peReferences, assembly.AssemblyReferences);
......
......@@ -445,8 +445,7 @@ internal static SyntaxTree CreateWithoutClone(CSharpSyntaxNode root)
public override SyntaxTree WithChangedText(SourceText newText)
{
// try to find the changes between the old text and the new text.
SourceText oldText;
if (this.TryGetText(out oldText))
if (this.TryGetText(out SourceText? oldText))
{
var changes = newText.GetChangeRanges(oldText);
......
......@@ -2,17 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using AnalyzerOptions = System.Collections.Immutable.ImmutableDictionary<string, string>;
using TreeOptions = System.Collections.Immutable.ImmutableDictionary<string, Microsoft.CodeAnalysis.ReportDiagnostic>;
namespace Microsoft.CodeAnalysis
{
......@@ -115,7 +114,7 @@ public static AnalyzerConfig Parse(SourceText text, string pathToFile)
throw new ArgumentException("Must be an absolute path to an editorconfig file", nameof(pathToFile));
}
Section globalSection = null;
Section? globalSection = null;
var namedSectionBuilder = ImmutableArray.CreateBuilder<Section>();
// N.B. The editorconfig documentation is quite loose on property interpretation.
......@@ -180,7 +179,7 @@ public static AnalyzerConfig Parse(SourceText text, string pathToFile)
// Add the last section
addNewSection();
return new AnalyzerConfig(globalSection, namedSectionBuilder.ToImmutable(), pathToFile);
return new AnalyzerConfig(globalSection!, namedSectionBuilder.ToImmutable(), pathToFile);
void addNewSection()
{
......
......@@ -874,7 +874,7 @@ public INamedTypeSymbol GetSpecialType(SpecialType specialType)
for (int i = 0; i < parts.Length - 1; i++)
{
INamespaceSymbol next = container.GetNestedNamespace(parts[i]);
INamespaceSymbol? next = container.GetNestedNamespace(parts[i]);
if (next == null)
{
AssertNoScriptTrees();
......
......@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
#define NDP4_AUTO_VERSION_ROLLFORWARD
using System;
......@@ -68,7 +69,7 @@ public bool Equals(Key other)
&& this.PublicKeyToken.SequenceEqual(other.PublicKeyToken);
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is Key && Equals((Key)obj);
}
......@@ -114,14 +115,14 @@ public struct Value
ImmutableArray<byte> newPublicKeyToken,
AssemblyVersion newVersion)
{
List<Value> values;
List<Value>? values;
var key = new Key(name, publicKeyToken);
if (!TryGetValue(key, out values))
{
Add(key, values = new List<Value>());
}
values.Add(new Value(versionLow, default(AssemblyVersion), newName, newPublicKeyToken, newVersion, isPortable: false));
values.Add(new Value(versionLow, versionHigh: default, newName, newPublicKeyToken, newVersion, isPortable: false));
}
public void Add(
......@@ -134,7 +135,7 @@ public struct Value
AssemblyVersion newVersion,
bool isPortable)
{
List<Value> values;
List<Value>? values;
var key = new Key(name, publicKeyToken);
if (!TryGetValue(key, out values))
{
......@@ -146,10 +147,10 @@ public struct Value
public bool TryGetValue(AssemblyIdentity identity, out Value value)
{
List<Value> values;
List<Value>? values;
if (!TryGetValue(new Key(identity.Name, identity.PublicKeyToken), out values))
{
value = default(Value);
value = default;
return false;
}
......@@ -171,7 +172,7 @@ public bool TryGetValue(AssemblyIdentity identity, out Value value)
}
}
value = default(Value);
value = default;
return false;
}
}
......
......@@ -2,13 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Metadata;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
......@@ -251,8 +251,8 @@ private AssemblyIdentity Port(AssemblyIdentity identity)
return identity;
}
Version newVersion = null;
ImmutableArray<byte> newPublicKeyToken = default(ImmutableArray<byte>);
Version? newVersion = null;
ImmutableArray<byte> newPublicKeyToken = default;
var version = (AssemblyVersion)identity.Version;
if (version >= new AssemblyVersion(2, 0, 0, 0) && version <= new AssemblyVersion(5, 9, 0, 0))
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using System.Diagnostics;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -25,7 +27,7 @@ private sealed class Data
public static readonly Data Disposed = new Data();
public readonly ImmutableArray<ModuleMetadata> Modules;
public readonly PEAssembly Assembly;
public readonly PEAssembly? Assembly;
private Data()
{
......@@ -50,7 +52,7 @@ public bool IsDisposed
/// Shall only throw <see cref="BadImageFormatException"/> or <see cref="IOException"/>.
/// Null of all modules were specified at construction time.
/// </summary>
private readonly Func<string, ModuleMetadata> _moduleFactoryOpt;
private readonly Func<string, ModuleMetadata>? _moduleFactoryOpt;
/// <summary>
/// Modules the <see cref="AssemblyMetadata"/> was created with, in case they are eagerly allocated.
......@@ -58,7 +60,7 @@ public bool IsDisposed
private readonly ImmutableArray<ModuleMetadata> _initialModules;
// Encapsulates the modules and the corresponding PEAssembly produced by the modules factory.
private Data _lazyData;
private Data? _lazyData;
// The actual array of modules exposed via Modules property.
// The same modules as the ones produced by the factory or their copies.
......@@ -166,7 +168,7 @@ public static AssemblyMetadata CreateFromFile(string path)
internal static AssemblyMetadata CreateFromFile(ModuleMetadata manifestModule, string path)
{
return new AssemblyMetadata(manifestModule, moduleName => ModuleMetadata.CreateFromFile(Path.Combine(Path.GetDirectoryName(path), moduleName)));
return new AssemblyMetadata(manifestModule, moduleName => ModuleMetadata.CreateFromFile(Path.Combine(Path.GetDirectoryName(path) ?? "", moduleName)));
}
/// <summary>
......@@ -302,7 +304,7 @@ public ImmutableArray<ModuleMetadata> GetModules()
/// <exception cref="BadImageFormatException">The PE image format is invalid.</exception>
/// <exception cref="IOException">IO error while reading the metadata. See <see cref="Exception.InnerException"/> for details.</exception>
/// <exception cref="ObjectDisposedException">The object has been disposed.</exception>
internal PEAssembly GetAssembly()
internal PEAssembly? GetAssembly()
{
return GetOrCreateData().Assembly;
}
......@@ -315,7 +317,7 @@ private Data GetOrCreateData()
if (_lazyData == null)
{
ImmutableArray<ModuleMetadata> modules = _initialModules;
ImmutableArray<ModuleMetadata>.Builder moduleBuilder = null;
ImmutableArray<ModuleMetadata>.Builder? moduleBuilder = null;
bool createdModulesUsed = false;
try
......@@ -445,11 +447,11 @@ public override MetadataImageKind Kind
/// <param name="display">Display string used in error messages to identity the reference.</param>
/// <returns>A reference to the assembly metadata.</returns>
public PortableExecutableReference GetReference(
DocumentationProvider documentation = null,
ImmutableArray<string> aliases = default(ImmutableArray<string>),
DocumentationProvider? documentation = null,
ImmutableArray<string> aliases = default,
bool embedInteropTypes = false,
string filePath = null,
string display = null)
string? filePath = null,
string? display = null)
{
return new MetadataImageReference(this, new MetadataReferenceProperties(MetadataImageKind.Assembly, aliases, embedInteropTypes), documentation, filePath, display);
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.CodeAnalysis.Text;
#nullable enable
namespace Microsoft.CodeAnalysis
{
......
......@@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -36,7 +37,7 @@ public struct MetadataReferenceProperties : IEquatable<MetadataReferenceProperti
/// <param name="kind">The image kind - assembly or module.</param>
/// <param name="aliases">Assembly aliases. Can't be set for a module.</param>
/// <param name="embedInteropTypes">True to embed interop types from the referenced assembly to the referencing compilation. Must be false for a module.</param>
public MetadataReferenceProperties(MetadataImageKind kind = MetadataImageKind.Assembly, ImmutableArray<string> aliases = default(ImmutableArray<string>), bool embedInteropTypes = false)
public MetadataReferenceProperties(MetadataImageKind kind = MetadataImageKind.Assembly, ImmutableArray<string> aliases = default, bool embedInteropTypes = false)
{
if (!kind.IsValid())
{
......@@ -157,7 +158,7 @@ public ImmutableArray<string> Aliases
/// </summary>
internal bool HasRecursiveAliases { get; private set; }
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return obj is MetadataReferenceProperties && Equals((MetadataReferenceProperties)obj);
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -306,7 +308,7 @@ public ImmutableArray<string> GetModuleNames()
/// <param name="filePath">Path describing the location of the metadata, or null if the metadata have no location.</param>
/// <param name="display">Display string used in error messages to identity the reference.</param>
/// <returns>A reference to the module metadata.</returns>
public PortableExecutableReference GetReference(DocumentationProvider documentation = null, string filePath = null, string display = null)
public PortableExecutableReference GetReference(DocumentationProvider? documentation = null, string? filePath = null, string? display = null)
{
return new MetadataImageReference(this, MetadataReferenceProperties.Module, documentation, filePath, display);
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis.FlowAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis.FlowAnalysis
......@@ -24,7 +26,7 @@ internal CaptureId(int value)
public bool Equals(CaptureId other) => Value == other.Value;
/// <inheritdoc/>
public override bool Equals(object obj) => obj is CaptureId && Equals((CaptureId)obj);
public override bool Equals(object? obj) => obj is CaptureId && Equals((CaptureId)obj);
/// <inheritdoc/>
public override int GetHashCode() => Value.GetHashCode();
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis.Operations;
namespace Microsoft.CodeAnalysis.FlowAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis.FlowAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -67,7 +69,7 @@ public RuleSet(string filePath, ReportDiagnostic generalOption, ImmutableDiction
/// <summary>
/// Create a RuleSet with a global effective action applied on it.
/// </summary>
public RuleSet WithEffectiveAction(ReportDiagnostic action)
public RuleSet? WithEffectiveAction(ReportDiagnostic action)
{
if (!_includes.IsEmpty)
{
......@@ -139,10 +141,11 @@ private RuleSet GetEffectiveRuleSet(HashSet<string> includedRulesetPaths)
// Recursively get the effective ruleset of the included file, in case they in turn
// contain includes.
var effectiveRuleset = ruleSet.GetEffectiveRuleSet(includedRulesetPaths);
RuleSet? effectiveRuleset = ruleSet.GetEffectiveRuleSet(includedRulesetPaths);
// Apply the includeAction on this ruleset.
effectiveRuleset = effectiveRuleset.WithEffectiveAction(ruleSetInclude.Action);
Debug.Assert(effectiveRuleset is object);
// If the included ruleset's global option is stricter, then make that the effective option.
if (IsStricterThan(effectiveRuleset.GeneralDiagnosticOption, effectiveGeneralOption))
......@@ -253,12 +256,7 @@ private static bool IsStricterThan(ReportDiagnostic action1, ReportDiagnostic ac
public static RuleSet LoadEffectiveRuleSetFromFile(string filePath)
{
var ruleSet = RuleSetProcessor.LoadFromFile(filePath);
if (ruleSet != null)
{
return ruleSet.GetEffectiveRuleSet(new HashSet<string>());
}
return null;
return ruleSet.GetEffectiveRuleSet(new HashSet<string>());
}
/// <summary>
......@@ -300,9 +298,8 @@ internal static ReportDiagnostic GetDiagnosticOptionsFromRulesetFile(string? rul
return GetDiagnosticOptionsFromRulesetFile(diagnosticOptions, rulesetFileFullPath, diagnosticsOpt, messageProviderOpt);
}
#nullable restore
private static ReportDiagnostic GetDiagnosticOptionsFromRulesetFile(Dictionary<string, ReportDiagnostic> diagnosticOptions, string resolvedPath, IList<Diagnostic> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
private static ReportDiagnostic GetDiagnosticOptionsFromRulesetFile(Dictionary<string, ReportDiagnostic> diagnosticOptions, string resolvedPath, IList<Diagnostic>? diagnosticsOpt, CommonMessageProvider? messageProviderOpt)
{
Debug.Assert(resolvedPath != null);
......
......@@ -2,12 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Security;
using System.Xml;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
......@@ -48,12 +46,12 @@ public RuleSetInclude(string includePath, ReportDiagnostic action)
/// Gets the RuleSet associated with this ruleset include
/// </summary>
/// <param name="parent">The parent of this ruleset include</param>
public RuleSet LoadRuleSet(RuleSet parent)
public RuleSet? LoadRuleSet(RuleSet parent)
{
// Try to load the rule set
RuleSet ruleSet = null;
RuleSet? ruleSet = null;
string path = _includePath;
string? path = _includePath;
try
{
path = GetIncludePath(parent);
......@@ -82,9 +80,9 @@ public RuleSet LoadRuleSet(RuleSet parent)
/// Returns a full path to the include file. Relative paths are expanded relative to the current rule set file.
/// </summary>
/// <param name="parent">The parent of this rule set include</param>
private string GetIncludePath(RuleSet parent)
private string? GetIncludePath(RuleSet parent)
{
var resolvedIncludePath = ResolveIncludePath(_includePath, parent?.FilePath);
var resolvedIncludePath = resolveIncludePath(_includePath, parent?.FilePath);
if (resolvedIncludePath == null)
{
return null;
......@@ -92,44 +90,44 @@ private string GetIncludePath(RuleSet parent)
// Return the canonical full path
return Path.GetFullPath(resolvedIncludePath);
}
private static string ResolveIncludePath(string includePath, string parentRulesetPath)
{
var resolvedIncludePath = ResolveIncludePathCore(includePath, parentRulesetPath);
if (resolvedIncludePath == null && PathUtilities.IsUnixLikePlatform)
static string? resolveIncludePath(string includePath, string? parentRulesetPath)
{
// Attempt to resolve legacy ruleset includes after replacing Windows style directory separator char with current plaform's directory separator char.
includePath = includePath.Replace('\\', Path.DirectorySeparatorChar);
resolvedIncludePath = ResolveIncludePathCore(includePath, parentRulesetPath);
}
return resolvedIncludePath;
}
var resolvedIncludePath = resolveIncludePathCore(includePath, parentRulesetPath);
if (resolvedIncludePath == null && PathUtilities.IsUnixLikePlatform)
{
// Attempt to resolve legacy ruleset includes after replacing Windows style directory separator char with current plaform's directory separator char.
includePath = includePath.Replace('\\', Path.DirectorySeparatorChar);
resolvedIncludePath = resolveIncludePathCore(includePath, parentRulesetPath);
}
private static string ResolveIncludePathCore(string includePath, string parentRulesetPath)
{
includePath = Environment.ExpandEnvironmentVariables(includePath);
return resolvedIncludePath;
}
// If a full path is specified then use it
if (Path.IsPathRooted(includePath))
static string? resolveIncludePathCore(string includePath, string? parentRulesetPath)
{
if (File.Exists(includePath))
includePath = Environment.ExpandEnvironmentVariables(includePath);
// If a full path is specified then use it
if (Path.IsPathRooted(includePath))
{
return includePath;
if (File.Exists(includePath))
{
return includePath;
}
}
}
else if (!string.IsNullOrEmpty(parentRulesetPath))
{
// Otherwise, try to find the include file relative to the parent ruleset.
includePath = PathUtilities.CombinePathsUnchecked(Path.GetDirectoryName(parentRulesetPath), includePath);
if (File.Exists(includePath))
else if (!string.IsNullOrEmpty(parentRulesetPath))
{
return includePath;
// Otherwise, try to find the include file relative to the parent ruleset.
includePath = PathUtilities.CombinePathsUnchecked(Path.GetDirectoryName(parentRulesetPath) ?? "", includePath);
if (File.Exists(includePath))
{
return includePath;
}
}
}
return null;
return null;
}
}
}
}
......@@ -54,14 +54,15 @@ internal class RuleSetProcessor
/// Creates and loads the rule set from a file
/// </summary>
/// <param name="filePath">The file path to load the rule set</param>
#nullable enable
public static RuleSet LoadFromFile(string filePath)
{
// First read the file without doing any validation
filePath = FileUtilities.NormalizeAbsolutePath(filePath);
XmlReaderSettings settings = GetDefaultXmlReaderSettings();
XDocument ruleSetDocument = null;
XElement ruleSetNode = null;
XDocument? ruleSetDocument = null;
XElement? ruleSetNode = null;
using (Stream stream = FileUtilities.OpenRead(filePath))
using (XmlReader xmlReader = XmlReader.Create(stream, settings))
......@@ -137,6 +138,7 @@ private static RuleSet ReadRuleSet(XElement ruleSetNode, string filePath)
return new RuleSet(filePath, generalOption, specificOptions.ToImmutable(), includes.ToImmutable());
}
#nullable restore
/// <summary>
/// Load the rules from the XML node
......
......@@ -2,14 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
#nullable enable
using System.Reflection.Metadata;
using System.Security.Cryptography;
using Microsoft.Cci;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
......@@ -23,7 +20,7 @@ protected StrongNameProvider()
}
public abstract override int GetHashCode();
public override abstract bool Equals(object other);
public override abstract bool Equals(object? other);
internal abstract StrongNameFileSystem FileSystem { get; }
......@@ -40,6 +37,6 @@ protected StrongNameProvider()
/// <summary>
/// Create a <see cref="StrongNameKeys"/> for the provided information.
/// </summary>
internal abstract StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider);
internal abstract StrongNameKeys CreateKeys(string? keyFilePath, string? keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider);
}
}
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
......@@ -2,9 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.PooledObjects;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Diagnostics;
namespace Microsoft.CodeAnalysis
......@@ -374,7 +376,7 @@ public class SymbolDisplayFormat
SymbolDisplayKindOptions kindOptions = default(SymbolDisplayKindOptions),
SymbolDisplayMiscellaneousOptions miscellaneousOptions = default(SymbolDisplayMiscellaneousOptions))
: this(
default(SymbolDisplayCompilerInternalOptions),
compilerInternalOptions: default,
globalNamespaceStyle,
typeQualificationStyle,
genericsOptions,
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......
......@@ -2,8 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
{
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......@@ -17,7 +19,7 @@ public struct SymbolDisplayPart
{
private readonly SymbolDisplayPartKind _kind;
private readonly string _text;
private readonly ISymbol _symbol;
private readonly ISymbol? _symbol;
/// <summary>
/// Gets the kind of this display part.
......@@ -29,7 +31,7 @@ public struct SymbolDisplayPart
/// For example, the <see cref="ITypeSymbol"/> associated with a class name.
/// </summary>
/// <returns></returns>
public ISymbol Symbol { get { return _symbol; } }
public ISymbol? Symbol { get { return _symbol; } }
/// <summary>
/// Construct a non-formattable <see cref="SymbolDisplayPart"/> (i.e. with a fixed string value).
......@@ -37,7 +39,7 @@ public struct SymbolDisplayPart
/// <param name="kind">The kind of the display part.</param>
/// <param name="symbol">An optional associated symbol.</param>
/// <param name="text">The fixed string value of the part.</param>
public SymbolDisplayPart(SymbolDisplayPartKind kind, ISymbol symbol, string text)
public SymbolDisplayPart(SymbolDisplayPartKind kind, ISymbol? symbol, string text)
{
if (!kind.IsValid())
{
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -2,6 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Diagnostics;
namespace Microsoft.CodeAnalysis
{
public static partial class ISymbolExtensions
......@@ -10,7 +14,7 @@ public static partial class ISymbolExtensions
/// Returns the constructed form of the ReducedFrom property,
/// including the type arguments that were either inferred during reduction or supplied at the call site.
/// </summary>
public static IMethodSymbol GetConstructedReducedFrom(this IMethodSymbol method)
public static IMethodSymbol? GetConstructedReducedFrom(this IMethodSymbol method)
{
if (method.MethodKind != MethodKind.ReducedExtension)
{
......@@ -19,6 +23,7 @@ public static IMethodSymbol GetConstructedReducedFrom(this IMethodSymbol method)
}
var reducedFrom = method.ReducedFrom;
Debug.Assert(reducedFrom is object);
if (!reducedFrom.IsGenericMethod)
{
// not generic, no inferences were made
......@@ -31,14 +36,16 @@ public static IMethodSymbol GetConstructedReducedFrom(this IMethodSymbol method)
for (int i = 0, n = method.TypeParameters.Length; i < n; i++)
{
var arg = method.TypeArguments[i];
var typeParameter = method.TypeParameters[i];
Debug.Assert(typeParameter.ReducedFrom is object);
// make sure we don't construct with type parameters originating from reduced symbol.
if (arg.Equals(method.TypeParameters[i]))
if (arg.Equals(typeParameter))
{
arg = method.TypeParameters[i].ReducedFrom;
arg = typeParameter.ReducedFrom;
}
typeArgs[method.TypeParameters[i].ReducedFrom.Ordinal] = arg;
typeArgs[typeParameter.ReducedFrom.Ordinal] = arg;
}
// add any inferences
......@@ -67,7 +74,7 @@ internal static bool IsDefaultTupleElement(this IFieldSymbol field)
/// </summary>
internal static bool IsTupleElement(this IFieldSymbol field)
{
return (object)field.CorrespondingTupleField != null;
return field.CorrespondingTupleField is object;
}
/// <summary>
......@@ -78,12 +85,12 @@ internal static bool IsTupleElement(this IFieldSymbol field)
/// Note that it is possible for an element to be both "Default" and to have a user provided name.
/// That could happen if the provided name matches the default name such as "Item10"
/// </remarks>
internal static string ProvidedTupleElementNameOrNull(this IFieldSymbol field)
internal static string? ProvidedTupleElementNameOrNull(this IFieldSymbol field)
{
return field.IsTupleElement() && !field.IsImplicitlyDeclared ? field.Name : null;
}
internal static INamespaceSymbol GetNestedNamespace(this INamespaceSymbol container, string name)
internal static INamespaceSymbol? GetNestedNamespace(this INamespaceSymbol container, string name)
{
foreach (var sym in container.GetMembers(name))
{
......
......@@ -2,11 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
......
......@@ -409,7 +409,7 @@ public SeparatedSyntaxList<TNode> InsertRange(int index, IEnumerable<TNode> node
}
// if item after last inserted node is a node, add separator
if (insertionIndex < nodesWithSeps.Count && nodesWithSeps[insertionIndex].IsNode)
if (insertionIndex < nodesWithSeps.Count && nodesWithSeps[insertionIndex] is { IsNode: true } nodeOrToken)
{
var node = nodesWithSeps[insertionIndex].AsNode();
Debug.Assert(node is object);
......
......@@ -2,9 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
{
......@@ -357,7 +358,7 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
/// </summary>
public static TSyntax WithLeadingTrivia<TSyntax>(
this TSyntax node,
IEnumerable<SyntaxTrivia> trivia) where TSyntax : SyntaxNode
IEnumerable<SyntaxTrivia>? trivia) where TSyntax : SyntaxNode
{
var first = node.GetFirstToken(includeZeroWidth: true);
var newFirst = first.WithLeadingTrivia(trivia);
......@@ -371,7 +372,7 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
this TSyntax node
) where TSyntax : SyntaxNode
{
return node.WithLeadingTrivia((IEnumerable<SyntaxTrivia>)null);
return node.WithLeadingTrivia((IEnumerable<SyntaxTrivia>?)null);
}
/// <summary>
......@@ -379,9 +380,9 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
/// </summary>
public static TSyntax WithLeadingTrivia<TSyntax>(
this TSyntax node,
params SyntaxTrivia[] trivia) where TSyntax : SyntaxNode
params SyntaxTrivia[]? trivia) where TSyntax : SyntaxNode
{
return node.WithLeadingTrivia((IEnumerable<SyntaxTrivia>)trivia);
return node.WithLeadingTrivia((IEnumerable<SyntaxTrivia>?)trivia);
}
/// <summary>
......@@ -401,7 +402,7 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
/// </summary>
public static TSyntax WithTrailingTrivia<TSyntax>(
this TSyntax node,
IEnumerable<SyntaxTrivia> trivia) where TSyntax : SyntaxNode
IEnumerable<SyntaxTrivia>? trivia) where TSyntax : SyntaxNode
{
var last = node.GetLastToken(includeZeroWidth: true);
var newLast = last.WithTrailingTrivia(trivia);
......@@ -413,7 +414,7 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
/// </summary>
public static TSyntax WithoutTrailingTrivia<TSyntax>(this TSyntax node) where TSyntax : SyntaxNode
{
return node.WithTrailingTrivia((IEnumerable<SyntaxTrivia>)null);
return node.WithTrailingTrivia((IEnumerable<SyntaxTrivia>?)null);
}
/// <summary>
......@@ -421,15 +422,15 @@ public static SyntaxToken WithoutTrivia(this SyntaxToken token)
/// </summary>
public static TSyntax WithTrailingTrivia<TSyntax>(
this TSyntax node,
params SyntaxTrivia[] trivia) where TSyntax : SyntaxNode
params SyntaxTrivia[]? trivia) where TSyntax : SyntaxNode
{
return node.WithTrailingTrivia((IEnumerable<SyntaxTrivia>)trivia);
return node.WithTrailingTrivia((IEnumerable<SyntaxTrivia>?)trivia);
}
/// <summary>
/// Attaches the node to a SyntaxTree that the same options as <paramref name="oldTree"/>
/// </summary>
internal static SyntaxNode AsRootOfNewTreeWithOptionsFrom(this SyntaxNode node, SyntaxTree oldTree)
internal static SyntaxNode? AsRootOfNewTreeWithOptionsFrom(this SyntaxNode node, SyntaxTree oldTree)
{
return node != null ? oldTree.WithRootAndOptions(node, oldTree.Options).GetRoot() : null;
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Text;
......@@ -28,14 +30,14 @@ public abstract class SyntaxReference
/// This action may cause a parse to happen to recover the syntax node.
/// </summary>
/// <returns>The original referenced syntax node.</returns>
public abstract SyntaxNode GetSyntax(CancellationToken cancellationToken = default(CancellationToken));
public abstract SyntaxNode GetSyntax(CancellationToken cancellationToken = default);
/// <summary>
/// Retrieves the original referenced syntax node.
/// This action may cause a parse to happen to recover the syntax node.
/// </summary>
/// <returns>The original referenced syntax node.</returns>
public virtual Task<SyntaxNode> GetSyntaxAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<SyntaxNode> GetSyntaxAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(this.GetSyntax(cancellationToken));
}
......
......@@ -2,8 +2,9 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
{
......
......@@ -468,15 +468,15 @@ public SyntaxToken WithLeadingTrivia(SyntaxTriviaList trivia)
/// <summary>
/// Creates a new token from this token with the leading trivia specified..
/// </summary>
public SyntaxToken WithLeadingTrivia(params SyntaxTrivia[] trivia)
public SyntaxToken WithLeadingTrivia(params SyntaxTrivia[]? trivia)
{
return this.WithLeadingTrivia((IEnumerable<SyntaxTrivia>)trivia);
return this.WithLeadingTrivia((IEnumerable<SyntaxTrivia>?)trivia);
}
/// <summary>
/// Creates a new token from this token with the leading trivia specified..
/// </summary>
public SyntaxToken WithLeadingTrivia(IEnumerable<SyntaxTrivia> trivia)
public SyntaxToken WithLeadingTrivia(IEnumerable<SyntaxTrivia>? trivia)
{
var greenList = trivia?.Select(t => t.RequiredUnderlyingNode);
......@@ -496,15 +496,15 @@ public SyntaxToken WithTrailingTrivia(SyntaxTriviaList trivia)
/// <summary>
/// Creates a new token from this token with the trailing trivia specified.
/// </summary>
public SyntaxToken WithTrailingTrivia(params SyntaxTrivia[] trivia)
public SyntaxToken WithTrailingTrivia(params SyntaxTrivia[]? trivia)
{
return this.WithTrailingTrivia((IEnumerable<SyntaxTrivia>)trivia);
return this.WithTrailingTrivia((IEnumerable<SyntaxTrivia>?)trivia);
}
/// <summary>
/// Creates a new token from this token with the trailing trivia specified.
/// </summary>
public SyntaxToken WithTrailingTrivia(IEnumerable<SyntaxTrivia> trivia)
public SyntaxToken WithTrailingTrivia(IEnumerable<SyntaxTrivia>? trivia)
{
var greenList = trivia?.Select(t => t.RequiredUnderlyingNode);
......
......@@ -2,12 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
......@@ -91,12 +92,12 @@ public ParseOptions Options
/// <summary>
/// Gets the syntax tree's text if it is available.
/// </summary>
public abstract bool TryGetText(out SourceText text);
public abstract bool TryGetText([NotNullWhen(true)] out SourceText? text);
/// <summary>
/// Gets the text of the source document.
/// </summary>
public abstract SourceText GetText(CancellationToken cancellationToken = default(CancellationToken));
public abstract SourceText GetText(CancellationToken cancellationToken = default);
/// <summary>
/// The text encoding of the source document.
......@@ -110,31 +111,28 @@ public ParseOptions Options
/// By default, the work associated with this method will be executed immediately on the current thread.
/// Implementations that wish to schedule this work differently should override <see cref="GetTextAsync(CancellationToken)"/>.
/// </remarks>
public virtual Task<SourceText> GetTextAsync(CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<SourceText> GetTextAsync(CancellationToken cancellationToken = default)
{
SourceText text;
return Task.FromResult(this.TryGetText(out text) ? text : this.GetText(cancellationToken));
return Task.FromResult(this.TryGetText(out SourceText? text) ? text : this.GetText(cancellationToken));
}
/// <summary>
/// Gets the root of the syntax tree if it is available.
/// </summary>
public bool TryGetRoot(out SyntaxNode root)
public bool TryGetRoot([NotNullWhen(true)] out SyntaxNode? root)
{
return TryGetRootCore(out root);
}
#nullable enable
/// <summary>
/// Gets the root of the syntax tree if it is available.
/// </summary>
protected abstract bool TryGetRootCore([NotNullWhen(true)] out SyntaxNode? root);
#nullable restore
/// <summary>
/// Gets the root node of the syntax tree, causing computation if necessary.
/// </summary>
public SyntaxNode GetRoot(CancellationToken cancellationToken = default(CancellationToken))
public SyntaxNode GetRoot(CancellationToken cancellationToken = default)
{
return GetRootCore(cancellationToken);
}
......@@ -147,7 +145,7 @@ public SyntaxNode GetRoot(CancellationToken cancellationToken = default(Cancella
/// <summary>
/// Gets the root node of the syntax tree asynchronously.
/// </summary>
public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = default(CancellationToken))
public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = default)
{
return GetRootAsyncCore(cancellationToken);
}
......@@ -172,7 +170,7 @@ public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = defau
/// This method does not filter diagnostics based on #pragmas and compiler options
/// like nowarn, warnaserror etc.
/// </summary>
public abstract IEnumerable<Diagnostic> GetDiagnostics(CancellationToken cancellationToken = default(CancellationToken));
public abstract IEnumerable<Diagnostic> GetDiagnostics(CancellationToken cancellationToken = default);
/// <summary>
/// Gets a list of all the diagnostics in the sub tree that has the specified node as its root.
......@@ -212,7 +210,7 @@ public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = defau
/// A valid <see cref="FileLinePositionSpan"/> that contains path, line and column information.
/// The values are not affected by line mapping directives (<c>#line</c>).
/// </returns>
public abstract FileLinePositionSpan GetLineSpan(TextSpan span, CancellationToken cancellationToken = default(CancellationToken));
public abstract FileLinePositionSpan GetLineSpan(TextSpan span, CancellationToken cancellationToken = default);
/// <summary>
/// Gets the location in terms of path, line and column after applying source line mapping directives
......@@ -229,14 +227,14 @@ public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = defau
/// A location path is considered mapped if the first <c>#line</c> directive that precedes it and that
/// either specifies an explicit file path or is <c>#line default</c> exists and specifies an explicit path.
/// </returns>
public abstract FileLinePositionSpan GetMappedLineSpan(TextSpan span, CancellationToken cancellationToken = default(CancellationToken));
public abstract FileLinePositionSpan GetMappedLineSpan(TextSpan span, CancellationToken cancellationToken = default);
/// <summary>
/// Returns the visibility for the line at the given position.
/// </summary>
/// <param name="position">The position to check.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public virtual LineVisibility GetLineVisibility(int position, CancellationToken cancellationToken = default(CancellationToken))
public virtual LineVisibility GetLineVisibility(int position, CancellationToken cancellationToken = default)
{
return LineVisibility.Visible;
}
......@@ -266,7 +264,7 @@ internal virtual FileLinePositionSpan GetMappedLineSpanAndVisibility(TextSpan sp
/// Unlike Dev12 we do account for #line and #ExternalSource directives when determining value for
/// <see cref="System.Runtime.CompilerServices.CallerFilePathAttribute"/>.
/// </remarks>
internal string GetDisplayPath(TextSpan span, SourceReferenceResolver resolver)
internal string GetDisplayPath(TextSpan span, SourceReferenceResolver? resolver)
{
var mappedSpan = GetMappedLineSpan(span);
if (resolver == null || mappedSpan.Path.IsEmpty())
......
......@@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.CodeAnalysis.Text;
#nullable enable
namespace Microsoft.CodeAnalysis
{
......@@ -40,7 +40,7 @@ public virtual void Visit(SyntaxNode node)
{
if (this.Depth >= SyntaxWalkerDepth.Node)
{
Visit(child.AsNode());
Visit(child.AsNode()!);
}
}
else if (child.IsToken)
......@@ -100,7 +100,7 @@ protected virtual void VisitTrivia(SyntaxTrivia trivia)
{
if (this.Depth >= SyntaxWalkerDepth.StructuredTrivia && trivia.HasStructure)
{
this.Visit(trivia.GetStructure());
this.Visit(trivia.GetStructure()!);
}
}
}
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
......@@ -15,11 +15,10 @@
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.SolutionCrawler;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp.UseExpressionBody
{
......@@ -145,6 +144,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
var parent = declaration is AccessorDeclarationSyntax
? declaration.Parent
: declaration;
RoslynDebug.Assert(parent is object);
var updatedParent = parent.ReplaceNode(declaration, updatedDeclaration)
.WithAdditionalAnnotations(Formatter.Annotation);
......
......@@ -2739,7 +2739,7 @@ private static bool HasBackingField(IEventSymbol @event)
foreach (var attribute in attributes)
{
RoslynDebug.Assert(attribute.AttributeClass is object); // TODO2
RoslynDebug.Assert(attribute.AttributeClass is object);
if (attribute.AttributeClass.Equals(lazyLayoutAttribute) && attribute.ConstructorArguments.Length == 1)
{
var layoutValue = attribute.ConstructorArguments.Single().Value;
......
......@@ -70,6 +70,7 @@ public enum Strategy
// Mark the context with an annotation.
// This will allow us to find it after we have called MakeSafeToAddNamespaces.
var annotation = new SyntaxAnnotation();
RoslynDebug.Assert(context is object);
document = document.WithSyntaxRoot(root.ReplaceNode(context, context.WithAdditionalAnnotations(annotation)));
root = (await document.GetSyntaxRootAsync().ConfigureAwait(false))!;
......
......@@ -422,6 +422,7 @@ public async Task<IEnumerable<TextChange>> GetTextChangesAsync(Document oldDocum
var tree = (await this.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false))!;
var oldTree = await oldDocument.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
RoslynDebug.Assert(oldTree is object);
return tree.GetChanges(oldTree);
}
......
......@@ -406,7 +406,7 @@ public static int GetArity(this ISymbol symbol)
var method = parameter.ContainingSymbol as IMethodSymbol;
if (method?.IsReducedExtension() == true)
{
symbol = method.GetConstructedReducedFrom().Parameters[parameter.Ordinal + 1];
symbol = method.GetConstructedReducedFrom()!.Parameters[parameter.Ordinal + 1];
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册