Skip to content

Commit 0875df1

Browse files
committed
wip
1 parent e07a17c commit 0875df1

File tree

2 files changed

+65
-67
lines changed

2 files changed

+65
-67
lines changed

src/NetEscapades.EnumGenerators.Generators/Diagnostics/UsageAnalyzers/GetNamesCodeFixProvider.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ protected override Task FixWithEditor(DocumentEditor editor, Diagnostic diagnost
4747

4848
// Create new invocation: ExtensionsClass.GetNames()
4949
var generator = editor.Generator;
50-
var memberAccess = (MemberAccessExpressionSyntax)generator.MemberAccessExpression(
51-
generator.TypeExpression(extensionTypeSymbol), "GetNames");
52-
var newInvocation = SyntaxFactory.InvocationExpression(memberAccess)
53-
.WithLeadingTrivia(invocation.GetLeadingTrivia())
54-
.WithTrailingTrivia(invocation.GetTrailingTrivia())
50+
var newInvocation = generator.InvocationExpression(
51+
generator.MemberAccessExpression(generator.TypeExpression(extensionTypeSymbol), "GetNames"))
52+
.WithTriviaFrom(invocation)
5553
.WithAdditionalAnnotations(Simplifier.AddImportsAnnotation, Simplifier.Annotation);
5654

5755
editor.ReplaceNode(invocation, newInvocation);

tests/NetEscapades.EnumGenerators.Tests/GetNamesAnalyzerTests.cs

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,68 @@ public void TestMethod()
428428
await VerifyAnalyzerAsync(test, EnableState.Disabled);
429429
}
430430

431+
[Fact]
432+
public async Task GetNamesAsMethodArgumentShouldPreserveWhitespace()
433+
{
434+
var test = GetTestCode(
435+
/* lang=c# */
436+
"""
437+
public class TestClass
438+
{
439+
public void TestMethod()
440+
{
441+
SomeMethod({|NEEG008:Enum.GetNames(typeof(MyEnum))|});
442+
}
443+
444+
private void SomeMethod(string[] names) { }
445+
}
446+
""");
447+
448+
var fix = GetTestCode(
449+
/* lang=c# */
450+
"""
451+
public class TestClass
452+
{
453+
public void TestMethod()
454+
{
455+
SomeMethod(MyEnumExtensions.GetNames());
456+
}
457+
458+
private void SomeMethod(string[] names) { }
459+
}
460+
""");
461+
await VerifyCodeFixAsync(test, fix);
462+
}
463+
464+
[Fact]
465+
public async Task GetNamesWithExtraWhitespaceShouldPreserveWhitespace()
466+
{
467+
var test = GetTestCode(
468+
/* lang=c# */
469+
"""
470+
public class TestClass
471+
{
472+
public void TestMethod()
473+
{
474+
{|NEEG008:Enum.GetNames(typeof(MyEnum))|};
475+
}
476+
}
477+
""");
478+
479+
var fix = GetTestCode(
480+
/* lang=c# */
481+
"""
482+
public class TestClass
483+
{
484+
public void TestMethod()
485+
{
486+
MyEnumExtensions.GetNames();
487+
}
488+
}
489+
""");
490+
await VerifyCodeFixAsync(test, fix);
491+
}
492+
431493
private static string GetTestCodeWithExternalEnum(string testCode) =>
432494
$$"""
433495
using System;
@@ -499,66 +561,4 @@ public static class MyEnumExtensions
499561
{{TestHelpers.LoadEmbeddedAttribute()}}
500562
{{TestHelpers.LoadEmbeddedMetadataSource()}}
501563
""";
502-
503-
[Fact]
504-
public async Task GetNamesAsMethodArgumentShouldPreserveWhitespace()
505-
{
506-
var test = GetTestCode(
507-
/* lang=c# */
508-
"""
509-
public class TestClass
510-
{
511-
public void TestMethod()
512-
{
513-
SomeMethod({|NEEG008:Enum.GetNames(typeof(MyEnum))|});
514-
}
515-
516-
private void SomeMethod(string[] names) { }
517-
}
518-
""");
519-
520-
var fix = GetTestCode(
521-
/* lang=c# */
522-
"""
523-
public class TestClass
524-
{
525-
public void TestMethod()
526-
{
527-
SomeMethod(MyEnumExtensions.GetNames());
528-
}
529-
530-
private void SomeMethod(string[] names) { }
531-
}
532-
""");
533-
await Verifier.VerifyCodeFixAsync(test, fix);
534-
}
535-
536-
[Fact]
537-
public async Task GetNamesWithExtraWhitespaceShouldPreserveWhitespace()
538-
{
539-
var test = GetTestCode(
540-
/* lang=c# */
541-
"""
542-
public class TestClass
543-
{
544-
public void TestMethod()
545-
{
546-
var names = {|NEEG008:Enum.GetNames(typeof(MyEnum))|};
547-
}
548-
}
549-
""");
550-
551-
var fix = GetTestCode(
552-
/* lang=c# */
553-
"""
554-
public class TestClass
555-
{
556-
public void TestMethod()
557-
{
558-
var names = MyEnumExtensions.GetNames();
559-
}
560-
}
561-
""");
562-
await Verifier.VerifyCodeFixAsync(test, fix);
563-
}
564564
}

0 commit comments

Comments
 (0)