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

Commit

Permalink
IAnnotable + Enum
Browse files Browse the repository at this point in the history
MethodBlock
TypeBlock e.g. classes/structs
NamespaceBlock
tweaks
  • Loading branch information
Paul Balaji committed Jan 16, 2020
1 parent 7d05201 commit 809c155
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
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);
}
}
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);
}
}
}
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;
}
}
}
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));
}
}
}
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;
}
}
}

0 comments on commit 809c155

Please sign in to comment.