DefaultSourceCode class final

Represents the concrete implementation of SourceCode, encapsulating an asset, its code structure, raw content, and rendered content.

DefaultSourceCode provides access to both the structured representation of the code via CodeStructure and the string representations of the code.

Responsibilities

  • Store the associated Asset.
  • Store the hierarchical CodeStructure representing the parsed code elements.
  • Store the original raw content of the source code.
  • Store the rendered content, which may include dynamic substitutions or template evaluations.

Design Notes

  • Immutable: all fields are final and provided via the constructor.
  • Provides direct getters for all properties, ensuring thread-safety and consistency.
  • Useful in template engines for separating source and rendered output.

Usage Example

final codeStructure = DefaultCodeStructure(elements: []);
final sourceCode = DefaultSourceCode(
  asset,
  codeStructure,
  '<div>Hello World</div>',
  '{{content}}',
);

print(sourceCode.getAsset()); // asset reference
print(sourceCode.getCodeStructure()); // DefaultCodeStructure instance
print(sourceCode.getRenderedContent()); // '<div>Hello World</div>'
print(sourceCode.getRawContent()); // '{{content}}'
Implemented types

Constructors

DefaultSourceCode(Asset _asset, CodeStructure _codeStructure, String _renderedContent, String _rawContent)
Creates a new DefaultSourceCode instance with the given _asset, _codeStructure, _renderedContent, and _rawContent.
const

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

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
getAsset() → Asset
Returns the Asset associated with this source code.
override
getCodeStructure() CodeStructure
Returns the structured representation of the code.
override
getRawContent() String
Returns the raw/unprocessed template content.
override
getRenderedContent() String
Returns the fully rendered content as a string.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited