Skip to content

Commit b340c28

Browse files
committed
Merge branch 'master' into aot-online
2 parents 46ba80d + 451c82d commit b340c28

19 files changed

+574
-308
lines changed

lib/dartdoc.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import 'package:dartdoc/src/logging.dart';
2323
import 'package:dartdoc/src/markdown_processor.dart' show markdownStats;
2424
import 'package:dartdoc/src/model/model.dart';
2525
import 'package:dartdoc/src/package_meta.dart';
26+
import 'package:dartdoc/src/tool_definition.dart';
2627
import 'package:dartdoc/src/tool_runner.dart';
2728
import 'package:dartdoc/src/tuple.dart';
2829
import 'package:dartdoc/src/utils.dart';

lib/resources/favicon.png

851 Bytes
Loading

lib/src/comment_references/model_comment_reference.dart

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ abstract class ModelCommentReference {
1515
bool get allowDefaultConstructor;
1616
String get codeRef;
1717
bool get hasConstructorHint;
18+
bool get hasCallableHint;
1819
List<String> get referenceBy;
1920
Element get staticElement;
2021

@@ -32,22 +33,42 @@ abstract class ModelCommentReference {
3233
/// information needed for Dartdoc. Drops link to the [CommentReference]
3334
/// and [ResourceProvider] after construction.
3435
class _ModelCommentReferenceImpl implements ModelCommentReference {
36+
bool _allowDefaultConstructor;
3537
@override
3638
bool get allowDefaultConstructor {
37-
if (parsed.length >= 2) {
38-
return parsed[parsed.length - 2] == parsed[parsed.length - 1];
39+
if (_allowDefaultConstructor == null) {
40+
_allowDefaultConstructor = false;
41+
var foundFirst = false;
42+
String checkText;
43+
// Check for two identically named identifiers at the end of the
44+
// parse list, skipping over any junk or other nodes.
45+
for (var node in parsed.reversed.whereType<IdentifierNode>()) {
46+
if (foundFirst) {
47+
if (checkText == node.text) {
48+
_allowDefaultConstructor = true;
49+
}
50+
break;
51+
} else {
52+
foundFirst = true;
53+
checkText = node.text;
54+
}
55+
}
3956
}
40-
return false;
57+
return _allowDefaultConstructor;
4158
}
4259

4360
@override
4461
final String codeRef;
4562

4663
@override
47-
bool get hasConstructorHint =>
64+
bool get hasCallableHint =>
4865
parsed.isNotEmpty &&
4966
(parsed.first is ConstructorHintStartNode ||
50-
parsed.last is ConstructorHintEndNode);
67+
parsed.last is CallableHintEndNode);
68+
69+
@override
70+
bool get hasConstructorHint =>
71+
parsed.isNotEmpty && parsed.first is ConstructorHintStartNode;
5172

5273
@override
5374
List<String> get referenceBy => parsed

lib/src/comment_references/parser.dart

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class CommentReferenceParser {
133133
if (suffixResult.type == _SuffixResultType.notSuffix) {
134134
// Invalid trailing junk; reject the reference.
135135
return [];
136-
} else if (suffixResult.type == _SuffixResultType.parsedConstructorHint) {
136+
} else if (suffixResult.type == _SuffixResultType.parsedCallableHint) {
137137
children.add(suffixResult.node);
138138
}
139139

@@ -142,7 +142,6 @@ class CommentReferenceParser {
142142
}
143143

144144
static const _constructorHintPrefix = 'new';
145-
146145
static const _ignorePrefixes = ['const', 'final', 'var'];
147146

148147
/// Implement parsing a prefix to a comment reference.
@@ -153,17 +152,19 @@ class CommentReferenceParser {
153152
///
154153
/// <constructorPrefixHint> ::= 'new '
155154
///
156-
/// <leadingJunk> ::= ('const' | 'final' | 'var' | 'operator')(' '+)
155+
/// <leadingJunk> ::= ('const' | 'final' | 'var')(' '+)
157156
/// ```
158157
_PrefixParseResult _parsePrefix() {
159158
if (_atEnd) {
160159
return _PrefixParseResult.endOfFile;
161160
}
162-
if (_tryMatchLiteral(_constructorHintPrefix)) {
161+
if (_tryMatchLiteral(_constructorHintPrefix,
162+
requireTrailingNonidentifier: true)) {
163163
return _PrefixParseResult.ok(
164164
ConstructorHintStartNode(_constructorHintPrefix));
165165
}
166-
if (_ignorePrefixes.any((p) => _tryMatchLiteral(p))) {
166+
if (_ignorePrefixes
167+
.any((p) => _tryMatchLiteral(p, requireTrailingNonidentifier: true))) {
167168
return _PrefixParseResult.junk;
168169
}
169170

@@ -234,10 +235,10 @@ class CommentReferenceParser {
234235
IdentifierNode(codeRef.substring(startIndex, _index)));
235236
}
236237

237-
static const _constructorHintSuffix = '()';
238+
static const _callableHintSuffix = '()';
238239

239240
/// ```text
240-
/// <suffix> ::= <constructorPostfixHint>
241+
/// <suffix> ::= <callableHintSuffix>
241242
/// | <trailingJunk>
242243
///
243244
/// <trailingJunk> ::= '<'<CHARACTER>*'>'
@@ -246,18 +247,18 @@ class CommentReferenceParser {
246247
/// | '?'
247248
/// | '!'
248249
///
249-
/// <constructorPostfixHint> ::= '()'
250+
/// <callableHintSuffix> ::= '()'
250251
/// ```
251252
_SuffixParseResult _parseSuffix() {
252253
var startIndex = _index;
253254
_walkPastWhitespace();
254255
if (_atEnd) {
255256
return _SuffixParseResult.missing;
256257
}
257-
if (_tryMatchLiteral(_constructorHintSuffix)) {
258+
if (_tryMatchLiteral(_callableHintSuffix)) {
258259
if (_atEnd) {
259260
return _SuffixParseResult.ok(
260-
ConstructorHintEndNode(codeRef.substring(startIndex, _index)));
261+
CallableHintEndNode(codeRef.substring(startIndex, _index)));
261262
}
262263
return _SuffixParseResult.notSuffix;
263264
}
@@ -278,10 +279,12 @@ class CommentReferenceParser {
278279

279280
/// Advances [_index] on match, preserves on non-match.
280281
bool _tryMatchLiteral(String characters,
281-
{bool acceptTrailingWhitespace = true}) {
282+
{bool acceptTrailingWhitespace = true,
283+
bool requireTrailingNonidentifier = false}) {
282284
assert(acceptTrailingWhitespace != null);
283285
if (characters.length + _index > _referenceLength) return false;
284-
for (var startIndex = _index;
286+
int startIndex;
287+
for (startIndex = _index;
285288
_index - startIndex < characters.length;
286289
_index++) {
287290
if (codeRef.codeUnitAt(_index) !=
@@ -290,6 +293,12 @@ class CommentReferenceParser {
290293
return false;
291294
}
292295
}
296+
if (requireTrailingNonidentifier) {
297+
if (_atEnd || !_nonIdentifierChars.contains(_thisChar)) {
298+
_index = startIndex;
299+
return false;
300+
}
301+
}
293302
if (acceptTrailingWhitespace) _walkPastWhitespace();
294303
return true;
295304
}
@@ -386,10 +395,10 @@ enum _SuffixResultType {
386395
junk, // Found known types of junk it is OK to ignore.
387396
missing, // There is no suffix here. Same as EOF as this is a suffix.
388397
notSuffix, // Found something, but not a valid suffix.
389-
parsedConstructorHint, // Parsed a [ConstructorHintEndNode].
398+
parsedCallableHint, // Parsed a [CallableHintEndNode].
390399
}
391400

392-
/// The result of attempting to parse a prefix to a comment reference.
401+
/// The result of attempting to parse a suffix to a comment reference.
393402
class _SuffixParseResult {
394403
final _SuffixResultType type;
395404

@@ -398,7 +407,7 @@ class _SuffixParseResult {
398407
const _SuffixParseResult._(this.type, this.node);
399408

400409
factory _SuffixParseResult.ok(CommentReferenceNode node) =>
401-
_SuffixParseResult._(_SuffixResultType.parsedConstructorHint, node);
410+
_SuffixParseResult._(_SuffixResultType.parsedCallableHint, node);
402411

403412
static const _SuffixParseResult junk =
404413
_SuffixParseResult._(_SuffixResultType.junk, null);
@@ -426,14 +435,14 @@ class ConstructorHintStartNode extends CommentReferenceNode {
426435
String toString() => 'ConstructorHintStartNode["$text"]';
427436
}
428437

429-
class ConstructorHintEndNode extends CommentReferenceNode {
438+
class CallableHintEndNode extends CommentReferenceNode {
430439
@override
431440
final String text;
432441

433-
ConstructorHintEndNode(this.text);
442+
CallableHintEndNode(this.text);
434443

435444
@override
436-
String toString() => 'ConstructorHintEndNode["$text"]';
445+
String toString() => 'CallableHintEndNode["$text"]';
437446
}
438447

439448
/// Represents an identifier.

0 commit comments

Comments
 (0)