Skip to content

Commit 5e9fb5b

Browse files
committed
Skip the generation of unused methods, fixes #57
1 parent 007c891 commit 5e9fb5b

37 files changed

+464
-28
lines changed

Source/AsyncGenerator.Tests/AsyncGenerator.Tests.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@
196196
<Compile Include="DocumentationComments\Input\MissingMembers.cs" />
197197
<Compile Include="DocumentationComments\Input\Comments.cs" />
198198
<Compile Include="DocumentationComments\CommentsFixture.cs" />
199+
<Compile Include="Github\Issue57\Fixture.cs" />
200+
<Compile Include="Github\Issue57\Input\ExplicitInterface.cs" />
201+
<Compile Include="Github\Issue57\Input\TestCase.cs" />
199202
<Compile Include="MethodReferences\Fixture.cs" />
200203
<Compile Include="MethodReferences\Input\ForwardCall.cs" />
201204
<Compile Include="Nameof\Fixture.cs" />
@@ -800,6 +803,21 @@
800803
<ItemGroup>
801804
<EmbeddedResource Include="DocumentationComments\Output\CommentsNewTypeAddMissing.txt" />
802805
</ItemGroup>
806+
<ItemGroup>
807+
<EmbeddedResource Include="Github\Issue57\Output\TestCase.txt" />
808+
</ItemGroup>
809+
<ItemGroup>
810+
<EmbeddedResource Include="Github\Issue57\Output\TestCaseWithToken.txt" />
811+
</ItemGroup>
812+
<ItemGroup>
813+
<EmbeddedResource Include="Github\Issue57\Output\TestCaseNewType.txt" />
814+
</ItemGroup>
815+
<ItemGroup>
816+
<EmbeddedResource Include="Github\Issue57\Output\TestCaseNewTypeWithToken.txt" />
817+
</ItemGroup>
818+
<ItemGroup>
819+
<EmbeddedResource Include="Github\Issue57\Output\ExplicitInterface.txt" />
820+
</ItemGroup>
803821
<Choose>
804822
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
805823
<ItemGroup>

Source/AsyncGenerator.Tests/AsyncProperites/Input/AbstractGetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private bool Write()
2121
return SimpleFile.Write("");
2222
}
2323

