@@ -10,7 +10,10 @@ import 'package:dart_style/dart_style.dart';
1010import 'package:source_gen/source_gen.dart' ;
1111
1212/// Comment flag used to indicate where imports should be added in the generated code.
13- const String importFlag = '// crystallis_generator(add_import):' ;
13+ const String kImportFlag = '// crystallis_generator(add_import):' ;
14+
15+ /// Import statement to be added for generated classes.
16+ const String kCrystallisGeneratedImport = "import 'package:crystallis/generated.dart';" ;
1417
1518/// Entry point for the Crystallis code generator.
1619Builder crystallisBuilder (BuilderOptions options) {
@@ -44,19 +47,19 @@ Builder crystallisBuilder(BuilderOptions options) {
4447 // add imports after crystalllis import
4548 final Set <String > imports = code
4649 .split ('\n ' )
47- .where ((line) => line.trim ().startsWith (importFlag ))
48- .map ((line) => 'import ${line .substring (importFlag .length + line .indexOf (importFlag )).trim ()};' )
50+ .where ((line) => line.trim ().startsWith (kImportFlag ))
51+ .map ((line) => 'import ${line .substring (kImportFlag .length + line .indexOf (kImportFlag )).trim ()};' )
4952 .toSet ();
5053
5154 // clean code of import flags
5255 code = code
5356 .split ('\n ' ) //
54- .where ((line) => ! line.trim ().startsWith (importFlag ))
57+ .where ((line) => ! line.trim ().startsWith (kImportFlag ))
5558 .join ('\n ' );
5659
5760 final lines = code.split ('\n ' );
5861 final int crystallisImportIndex = lines.indexWhere (
59- (line) => line.startsWith ("import 'package:crystallis/crystallis.dart';" ),
62+ (line) => line.startsWith (kCrystallisGeneratedImport ),
6063 );
6164
6265 if (crystallisImportIndex != - 1 ) {
@@ -140,7 +143,7 @@ class CrystallisGenerator extends GeneratorForAnnotation<Crystallise> {
140143 // (write only if they haven't been written to this file before)
141144 if (! _librariesWithImports.contains (buildStep.inputId.uri)) {
142145 _librariesWithImports.add (buildStep.inputId.uri);
143- buffer.writeln ("import 'package:crystallis/crystallis.dart';" );
146+ buffer.writeln (kCrystallisGeneratedImport );
144147 buffer.writeln ("import '${buildStep .inputId .uri .asPackageOrBaseName }';" );
145148 buffer.writeln ();
146149 }
@@ -260,7 +263,7 @@ class CrystallisGenerator extends GeneratorForAnnotation<Crystallise> {
260263 );
261264
262265 if (serializers.isNotEmpty) {
263- buffer.writeln (' $importFlag $importSerializer ' );
266+ buffer.writeln (' $kImportFlag $importSerializer ' );
264267
265268 /*
266269 * Custom serializer handling
@@ -283,7 +286,7 @@ class CrystallisGenerator extends GeneratorForAnnotation<Crystallise> {
283286 * Default serializer handling
284287 */
285288 if (f.type.isDartCoreMap) {
286- buffer.writeln (' $importFlag $importSerializer ' );
289+ buffer.writeln (' $kImportFlag $importSerializer ' );
287290 buffer.writeln (
288291 ' serializer: MapSerializer<${_typeArguments (f .type ).join (', ' )}>(),' ,
289292 );
0 commit comments