SourceCodeBuilder class final
Builder for constructing a SourceCode instance using a fluent API.
SourceCodeBuilder allows incremental configuration of all required properties for a DefaultSourceCode object, including asset, code structure, rendered content, and raw template content.
Responsibilities
- Set the associated
Assetfor the source code. - Set the hierarchical CodeStructure representing parsed elements.
- Set the rendered content after template evaluation.
- Set the raw content of the template before rendering.
- Build an immutable DefaultSourceCode instance.
Design Notes
- Supports fluent method chaining for concise code.
- Ensures all required fields are set before calling build.
- Useful in templating engines, code generation, and testing pipelines.
Usage Example
final codeStructure = CodeStructureBuilder()
.addElement(TextCodeElement(line: '1', content: 'Hello'))
.build();
final sourceCode = SourceCodeBuilder()
.withAsset(myAsset)
.withCodeStructure(codeStructure)
.withRawContent('{{content}}')
.withRenderedContent('<div>Hello</div>')
.build();
print(sourceCode.getRenderedContent()); // '<div>Hello</div>'
print(sourceCode.getRawContent()); // '{{content}}'
Constructors
- SourceCodeBuilder()
- Builder for constructing a SourceCode instance using a fluent API.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
) → SourceCode - Builds the SourceCode instance.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withAsset(
Asset asset) → SourceCodeBuilder - Sets the asset for this source code.
-
withCodeStructure(
CodeStructure codeStructure) → SourceCodeBuilder - Sets the code structure.
-
withRawContent(
String content) → SourceCodeBuilder - Sets the raw template content before rendering.
-
withRenderedContent(
String content) → SourceCodeBuilder - Sets the rendered content after template evaluation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited