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

Commit

Permalink
trycatch + formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Balaji committed Jan 13, 2020
1 parent b6168dc commit 9997a34
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public CodeGenerator(CodeGeneratorOptions options, IFileSystem fileSystem)

private static void ConfigureLogger()
{
var codeGeneratorOptions = CodeGeneratorOptions.Instance;
var codeGeneratorOptions = CodeGeneratorOptions.Instance;

var config = new NLog.Config.LoggingConfiguration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public IfElseBlock If(string declaration, Action<ScopeBody> populate)

public TryCatchBlock Try(Action<ScopeBody> populate)
{
var tryCatchBlock = new TryCatchBlock(populate);
return new TryCatchBlock(this, populate);
}

internal void AddTryCatchBlock(TryCatchBlock tryCatchBlock)
{
Add(tryCatchBlock);
return tryCatchBlock;
}

public void Return()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ namespace Improbable.Gdk.CodeGeneration.CodeWriter.Scopes
/// </summary>
public class TryCatchBlock : ScopeBodyList
{
internal TryCatchBlock(Action<ScopeBody> populate) : base("try", populate)
private ScopeBody parent;

internal TryCatchBlock(ScopeBody parent, Action<ScopeBody> populate) : base("try", populate)
{
this.parent = parent;
}

public TryCatchBlock Catch(string declaration, Action<ScopeBody> populate)
{
parent?.AddTryCatchBlock(this);
parent = null;

AddScope($"catch ({declaration})", populate);
return this;
}

public void Finally(Action<ScopeBody> populate)
{
parent?.AddTryCatchBlock(this);

AddScope("finally", populate);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Improbable.Gdk.CodeGeneration.CodeWriter;
using Improbable.Gdk.CodeGeneration.CodeWriter.Scopes;

namespace Improbable.Gdk.CodeGeneration.Model.Details
Expand Down Expand Up @@ -26,7 +25,7 @@ public string GetDeserializationString(string fieldInstance, string schemaObject
{
return new CustomScopeBlock(scope =>
{
scope.WriteLine(new []
scope.WriteLine(new[]
{
$"{fieldInstance} = new {Type}();",
$"var list = {fieldInstance};",
Expand Down Expand Up @@ -55,7 +54,7 @@ public string GetDeserializeUpdateString(string fieldInstance, string schemaObje

scope.Loop("for (var i = 0; i < listSize; i++)", each =>
{
each.WriteLine(new []
each.WriteLine(new[]
{
$"var value = {containedType.GetFieldIndexExpression(schemaObject, fieldNumber, "i")};",
$"{fieldInstance}.Add(value);"
Expand Down Expand Up @@ -93,7 +92,7 @@ public string GetDeserializeDataIntoUpdateString(string updateFieldInstance, str
{
return new CustomScopeBlock(scope =>
{
scope.WriteLine(new []
scope.WriteLine(new[]
{
$"var listSize = {containedType.GetCountExpression(schemaObject, fieldNumber)};",
$"{updateFieldInstance} = new global::Improbable.Gdk.Core.Option<{Type}>(new {Type}());"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string GetDeserializationString(string fieldInstance, string schemaObject
{
return new CustomScopeBlock(scope =>
{
scope.WriteLine(new []
scope.WriteLine(new[]
{
$"var map = new {Type}();",
$"var mapSize = {schemaObject}.GetObjectCount({fieldNumber});",
Expand All @@ -42,7 +42,7 @@ public string GetDeserializationString(string fieldInstance, string schemaObject

scope.Loop("for (var i = 0; i < mapSize; i++)", each =>
{
each.WriteLine(new []
each.WriteLine(new[]
{
$"var mapObj = {schemaObject}.IndexObject({fieldNumber}, (uint) i);",
$"var key = {keyType.GetDeserializationExpression("mapObj", 1)};",
Expand All @@ -68,7 +68,7 @@ public string GetDeserializeUpdateString(string fieldInstance, string schemaObje

scope.Loop("for (var i = 0; i < mapSize; i++)", each =>
{
each.WriteLine(new []
each.WriteLine(new[]
{
$"var mapObj = {schemaObject}.IndexObject({fieldNumber}, (uint) i);",
$"var key = {keyType.GetDeserializationExpression("mapObj", 1)};",
Expand Down Expand Up @@ -111,7 +111,7 @@ public string GetDeserializeDataIntoUpdateString(string updateFieldInstance, str
{
return new CustomScopeBlock(scope =>
{
scope.WriteLine(new []
scope.WriteLine(new[]
{
$"var map = new {Type}();",
$"var mapSize = {schemaObject}.GetObjectCount({fieldNumber});",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public string GetDeserializeDataIntoUpdateString(string updateFieldInstance, str

public string GetTrySetClearedFieldString(string fieldInstance, string componentUpdateSchemaObject, uint fieldNumber)
{
return "";
return string.Empty;
}
}
}

0 comments on commit 9997a34

Please sign in to comment.