content property

  1. @override
String get content
override

Implementation

@override
String get content {
  final parent = this.parent;

  if (parent == null) {
    throw Exception('Part files must have a parent.');
  }

  final content = super.content;
  if (content.contains(RegExp("^import '"))) {
    throw Exception('Part files cannot contain import statements.');
  }

  final partsToParent = [
    for (final _ in path.skip(1)) '..',
    parent.fileName,
  ];

  final parentPath = p.joinAll(partsToParent);

  return '''
part of '$parentPath';

$content''';
}