Skip to content

Commit e5eb224

Browse files
committed
Revert the TypeDeclarationCSharpSyntaxRewriter changes, they were wrong and breaking the whole world.
1 parent dc2d806 commit e5eb224

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/SyntaxRewriter/TypeDeclarationCSharpSyntaxRewriter.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace Microsoft.DotNet.GenAPI.SyntaxRewriter
1717
/// </summary>
1818
public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
1919
{
20-
private const string GlobalSystemObjectBaseTypeName = "global::System.Object";
21-
2220
private readonly bool _addPartialModifier;
2321

2422
/// <summary>
@@ -64,43 +62,32 @@ public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
6462

6563
private static T? RemoveBaseType<T>(T? node, Func<BaseTypeSyntax, bool> selector) where T : TypeDeclarationSyntax
6664
{
67-
if (node?.BaseList == null)
65+
if (node == null)
6866
{
6967
return null;
7068
}
7169

72-
BaseTypeSyntax? baseType = node.BaseList.Types.FirstOrDefault(selector);
70+
BaseTypeSyntax? baseType = node.BaseList?.Types.FirstOrDefault(selector);
7371
if (baseType == null)
7472
{
7573
// Base type not found
7674
return node;
7775
}
78-
SyntaxTriviaList baseTypeTrailingTrivia = baseType.GetTrailingTrivia();
79-
SeparatedSyntaxList<BaseTypeSyntax> baseTypes = node.BaseList.Types.Remove(baseType);
76+
77+
SeparatedSyntaxList<BaseTypeSyntax> baseTypes = node.BaseList!.Types.Remove(baseType);
8078
if (baseTypes.Count == 0)
8179
{
82-
// After the baseType is removed, there is a remaining space that also needs removing
83-
SyntaxTriviaList identifierTrailingTrivia = node.Identifier.TrailingTrivia;
84-
if (identifierTrailingTrivia.Any() && identifierTrailingTrivia.Last().IsKind(SyntaxKind.WhitespaceTrivia))
85-
{
86-
identifierTrailingTrivia = identifierTrailingTrivia.RemoveAt(identifierTrailingTrivia.Count - 1);
87-
identifierTrailingTrivia = identifierTrailingTrivia.AddRange(baseTypeTrailingTrivia); // Join what was after the removed baseType
88-
node = (T)node.WithIdentifier(SyntaxFactory.Identifier(node.Identifier.LeadingTrivia, node.Identifier.Text, identifierTrailingTrivia));
89-
}
90-
9180
// No more base implementations, remove the base list entirely
9281
// Make sure we update the identifier though to include the baselist trailing trivia (typically '\r\n')
9382
// so the trailing opening brace gets put onto a new line.
9483
return (T)node
9584
.WithBaseList(null)
96-
.WithTrailingTrivia(node.GetTrailingTrivia());
85+
.WithTrailingTrivia(node.BaseList.GetTrailingTrivia());
9786
}
9887
else
9988
{
10089
// Remove the type but retain all remaining types and trivia
101-
return (T)node
102-
.WithBaseList(node.BaseList.WithTypes(baseTypes))
103-
.WithTrailingTrivia(node.GetTrailingTrivia());
90+
return (T)node.WithBaseList(node.BaseList!.WithTypes(baseTypes));
10491
}
10592
}
10693

@@ -111,7 +98,7 @@ public class TypeDeclarationCSharpSyntaxRewriter : CSharpSyntaxRewriter
11198
return null;
11299
}
113100

114-
node = RemoveBaseType(node, GlobalSystemObjectBaseTypeName);
101+
node = RemoveBaseType(node, "global::System.Object");
115102
return _addPartialModifier ? AddPartialModifier(node) : node;
116103
}
117104

0 commit comments

Comments
 (0)