提交 f85d32f1 编写于 作者: D David Poeschl

Rename: Don't restrict rename project search set for explicit interface implementations

Fixes #8139

We were previously asserting that renaming a private member meant that the rename operation would occur entirely in that member's declaring project, but rename affect other projects if the private member is an explicit implementation of a public interface member.
上级 3b6ea89f
......@@ -3153,8 +3153,48 @@ namespace X
</Document>
</Project>
</Workspace>, renameTo:="IFooEx")
End Using
End Sub
<WorkItem(8139, "https://github.com/dotnet/roslyn/issues/8139")>
<Fact, Trait(Traits.Feature, Traits.Features.Rename)>
Public Sub RenameExplicitInterfaceImplementationFromDifferentProject()
Using result = RenameEngineResult.Create(
<Workspace>
<Project Language="C#" AssemblyName="Project1" CommonReferences="true">
<ProjectReference>Project2</ProjectReference>
<Document>
class Program
{
static void Main(string[] args)
{
Test(new Class1());
}
static void Test(IInterface i)
{
i.[|M|]();
}
}
</Document>
</Project>
<Project Language="C#" AssemblyName="Project2" CommonReferences="true">
<Document>
public class Class1 : IInterface
{
void IInterface.[|$$M|]() { } // Rename 'M' from here
}
public interface IInterface
{
void [|M|]();
}
</Document>
</Project>
</Workspace>, renameTo:="Foo")
End Using
End Sub
......
......@@ -79,9 +79,8 @@ internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbo
.Concat(documentsOfRenameSymbolDeclaration.First().Id)
.Select(d => d.ProjectId).Distinct();
if (symbol.DeclaredAccessibility == Accessibility.Private)
if (ShouldRenameOnlyAffectDeclaringProject(symbol))
{
// private members or classes cannot be used outside of the project they are declared in
var isSubset = renameLocations.Select(l => l.DocumentId.ProjectId).Distinct().Except(projectIdsOfRenameSymbolDeclaration).IsEmpty();
Contract.ThrowIfFalse(isSubset);
return projectIdsOfRenameSymbolDeclaration.SelectMany(p => solution.GetProject(p).Documents);
......@@ -97,6 +96,17 @@ internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbo
}
}
/// <summary>
/// Renaming a private symbol typically confines the set of references and potential
/// conflicts to that symbols declaring project. However, rename may cascade to
/// non-public symbols which may then require other projects be considered.
/// </summary>
private static bool ShouldRenameOnlyAffectDeclaringProject(ISymbol symbol)
{
// Explicit interface implementations can cascade to other projects
return symbol.DeclaredAccessibility == Accessibility.Private && !symbol.ExplicitInterfaceImplementations().Any();
}
internal static TokenRenameInfo GetTokenRenameInfo(
ISemanticFactsService semanticFacts,
SemanticModel semanticModel,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册