未验证 提交 a1fe543e 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #41072 from sharwell/filter-identifier-name

Avoid trying to simplify descendant identifier names
......@@ -2,8 +2,10 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Options;
......@@ -65,7 +67,14 @@ public override void VisitGenericName(GenericNameSyntax node)
public override void VisitIdentifierName(IdentifierNameSyntax node)
{
if (node.IsKind(SyntaxKind.IdentifierName) && TrySimplify(node))
// Always try to simplify identifiers with an 'Attribute' suffix.
//
// In other cases, don't bother looking at the right side of A.B or A::B. We will process those in
// one of our other top level Visit methods (like VisitQualifiedName).
var canTrySimplify = node.Identifier.ValueText!.EndsWith("Attribute", StringComparison.Ordinal)
|| !node.IsRightSideOfDotOrArrowOrColonColon();
if (canTrySimplify && TrySimplify(node))
{
// found a match. report it and stop processing.
return;
......
......@@ -41,7 +41,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.SimplifyTypeNames
End Sub
Public Overrides Sub VisitIdentifierName(node As IdentifierNameSyntax)
If node.IsKind(SyntaxKind.IdentifierName) AndAlso TrySimplify(node) Then
' Always try to simplify identifiers with an 'Attribute' suffix.
'
' In other cases, don't bother looking at the right side of A.B or A!B. We will process those in
' one of our other top level Visit methods (Like VisitQualifiedName).
Dim canTrySimplify = CaseInsensitiveComparison.EndsWith(node.Identifier.ValueText, "Attribute") _
OrElse Not node.IsRightSideOfDotOrBang()
If canTrySimplify AndAlso TrySimplify(node) Then
Return
End If
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册