24-
private void CheckSuccess()
24+
protected void CheckSuccess()
2525
{
2626
if (WriteSuccess && IsSuccess)
2727
{

Source/AsyncGenerator.Tests/AsyncProperites/Input/AbstractInterfaceGetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
99
{
1010
public class TestAbstractInterfaceGetter
1111
{
12-
void Test()
12+
protected void Test()
1313
{
1414
SimpleFile.Read();
1515
}

Source/AsyncGenerator.Tests/AsyncProperites/Input/AbstractInterfaceSetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
99
{
1010
public class TestAbstractInterfaceSetter
1111
{
12-
void Test()
12+
protected void Test()
1313
{
1414
SimpleFile.Read();
1515
}

Source/AsyncGenerator.Tests/AsyncProperites/Input/AbstractSetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private bool Write(string value)
2121
return SimpleFile.Write(value);
2222
}
2323

24-
private void SetSuccess()
24+
protected void SetSuccess()
2525
{
2626
if (IsSuccess)
2727
{

Source/AsyncGenerator.Tests/AsyncProperites/Input/ArrowGetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private bool Write()
1616
return SimpleFile.Write("");
1717
}
1818

19-
private void CheckSuccess()
19+
protected void CheckSuccess()
2020
{
2121
if (WriteSuccess)
2222
{

Source/AsyncGenerator.Tests/AsyncProperites/Input/Getter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private bool Write()
1919
return SimpleFile.Write("");
2020
}
2121

22-
private void CheckSuccess()
22+
protected void CheckSuccess()
2323
{
2424
if (WriteSuccess)
2525
{

Source/AsyncGenerator.Tests/AsyncProperites/Input/GetterWithAsyncPart.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private bool Write()
2424
return SimpleFile.Write("");
2525
}
2626

27-
private void CheckSuccess()
27+
protected void CheckSuccess()
2828
{
2929
if (WriteSuccess)
3030
{

Source/AsyncGenerator.Tests/AsyncProperites/Input/InterfaceGetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private bool Write()
2121
return SimpleFile.Write("");
2222
}
2323

24-
private void CheckSuccess()
24+
protected void CheckSuccess()
2525
{
2626
if (WriteSuccess && IsSuccess)
2727
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractGetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
3333
return SimpleFile.WriteAsync("");
3434
}
3535

36-
private async Task CheckSuccessAsync()
36+
protected async Task CheckSuccessAsync()
3737
{
3838
if (await (GetWriteSuccessAsync()) && IsSuccess)
3939
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractGetterNewType.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
4141
return SimpleFile.Write("");
4242
}
4343

44-
private async Task CheckSuccessAsync()
44+
protected async Task CheckSuccessAsync()
4545
{
4646
if (await (GetWriteSuccessAsync()) && IsSuccess)
4747
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractInterfaceGetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2222
/// </content>
2323
public partial class TestAbstractInterfaceGetter
2424
{
25-
Task TestAsync()
25+
protected Task TestAsync()
2626
{
2727
return SimpleFile.ReadAsync();
2828
}

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractInterfaceGetterWithTokens.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2323
/// </content>
2424
public partial class TestAbstractInterfaceGetter
2525
{
26-
Task TestAsync(CancellationToken cancellationToken = default(CancellationToken))
26+
protected Task TestAsync(CancellationToken cancellationToken = default(CancellationToken))
2727
{
2828
return SimpleFile.ReadAsync(cancellationToken);
2929
}

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractInterfaceSetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2222
/// </content>
2323
public partial class TestAbstractInterfaceSetter
2424
{
25-
Task TestAsync()
25+
protected Task TestAsync()
2626
{
2727
return SimpleFile.ReadAsync();
2828
}

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractInterfaceSetterWithTokens.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2323
/// </content>
2424
public partial class TestAbstractInterfaceSetter
2525
{
26-
Task TestAsync(CancellationToken cancellationToken = default(CancellationToken))
26+
protected Task TestAsync(CancellationToken cancellationToken = default(CancellationToken))
2727
{
2828
return SimpleFile.ReadAsync(cancellationToken);
2929
}

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractSetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
3333
return SimpleFile.WriteAsync(value);
3434
}
3535

36-
private async Task SetSuccessAsync()
36+
protected async Task SetSuccessAsync()
3737
{
3838
if (IsSuccess)
3939
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/AbstractSetterNewType.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
4141
return SimpleFile.Write(value);
4242
}
4343

44-
private async Task SetSuccessAsync()
44+
protected async Task SetSuccessAsync()
4545
{
4646
if (IsSuccess)
4747
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/ArrowGetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2929
return SimpleFile.WriteAsync("");
3030
}
3131

32-
private async Task CheckSuccessAsync()
32+
protected async Task CheckSuccessAsync()
3333
{
3434
if (await (GetWriteSuccessAsync()))
3535
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/Getter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
3232
return SimpleFile.WriteAsync("");
3333
}
3434

35-
private async Task CheckSuccessAsync()
35+
protected async Task CheckSuccessAsync()
3636
{
3737
if (await (GetWriteSuccessAsync()))
3838
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/GetterWithAsyncPart.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
2828
return SimpleFile.WriteAsync("");
2929
}
3030

31-
private async Task CheckSuccessAsync()
31+
protected async Task CheckSuccessAsync()
3232
{
3333
if (await (GetWriteSuccessAsync()))
3434
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/InterfaceGetter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
3333
return SimpleFile.WriteAsync("");
3434
}
3535

36-
private async Task CheckSuccessAsync()
36+
protected async Task CheckSuccessAsync()
3737
{
3838
if (await (GetWriteSuccessAsync()) && IsSuccess)
3939
{

Source/AsyncGenerator.Tests/AsyncProperites/Output/InterfaceGetterNewType.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace AsyncGenerator.Tests.AsyncProperites.Input
4141
return SimpleFile.Write("");
4242
}
4343

44-
private async Task CheckSuccessAsync()
44+
protected async Task CheckSuccessAsync()
4545
{
4646
if (await (GetWriteSuccessAsync()) && IsSuccess)
4747
{

Source/AsyncGenerator.Tests/Formatting/Fixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void TestAsyncAfterTransformation()
4141
{
4242
var config = Configure(nameof(Async), p => p
4343
.ConfigureAnalyzation(a => a
44-
.MethodConversion(symbol => MethodConversion.Smart)
44+
.MethodConversion(symbol => MethodConversion.ToAsync)
4545
.PreserveReturnType(symbol => true)
4646
)
4747
.ConfigureTransformation(t => t
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using AsyncGenerator.Core;
7+
using AsyncGenerator.Tests.Github.Issue57.Input;
8+
using NUnit.Framework;
9+
10+
namespace AsyncGenerator.Tests.Github.Issue57
11+
{
12+
[TestFixture]
13+
public class Fixture : BaseFixture
14+
{
15+
[Test]
16+
public void TestAfterTransformation()
17+
{
18+
var config = Configure(nameof(TestCase), p => p
19+
.ConfigureAnalyzation(a => a
20+
.MethodConversion(symbol => MethodConversion.Smart)
21+
)
22+
.ConfigureTransformation(t => t
23+
.AfterTransformation(result =>
24+
{
25+
AssertValidAnnotations(result);
26+
Assert.AreEqual(1, result.Documents.Count);
27+
var document = result.Documents[0];
28+
29+
Assert.NotNull(document.OriginalModified);
30+
Assert.AreEqual(GetOutputFile(nameof(TestCase)), document.Transformed.ToFullString());
31+
})
32+
)
33+
);
34+
var generator = new AsyncCodeGenerator();
35+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
36+
}
37+
38+
[Test]
39+
public void TestUnknownAfterTransformation()
40+
{
41+
var config = Configure(nameof(TestCase), p => p
42+
.ConfigureAnalyzation(a => a
43+
.MethodConversion(symbol => symbol.Name == "ReadInternal" ? MethodConversion.Unknown : MethodConversion.Smart)
44+
)
45+
.ConfigureTransformation(t => t
46+
.AfterTransformation(result =>
47+
{
48+
AssertValidAnnotations(result);
49+
Assert.AreEqual(1, result.Documents.Count);
50+
var document = result.Documents[0];
51+
52+
Assert.NotNull(document.OriginalModified);
53+
Assert.AreEqual(GetOutputFile(nameof(TestCase)), document.Transformed.ToFullString());
54+
})
55+
)
56+
);
57+
var generator = new AsyncCodeGenerator();
58+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
59+
}
60+
61+
[Test]
62+
public void TestWithTokenAfterTransformation()
63+
{
64+
var config = Configure(nameof(TestCase), p => p
65+
.ConfigureAnalyzation(a => a
66+
.MethodConversion(symbol => MethodConversion.Smart)
67+
.CancellationTokens(true)
68+
)
69+
.ConfigureTransformation(t => t
70+
.AfterTransformation(result =>
71+
{
72+
AssertValidAnnotations(result);
73+
Assert.AreEqual(1, result.Documents.Count);
74+
var document = result.Documents[0];
75+
76+
Assert.NotNull(document.OriginalModified);
77+
Assert.AreEqual(GetOutputFile(nameof(TestCase) + "WithToken"), document.Transformed.ToFullString());
78+
})
79+
)
80+
);
81+
var generator = new AsyncCodeGenerator();
82+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
83+
}
84+
85+
[Test]
86+
public void TestNewTypeAfterTransformation()
87+
{
88+
var config = Configure(nameof(TestCase), p => p
89+
.ConfigureAnalyzation(a => a
90+
.MethodConversion(symbol => MethodConversion.Smart)
91+
.TypeConversion(symbol => TypeConversion.NewType)
92+
)
93+
.ConfigureTransformation(t => t
94+
.AfterTransformation(result =>
95+
{
96+
AssertValidAnnotations(result);
97+
Assert.AreEqual(1, result.Documents.Count);
98+
var document = result.Documents[0];
99+
100+
Assert.IsNull(document.OriginalModified);
101+
Assert.AreEqual(GetOutputFile(nameof(TestCase) + "NewType"), document.Transformed.ToFullString());
102+
})
103+
)
104+
);
105+
var generator = new AsyncCodeGenerator();
106+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
107+
}
108+
109+
[Test]
110+
public void TestNewTypeWithTokenAfterTransformation()
111+
{
112+
var config = Configure(nameof(TestCase), p => p
113+
.ConfigureAnalyzation(a => a
114+
.MethodConversion(symbol => MethodConversion.Smart)
115+
.TypeConversion(symbol => TypeConversion.NewType)
116+
.CancellationTokens(true)
117+
)
118+
.ConfigureTransformation(t => t
119+
.AfterTransformation(result =>
120+
{
121+
AssertValidAnnotations(result);
122+
Assert.AreEqual(1, result.Documents.Count);
123+
var document = result.Documents[0];
124+
125+
Assert.IsNull(document.OriginalModified);
126+
Assert.AreEqual(GetOutputFile(nameof(TestCase) + "NewTypeWithToken"), document.Transformed.ToFullString());
127+
})
128+
)
129+
);
130+
var generator = new AsyncCodeGenerator();
131+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
132+
}
133+
134+
[Test]
135+
public void ExplicitInterfaceAfterTransformation()
136+
{
137+
var config = Configure(nameof(ExplicitInterface), p => p
138+
.ConfigureAnalyzation(a => a
139+
.MethodConversion(symbol => MethodConversion.Smart)
140+
)
141+
.ConfigureTransformation(t => t
142+
.AfterTransformation(result =>
143+
{
144+
AssertValidAnnotations(result);
145+
Assert.AreEqual(1, result.Documents.Count);
146+
var document = result.Documents[0];
147+
148+
Assert.NotNull(document.OriginalModified);
149+
Assert.AreEqual(GetOutputFile(nameof(ExplicitInterface)), document.Transformed.ToFullString());
150+
})
151+
)
152+
);
153+
var generator = new AsyncCodeGenerator();
154+
Assert.DoesNotThrowAsync(async () => await generator.GenerateAsync(config));
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)