Skip to content

Commit

Permalink
Override Copy method conversion to Unknown, when type conversion is P…
Browse files Browse the repository at this point in the history
…artial, fixes #68
  • Loading branch information
maca88 committed Nov 5, 2017
1 parent 04e7369 commit 661330d
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Source/AsyncGenerator.Tests/AsyncGenerator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@
<Compile Include="AbstractClass\Input\TestCase.cs" />
<Compile Include="AnonymousFunctions\Fixture.cs" />
<Compile Include="AnonymousFunctions\Input\MethodWithDelegate.cs" />
<Compile Include="ConfigurationOverride\Fixture.cs" />
<Compile Include="ConfigurationOverride\Input\PartialCopy.cs" />
<Compile Include="DocumentationComments\Input\MissingMembers.cs" />
<Compile Include="DocumentationComments\Input\Comments.cs" />
<Compile Include="DocumentationComments\CommentsFixture.cs" />
Expand Down Expand Up @@ -882,6 +884,9 @@
<ItemGroup>
<EmbeddedResource Include="ParallelFor\Output\TestCaseTokens.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ConfigurationOverride\Output\PartialCopy.txt" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
Expand Down
37 changes: 37 additions & 0 deletions Source/AsyncGenerator.Tests/ConfigurationOverride/Fixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using AsyncGenerator.Analyzation;
using AsyncGenerator.Core;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using NUnit.Framework;
using AsyncGenerator.Tests.ConfigurationOverride.Input;

namespace AsyncGenerator.Tests.ConfigurationOverride
{
[TestFixture]
public class Fixture : BaseFixture
{
[Test]
public Task TestAfterTransformation()
{
var copy = GetMethodName<PartialCopy>(o => o.Copy);
return ReadonlyTest(nameof(PartialCopy), p => p
.ConfigureAnalyzation(a => a
.MethodConversion(symbol => symbol.Name == copy ? MethodConversion.Copy : MethodConversion.Smart)
)
.ConfigureTransformation(t => t
.AfterTransformation(result =>
{
AssertValidAnnotations(result);
Assert.AreEqual(1, result.Documents.Count);
var document = result.Documents[0];
Assert.NotNull(document.OriginalModified);
Assert.AreEqual(GetOutputFile(nameof(PartialCopy)), document.Transformed.ToFullString());
})
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AsyncGenerator.TestCases;

namespace AsyncGenerator.Tests.ConfigurationOverride.Input
{
public class PartialCopy
{
public void Read()
{
Copy();
SimpleFile.Read();
}

public void Copy()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AsyncGenerator.TestCases;

namespace AsyncGenerator.Tests.ConfigurationOverride.Input
{
public partial class PartialCopy
{
public Task ReadAsync()
{
try
{
Copy();
return SimpleFile.ReadAsync();
}
catch (Exception ex)
{
return Task.FromException<object>(ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ void IgnoreOrCopy(string reason)
return;
}

// Override user configuration if the method is set to be copied on a partial type conversion
if (methodData.Conversion == MethodConversion.Copy &&
methodData.TypeData.GetSelfAndAncestorsTypeData().All(o => o.Conversion != TypeConversion.NewType))
{
Logger.Warn($"Invalid conversion for method {methodData.Symbol}. Method cannot be copied, " +
"when the containing type conversion is not set to be a new type. Override the method conversion to Unknown");
methodData.Conversion = MethodConversion.Unknown;
}

// Check if explicitly implements external interfaces
if (methodSymbol.MethodKind == MethodKind.ExplicitInterfaceImplementation)
{
Expand Down

0 comments on commit 661330d

Please sign in to comment.