@@ -15,6 +15,7 @@ import 'package:dartdoc/src/html/html_generator_instance.dart';
1515import 'package:dartdoc/src/html/template_data.dart' ;
1616import 'package:dartdoc/src/html/templates.dart' ;
1717import 'package:dartdoc/src/model/model.dart' ;
18+ import 'package:dartdoc/src/warnings.dart' ;
1819import 'package:path/path.dart' as path;
1920
2021typedef Renderer = String Function (String input);
@@ -48,7 +49,7 @@ class HtmlGenerator extends Generator {
4849 Stream <void > get onFileCreated => _onFileCreated.stream;
4950
5051 @override
51- final Set <String > writtenFiles = Set < String >() ;
52+ final Map <String , Warnable > writtenFiles = {} ;
5253
5354 static Future <HtmlGenerator > create (
5455 {HtmlGeneratorOptions options,
@@ -83,14 +84,23 @@ class HtmlGenerator extends Generator {
8384 assert (_instance == null );
8485
8586 var enabled = true ;
86- void write (String filePath, Object content, {bool allowOverwrite}) {
87+ void write (String filePath, Object content,
88+ {bool allowOverwrite, Warnable element}) {
8789 allowOverwrite ?? = false ;
8890 if (! enabled) {
8991 throw StateError ('`write` was called after `generate` completed.' );
9092 }
91- // If you see this assert, we're probably being called to build non-canonical
92- // docs somehow. Check data.self.isCanonical and callers for bugs.
93- assert (allowOverwrite || ! writtenFiles.contains (filePath));
93+ if (! allowOverwrite) {
94+ if (writtenFiles.containsKey (filePath)) {
95+ assert (element != null ,
96+ 'Attempted overwrite of ${filePath } without corresponding element' );
97+ Warnable originalElement = writtenFiles[filePath];
98+ Iterable <Warnable > referredFrom =
99+ originalElement != null ? [originalElement] : null ;
100+ element? .warn (PackageWarning .duplicateFile,
101+ message: filePath, referredFrom: referredFrom);
102+ }
103+ }
94104
95105 var file = File (path.join (outputDirectoryPath, filePath));
96106 var parent = file.parent;
@@ -107,7 +117,7 @@ class HtmlGenerator extends Generator {
107117 content, 'content' , '`content` must be `String` or `List<int>`.' );
108118 }
109119 _onFileCreated.add (file);
110- writtenFiles. add ( filePath) ;
120+ writtenFiles[ filePath] = element ;
111121 }
112122
113123 try {
0 commit comments