2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart=2.9
6
-
7
5
/// Utility code to convert markdown comments to html.
8
6
library dartdoc.markdown_processor;
9
7
@@ -162,7 +160,7 @@ class _IterableBlockParser extends md.BlockParser {
162
160
/// Return false if the passed [referable] is an unnamed [Constructor] ,
163
161
/// or if it is shadowing another type of element, or is a parameter of
164
162
/// one of the above.
165
- bool _rejectUnnamedAndShadowingConstructors (CommentReferable referable) {
163
+ bool _rejectUnnamedAndShadowingConstructors (CommentReferable ? referable) {
166
164
if (referable is Constructor ) {
167
165
if (referable.isUnnamedConstructor) return false ;
168
166
if (referable.enclosingElement
@@ -175,11 +173,11 @@ bool _rejectUnnamedAndShadowingConstructors(CommentReferable referable) {
175
173
176
174
/// Return false unless the passed [referable] represents a callable object.
177
175
/// Allows constructors but does not require them.
178
- bool _requireCallable (CommentReferable referable) =>
176
+ bool _requireCallable (CommentReferable ? referable) =>
179
177
referable is ModelElement && referable.isCallable;
180
178
181
179
/// Return false unless the passed [referable] represents a constructor.
182
- bool _requireConstructor (CommentReferable referable) =>
180
+ bool _requireConstructor (CommentReferable ? referable) =>
183
181
referable is Constructor ;
184
182
185
183
/// Implements _getMatchingLinkElement via [CommentReferable.referenceBy] .
@@ -188,40 +186,42 @@ MatchingLinkResult _getMatchingLinkElementCommentReferable(
188
186
var commentReference =
189
187
warnable.commentRefs[codeRef] ?? ModelCommentReference .synthetic (codeRef);
190
188
191
- bool Function (CommentReferable ) filter;
192
- bool Function (CommentReferable ) allowTree;
189
+ late final bool Function (CommentReferable ? ) filter;
190
+ late final bool Function (CommentReferable ? ) allowTree;
193
191
194
192
// Constructor references are pretty ambiguous by nature since they can be
195
193
// declared with the same name as the class they are constructing, and even
196
194
// if they don't use field-formal parameters, sometimes have parameters
197
195
// named the same as members.
198
196
// Maybe clean this up with inspiration from constructor tear-off syntax?
199
197
if (commentReference.allowUnnamedConstructor) {
198
+ allowTree = (_) => true ;
200
199
// Neither reject, nor require, a default constructor in the event
201
200
// the comment reference structure implies one. (We can not require it
202
201
// in case a library name is the same as a member class name and the class
203
202
// is the intended lookup). For example, [FooClass.FooClass] structurally
204
203
// "looks like" a default constructor, so we should allow it here.
205
- filter = commentReference.hasCallableHint ? _requireCallable : null ;
204
+ filter = commentReference.hasCallableHint ? _requireCallable : (_) => true ;
206
205
} else if (commentReference.hasConstructorHint &&
207
206
commentReference.hasCallableHint) {
207
+ allowTree = (_) => true ;
208
208
// This takes precedence over the callable hint if both are present --
209
209
// pick a constructor if and only constructor if we see `new`.
210
210
filter = _requireConstructor;
211
211
} else if (commentReference.hasCallableHint) {
212
+ allowTree = (_) => true ;
212
213
// Trailing parens indicate we are looking for a callable.
213
214
filter = _requireCallable;
214
215
} else {
215
- // Without hints, reject unnamed constructors and their parameters to force
216
- // resolution to the class.
217
- filter = _rejectUnnamedAndShadowingConstructors;
218
-
219
216
if (! commentReference.allowUnnamedConstructorParameter) {
220
217
allowTree = _rejectUnnamedAndShadowingConstructors;
218
+ } else {
219
+ allowTree = (_) => true ;
221
220
}
221
+ // Without hints, reject unnamed constructors and their parameters to force
222
+ // resolution to the class.
223
+ filter = _rejectUnnamedAndShadowingConstructors;
222
224
}
223
- allowTree ?? = (_) => true ;
224
- filter ?? = (_) => true ;
225
225
var lookupResult = warnable.referenceBy (commentReference.referenceBy,
226
226
allowTree: allowTree, filter: filter);
227
227
@@ -239,7 +239,10 @@ md.Node _makeLinkNode(String codeRef, Warnable warnable) {
239
239
if (linkedElement is ModelElement && linkedElement.isDeprecated) {
240
240
anchor.attributes['class' ] = 'deprecated' ;
241
241
}
242
- anchor.attributes['href' ] = linkedElement.href;
242
+ var href = linkedElement.href;
243
+ if (href != null ) {
244
+ anchor.attributes['href' ] = href;
245
+ }
243
246
return anchor;
244
247
}
245
248
// else this would be linkedElement.linkedName, but link bodies are slightly
@@ -250,9 +253,8 @@ md.Node _makeLinkNode(String codeRef, Warnable warnable) {
250
253
// current element.
251
254
warnable.warn (PackageWarning .unresolvedDocReference,
252
255
message: codeRef,
253
- referredFrom: warnable.documentationIsLocal
254
- ? null
255
- : warnable.documentationFrom);
256
+ referredFrom:
257
+ warnable.documentationIsLocal ? [] : warnable.documentationFrom);
256
258
}
257
259
}
258
260
@@ -328,8 +330,8 @@ Iterable<int> findFreeHangingGenericsPositions(String string) sync* {
328
330
}
329
331
330
332
class MarkdownDocument extends md.Document {
331
- factory MarkdownDocument .withElementLinkResolver (Canonicalization element) {
332
- md.Node /*?*/ linkResolver (String name, [String /*?*/ _]) {
333
+ factory MarkdownDocument .withElementLinkResolver (Warnable element) {
334
+ md.Node ? linkResolver (String name, [String ? _]) {
333
335
if (name.isEmpty) {
334
336
return null ;
335
337
}
@@ -343,11 +345,11 @@ class MarkdownDocument extends md.Document {
343
345
}
344
346
345
347
MarkdownDocument (
346
- {Iterable <md.BlockSyntax > blockSyntaxes,
347
- Iterable <md.InlineSyntax > inlineSyntaxes,
348
- md.ExtensionSet extensionSet,
349
- md.Resolver linkResolver,
350
- md.Resolver imageLinkResolver})
348
+ {Iterable <md.BlockSyntax >? blockSyntaxes,
349
+ Iterable <md.InlineSyntax >? inlineSyntaxes,
350
+ md.ExtensionSet ? extensionSet,
351
+ md.Resolver ? linkResolver,
352
+ md.Resolver ? imageLinkResolver})
351
353
: super (
352
354
blockSyntaxes: blockSyntaxes,
353
355
inlineSyntaxes: inlineSyntaxes,
@@ -362,7 +364,7 @@ class MarkdownDocument extends md.Document {
362
364
String text, bool processFullText) {
363
365
var hasExtendedContent = false ;
364
366
var lines = LineSplitter .split (text).toList ();
365
- md.Node firstNode;
367
+ md.Node ? firstNode;
366
368
var nodes = < md.Node > [];
367
369
for (var node in _IterableBlockParser (lines, this ).parseLinesGenerator ()) {
368
370
if (firstNode != null ) {
@@ -387,7 +389,7 @@ class MarkdownDocument extends md.Document {
387
389
nodes.insertAll (i, inlineNodes);
388
390
i += inlineNodes.length - 1 ;
389
391
} else if (node is md.Element && node.children != null ) {
390
- _parseInlineContent (node.children);
392
+ _parseInlineContent (node.children! );
391
393
}
392
394
}
393
395
}
@@ -407,7 +409,7 @@ class _InlineCodeSyntax extends md.InlineSyntax {
407
409
408
410
@override
409
411
bool onMatch (md.InlineParser parser, Match match) {
410
- var element = md.Element .text ('code' , _htmlEscape.convert (match[1 ] /*!*/ ));
412
+ var element = md.Element .text ('code' , _htmlEscape.convert (match[1 ]! ));
411
413
parser.addNode (element);
412
414
return true ;
413
415
}
@@ -416,7 +418,7 @@ class _InlineCodeSyntax extends md.InlineSyntax {
416
418
class _AutolinkWithoutScheme extends md.AutolinkSyntax {
417
419
@override
418
420
bool onMatch (md.InlineParser parser, Match match) {
419
- var url = match[1 ] /*!*/ ;
421
+ var url = match[1 ]! ;
420
422
var text = _htmlEscape.convert (url).replaceFirst (_hideSchemes, '' );
421
423
var anchor = md.Element .text ('a' , text);
422
424
anchor.attributes['href' ] = url;
0 commit comments