Skip to content

Commit ca63c71

Browse files
authored
Fix blocking issues related to flutter (#1501)
* Initial version, tests pass * Merge fixup * dartfmt * Test for MultiplyInheritedExecutableElement behavior * Strip out findShallowestInheritable and replace with preferredClass parameter passing * Add preferred class for disambiguating a few more cases * dartfmt and remove debug code * Update test package docs
1 parent c760f41 commit ca63c71

File tree

103 files changed

+4973
-84
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+4973
-84
lines changed

lib/dartdoc.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,28 @@ class DartDoc {
366366
path.normalize(origin),
367367
referredFrom: source);
368368
_onCheckProgress.add(pathToCheck);
369+
// Remove so that we properly count that the file doesn't exist for
370+
// the orphan check.
371+
visited.remove(fullPath);
369372
return null;
370373
}
371374
visited.add(fullPath);
372375
Iterable<String> stringLinks = stringLinksAndHref.item1;
373376
String baseHref = stringLinksAndHref.item2;
374377

378+
// Prevent extremely large stacks by storing the paths we are using
379+
// here instead -- occasionally, very large jobs have overflowed
380+
// the stack without this.
381+
// (newPathToCheck, newFullPath)
382+
Set<Tuple2<String, String>> toVisit = new Set();
383+
375384
for (String href in stringLinks) {
376-
if (!href.startsWith('http') && !href.contains('#')) {
385+
Uri uri;
386+
try {
387+
uri = Uri.parse(href);
388+
} catch (FormatError) {}
389+
390+
if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
377391
var full;
378392
if (baseHref != null) {
379393
full = '${path.dirname(pathToCheck)}/$baseHref/$href';
@@ -384,11 +398,15 @@ class DartDoc {
384398
String newFullPath = path.joinAll([origin, newPathToCheck]);
385399
newFullPath = path.normalize(newFullPath);
386400
if (!visited.contains(newFullPath)) {
387-
_doCheck(package, origin, visited, newPathToCheck, pathToCheck,
388-
newFullPath);
401+
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
402+
visited.add(newFullPath);
389403
}
390404
}
391405
}
406+
for (Tuple2 visitPaths in toVisit) {
407+
_doCheck(package, origin, visited, visitPaths.item1, pathToCheck,
408+
visitPaths.item2);
409+
}
392410
_onCheckProgress.add(pathToCheck);
393411
}
394412

lib/src/markdown_processor.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ MatchingLinkResult _getMatchingLinkElement(
251251

252252
// Try expensive not-scoped lookup.
253253
if (refElement == null) {
254-
refElement = _findRefElementInLibrary(codeRef, element, commentRefs);
254+
Class preferredClass = _getPreferredClass(element);
255+
refElement =
256+
_findRefElementInLibrary(codeRef, element, commentRefs, preferredClass);
255257
}
256258

257259
// This is faster but does not take canonicalization into account; try
@@ -281,7 +283,7 @@ MatchingLinkResult _getMatchingLinkElement(
281283
if (searchElement is Member)
282284
searchElement = Package.getBasestElement(refElement);
283285

284-
Class preferredClass = _getPreferredClass(element);
286+
final Class preferredClass = _getPreferredClass(element);
285287
ModelElement refModelElement = element.package.findCanonicalModelElementFor(
286288
searchElement,
287289
preferredClass: preferredClass);
@@ -357,6 +359,8 @@ bool _ConsiderIfConstructor(String codeRef, ModelElement modelElement) {
357359
Constructor aConstructor = modelElement;
358360
List<String> codeRefParts = codeRef.split('.');
359361
if (codeRefParts.length > 1) {
362+
// Pick the last two parts, in case a specific library was part of the
363+
// codeRef.
360364
if (codeRefParts[codeRefParts.length - 1] ==
361365
codeRefParts[codeRefParts.length - 2]) {
362366
// Foobar.Foobar -- assume they really do mean the constructor for this class.
@@ -380,8 +384,8 @@ Map<String, Set<ModelElement>> _findRefElementCache;
380384
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
381385
// removes out that are gratuitous and debug the individual pieces.
382386
// TODO(jcollins-g): A complex package winds up spending a lot of cycles in here. Optimize.
383-
Element _findRefElementInLibrary(
384-
String codeRef, ModelElement element, List<CommentReference> commentRefs) {
387+
Element _findRefElementInLibrary(String codeRef, ModelElement element,
388+
List<CommentReference> commentRefs, Class preferredClass) {
385389
assert(element != null);
386390
assert(element.package.allLibrariesAdded);
387391

@@ -394,21 +398,24 @@ Element _findRefElementInLibrary(
394398
// This might be an operator. Strip the operator prefix and try again.
395399
if (results.isEmpty && codeRef.startsWith('operator')) {
396400
String newCodeRef = codeRef.replaceFirst('operator', '');
397-
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
401+
return _findRefElementInLibrary(
402+
newCodeRef, element, commentRefs, preferredClass);
398403
}
399404

400405
results.remove(null);
401406
// Oh, and someone might have some type parameters or other garbage.
402407
if (results.isEmpty && codeRef.contains(trailingIgnoreStuff)) {
403408
String newCodeRef = codeRef.replaceFirst(trailingIgnoreStuff, '');
404-
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
409+
return _findRefElementInLibrary(
410+
newCodeRef, element, commentRefs, preferredClass);
405411
}
406412

407413
results.remove(null);
408414
// Oh, and someone might have thrown on a 'const' or 'final' in front.
409415
if (results.isEmpty && codeRef.contains(leadingIgnoreStuff)) {
410416
String newCodeRef = codeRef.replaceFirst(leadingIgnoreStuff, '');
411-
return _findRefElementInLibrary(newCodeRef, element, commentRefs);
417+
return _findRefElementInLibrary(
418+
newCodeRef, element, commentRefs, preferredClass);
412419
}
413420

414421
// Maybe this ModelElement has parameters, and this is one of them.
@@ -422,7 +429,7 @@ Element _findRefElementInLibrary(
422429
if (results.isEmpty) {
423430
// Maybe this is local to a class.
424431
// TODO(jcollins-g): tryClasses is a strict subset of the superclass chain. Optimize.
425-
List<Class> tryClasses = [_getPreferredClass(element)];
432+
List<Class> tryClasses = [preferredClass];
426433
Class realClass = tryClasses.first;
427434
if (element is Inheritable) {
428435
ModelElement overriddenElement = element.overriddenElement;
@@ -482,7 +489,8 @@ Element _findRefElementInLibrary(
482489
_findRefElementCache.containsKey(codeRefChomped)) {
483490
for (final modelElement in _findRefElementCache[codeRefChomped]) {
484491
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
485-
results.add(package.findCanonicalModelElementFor(modelElement.element));
492+
results.add(package.findCanonicalModelElementFor(modelElement.element,
493+
preferredClass: preferredClass));
486494
}
487495
}
488496
results.remove(null);
@@ -492,7 +500,8 @@ Element _findRefElementInLibrary(
492500
for (final modelElement in library.allModelElements) {
493501
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
494502
if (codeRefChomped == modelElement.fullyQualifiedNameWithoutLibrary) {
495-
results.add(package.findCanonicalModelElementFor(modelElement.element));
503+
results.add(package.findCanonicalModelElementFor(modelElement.element,
504+
preferredClass: preferredClass));
496505
}
497506
}
498507
}

0 commit comments

Comments
 (0)