提交 9f507167 编写于 作者: C CyrusNajmabadi

Break types into separate files.

上级 48826c20
......@@ -268,8 +268,11 @@
<Compile Include="Implementation\Diagnostics\SuggestionTag.cs" />
<Compile Include="Implementation\FindReferences\DefinitionItem.cs" />
<Compile Include="Implementation\FindReferences\DefinitionLocation.cs" />
<Compile Include="Implementation\FindReferences\DefinitionLocation.NonNavigatingDefinitionLocation.cs" />
<Compile Include="Implementation\FindReferences\DefinitionLocation.SymbolDefinitionLocation.cs" />
<Compile Include="Implementation\FindReferences\DefinitionsAndReferences.cs" />
<Compile Include="Implementation\FindReferences\DocumentLocation.cs" />
<Compile Include="Implementation\FindReferences\DefinitionLocation.DocumentDefinitionLocation.cs" />
<Compile Include="Implementation\FindReferences\SourceReferenceItem.cs" />
<Compile Include="Implementation\FindReferences\FindReferencesUtilities.cs" />
<Compile Include="Implementation\FindReferences\IDefinitionsAndReferencesFactory.cs" />
......
// 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.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Editor.Implementation.FindReferences
{
internal partial class DefinitionLocation
{
private sealed class DocumentDefinitionLocation : DefinitionLocation
{
private readonly DocumentLocation _location;
public DocumentDefinitionLocation(DocumentLocation location)
{
_location = location;
}
public override ImmutableArray<TaggedText> OriginationParts =>
ImmutableArray.Create(new TaggedText(TextTags.Text, _location.Document.Project.Name));
public override bool CanNavigateTo()
{
return _location.CanNavigateTo();
}
public override bool TryNavigateTo()
{
return _location.TryNavigateTo();
}
}
}
}
// 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.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Editor.Implementation.FindReferences
{
internal partial class DefinitionLocation
{
private sealed class NonNavigatingDefinitionLocation : DefinitionLocation
{
private readonly ImmutableArray<TaggedText> _originationParts;
public NonNavigatingDefinitionLocation(ImmutableArray<TaggedText> originationParts)
{
_originationParts = originationParts;
}
public override ImmutableArray<TaggedText> OriginationParts => _originationParts;
public override bool CanNavigateTo()
{
return false;
}
public override bool TryNavigateTo()
{
return false;
}
}
}
}
// 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.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.Navigation;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.FindReferences
{
internal partial class DefinitionLocation
{
private sealed class SymbolDefinitionLocation : DefinitionLocation
{
private readonly Workspace _workspace;
private readonly ProjectId _referencingProjectId;
private readonly SymbolKey _symbolKey;
private readonly ImmutableArray<TaggedText> _originationParts;
public SymbolDefinitionLocation(ISymbol definition, Project project)
{
_workspace = project.Solution.Workspace;
_referencingProjectId = project.Id;
_symbolKey = definition.GetSymbolKey();
_originationParts = GetOriginationParts(definition);
}
public override ImmutableArray<TaggedText> OriginationParts => _originationParts;
public override bool CanNavigateTo()
{
return TryNavigateTo((symbol, project, service) => true);
}
public override bool TryNavigateTo()
{
return TryNavigateTo((symbol, project, service) =>
service.TryNavigateToSymbol(symbol, project));
}
private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool> action)
{
var symbol = ResolveSymbolInCurrentSolution();
var referencingProject = _workspace.CurrentSolution.GetProject(_referencingProjectId);
if (symbol == null || referencingProject == null)
{
return false;
}
if (symbol.Kind == SymbolKind.Namespace)
{
return false;
}
var navigationService = _workspace.Services.GetService<ISymbolNavigationService>();
return action(symbol, referencingProject, navigationService);
}
private ISymbol ResolveSymbolInCurrentSolution()
{
var compilation = _workspace.CurrentSolution.GetProject(_referencingProjectId)
.GetCompilationAsync(CancellationToken.None)
.WaitAndGetResult(CancellationToken.None);
return _symbolKey.Resolve(compilation).Symbol;
}
}
}
}
\ No newline at end of file
// 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.Immutable;
using System.Threading;
using Microsoft.CodeAnalysis.Navigation;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.FindReferences
{
......@@ -18,7 +14,7 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.FindReferences
/// Subclassing is also supported for scenarios that fall outside the bounds of
/// these common cases.
/// </summary>
internal abstract class DefinitionLocation
internal abstract partial class DefinitionLocation
{
/// <summary>
/// Where the location originally came from (for example, the containing assembly or
......@@ -49,29 +45,6 @@ public static DefinitionLocation CreateSymbolLocation(ISymbol symbol, Project re
return new NonNavigatingDefinitionLocation(originationParts);
}
private sealed class DocumentDefinitionLocation : DefinitionLocation
{
private readonly DocumentLocation _location;
public DocumentDefinitionLocation(DocumentLocation location)
{
_location = location;
}
public override ImmutableArray<TaggedText> OriginationParts =>
ImmutableArray.Create(new TaggedText(TextTags.Text, _location.Document.Project.Name));
public override bool CanNavigateTo()
{
return _location.CanNavigateTo();
}
public override bool TryNavigateTo()
{
return _location.TryNavigateTo();
}
}
internal static ImmutableArray<TaggedText> GetOriginationParts(ISymbol symbol)
{
var assemblyName = symbol.ContainingAssembly?.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat);
......@@ -79,83 +52,5 @@ internal static ImmutableArray<TaggedText> GetOriginationParts(ISymbol symbol)
? ImmutableArray<TaggedText>.Empty
: ImmutableArray.Create(new TaggedText(TextTags.Assembly, assemblyName));
}
private sealed class SymbolDefinitionLocation : DefinitionLocation
{
private readonly Workspace _workspace;
private readonly ProjectId _referencingProjectId;
private readonly SymbolKey _symbolKey;
private readonly ImmutableArray<TaggedText> _originationParts;
public SymbolDefinitionLocation(ISymbol definition, Project project)
{
_workspace = project.Solution.Workspace;
_referencingProjectId = project.Id;
_symbolKey = definition.GetSymbolKey();
_originationParts = GetOriginationParts(definition);
}
public override ImmutableArray<TaggedText> OriginationParts => _originationParts;
public override bool CanNavigateTo()
{
return TryNavigateTo((symbol, project, service) => true);
}
public override bool TryNavigateTo()
{
return TryNavigateTo((symbol, project, service) =>
service.TryNavigateToSymbol(symbol, project));
}
private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool> action)
{
var symbol = ResolveSymbolInCurrentSolution();
var referencingProject = _workspace.CurrentSolution.GetProject(_referencingProjectId);
if (symbol == null || referencingProject == null)
{
return false;
}
if (symbol.Kind == SymbolKind.Namespace)
{
return false;
}
var navigationService = _workspace.Services.GetService<ISymbolNavigationService>();
return action(symbol, referencingProject, navigationService);
}
private ISymbol ResolveSymbolInCurrentSolution()
{
var compilation = _workspace.CurrentSolution.GetProject(_referencingProjectId)
.GetCompilationAsync(CancellationToken.None)
.WaitAndGetResult(CancellationToken.None);
return _symbolKey.Resolve(compilation).Symbol;
}
}
private sealed class NonNavigatingDefinitionLocation : DefinitionLocation
{
private readonly ImmutableArray<TaggedText> _originationParts;
public NonNavigatingDefinitionLocation(ImmutableArray<TaggedText> originationParts)
{
_originationParts = originationParts;
}
public override ImmutableArray<TaggedText> OriginationParts => _originationParts;
public override bool CanNavigateTo()
{
return false;
}
public override bool TryNavigateTo()
{
return false;
}
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册