toJson method
Serializes this declaration into a JSON-compatible map.
The returned map must:
- Contain only JSON-encodable values
- Fully describe the declaration's identity and structure
This method is used for:
- Debugging
- Tooling output
- Snapshot comparisons
Implementation
@override
Map<String, Object> toJson() {
Map<String, Object> result = {};
result['declaration'] = 'source';
result['name'] = getName();
final annotations = getAnnotations().map((a) => a.toJson()).toList();
if (annotations.isNotEmpty) {
result['annotations'] = annotations;
}
final sourceLocation = getSourceLocation();
if (sourceLocation != null) {
result['sourceLocation'] = sourceLocation.toString();
}
result['runtimeType'] = runtimeType.toString();
return result;
}