Skip to content

Commit 21a1ecd

Browse files
committed
Don't truncate the attribute name, leave the type name full.
Finally fixed the records.
1 parent e5eb224 commit 21a1ecd

File tree

5 files changed

+102
-89
lines changed

5 files changed

+102
-89
lines changed

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/MemoryOutputDiffGenerator.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ internal MemoryOutputDiffGenerator(
9696
GlobalPrefixRemover.Singleton, // And then call this ASAP afterwards so there are fewer identifiers to visit
9797
PrimitiveSimplificationRewriter.Singleton,
9898
RemoveBodyCSharpSyntaxRewriter.Singleton,
99-
AttributeNameSuffixRemover.Singleton,
10099
SingleLineStatementCSharpSyntaxRewriter.Singleton,
101100
],
102101
AdditionalAnnotations = [Formatter.Annotation] // Formatter is needed to fix some spacing
@@ -571,20 +570,38 @@ private static SyntaxNode GetChildlessNode(MemberDeclarationSyntax node)
571570
private string GetDeclarationAndOpeningBraceCode(SyntaxNode childlessNode, SyntaxTriviaList leadingTrivia)
572571
{
573572
SyntaxToken openBrace = SyntaxFactory.Token(SyntaxKind.OpenBraceToken)
574-
.WithLeadingTrivia(leadingTrivia)
575573
.WithTrailingTrivia(_endOfLineTrivia);
576574

577-
SyntaxNode unclosedNode = childlessNode switch
575+
SyntaxNode unclosedNode;
576+
577+
if (childlessNode is RecordDeclarationSyntax recordDecl)
578+
{
579+
if (recordDecl.OpenBraceToken.IsKind(SyntaxKind.None))
580+
{
581+
unclosedNode = recordDecl;
582+
}
583+
else
584+
{
585+
// Add the missing newline after the declaration
586+
SyntaxTriviaList endLineAndLeadingTrivia = SyntaxFactory.TriviaList(_endOfLineTrivia).AddRange(leadingTrivia);
587+
openBrace = openBrace.WithLeadingTrivia(endLineAndLeadingTrivia);
588+
unclosedNode = recordDecl.WithOpenBraceToken(openBrace).WithCloseBraceToken(_missingCloseBrace);
589+
}
590+
}
591+
else
578592
{
579-
RecordDeclarationSyntax recordDecl => recordDecl.OpenBraceToken.IsMissing ? recordDecl : recordDecl.WithCloseBraceToken(_missingCloseBrace),
580-
BaseTypeDeclarationSyntax typeDecl => typeDecl.WithOpenBraceToken(openBrace)
581-
.WithCloseBraceToken(_missingCloseBrace),
593+
openBrace = openBrace.WithLeadingTrivia(leadingTrivia);
594+
unclosedNode = childlessNode switch
595+
{
596+
BaseTypeDeclarationSyntax typeDecl => typeDecl.WithOpenBraceToken(openBrace)
597+
.WithCloseBraceToken(_missingCloseBrace),
582598

583-
NamespaceDeclarationSyntax nsDecl => nsDecl.WithOpenBraceToken(openBrace)
584-
.WithCloseBraceToken(_missingCloseBrace),
599+
NamespaceDeclarationSyntax nsDecl => nsDecl.WithOpenBraceToken(openBrace)
600+
.WithCloseBraceToken(_missingCloseBrace),
585601

586-
_ => childlessNode
587-
};
602+
_ => childlessNode
603+
};
604+
}
588605

