@@ -238,14 +238,14 @@ class PackageGraph with CommentReferable, Nameable {
238
238
for (var directive in unit.directives.whereType <LibraryDirective >()) {
239
239
// There should be only one library directive. If there are more, there
240
240
// is no harm in grabbing ModelNode for each.
241
- var commentReferenceData = directive.documentationComment? .data;
241
+ var commentData = directive.documentationComment? .data;
242
242
_modelNodes.putIfAbsent (
243
243
resolvedLibrary.element,
244
244
() => ModelNode (
245
245
directive,
246
246
resolvedLibrary.element,
247
247
analysisContext,
248
- commentReferenceData : commentReferenceData ,
248
+ commentData : commentData ,
249
249
));
250
250
}
251
251
@@ -287,50 +287,39 @@ class PackageGraph with CommentReferable, Nameable {
287
287
}
288
288
289
289
void _populateModelNodeFor (Declaration declaration) {
290
- var commentReferenceData = declaration.documentationComment? .data;
290
+ var commentData = declaration.documentationComment? .data;
291
+
292
+ void addModelNode (Declaration declaration) {
293
+ var element = declaration.declaredElement;
294
+ if (element == null ) {
295
+ throw StateError ("Expected '$declaration ' to declare an element" );
296
+ }
297
+ _modelNodes.putIfAbsent (
298
+ element,
299
+ () => ModelNode (
300
+ declaration,
301
+ element,
302
+ analysisContext,
303
+ commentData: commentData,
304
+ ),
305
+ );
306
+ }
291
307
292
308
if (declaration is FieldDeclaration ) {
293
309
var fields = declaration.fields.variables;
294
310
for (var field in fields) {
295
- var element = field.declaredElement! ;
296
- _modelNodes.putIfAbsent (
297
- element,
298
- () => ModelNode (
299
- field,
300
- element,
301
- analysisContext,
302
- commentReferenceData: commentReferenceData,
303
- ),
304
- );
311
+ addModelNode (field);
305
312
}
306
313
return ;
307
314
}
308
315
if (declaration is TopLevelVariableDeclaration ) {
309
316
var fields = declaration.variables.variables;
310
317
for (var field in fields) {
311
- var element = field.declaredElement! ;
312
- _modelNodes.putIfAbsent (
313
- element,
314
- () => ModelNode (
315
- field,
316
- element,
317
- analysisContext,
318
- commentReferenceData: commentReferenceData,
319
- ),
320
- );
318
+ addModelNode (field);
321
319
}
322
320
return ;
323
321
}
324
- var element = declaration.declaredElement! ;
325
- _modelNodes.putIfAbsent (
326
- element,
327
- () => ModelNode (
328
- declaration,
329
- element,
330
- analysisContext,
331
- commentReferenceData: commentReferenceData,
332
- ),
333
- );
322
+ addModelNode (declaration);
334
323
}
335
324
336
325
ModelNode ? getModelNodeFor (Element element) => _modelNodes[element];
@@ -1073,10 +1062,16 @@ class InheritableElementsKey {
1073
1062
1074
1063
extension on Comment {
1075
1064
/// A mapping of all comment references to their various data.
1076
- Map <String , CommentReferenceData > get data {
1077
- if (references.isEmpty) return const {};
1065
+ CommentData get data {
1066
+ var docImportsData = < CommentDocImportData > [];
1067
+ for (var docImport in docImports) {
1068
+ docImportsData.add (
1069
+ CommentDocImportData (
1070
+ offset: docImport.offset, end: docImport.import.end),
1071
+ );
1072
+ }
1078
1073
1079
- var data = < String , CommentReferenceData > {};
1074
+ var referencesData = < String , CommentReferenceData > {};
1080
1075
for (var reference in references) {
1081
1076
var commentReferable = reference.expression;
1082
1077
String name;
@@ -1096,15 +1091,16 @@ extension on Comment {
1096
1091
continue ;
1097
1092
}
1098
1093
1099
- if (staticElement != null && ! data .containsKey (name)) {
1100
- data [name] = CommentReferenceData (
1094
+ if (staticElement != null && ! referencesData .containsKey (name)) {
1095
+ referencesData [name] = CommentReferenceData (
1101
1096
staticElement,
1102
1097
name,
1103
1098
commentReferable.offset,
1104
1099
commentReferable.length,
1105
1100
);
1106
1101
}
1107
1102
}
1108
- return data;
1103
+ return CommentData (
1104
+ offset: offset, docImports: docImportsData, references: referencesData);
1109
1105
}
1110
1106
}
0 commit comments