提交 39d23223 编写于 作者: G Gen Lu

Use constants for complex receiver type names

上级 968f15db
......@@ -120,11 +120,11 @@ private static string GetReceiverTypeName(ITypeSymbol typeSymbol)
// We do not differentiate array of different kinds sicne they are all represented in the indices as "NonArrayElementTypeName[]"
// e.g. int[], int[][], int[,], etc. are all represented as "int[]", whereas array of complex type such as T[] is "[]".
return elementTypeName + "[]";
return elementTypeName + FindSymbols.Extensions.ArrayReceiverTypeNameSuffix;
default:
// Complex types are represented by "";
return string.Empty;
return FindSymbols.Extensions.ComplexReceiverTypeName;
}
}
......@@ -237,14 +237,14 @@ private static string GetReceiverTypeName(ITypeSymbol typeSymbol)
return completionItemsbuilder.ToImmutable();
// Add strings represent complex types (i.e. "" and "[]") to the receiver type, so we would include in the filter
// info about extension methods with complex receiver type.
// Add strings represent complex types (i.e. "" for non-array types and "[]" for array types) to the receiver type,
// so we would include in the filter info about extension methods with complex receiver type.
static ImmutableArray<string> AttachComplexTypes(ImmutableArray<string> receiverTypeNames)
{
using var _ = ArrayBuilder<string>.GetInstance(receiverTypeNames.Length + 2, out var receiverTypeNamesBuilder);
receiverTypeNamesBuilder.AddRange(receiverTypeNames);
receiverTypeNamesBuilder.Add(string.Empty);
receiverTypeNamesBuilder.Add("[]");
receiverTypeNamesBuilder.Add(FindSymbols.Extensions.ComplexReceiverTypeName);
receiverTypeNamesBuilder.Add(FindSymbols.Extensions.ComplexArrayReceiverTypeName);
return receiverTypeNamesBuilder.ToImmutable();
}
......
......@@ -13,6 +13,10 @@ namespace Microsoft.CodeAnalysis.FindSymbols
{
internal static partial class Extensions
{
public const string ComplexReceiverTypeName = "";
public const string ComplexArrayReceiverTypeName = "[]";
public const string ArrayReceiverTypeNameSuffix = "[]";
public static async Task<IEnumerable<SyntaxToken>> GetConstructorInitializerTokensAsync(this Document document, SemanticModel model, CancellationToken cancellationToken)
{
var root = await model.SyntaxTree.GetRootAsync(cancellationToken).ConfigureAwait(false);
......
......@@ -87,7 +87,11 @@ private string GetDebuggerDisplay()
public readonly string Name;
/// <summary>
/// Indicate if the type of parameter is any kind of array (used for both simple and complex types)
/// Indicate if the type of parameter is any kind of array.
/// This is relevant for both simple and complex types. For example:
/// - array of simple type like int[], int[][], int[][,], etc. are all ultimately represented as "int[]" in index.
/// - array of complex type like T[], T[][], etc are all represented as "[]" in index,
/// in contrast to just "" for non-array types.
/// </summary>
public readonly bool IsArray;
......
......@@ -730,10 +730,10 @@ private ImmutableArray<BuilderNode> GenerateUnsortedNodes(MultiDictionary<string
// similar for complex receiver types, "[]" means it's an array type, "" otherwise.
var parameterTypeName = (parameterTypeInfo.IsComplexType, parameterTypeInfo.IsArray) switch
{
(true, true) => "[]",
(true, false) => string.Empty,
(false, true) => parameterTypeInfo.Name + "[]",
(false, false) => parameterTypeInfo.Name
(true, true) => Extensions.ComplexArrayReceiverTypeName, // complex array type, e.g. "T[,]"
(true, false) => Extensions.ComplexReceiverTypeName, // complex non-array type, e.g. "T"
(false, true) => parameterTypeInfo.Name + Extensions.ArrayReceiverTypeNameSuffix, // simple array type, e.g. "int[][,]"
(false, false) => parameterTypeInfo.Name // simple non-array type, e.g. "int"
};
receiverTypeNameToMethodMap.Add(parameterTypeName, new ExtensionMethodInfo(fullyQualifiedContainerName, child.Name));
......
......@@ -43,7 +43,7 @@ internal partial class SyntaxTreeIndex
/// </summary>
public readonly ImmutableDictionary<string, ImmutableArray<int>> ReceiverTypeNameToExtensionMethodMap { get; }
public bool ContainsExtensionMethod => ReceiverTypeNameToExtensionMethodMap.Count > 0;
public bool ContainsExtensionMethod => !ReceiverTypeNameToExtensionMethodMap.IsEmpty;
public ExtensionMethodInfo(ImmutableDictionary<string, ImmutableArray<int>> receiverTypeNameToExtensionMethodMap)
{
......
......@@ -314,7 +314,7 @@ internal sealed partial class SyntaxTreeIndex
// simply treat it as a complex method.
if (originalName == null)
{
receiverTypeName = string.Empty;
receiverTypeName = Extensions.ComplexReceiverTypeName;
}
else
{
......
......@@ -36,13 +36,17 @@ internal abstract class AbstractDeclaredSymbolInfoFactoryService : IDeclaredSymb
// e.g. int[], int[][], int[,], etc. are all represented as int[] in the index.
protected static string CreateReceiverTypeString(string typeName, bool isArray)
{
if (typeName == null)
if (string.IsNullOrEmpty(typeName))
{
return isArray ? "[]" : string.Empty;
return isArray
? FindSymbols.Extensions.ComplexArrayReceiverTypeName
: FindSymbols.Extensions.ComplexReceiverTypeName;
}
else
{
return isArray ? typeName + "[]" : typeName;
return isArray
? typeName + FindSymbols.Extensions.ArrayReceiverTypeNameSuffix
: typeName;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册