589606
return unclosedNode.WithLeadingTrivia(leadingTrivia).ToFullString();
590607
}
@@ -612,16 +629,22 @@ private static string GetDocId(SyntaxNode node, SemanticModel model)
612629
{
613630
ISymbol? symbol = node switch
614631
{
632+
DestructorDeclarationSyntax destructorDeclaration => model.GetDeclaredSymbol(destructorDeclaration),
615633
FieldDeclarationSyntax fieldDeclaration => model.GetDeclaredSymbol(fieldDeclaration.Declaration.Variables.First()),
616634
EventDeclarationSyntax eventDeclaration => model.GetDeclaredSymbol(eventDeclaration),
617635
EventFieldDeclarationSyntax eventFieldDeclaration => model.GetDeclaredSymbol(eventFieldDeclaration.Declaration.Variables.First()),
618636
PropertyDeclarationSyntax propertyDeclaration => model.GetDeclaredSymbol(propertyDeclaration),
619-
DestructorDeclarationSyntax destructorDeclaration => model.GetDeclaredSymbol(destructorDeclaration),
620637
_ => model.GetDeclaredSymbol(node)
621638
};
622639

623640
if (symbol?.GetDocumentationCommentId() is string docId)
624641
{
642+
if (node is RecordDeclarationSyntax record && record.ParameterList != null && record.ParameterList.Parameters.Any())
643+
{
644+
// Special case for when a record has a parameter list, we need to be able to differentiate the signature's parameters too,
645+
// but the regular DocId does not differentiate that.
646+
return $"{docId}({record.ParameterList.Parameters.ToFullString()})";
647+
}
625648
return docId;
626649
}
627650

src/Compatibility/ApiDiff/Microsoft.DotNet.ApiDiff/SyntaxRewriter/AttributeNameSuffixRemover.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/Microsoft.DotNet.ApiDiff.Tests/Diff.Attribute.Tests.cs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class MyClass
3939
expectedCode: """
4040
namespace MyNamespace
4141
{
42-
+ [MyAttribute]
42+
+ [MyNamespace.MyAttributeAttribute]
4343
public class MyClass
4444
{
4545
}
@@ -85,17 +85,17 @@ public MyClass() { }
8585
expectedCode: """
8686
namespace MyNamespace
8787
{
88-
- [System.AttributeUsage(System.AttributeTargets.All)]
88+
- [System.AttributeUsageAttribute(System.AttributeTargets.All)]
8989
- public class MyAttribute1Attribute : System.Attribute
9090
- {
9191
- public MyAttribute1Attribute();
9292
- }
93-
- [MyAttribute1]
94-
+ [MyAttribute2]
93+
- [MyNamespace.MyAttribute1Attribute]
94+
+ [MyNamespace.MyAttribute2Attribute]
9595
public class MyClass
9696
{
9797
}
98-
+ [System.AttributeUsage(System.AttributeTargets.All)]
98+
+ [System.AttributeUsageAttribute(System.AttributeTargets.All)]
9999
+ public class MyAttribute2Attribute : System.Attribute
100100
+ {
101101
+ public MyAttribute2Attribute();
@@ -149,8 +149,8 @@ public MyClass() { }
149149
expectedCode: """
150150
namespace MyNamespace
151151
{
152-
- [MyAttribute1]
153-
+ [MyAttribute2]
152+
- [MyNamespace.MyAttribute1Attribute]
153+
+ [MyNamespace.MyAttribute2Attribute]
154154
public class MyClass
155155
{
156156
}
@@ -196,7 +196,7 @@ namespace MyNamespace
196196
- {
197197
- public MyClass1();
198198
- }
199-
+ [MyAttribute]
199+
+ [MyNamespace.MyAttributeAttribute]
200200
+ public class MyClass2
201201
+ {
202202
+ public MyClass2();
@@ -240,12 +240,12 @@ public MyClass2() { }
240240
expectedCode: """
241241
namespace MyNamespace
242242
{
243-
- [MyAttribute]
243+
- [MyNamespace.MyAttributeAttribute]
244244
- public class MyClass1
245245
- {
246246
- public MyClass1();
247247
- }
248-
+ [MyAttribute]
248+
+ [MyNamespace.MyAttributeAttribute]
249249
+ public class MyClass2
250250
+ {
251251
+ public MyClass2();
@@ -294,7 +294,7 @@ namespace MyNamespace
294294
{
295295
public class MyClass
296296
{
297-
+ [MyAttribute]
297+
+ [MyNamespace.MyAttributeAttribute]
298298
public void MyMethod();
299299
}
300300
}
@@ -341,17 +341,17 @@ public void MyMethod() { }
341341
expectedCode: """
342342
namespace MyNamespace
343343
{
344-
- [System.AttributeUsage(System.AttributeTargets.All)]
344+
- [System.AttributeUsageAttribute(System.AttributeTargets.All)]
345345
- public class MyAttribute1Attribute : System.Attribute
346346
- {
347347
- }
348348
public class MyClass
349349
{
350-
- [MyAttribute1]
351-
+ [MyAttribute2]
350+
- [MyNamespace.MyAttribute1Attribute]
351+
+ [MyNamespace.MyAttribute2Attribute]
352352
public void MyMethod();
353353
}
354-
+ [System.AttributeUsage(System.AttributeTargets.All)]
354+
+ [System.AttributeUsageAttribute(System.AttributeTargets.All)]
355355
+ public class MyAttribute2Attribute : System.Attribute
356356
+ {
357357
+ }
@@ -409,8 +409,8 @@ namespace MyNamespace
409409
{
410410
public class MyClass
411411
{
412-
- [MyAttribute1]
413-
+ [MyAttribute2]
412+
- [MyNamespace.MyAttribute1Attribute]
413+
+ [MyNamespace.MyAttribute2Attribute]
414414
public void MyMethod();
415415
}
416416
}
@@ -457,7 +457,7 @@ namespace MyNamespace
457457
public class MyClass
458458
{
459459
- public void MyMethod1();
460-
+ [MyAttribute]
460+
+ [MyNamespace.MyAttributeAttribute]
461461
+ public void MyMethod2();
462462
}
463463
}
@@ -504,9 +504,9 @@ namespace MyNamespace
504504
{
505505
public class MyClass
506506
{
507-
- [MyAttribute]
507+
- [MyNamespace.MyAttributeAttribute]
508508
- public void MyMethod1();
509-
+ [MyAttribute]
509+
+ [MyNamespace.MyAttributeAttribute]
510510
+ public void MyMethod2();
511511
}
512512
}
@@ -557,9 +557,9 @@ namespace MyNamespace
557557
public class MyClass
558558
{
559559
- public MyClass(int x);
560-
+ public MyClass([MyAttribute] int x);
560+
+ public MyClass([MyNamespace.MyAttributeAttribute] int x);
561561
- public void MyMethod(int y);
562-
+ public void MyMethod([MyAttribute] int y);
562+
+ public void MyMethod([MyNamespace.MyAttributeAttribute] int y);
563563
}
564564
}
565565
""",
@@ -612,8 +612,8 @@ public class MyClass
612612
expectedCode: """
613613
namespace MyNamespace
614614
{
615-
+ [MyAttribute1]
616-
+ [MyAttribute2]
615+
+ [MyNamespace.MyAttribute1Attribute]
616+
+ [MyNamespace.MyAttribute2Attribute]
617617
public class MyClass
618618
{
619619
}
@@ -668,8 +668,8 @@ namespace MyNamespace
668668
{
669669
public class MyClass
670670
{
671-
+ [MyAttribute1]
672-
+ [MyAttribute2]
671+
+ [MyNamespace.MyAttribute1Attribute]
672+
+ [MyNamespace.MyAttribute2Attribute]
673673
public MyClass(int x);
674674
}
675675
}
@@ -726,9 +726,9 @@ namespace MyNamespace
726726
public class MyClass
727727
{
728728
- public MyClass(int x);
729-
+ public MyClass([MyAttribute1, MyAttribute2] int x);
729+
+ public MyClass([MyNamespace.MyAttribute1Attribute, MyNamespace.MyAttribute2Attribute] int x);
730730
- public void MyMethod(int y);
731-
+ public void MyMethod([MyAttribute1, MyAttribute2] int y);
731+
+ public void MyMethod([MyNamespace.MyAttribute1Attribute, MyNamespace.MyAttribute2Attribute] int y);
732732
}
733733
}
734734
""",
@@ -773,7 +773,7 @@ public class MyClass
773773
expectedCode: """
774774
namespace MyNamespace
775775
{
776-
+ [MyAttribute]
776+
+ [MyNamespace.MyAttributeAttribute]
777777
public class MyClass
778778
{
779779
}
@@ -816,14 +816,14 @@ public class MyClass
816816
expectedCode: """
817817
namespace MyNamespace
818818
{
819-
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
820-
+ [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Text")]
821-
+ [MyAttribute]
822-
+ [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Text")]
819+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
820+
+ [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Text")]
821+
+ [MyNamespace.MyAttributeAttribute]
822+
+ [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Text")]
823823
public class MyClass
824824
{
825825
}
826-
+ [System.AttributeUsage(System.AttributeTargets.All)]
826+
+ [System.AttributeUsageAttribute(System.AttributeTargets.All)]
827827
+ public class MyAttributeAttribute : System.Attribute
828828
+ {
829829
+ public MyAttributeAttribute();
@@ -863,13 +863,13 @@ public class MyClass
863863
expectedCode: """
864864
namespace MyNamespace
865865
{
866-
+ [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
867-
+ [System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Text")]
868-
+ [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Text")]
866+
+ [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
867+
+ [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Text")]
868+
+ [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Text")]
869869
public class MyClass
870870
{
871871
}
872-
+ [System.AttributeUsage(System.AttributeTargets.All)]
872+
+ [System.AttributeUsageAttribute(System.AttributeTargets.All)]
873873
+ public class MyAttributeAttribute : System.Attribute
874874
+ {
875875
+ public MyAttributeAttribute();
@@ -945,11 +945,11 @@ public MyClass() { }
945945
expectedCode: """
946946
namespace MyNamespace
947947
{
948-
+ [MyAttribute("First", "Second")]
948+
+ [MyNamespace.MyAttributeAttribute("First", "Second")]
949949
public class MyClass
950950
{
951951
}
952-
+ [System.AttributeUsage(System.AttributeTargets.All)]
952+
+ [System.AttributeUsageAttribute(System.AttributeTargets.All)]
953953
+ public class MyAttributeAttribute : System.Attribute
954954
+ {
955955
+ public MyAttributeAttribute(string first, string second);

0 commit comments

Comments
 (0)