appendClassContent method
Append the content of dart class
var newClassContent = '''abstract class Routes {
Routes._();
}
abstract class _Paths {
_Paths._();
}'''.appendClassContent('Routes', 'static const HOME = _Paths.HOME;' );
print(newClassContent);
abstract class Routes { Routes._(); static const HOME = _Paths.HOME; } abstract class _Paths { Paths.(); }
Implementation
String appendClassContent(String className, String value) {
var matches =
RegExp('class $className {.*?(^})', multiLine: true, dotAll: true)
.allMatches(this);
//TODO: Add exception in the translations
if (matches.isEmpty) {
throw CliException('The class $className is not found in the file $this');
} else if (matches.length > 1) {
throw CliException(
'The class $className is found more than once in the file $this');
}
var match = matches.first;
return insert(match.end - 1, value);
}