提交 0482b0e3 编写于 作者: C CyrusNajmabadi

Cleanup, and move to more strict contracts.

上级 8a86f631
...@@ -140,16 +140,18 @@ private async Task<Document> ProcessNode(Document document, SyntaxNode node, str ...@@ -140,16 +140,18 @@ private async Task<Document> ProcessNode(Document document, SyntaxNode node, str
var syntaxFacts = project.LanguageServices.GetService<ISyntaxFactsService>(); var syntaxFacts = project.LanguageServices.GetService<ISyntaxFactsService>();
syntaxFacts.GetNameAndArityOfSimpleName(node, out var name, out var arity); syntaxFacts.GetNameAndArityOfSimpleName(node, out var name, out var arity);
var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync(
project, name, this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false); project, SearchQuery.Create(name, this.IgnoreCase),
SymbolFilter.Type, cancellationToken).ConfigureAwait(false);
var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol); var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol);
// also lookup type symbols with the "Attribute" suffix. // also lookup type symbols with the "Attribute" suffix.
var inAttributeContext = syntaxFacts.IsAttributeName(node); var inAttributeContext = syntaxFacts.IsAttributeName(node);
if (inAttributeContext) if (inAttributeContext)
{ {
var attributeSymbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( var attributeSymbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync(
project, name + "Attribute", this.IgnoreCase, SymbolFilter.Type, cancellationToken).ConfigureAwait(false); project, SearchQuery.Create(name + "Attribute", this.IgnoreCase),
SymbolFilter.Type, cancellationToken).ConfigureAwait(false);
symbols = symbols.Concat(attributeSymbolAndProjectIds.SelectAsArray(t => t.Symbol)); symbols = symbols.Concat(attributeSymbolAndProjectIds.SelectAsArray(t => t.Symbol));
} }
...@@ -189,8 +191,9 @@ private static bool HasValidContainer(ISymbol symbol) ...@@ -189,8 +191,9 @@ private static bool HasValidContainer(ISymbol symbol)
return ImmutableArray<SymbolResult>.Empty; return ImmutableArray<SymbolResult>.Empty;
} }
var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsAsync( var symbolAndProjectIds = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync(
project, name, this.IgnoreCase, SymbolFilter.Namespace, cancellationToken).ConfigureAwait(false); project, SearchQuery.Create(name, this.IgnoreCase),
SymbolFilter.Namespace, cancellationToken).ConfigureAwait(false);
var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol); var symbols = symbolAndProjectIds.SelectAsArray(t => t.Symbol);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FindSymbols namespace Microsoft.CodeAnalysis.FindSymbols
{ {
...@@ -16,7 +17,7 @@ internal static partial class DeclarationFinder ...@@ -16,7 +17,7 @@ internal static partial class DeclarationFinder
Project project, SearchQuery query, SymbolFilter filter, Project project, SearchQuery query, SymbolFilter filter,
ArrayBuilder<SymbolAndProjectId> list, CancellationToken cancellationToken) ArrayBuilder<SymbolAndProjectId> list, CancellationToken cancellationToken)
{ {
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
return AddCompilationDeclarationsWithNormalQueryAsync( return AddCompilationDeclarationsWithNormalQueryAsync(
project, query, filter, list, project, query, filter, list,
startingCompilation: null, startingCompilation: null,
...@@ -33,7 +34,7 @@ internal static partial class DeclarationFinder ...@@ -33,7 +34,7 @@ internal static partial class DeclarationFinder
IAssemblySymbol startingAssembly, IAssemblySymbol startingAssembly,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
using (Logger.LogBlock(FunctionId.SymbolFinder_Project_AddDeclarationsAsync, cancellationToken)) using (Logger.LogBlock(FunctionId.SymbolFinder_Project_AddDeclarationsAsync, cancellationToken))
{ {
...@@ -67,7 +68,7 @@ internal static partial class DeclarationFinder ...@@ -67,7 +68,7 @@ internal static partial class DeclarationFinder
{ {
// All entrypoints to this function are Find functions that are only searching // All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search). // for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken)) using (Logger.LogBlock(FunctionId.SymbolFinder_Assembly_AddDeclarationsAsync, cancellationToken))
{ {
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Remote; using Microsoft.CodeAnalysis.Remote;
using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities; using Roslyn.Utilities;
...@@ -18,52 +16,12 @@ namespace Microsoft.CodeAnalysis.FindSymbols ...@@ -18,52 +16,12 @@ namespace Microsoft.CodeAnalysis.FindSymbols
internal static partial class DeclarationFinder internal static partial class DeclarationFinder
{ {
/// <summary> public static async Task<ImmutableArray<SymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
/// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name.
/// </summary>
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindAllDeclarationsAsync(
Project project, string name, bool ignoreCase, CancellationToken cancellationToken)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (string.IsNullOrWhiteSpace(name))
{
return ImmutableArray<SymbolAndProjectId>.Empty;
}
return await FindAllDeclarationsWithNormalQueryAsync(
project, SearchQuery.Create(name, ignoreCase), SymbolFilter.All, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// Find the declared symbols from either source, referenced projects or metadata assemblies with the specified name.
/// </summary>
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindAllDeclarationsAsync(
Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (string.IsNullOrWhiteSpace(name))
{
return ImmutableArray<SymbolAndProjectId>.Empty;
}
return await FindAllDeclarationsWithNormalQueryAsync(
project, SearchQuery.Create(name, ignoreCase), filter, cancellationToken: cancellationToken).ConfigureAwait(false);
}
internal static async Task<ImmutableArray<SymbolAndProjectId>> FindAllDeclarationsWithNormalQueryAsync(
Project project, SearchQuery query, SymbolFilter criteria, CancellationToken cancellationToken) Project project, SearchQuery query, SymbolFilter criteria, CancellationToken cancellationToken)
{ {
// All entrypoints to this function are Find functions that are only searching // All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search). // for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
if (project == null) if (project == null)
{ {
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.FindSymbols namespace Microsoft.CodeAnalysis.FindSymbols
{ {
...@@ -20,8 +14,8 @@ public static partial class SymbolFinder ...@@ -20,8 +14,8 @@ public static partial class SymbolFinder
public static async Task<IEnumerable<ISymbol>> FindDeclarationsAsync( public static async Task<IEnumerable<ISymbol>> FindDeclarationsAsync(
Project project, string name, bool ignoreCase, CancellationToken cancellationToken = default(CancellationToken)) Project project, string name, bool ignoreCase, CancellationToken cancellationToken = default(CancellationToken))
{ {
var declarations = await DeclarationFinder.FindAllDeclarationsAsync( var declarations = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync(
project, name, ignoreCase, cancellationToken).ConfigureAwait(false); project, SearchQuery.Create(name, ignoreCase), SymbolFilter.All, cancellationToken).ConfigureAwait(false);
return declarations.SelectAsArray(t => t.Symbol); return declarations.SelectAsArray(t => t.Symbol);
} }
...@@ -31,8 +25,8 @@ public static partial class SymbolFinder ...@@ -31,8 +25,8 @@ public static partial class SymbolFinder
public static async Task<IEnumerable<ISymbol>> FindDeclarationsAsync( public static async Task<IEnumerable<ISymbol>> FindDeclarationsAsync(
Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken)) Project project, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
{ {
var declarations = await DeclarationFinder.FindAllDeclarationsAsync( var declarations = await DeclarationFinder.FindAllDeclarationsWithNormalQueryAsync(
project, name, ignoreCase, filter, cancellationToken).ConfigureAwait(false); project, SearchQuery.Create(name, ignoreCase), filter, cancellationToken).ConfigureAwait(false);
return declarations.SelectAsArray(t => t.Symbol); return declarations.SelectAsArray(t => t.Symbol);
} }
} }
......
...@@ -119,7 +119,7 @@ internal partial class SymbolTreeInfo ...@@ -119,7 +119,7 @@ internal partial class SymbolTreeInfo
{ {
// All entrypoints to this function are Find functions that are only searching // All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search). // for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
return this.FindAsync( return this.FindAsync(
query, new AsyncLazy<IAssemblySymbol>(assembly), query, new AsyncLazy<IAssemblySymbol>(assembly),
...@@ -132,7 +132,7 @@ internal partial class SymbolTreeInfo ...@@ -132,7 +132,7 @@ internal partial class SymbolTreeInfo
{ {
// All entrypoints to this function are Find functions that are only searching // All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search). // for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
var symbols = await FindAsyncWorker(query, lazyAssembly, cancellationToken).ConfigureAwait(false); var symbols = await FindAsyncWorker(query, lazyAssembly, cancellationToken).ConfigureAwait(false);
...@@ -146,7 +146,7 @@ internal partial class SymbolTreeInfo ...@@ -146,7 +146,7 @@ internal partial class SymbolTreeInfo
{ {
// All entrypoints to this function are Find functions that are only searching // All entrypoints to this function are Find functions that are only searching
// for specific strings (i.e. they never do a custom search). // for specific strings (i.e. they never do a custom search).
Debug.Assert(query.Kind != SearchKind.Custom); Contract.ThrowIfTrue(query.Kind == SearchKind.Custom, "Custom queries are not supported in this API");
// If the query has a specific string provided, then call into the SymbolTreeInfo // If the query has a specific string provided, then call into the SymbolTreeInfo
// helpers optimized for lookup based on an exact name. // helpers optimized for lookup based on an exact name.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册