Skip to content

Commit

Permalink
Minor improvements in primitive type conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
yallie committed Nov 4, 2018
1 parent 5c4127c commit a77061d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion ApexParser/ApexParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.6.16</Version>
<Version>0.6.17</Version>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Authors>ApexSharp.com</Authors>
<Company>ApexSharp.com</Company>
Expand All @@ -38,6 +38,9 @@
<PackageTags>Apex, Parser, Roslyn</PackageTags>
<PackageReleaseNotes>Beta release. What's new:

v0.6.17:
— Minor improvement in the primitive type conversion

v0.6.16:
— Improved the typeof expression handling
— Added using Apex to the generated C# code
Expand Down
2 changes: 1 addition & 1 deletion ApexParser/Toolbox/GenericExpressionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static string ConvertCSharpIsTypeExpressionToApex(string expression)
CSharpTypes.Where(p => p.Key != ApexKeywords.Int).ToDictionary(p => p.Value, p => p.Key);

private static Dictionary<Regex, string> CSharpTypeRegexExcludingMemberReferences { get; } =
CSharpTypes.ToDictionary(p => new Regex($"\\b{p.Key}\\b(?!\\s*\\.)",
CSharpTypes.ToDictionary(p => new Regex($"\\b(?<!\\.){p.Key}\\b(?!\\s*\\.)",
RegexOptions.IgnoreCase | RegexOptions.Compiled), p => p.Value);

private static Dictionary<Regex, string> ApexTypeRegex { get; } =
Expand Down
6 changes: 4 additions & 2 deletions ApexParserTest/ApexRoundtrip/PrimitiveTypes_CSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public class PrimitiveTypes

public bool IsWinner = true;

public Date MyDate = Date.Today();
public Date MyDate = Date.today();

public Datetime MyDateTime = Datetime.Now();
public Datetime MyDateTime = Datetime.now();

private Date AnotherDate = Date.today().date();

public decimal MyDecimal = 12.4567m;

Expand Down
6 changes: 4 additions & 2 deletions ApexParserTest/ApexRoundtrip/PrimitiveTypes_Formatted.cls
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ public class PrimitiveTypes

public Boolean IsWinner = true;

public Date MyDate = Date.Today();
public Date MyDate = Date.today();

public Datetime MyDateTime = Datetime.Now();
public Datetime MyDateTime = Datetime.now();

private Date AnotherDate = Date.today().date();

public Decimal MyDecimal = 12.4567;

Expand Down
5 changes: 3 additions & 2 deletions ApexParserTest/ApexRoundtrip/PrimitiveTypes_Original.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ public class PrimitiveTypes
public Blob MyBlob = Blob.ValueOf('Jay');
public Boolean IsWinner = true;

public Date MyDate = Date.Today();
public Datetime MyDateTime = Datetime.Now();
public Date MyDate = Date.today();
public Datetime MyDateTime = Datetime.now();
private Date AnotherDate = Date.today().date();

public Decimal MyDecimal = 12.4567;
//public Double d=3.133433;
Expand Down
14 changes: 14 additions & 0 deletions ApexParserTest/Toolbox/GenericExpressionHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ public void ApexPritimiveTypesStaticMethodsAreNotConvertedToCSharp()
Assert.AreEqual("a = Integer.valueOf(b)", ToApex("a = Integer.valueOf(b)"));
}

[Test]
public void ApexMembersSpelledTheSameWayAsPrimitiveTypesAreNotConvertedToCSharp()
{
string ToCSharp(string expr) => GenericExpressionHelper.ConvertApexTypesToCSharp(expr);
string ToApex(string expr) => GenericExpressionHelper.ConvertCSharpTypesToApex(expr);

Assert.AreEqual("a = (Date)x", ToCSharp("a = (date)x"));
Assert.AreEqual("a = new Date(x)", ToCSharp("a = new date(x)"));
Assert.AreEqual("a = new Date(x).date()", ToCSharp("a = new Date(x).date()"));

Assert.AreEqual("a = new Date(x)", ToApex("a = new Date(x)"));
Assert.AreEqual("a = new Date(x).date()", ToApex("a = new Date(x).date()"));
}

[Test]
public void DoubleLiteralsAreConvertedToDecimalLiterals()
{
Expand Down

0 comments on commit a77061d

Please sign in to comment.