提交 ca8e378b 编写于 作者: R Ravi Chande

Resolve rename conflicts in nameof in attributes

The expander can operate on a specific set of known nodes, so when
rename finds a conflict in a particular node, it uses the span of a
parent that the expander knows how to handle. For normal
ArgumentSyntaxes, this is covered by being within a StatementSyntax.
However, nameof within an attribute constructor isn't in a statement, so
rename needs to expand to the span of the attribute.
上级 c03dd877
......@@ -700,8 +700,8 @@ class Program
</Project>
</Workspace>, renameTo:="BarAttribute")
result.AssertLabeledSpansAre("short", "BarAttribute", RelatedLocationType.ResolvedReferenceConflict)
result.AssertLabeledSpansAre("long", "BarAttribute", RelatedLocationType.NoConflict)
result.AssertLabeledSpansAre("short", "BarAttribute()", RelatedLocationType.ResolvedReferenceConflict)
result.AssertLabeledSpansAre("long", "BarAttributeAttribute()", RelatedLocationType.NoConflict)
End Using
End Sub
......
......@@ -543,7 +543,7 @@ class C
</Workspace>, renameTo:="Method")
result.AssertLabeledSpansAre("first", "Method", RelatedLocationType.NoConflict)
result.AssertLabeledSpansAre("second", "C.Method", type:=RelatedLocationType.ResolvedReferenceConflict)
result.AssertLabeledSpansAre("second", "DefaultValue(C.Method)", type:=RelatedLocationType.ResolvedReferenceConflict)
End Using
End Sub
End Class
......
......@@ -63,7 +63,7 @@ class [|$$MainAttribute|] : System.Attribute
</Project>
</Workspace>, renameTo:="ifAttribute")
result.AssertLabeledSpecialSpansAre("resolved", "ifAttribute", RelatedLocationType.ResolvedReferenceConflict)
result.AssertLabeledSpecialSpansAre("resolved", "ifAttribute()", RelatedLocationType.ResolvedReferenceConflict)
End Using
End Sub
......
......@@ -6770,6 +6770,28 @@ class C
End Using
End Sub
<WorkItem(446, "https://github.com/dotnet/roslyn/issues/446")>
<Fact>
<Trait(Traits.Feature, Traits.Features.Rename)>
Public Sub RenameWithNameOfInAttribute()
Using result = RenameEngineResult.Create(
<Workspace>
<Project Language="C#" CommonReferences="true">
<Document>
class C
{
// Rename F to Fail
static void [|F|]$$(int x) { }
[System.Obsolete(nameof({|conflict:Fail|}))]
static void Fail() { }
}
</Document>
</Project>
</Workspace>, renameTo:="Fail")
result.AssertLabeledSpansAre("conflict", type:=RelatedLocationType.UnresolvedConflict)
End Using
End Sub
#End Region
End Class
......
......@@ -1096,6 +1096,12 @@ private static SyntaxNode GetExpansionTarget(SyntaxToken token)
return enclosingInitializer.Value;
}
var attributeSyntax = token.GetAncestor<AttributeSyntax>();
if (attributeSyntax != null)
{
return attributeSyntax;
}
// there seems to be no statement above this one. Let's see if we can at least get an SimpleNameSyntax
return enclosingStatement ?? enclosingNameMemberCrefOrnull ?? token.GetAncestors(n => n is SimpleNameSyntax).FirstOrDefault();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册