Skip to content
This repository was archived by the owner on Nov 11, 2025. It is now read-only.

Commit 90ef664

Browse files
author
Mike Blair
committed
Add source code and tests
1 parent c75388f commit 90ef664

File tree

296 files changed

+55113
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

296 files changed

+55113
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<ImplicitUsings>disable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\FractalDataWorks.Net\FractalDataWorks.net.csproj" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace FractalDataWorks.CodeBuilder.Abstractions;
5+
6+
/// <summary>
7+
/// Builder interface for generating class definitions.
8+
/// </summary>
9+
public interface IClassBuilder : ICodeBuilder
10+
{
11+
/// <summary>
12+
/// Sets the namespace for the class.
13+
/// </summary>
14+
/// <param name="namespaceName">The namespace name.</param>
15+
/// <returns>The builder for method chaining.</returns>
16+
IClassBuilder WithNamespace(string namespaceName);
17+
18+
/// <summary>
19+
/// Adds using directives.
20+
/// </summary>
21+
/// <param name="usings">The using directives to add.</param>
22+
/// <returns>The builder for method chaining.</returns>
23+
IClassBuilder WithUsings(params string[] usings);
24+
25+
/// <summary>
26+
/// Sets the class name.
27+
/// </summary>
28+
/// <param name="className">The class name.</param>
29+
/// <returns>The builder for method chaining.</returns>
30+
IClassBuilder WithName(string className);
31+
32+
/// <summary>
33+
/// Sets the access modifier for the class.
34+
/// </summary>
35+
/// <param name="accessModifier">The access modifier (public, internal, etc.).</param>
36+
/// <returns>The builder for method chaining.</returns>
37+
IClassBuilder WithAccessModifier(string accessModifier);
38+
39+
/// <summary>
40+
/// Makes the class static.
41+
/// </summary>
42+
/// <returns>The builder for method chaining.</returns>
43+
IClassBuilder AsStatic();
44+
45+
/// <summary>
46+
/// Makes the class abstract.
47+
/// </summary>
48+
/// <returns>The builder for method chaining.</returns>
49+
IClassBuilder AsAbstract();
50+
51+
/// <summary>
52+
/// Makes the class sealed.
53+
/// </summary>
54+
/// <returns>The builder for method chaining.</returns>
55+
IClassBuilder AsSealed();
56+
57+
/// <summary>
58+
/// Makes the class partial.
59+
/// </summary>
60+
/// <returns>The builder for method chaining.</returns>
61+
IClassBuilder AsPartial();
62+
63+
/// <summary>
64+
/// Sets the base class.
65+
/// </summary>
66+
/// <param name="baseClass">The base class name.</param>
67+
/// <returns>The builder for method chaining.</returns>
68+
IClassBuilder WithBaseClass(string baseClass);
69+
70+
/// <summary>
71+
/// Adds interfaces that the class implements.
72+
/// </summary>
73+
/// <param name="interfaces">The interface names.</param>
74+
/// <returns>The builder for method chaining.</returns>
75+
IClassBuilder WithInterfaces(params string[] interfaces);
76+
77+
/// <summary>
78+
/// Adds generic type parameters.
79+
/// </summary>
80+
/// <param name="typeParameters">The type parameter names.</param>
81+
/// <returns>The builder for method chaining.</returns>
82+
IClassBuilder WithGenericParameters(params string[] typeParameters);
83+
84+
/// <summary>
85+
/// Adds generic type constraints.
86+
/// </summary>
87+
/// <param name="typeParameter">The type parameter to constrain.</param>
88+
/// <param name="constraints">The constraints.</param>
89+
/// <returns>The builder for method chaining.</returns>
90+
IClassBuilder WithGenericConstraint(string typeParameter, params string[] constraints);
91+
92+
/// <summary>
93+
/// Adds an attribute to the class.
94+
/// </summary>
95+
/// <param name="attribute">The attribute code.</param>
96+
/// <returns>The builder for method chaining.</returns>
97+
IClassBuilder WithAttribute(string attribute);
98+
99+
/// <summary>
100+
/// Adds a field to the class.
101+
/// </summary>
102+
/// <param name="fieldBuilder">The field builder.</param>
103+
/// <returns>The builder for method chaining.</returns>
104+
IClassBuilder WithField(IFieldBuilder fieldBuilder);
105+
106+
/// <summary>
107+
/// Adds a property to the class.
108+
/// </summary>
109+
/// <param name="propertyBuilder">The property builder.</param>
110+
/// <returns>The builder for method chaining.</returns>
111+
IClassBuilder WithProperty(IPropertyBuilder propertyBuilder);
112+
113+
/// <summary>
114+
/// Adds a method to the class.
115+
/// </summary>
116+
/// <param name="methodBuilder">The method builder.</param>
117+
/// <returns>The builder for method chaining.</returns>
118+
IClassBuilder WithMethod(IMethodBuilder methodBuilder);
119+
120+
/// <summary>
121+
/// Adds a constructor to the class.
122+
/// </summary>
123+
/// <param name="constructorBuilder">The constructor builder.</param>
124+
/// <returns>The builder for method chaining.</returns>
125+
IClassBuilder WithConstructor(IConstructorBuilder constructorBuilder);
126+
127+
/// <summary>
128+
/// Adds a nested class.
129+
/// </summary>
130+
/// <param name="nestedClassBuilder">The nested class builder.</param>
131+
/// <returns>The builder for method chaining.</returns>
132+
IClassBuilder WithNestedClass(IClassBuilder nestedClassBuilder);
133+
134+
/// <summary>
135+
/// Adds XML documentation comments.
136+
/// </summary>
137+
/// <param name="summary">The summary text.</param>
138+
/// <returns>The builder for method chaining.</returns>
139+
IClassBuilder WithXmlDoc(string summary);
140+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
namespace FractalDataWorks.CodeBuilder.Abstractions;
4+
5+
/// <summary>
6+
/// Base interface for code builders that generate source code.
7+
/// </summary>
8+
public interface ICodeBuilder
9+
{
10+
/// <summary>
11+
/// Builds the code and returns it as a string.
12+
/// </summary>
13+
/// <returns>The generated code.</returns>
14+
string Build();
15+
16+
/// <summary>
17+
/// Gets the current indentation level.
18+
/// </summary>
19+
int IndentLevel { get; }
20+
21+
/// <summary>
22+
/// Gets or sets the indentation string (default is 4 spaces).
23+
/// </summary>
24+
string IndentString { get; set; }
25+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Collections.Generic;
2+
3+
namespace FractalDataWorks.CodeBuilder.Abstractions;
4+
5+
/// <summary>
6+
/// Interface for code generators that transform syntax trees or definitions into source code.
7+
/// </summary>
8+
public interface ICodeGenerator
9+
{
10+
/// <summary>
11+
/// Gets the target language for this generator.
12+
/// </summary>
13+
string TargetLanguage { get; }
14+
15+
/// <summary>
16+
/// Generates code from a syntax tree.
17+
/// </summary>
18+
/// <param name="syntaxTree">The syntax tree to generate from.</param>
19+
/// <returns>The generated source code.</returns>
20+
string Generate(ISyntaxTree syntaxTree);
21+
22+
/// <summary>
23+
/// Generates code from a class builder.
24+
/// </summary>
25+
/// <param name="classBuilder">The class builder.</param>
26+
/// <returns>The generated source code.</returns>
27+
string Generate(IClassBuilder classBuilder);
28+
29+
/// <summary>
30+
/// Generates code from an interface builder.
31+
/// </summary>
32+
/// <param name="interfaceBuilder">The interface builder.</param>
33+
/// <returns>The generated source code.</returns>
34+
string Generate(IInterfaceBuilder interfaceBuilder);
35+
36+
/// <summary>
37+
/// Generates code from an enum builder.
38+
/// </summary>
39+
/// <param name="enumBuilder">The enum builder.</param>
40+
/// <returns>The generated source code.</returns>
41+
string Generate(IEnumBuilder enumBuilder);
42+
43+
/// <summary>
44+
/// Generates a compilation unit with multiple types.
45+
/// </summary>
46+
/// <param name="builders">The builders for the types to include.</param>
47+
/// <returns>The generated source code.</returns>
48+
string GenerateCompilationUnit(IEnumerable<ICodeBuilder> builders);
49+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Threading;
2+
using System.Threading.Tasks;
3+
using FractalDataWorks;
4+
5+
namespace FractalDataWorks.CodeBuilder.Abstractions;
6+
7+
/// <summary>
8+
/// Defines a parser that can convert source code into a syntax tree.
9+
/// </summary>
10+
public interface ICodeParser
11+
{
12+
/// <summary>
13+
/// Gets the language this parser supports.
14+
/// </summary>
15+
string Language { get; }
16+
17+
/// <summary>
18+
/// Parses the source code into a syntax tree.
19+
/// </summary>
20+
/// <param name="sourceCode">The source code to parse.</param>
21+
/// <param name="filePath">Optional file path for context.</param>
22+
/// <param name="cancellationToken">Cancellation token.</param>
23+
/// <returns>Result containing the syntax tree or error information.</returns>
24+
Task<IFdwResult<ISyntaxTree>> ParseAsync(
25+
string sourceCode,
26+
string? filePath = null,
27+
CancellationToken cancellationToken = default);
28+
29+
/// <summary>
30+
/// Validates the source code without building a full syntax tree.
31+
/// </summary>
32+
/// <param name="sourceCode">The source code to validate.</param>
33+
/// <param name="cancellationToken">Cancellation token.</param>
34+
/// <returns>Result indicating whether the code is valid.</returns>
35+
Task<IFdwResult> ValidateAsync(
36+
string sourceCode,
37+
CancellationToken cancellationToken = default);
38+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System;
2+
3+
namespace FractalDataWorks.CodeBuilder.Abstractions;
4+
5+
/// <summary>
6+
/// Builder interface for generating constructor definitions.
7+
/// </summary>
8+
public interface IConstructorBuilder : ICodeBuilder
9+
{
10+
/// <summary>
11+
/// Sets the access modifier.
12+
/// </summary>
13+
/// <param name="accessModifier">The access modifier.</param>
14+
/// <returns>The builder for method chaining.</returns>
15+
IConstructorBuilder WithAccessModifier(string accessModifier);
16+
17+
/// <summary>
18+
/// Makes the constructor static.
19+
/// </summary>
20+
/// <returns>The builder for method chaining.</returns>
21+
IConstructorBuilder AsStatic();
22+
23+
/// <summary>
24+
/// Adds a parameter to the constructor.
25+
/// </summary>
26+
/// <param name="type">The parameter type.</param>
27+
/// <param name="name">The parameter name.</param>
28+
/// <param name="defaultValue">Optional default value.</param>
29+
/// <returns>The builder for method chaining.</returns>
30+
IConstructorBuilder WithParameter(string type, string name, string? defaultValue = null);
31+
32+
/// <summary>
33+
/// Adds a base constructor call.
34+
/// </summary>
35+
/// <param name="arguments">The arguments to pass to the base constructor.</param>
36+
/// <returns>The builder for method chaining.</returns>
37+
IConstructorBuilder WithBaseCall(params string[] arguments);
38+
39+
/// <summary>
40+
/// Adds a this constructor call.
41+
/// </summary>
42+
/// <param name="arguments">The arguments to pass to the this constructor.</param>
43+
/// <returns>The builder for method chaining.</returns>
44+
IConstructorBuilder WithThisCall(params string[] arguments);
45+
46+
/// <summary>
47+
/// Adds an attribute to the constructor.
48+
/// </summary>
49+
/// <param name="attribute">The attribute code.</param>
50+
/// <returns>The builder for method chaining.</returns>
51+
IConstructorBuilder WithAttribute(string attribute);
52+
53+
/// <summary>
54+
/// Sets the constructor body.
55+
/// </summary>
56+
/// <param name="body">The constructor body code.</param>
57+
/// <returns>The builder for method chaining.</returns>
58+
IConstructorBuilder WithBody(string body);
59+
60+
/// <summary>
61+
/// Adds a line to the constructor body.
62+
/// </summary>
63+
/// <param name="line">The line of code to add.</param>
64+
/// <returns>The builder for method chaining.</returns>
65+
IConstructorBuilder AddBodyLine(string line);
66+
67+
/// <summary>
68+
/// Adds XML documentation comments.
69+
/// </summary>
70+
/// <param name="summary">The summary text.</param>
71+
/// <returns>The builder for method chaining.</returns>
72+
IConstructorBuilder WithXmlDoc(string summary);
73+
74+
/// <summary>
75+
/// Adds XML documentation for a parameter.
76+
/// </summary>
77+
/// <param name="parameterName">The parameter name.</param>
78+
/// <param name="description">The parameter description.</param>
79+
/// <returns>The builder for method chaining.</returns>
80+
IConstructorBuilder WithParamDoc(string parameterName, string description);
81+
}

0 commit comments

Comments
 (0)