提交 b4c9c9e6 编写于 作者: C CyrusNajmabadi

Add more contract guarantees

上级 9862f360
......@@ -155,7 +155,7 @@ private static Metadata GetMetadataNoThrow(PortableExecutableReference reference
{
var filePath = reference.FilePath;
return TryLoadOrCreateAsync(
var result = TryLoadOrCreateAsync(
solution,
checksum,
filePath,
......@@ -165,6 +165,8 @@ private static Metadata GetMetadataNoThrow(PortableExecutableReference reference
getPersistedChecksum: info => info.Checksum,
readObject: reader => ReadSymbolTreeInfo(reader, (names, nodes) => GetSpellCheckerTask(solution, checksum, filePath, names, nodes)),
cancellationToken: cancellationToken);
Contract.ThrowIfFalse(result != null || loadOnly == true, "Result can only be null if 'loadOnly: true' was passed.");
return result;
}
private static Task<SymbolTreeInfo> CreateMetadataSymbolTreeInfoAsync(
......
......@@ -19,25 +19,6 @@ internal partial class SymbolTreeInfo : IObjectWritable
private const string PrefixMetadataSymbolTreeInfo = "<SymbolTreeInfo>";
private const string SerializationFormat = "17";
/// <summary>
/// Loads the SymbolTreeInfo for a given assembly symbol (metadata or project). If the
/// info can't be loaded, it will be created (and persisted if possible).
/// </summary>
private static Task<SymbolTreeInfo> LoadOrCreateSourceSymbolTreeInfoAsync(
Project project, Checksum checksum, bool loadOnly, CancellationToken cancellationToken)
{
return TryLoadOrCreateAsync(
project.Solution,
checksum,
project.FilePath,
loadOnly,
createAsync: () => CreateSourceSymbolTreeInfoAsync(project, checksum, cancellationToken),
keySuffix: "_Source",
getPersistedChecksum: info => info.Checksum,
readObject: reader => ReadSymbolTreeInfo(reader, (names, nodes) => GetSpellCheckerTask(project.Solution, checksum, project.FilePath, names, nodes)),
cancellationToken: cancellationToken);
}
/// <summary>
/// Loads the SpellChecker for a given assembly symbol (metadata or project). If the
/// info can't be loaded, it will be created (and persisted if possible).
......@@ -48,7 +29,7 @@ internal partial class SymbolTreeInfo : IObjectWritable
string filePath,
Func<Task<SpellChecker>> createAsync)
{
return TryLoadOrCreateAsync(
var result = TryLoadOrCreateAsync(
solution,
checksum,
filePath,
......@@ -58,6 +39,8 @@ internal partial class SymbolTreeInfo : IObjectWritable
getPersistedChecksum: s => s.Checksum,
readObject: SpellChecker.ReadFrom,
cancellationToken: CancellationToken.None);
Contract.ThrowIfNull(result, "Result should never be null as we passed 'loadOnly: false'.");
return result;
}
/// <summary>
......
......@@ -29,9 +29,17 @@ private static void FreeSymbolMap(MultiDictionary<string, ISymbol> symbolMap)
public static Task<SymbolTreeInfo> GetInfoForSourceAssemblyAsync(
Project project, Checksum checksum, CancellationToken cancellationToken)
{
var result = LoadOrCreateSourceSymbolTreeInfoAsync(
project, checksum, loadOnly: false, cancellationToken: cancellationToken);
Contract.ThrowIfNull(result);
var result = TryLoadOrCreateAsync(
project.Solution,
checksum,
project.FilePath,
loadOnly: false,
createAsync: () => CreateSourceSymbolTreeInfoAsync(project, checksum, cancellationToken),
keySuffix: "_Source",
getPersistedChecksum: info => info.Checksum,
readObject: reader => ReadSymbolTreeInfo(reader, (names, nodes) => GetSpellCheckerTask(project.Solution, checksum, project.FilePath, names, nodes)),
cancellationToken: cancellationToken);
Contract.ThrowIfNull(result, "Result should never be null as we passed 'loadOnly: false'.");
return result;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册