Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Fix formatting for implicit conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Oct 21, 2018
1 parent dce9a8a commit 94e5909
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 33 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,27 @@
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="_001_ExplicitConversionForInvalidAssigment" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\001_ExplicitConversionForInvalidAssigment.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\001_ExplicitConversionForInvalidAssigment.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_001_ExplicitConversionForInvalidAssigment_FIXED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_002_ExplicitConversionForInvalidReturn" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\002_ExplicitConversionForInvalidReturn.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\002_ExplicitConversionForInvalidReturn.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_002_ExplicitConversionForInvalidReturn_FIXED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_003_ExplicitConversionForInvalidYield" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\003_ExplicitConversionForInvalidYield.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\003_ExplicitConversionForInvalidYield.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_003_ExplicitConversionForInvalidYield_FIXED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.cs;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
<value>TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_004_ExplicitConversionForInvalidAssigmentInInitBlock" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\004_ExplicitConversionForInvalidAssigmentInInitBlock.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public void should_be_able_to_generate_conversion_for_invalid_yield_statement()

}

[Test]
public void should_be_able_to_generate_conversion_for_invalid_assignment_statement_in_init_block()
{
VerifyCSharpFix(ExplicitConversionTestCases._004_ExplicitConversionForInvalidAssigmentInInitBlock, ExplicitConversionTestCases._004_ExplicitConversionForInvalidAssigmentInInitBlock_FIXED, ExplicitConversionCodeFixProvider.CS0029, 0);
}

protected override CodeFixProvider GetCSharpCodeFixProvider()
{
return new ExplicitConversionCodeFixProvider();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
{
public class TestMapper
{
public AddressDTO Address { get; set; }

public UserDTO DoSomething()
{
var addressEntity = new AddressEntity();
return new UserDTO{
Address = addressEntity
}
}
}

public class UserDTO{
public AddressDTO Address {get; set;}
}

public class AddressDTO
{
public string FlatNo { get; set; }
public string BuildtingNo { get; set; }
public string Street { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
}

public class AddressEntity
{
public string FlatNo { get; set; }
public string BuildtingNo { get; set; }
public string Street { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MappingGenerator.Test.ExplicitConversions.TestCaseData
{
public class TestMapper
{
public AddressDTO Address { get; set; }

public UserDTO DoSomething()
{
var addressEntity = new AddressEntity();
return new UserDTO{
Address = new AddressDTO()
{
FlatNo = addressEntity.FlatNo,
BuildtingNo = addressEntity.BuildtingNo,
Street = addressEntity.Street,
ZipCode = addressEntity.ZipCode,
City = addressEntity.City
}
}
}
}

public class UserDTO{
public AddressDTO Address {get; set;}
}

public class AddressDTO
{
public string FlatNo { get; set; }
public string BuildtingNo { get; set; }
public string Street { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
}

public class AddressEntity
{
public string FlatNo { get; set; }
public string BuildtingNo { get; set; }
public string Street { get; set; }
public string ZipCode { get; set; }
public string City { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Remove="ExplicitConversions\TestCaseData\001_ExplicitConversionForInvalidAssigment.cs" />
<Compile Remove="ExplicitConversions\TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.cs" />
<Compile Remove="ExplicitConversions\TestCaseData\002_ExplicitConversionForInvalidReturn.cs" />
<Compile Remove="ExplicitConversions\TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.cs" />
<Compile Remove="ExplicitConversions\TestCaseData\003_ExplicitConversionForInvalidYield.cs" />
<Compile Remove="ExplicitConversions\TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.cs" />
<Compile Remove="Splatting\TestCaseData\001_SplattingInMethodInvocation.cs" />
<Compile Remove="Splatting\TestCaseData\001_SplattingInMethodInvocationWithNamedParameters_FIXED.cs" />
<Compile Remove="Splatting\TestCaseData\001_SplattingInMethodInvocation_FIXED.cs" />
Expand All @@ -30,12 +24,6 @@
</ItemGroup>

<ItemGroup>
<None Include="ExplicitConversions\TestCaseData\001_ExplicitConversionForInvalidAssigment.cs" />
<None Include="ExplicitConversions\TestCaseData\001_ExplicitConversionForInvalidAssigment_FIXED.cs" />
<None Include="ExplicitConversions\TestCaseData\002_ExplicitConversionForInvalidReturn.cs" />
<None Include="ExplicitConversions\TestCaseData\002_ExplicitConversionForInvalidReturn_FIXED.cs" />
<None Include="ExplicitConversions\TestCaseData\003_ExplicitConversionForInvalidYield.cs" />
<None Include="ExplicitConversions\TestCaseData\003_ExplicitConversionForInvalidYield_FIXED.cs" />
<None Include="Splatting\TestCaseData\003_SplattingWithBestOverloadMatch_FIXED.cs" />
<None Include="Splatting\TestCaseData\003_SplattingWithBestOverloadMatch.cs" />
<None Include="Splatting\TestCaseData\001_SplattingInMethodInvocation_FIXED.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private async Task<Document> GenerateExplicitConversion(Document document, Assig
{
var mappingEngine = await CreateMappingEngine(document, assignmentExpression, cancellationToken);
var sourceType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Right).Type;
var destimationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).Type;
var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right, sourceType, destimationType);
var destinationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).Type;
var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right.WithoutTrivia(), sourceType, destinationType);
return await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken);
}

Expand All @@ -74,15 +74,15 @@ private async Task<Document> GenerateExplicitConversion(Document document, Retur
{
var mappingEngine = await CreateMappingEngine(document, returnStatement, cancellationToken);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(returnStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression, returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType);
var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression.WithoutTrivia(), returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType);
return await ReplaceNode(document, returnStatement, returnStatement.WithExpression(mappingExpression), cancellationToken);
}

private async Task<Document> GenerateExplicitConversion(Document document, YieldStatementSyntax yieldStatement, CancellationToken cancellationToken)
{
var mappingEngine = await CreateMappingEngine(document, yieldStatement, cancellationToken);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(yieldStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression, returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType);
var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression.WithoutTrivia(), returnExpressionTypeInfo.Type, returnExpressionTypeInfo.ConvertedType);
return await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken);
}

Expand Down

0 comments on commit 94e5909

Please sign in to comment.