提交 e031fa96 编写于 作者: A Andrew Casey

Reduce code duplication.

上级 0b6941b8
......@@ -1504,17 +1504,7 @@ private void AddMemberLookupSymbolsInfoInSubmissions(LookupSymbolsInfo result, T
{
foreach (var usingAlias in usingAliases)
{
var aliasSymbol = usingAlias.Alias;
var targetSymbol = aliasSymbol.GetAliasTarget(basesBeingResolved: null);
if (originalBinder.CanAddLookupSymbolInfo(targetSymbol, options, null))
{
// Note: we do not mark nodes when looking up arities or names. This is because these two
// types of lookup are only around to make the public
// SemanticModel.LookupNames/LookupSymbols work and do not count as usages of the directives
// when the actual code is bound.
result.AddSymbol(aliasSymbol, aliasSymbol.Name, 0);
}
AddAliasSymbolToResult(result, usingAlias.Alias, options, originalBinder);
}
}
......@@ -1525,6 +1515,21 @@ private void AddMemberLookupSymbolsInfoInSubmissions(LookupSymbolsInfo result, T
}
}
/// <remarks>
/// Note: we do not mark nodes when looking up arities or names. This is because these two
/// types of lookup are only around to make the public
/// SemanticModel.LookupNames/LookupSymbols work and do not count as usages of the directives
/// when the actual code is bound.
/// </remarks>
internal static void AddAliasSymbolToResult(LookupSymbolsInfo result, AliasSymbol aliasSymbol, LookupOptions options, Binder originalBinder)
{
var targetSymbol = aliasSymbol.GetAliasTarget(basesBeingResolved: null);
if (originalBinder.CanAddLookupSymbolInfo(targetSymbol, options, null))
{
result.AddSymbol(aliasSymbol, aliasSymbol.Name, 0);
}
}
private static void AddMemberLookupSymbolsInfoInNamespace(LookupSymbolsInfo result, NamespaceSymbol ns, LookupOptions options, Binder originalBinder)
{
foreach (var symbol in GetCandidateMembers(ns, options, originalBinder))
......
......@@ -318,7 +318,8 @@ private void MarkImportDirective(CSharpSyntaxNode directive, bool callerIsSemant
private static void MarkImportDirective(CSharpCompilation compilation, CSharpSyntaxNode directive, bool callerIsSemanticModel)
{
if (directive != null && compilation != null && !callerIsSemanticModel)
Debug.Assert(compilation != null); // If any directives are used, then there must be a compilation.
if (directive != null && !callerIsSemanticModel)
{
compilation.MarkImportDirectiveAsUsed(directive);
}
......@@ -598,25 +599,12 @@ internal void AddLookupSymbolsInfoInAliases(Binder originalBinder, LookupSymbols
{
foreach (var usingAlias in this.UsingAliases.Values)
{
var usingAliasSymbol = usingAlias.Alias;
var usingAliasTargetSymbol = usingAliasSymbol.GetAliasTarget(basesBeingResolved: null);
if (originalBinder.CanAddLookupSymbolInfo(usingAliasTargetSymbol, options, null))
{
result.AddSymbol(usingAliasSymbol, usingAliasSymbol.Name, 0);
}
Binder.AddAliasSymbolToResult(result, usingAlias.Alias, options, originalBinder);
}
if (this.ExternAliases != null)
foreach (var externAlias in this.ExternAliases)
{
foreach (var externAlias in this.ExternAliases)
{
var externAliasSymbol = externAlias.Alias;
var externAliasTargetSymbol = externAliasSymbol.GetAliasTarget(basesBeingResolved: null);
if (originalBinder.CanAddLookupSymbolInfo(externAliasTargetSymbol, options, null))
{
result.AddSymbol(externAliasSymbol, externAliasSymbol.Name, 0);
}
}
Binder.AddAliasSymbolToResult(result, externAlias.Alias, options, originalBinder);
}
}
......
......@@ -1220,26 +1220,6 @@ private ImmutableArray<NamespaceOrTypeAndUsingDirective> BindExternalUsings()
var externalUsings = ArrayBuilder<NamespaceOrTypeAndUsingDirective>.GetInstance();
var uniqueTargets = PooledHashSet<NamespaceOrTypeSymbol>.GetInstance();
foreach (var previousUsing in previousSubmission.ExternalUsings)
{
var previousTarget = previousUsing.NamespaceOrType;
if (previousTarget.IsType)
{
if (uniqueTargets.Add(previousTarget))
{
externalUsings.Add(previousUsing);
}
}
else
{
var expandedNamespace = ExpandPreviousSubmissionNamespace((NamespaceSymbol)previousTarget, this.GlobalNamespace);
if (uniqueTargets.Add(expandedNamespace))
{
externalUsings.Add(new NamespaceOrTypeAndUsingDirective(expandedNamespace, previousUsing.UsingDirective));
}
}
}
// The previous submission should not have had extern aliases (unsupported)
// and using aliases are handled separately (during lookup) so we only need
// to extract the regular usings.
......@@ -1258,7 +1238,7 @@ private ImmutableArray<NamespaceOrTypeAndUsingDirective> BindExternalUsings()
//}
//else
{
foreach (var previousUsing in previousSubmission.SubmissionImports.Usings)
foreach (var previousUsing in previousSubmission.ExternalUsings.Concat(previousSubmission.SubmissionImports.Usings))
{
var previousTarget = previousUsing.NamespaceOrType;
if (previousTarget.IsType)
......@@ -1324,7 +1304,7 @@ private static NamespaceSymbol ExpandPreviousSubmissionNamespace(NamespaceSymbol
/// <remarks>
/// Always consider whether usings should be considered before accessing this (e.g. not when binding other usings).
/// </remarks>
internal Dictionary<string, AliasAndUsingDirective> SubmissionUsingAliases => SubmissionImports?.UsingAliases;
internal ImmutableDictionary<string, AliasAndUsingDirective> SubmissionUsingAliases => SubmissionImports?.UsingAliases;
private Imports SubmissionImports
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册