-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from dragonfruitnetwork/switch-source-generator
Replace source generator
- Loading branch information
Showing
60 changed files
with
4,302 additions
and
296 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,5 @@ | ||
root = true | ||
|
||
[*.cs] | ||
generated_code = true | ||
dotnet_analyzer_diagnostic.severity = none |
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,9 @@ | ||
namespace StrawberryShake.CodeGeneration; | ||
|
||
public enum AccessModifier | ||
{ | ||
Public = 0, | ||
Internal = 1, | ||
Protected = 2, | ||
Private = 3, | ||
} |
40 changes: 40 additions & 0 deletions
40
DragonFruit.Data.Roslyn/CodeGeneration/Builders/AbstractTypeBuilder.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,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace StrawberryShake.CodeGeneration.CSharp.Builders; | ||
|
||
public abstract class AbstractTypeBuilder : ITypeBuilder | ||
{ | ||
protected List<PropertyBuilder> Properties { get; } = []; | ||
|
||
protected string? Name { get; private set; } | ||
|
||
protected List<string> Implements { get; } = []; | ||
|
||
public abstract void Build(CodeWriter writer); | ||
|
||
protected void SetName(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public void AddProperty(PropertyBuilder property) | ||
{ | ||
if (property is null) | ||
{ | ||
throw new ArgumentNullException(nameof(property)); | ||
} | ||
|
||
Properties.Add(property); | ||
} | ||
|
||
public void AddImplements(string value) | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
throw new ArgumentException(nameof(value)); | ||
} | ||
|
||
Implements.Add(value); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
DragonFruit.Data.Roslyn/CodeGeneration/Builders/ArrayBuilder.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,98 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace StrawberryShake.CodeGeneration.CSharp.Builders; | ||
|
||
public class ArrayBuilder : ICode | ||
{ | ||
private string? _prefix; | ||
private string? _type; | ||
private bool _determineStatement = true; | ||
private bool _setReturn; | ||
private readonly List<ICode> _assignment = []; | ||
|
||
private ArrayBuilder() | ||
{ | ||
} | ||
|
||
public ArrayBuilder SetType(string type) | ||
{ | ||
_type = type; | ||
return this; | ||
} | ||
|
||
public ArrayBuilder AddAssignment(ICode code) | ||
{ | ||
_assignment.Add(code); | ||
return this; | ||
} | ||
|
||
public ArrayBuilder SetDetermineStatement(bool value) | ||
{ | ||
_determineStatement = value; | ||
return this; | ||
} | ||
|
||
public ArrayBuilder SetPrefix(string prefix) | ||
{ | ||
_prefix = prefix; | ||
return this; | ||
} | ||
|
||
public ArrayBuilder SetReturn(bool value = true) | ||
{ | ||
_setReturn = value; | ||
return this; | ||
} | ||
|
||
public void Build(CodeWriter writer) | ||
{ | ||
if (_type is null) | ||
{ | ||
throw new ArgumentNullException(nameof(_type)); | ||
} | ||
|
||
if (_determineStatement) | ||
{ | ||
writer.WriteIndent(); | ||
} | ||
|
||
if (_setReturn) | ||
{ | ||
writer.Write("return "); | ||
} | ||
|
||
writer.Write(_prefix); | ||
|
||
writer.Write("new "); | ||
writer.Write(_type); | ||
writer.Write("[] {"); | ||
writer.WriteLine(); | ||
|
||
using (writer.IncreaseIndent()) | ||
{ | ||
for (var i = 0; i < _assignment.Count; i++) | ||
{ | ||
writer.WriteIndent(); | ||
_assignment[i].Build(writer); | ||
if (i != _assignment.Count - 1) | ||
{ | ||
writer.Write(","); | ||
writer.WriteLine(); | ||
} | ||
} | ||
} | ||
|
||
writer.WriteLine(); | ||
writer.WriteIndent(); | ||
writer.Write("}"); | ||
|
||
if (_determineStatement) | ||
{ | ||
writer.Write(";"); | ||
writer.WriteLine(); | ||
} | ||
} | ||
|
||
public static ArrayBuilder New() => new ArrayBuilder(); | ||
} |
Oops, something went wrong.