This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MethodBlock TypeBlock e.g. classes/structs NamespaceBlock tweaks
- Loading branch information
Paul Balaji
committed
Jan 16, 2020
1 parent
7d05201
commit 809c155
Showing
5 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...obable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/CodeWriter/Interfaces/IAnnotatable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Improbable.Gdk.CodeGeneration.CodeWriter | ||
{ | ||
public interface IAnnotatable | ||
{ | ||
void Annotate(string annotation); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...io.improbable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/CodeWriter/Scopes/EnumBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Improbable.Gdk.CodeGeneration.CodeWriter.Scopes | ||
{ | ||
public class EnumBlock : ScopeBlock, IAnnotatable | ||
{ | ||
private static readonly string EnumMemberSeparator = $",{Environment.NewLine}"; | ||
|
||
internal EnumBlock(string declaration, Action<EnumBlock> populate) : base(declaration) | ||
{ | ||
populate(this); | ||
} | ||
|
||
public void Member(string snippet) | ||
{ | ||
Add(new Text(snippet)); | ||
} | ||
|
||
public void Members(ICollection<string> snippets) | ||
{ | ||
Add(new TextList(EnumMemberSeparator, snippets)); | ||
} | ||
|
||
public void Annotate(string annotation) | ||
{ | ||
Annotation = annotation; | ||
} | ||
|
||
public override string Format(int indentLevel = 0) | ||
{ | ||
return base.Format(indentLevel, EnumMemberSeparator); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
....improbable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/CodeWriter/Scopes/MethodBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace Improbable.Gdk.CodeGeneration.CodeWriter.Scopes | ||
{ | ||
public class MethodBlock : ScopeBody, IAnnotatable | ||
{ | ||
internal MethodBlock(string declaration, Action<MethodBlock> populate) : base(declaration) | ||
{ | ||
populate(this); | ||
} | ||
|
||
public void Annotate(string annotation) | ||
{ | ||
Annotation = annotation; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...probable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/CodeWriter/Scopes/NamespaceBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Improbable.Gdk.CodeGeneration.CodeWriter.Scopes | ||
{ | ||
public class NamespaceBlock : ScopeBlock | ||
{ | ||
internal NamespaceBlock(string declaration, Action<NamespaceBlock> populate) : base($"namespace {declaration}") | ||
{ | ||
populate(this); | ||
} | ||
|
||
public void Line(string snippet) | ||
{ | ||
Add(new Text(snippet)); | ||
} | ||
|
||
public void Line(Action<StringBuilder> populate) | ||
{ | ||
var sb = new StringBuilder(); | ||
populate(sb); | ||
|
||
Add(new Text(sb.ToString())); | ||
} | ||
|
||
public void Line(ICollection<string> snippets) | ||
{ | ||
if (snippets.Any()) | ||
{ | ||
Add(new TextList(snippets)); | ||
} | ||
} | ||
|
||
public void CustomScope(Action<CustomScopeBlock> populate) | ||
{ | ||
Add(new CustomScopeBlock(populate)); | ||
} | ||
|
||
public void CustomScope(string declaration, Action<CustomScopeBlock> populate) | ||
{ | ||
Add(new CustomScopeBlock(declaration, populate)); | ||
} | ||
|
||
public void Enum(EnumBlock enumBlock) | ||
{ | ||
Add(enumBlock); | ||
} | ||
|
||
public void Enum(string declaration, Action<EnumBlock> populate) | ||
{ | ||
Add(new EnumBlock(declaration, populate)); | ||
} | ||
|
||
public void Type(TypeBlock typeBlock) | ||
{ | ||
Add(typeBlock); | ||
} | ||
|
||
public void Type(string declaration, Action<TypeBlock> populate) | ||
{ | ||
Add(new TypeBlock(declaration, populate)); | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...io.improbable.gdk.tools/.CodeGenTemplate/CodeGenerationLib/CodeWriter/Scopes/TypeBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Improbable.Gdk.CodeGeneration.CodeWriter.Scopes | ||
{ | ||
public class TypeBlock : ScopeBlock, IAnnotatable | ||
{ | ||
internal TypeBlock(string declaration, Action<TypeBlock> populate) : base(declaration) | ||
{ | ||
populate(this); | ||
} | ||
|
||
public void Line(string snippet) | ||
{ | ||
Add(new Text(snippet)); | ||
} | ||
|
||
public void Line(Action<StringBuilder> populate) | ||
{ | ||
var sb = new StringBuilder(); | ||
populate(sb); | ||
|
||
Add(new Text(sb.ToString())); | ||
} | ||
|
||
public void Line(ICollection<string> snippets) | ||
{ | ||
if (snippets.Any()) | ||
{ | ||
Add(new TextList(snippets)); | ||
} | ||
} | ||
|
||
public void Initializer(string declaration, Func<IEnumerable<string>> populate) | ||
{ | ||
Add(new InitializerBlock(declaration, populate)); | ||
} | ||
|
||
public void CustomScope(Action<CustomScopeBlock> populate) | ||
{ | ||
Add(new CustomScopeBlock(populate)); | ||
} | ||
|
||
public void CustomScope(string declaration, Action<CustomScopeBlock> populate) | ||
{ | ||
Add(new CustomScopeBlock(declaration, populate)); | ||
} | ||
|
||
public void Method(string declaration, Action<MethodBlock> populate) | ||
{ | ||
Add(new MethodBlock(declaration, populate)); | ||
} | ||
|
||
public void Enum(EnumBlock enumBlock) | ||
{ | ||
Add(enumBlock); | ||
} | ||
|
||
public void Enum(string declaration, Action<EnumBlock> populate) | ||
{ | ||
Add(new EnumBlock(declaration, populate)); | ||
} | ||
|
||
public void Type(TypeBlock typeBlock) | ||
{ | ||
Add(typeBlock); | ||
} | ||
|
||
public void Type(string declaration, Action<TypeBlock> populate) | ||
{ | ||
Add(new TypeBlock(declaration, populate)); | ||
} | ||
|
||
public void Annotate(string annotation) | ||
{ | ||
Annotation = annotation; | ||
} | ||
} | ||
} |