From 96ebd97eef1c622c86a5b85a8abafeceb4aa7d3d Mon Sep 17 00:00:00 2001 From: Janice Collins Date: Fri, 12 May 2017 13:20:13 -0700 Subject: [PATCH] Upgrade analyzer to 0.30 and work around issues --- CHANGELOG.md | 2 ++ lib/src/markdown_processor.dart | 16 ++++++------ lib/src/model.dart | 25 ++++++++++++++----- pubspec.lock | 18 ++++++++++--- pubspec.yaml | 2 +- .../fake/SpecialList/map.html | 2 +- .../fake/SpecialList/replaceRange.html | 2 +- .../fake/SpecialList/take.html | 2 +- .../fake/SpecialList/takeWhile.html | 2 +- .../fake/SpecialList/where.html | 2 +- 10 files changed, 49 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e811c1c743..8b383693c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* Update analyzer to 0.30. #1403 + ## 0.11.2 * Fix regression where warnings generated by the README could result in a fatal exception. #1409 diff --git a/lib/src/markdown_processor.dart b/lib/src/markdown_processor.dart index 4c1f441e54..b78da35dd0 100644 --- a/lib/src/markdown_processor.dart +++ b/lib/src/markdown_processor.dart @@ -169,12 +169,6 @@ NodeList _getCommentRefs(Documentable documentable) { // CommentReference list. if (documentable is! ModelElement) return null; ModelElement modelElement = documentable; - Class preferredClass = _getPreferredClass(modelElement); - ModelElement cModelElement = modelElement.package - .findCanonicalModelElementFor(modelElement.element, - preferredClass: preferredClass); - if (cModelElement == null) return null; - modelElement = cModelElement; if (modelElement.element.documentationComment == null && modelElement.canOverride()) { @@ -255,7 +249,10 @@ MatchingLinkResult _getMatchingLinkElement( // Did not find it anywhere. if (refElement == null) { - return new MatchingLinkResult(null, null); + // TODO(jcollins-g): remove squelching of non-canonical warnings here + // once we no longer process full markdown for + // oneLineDocs (#1417) + return new MatchingLinkResult(null, null, warn: element.isCanonical); } // Ignore all parameters. @@ -263,8 +260,9 @@ MatchingLinkResult _getMatchingLinkElement( return new MatchingLinkResult(null, null, warn: false); Library refLibrary = element.package.findOrCreateLibraryFor(refElement); - Element searchElement = - refElement is Member ? refElement.baseElement : refElement; + Element searchElement = refElement; + if (searchElement is Member) + searchElement = Package.getBasestElement(refElement); Class preferredClass = _getPreferredClass(element); ModelElement refModelElement = element.package.findCanonicalModelElementFor( diff --git a/lib/src/model.dart b/lib/src/model.dart index 3a7827ed17..8e35c8042f 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -121,9 +121,9 @@ abstract class Inheritable { Element searchElement = element; if (!_canonicalEnclosingClassIsSet) { if (isInherited) { - while (searchElement is Member) { - searchElement = (searchElement as Member).baseElement; - } + searchElement = searchElement is Member + ? Package.getBasestElement(searchElement) + : searchElement; bool foundElement = false; // TODO(jcollins-g): generate warning if an inherited element's definition // is in an intermediate non-canonical class in the inheritance chain @@ -363,8 +363,6 @@ class Class extends ModelElement implements EnclosedElement { _allElements.addAll(constructors.map((e) => e.element)); _allElements.addAll(staticMethods.map((e) => e.element)); _allElements.addAll(staticProperties.map((e) => e.element)); - _allElements.addAll(_allElements.where((e) => e is Member) - ..map((e) => (e as Member).baseElement)); } return _allElements.contains(element); } @@ -1744,7 +1742,9 @@ abstract class ModelElement implements Comparable, Nameable, Documentable { // It isn't a disambiguator because EnumFields are not inherited, ever. // TODO(jcollins-g): cleanup class hierarchy so that EnumFields aren't // Inheritable, somehow? - if (e is Member) e = (e as Member).baseElement; + if (e is Member) { + e = Package.getBasestElement(e); + } Tuple4 key = new Tuple4(e, library, enclosingClass, enclosingCombo); ModelElement newModelElement; @@ -3313,12 +3313,24 @@ class Package implements Nameable, Documentable { return _canonicalLibraryFor[e]; } + // TODO(jcollins-g): Revise when dart-lang/sdk#29600 is fixed. + static Element getBasestElement(Member member) { + Element element = member; + while (element is Member) { + element = (element as Member).baseElement; + } + return element; + } + /// Tries to find a canonical ModelElement for this element. If we know /// this element is related to a particular class, pass preferredClass to /// disambiguate. ModelElement findCanonicalModelElementFor(Element e, {Class preferredClass}) { assert(allLibrariesAdded); Library lib = findCanonicalLibraryFor(e); + if (lib == null && preferredClass != null) { + lib = findCanonicalLibraryFor(preferredClass.element); + } ModelElement modelElement; // TODO(jcollins-g): The data structures should be changed to eliminate guesswork // with member elements. @@ -3326,6 +3338,7 @@ class Package implements Nameable, Documentable { // Prefer Fields over Accessors. if (e is PropertyAccessorElement) e = (e as PropertyAccessorElement).variable; + if (e is Member) e = getBasestElement(e); Set candidates = new Set(); Tuple2 iKey = new Tuple2(e, lib); Tuple4 key = diff --git a/pubspec.lock b/pubspec.lock index 28a816ba7f..d7d8da4400 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -6,7 +6,7 @@ packages: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.29.9" + version: "0.30.0" ansicolor: description: name: ansicolor @@ -73,6 +73,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.13.4" + front_end: + description: + name: front_end + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0-alpha.4" glob: description: name: glob @@ -115,6 +121,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.0" + kernel: + description: + name: kernel + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0-alpha.1" logging: description: name: logging @@ -132,7 +144,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+2" + version: "0.12.1" meta: description: name: meta @@ -282,7 +294,7 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "0.12.20+4" + version: "0.12.20+13" tuple: description: name: tuple diff --git a/pubspec.yaml b/pubspec.yaml index ca637efd3c..4f3ea29c91 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,7 @@ homepage: https://github.com/dart-lang/dartdoc environment: sdk: '>=1.14.0 <2.0.0' dependencies: - analyzer: ^0.29.8 + analyzer: ^0.30.0 args: ^0.13.0 collection: ^1.2.0 html: '>=0.12.1 <0.14.0' diff --git a/testing/test_package_docs/fake/SpecialList/map.html b/testing/test_package_docs/fake/SpecialList/map.html index e1406dde02..0701e5ddb5 100644 --- a/testing/test_package_docs/fake/SpecialList/map.html +++ b/testing/test_package_docs/fake/SpecialList/map.html @@ -156,7 +156,7 @@
class SpecialList
function f multiple times on the same element.

Methods on the returned iterable are allowed to omit calling f on any element where the result isn't needed. -For example, elementAt may call f only once.

+For example, elementAt may call f only once.

diff --git a/testing/test_package_docs/fake/SpecialList/replaceRange.html b/testing/test_package_docs/fake/SpecialList/replaceRange.html index bb730746e5..8ad573d46e 100644 --- a/testing/test_package_docs/fake/SpecialList/replaceRange.html +++ b/testing/test_package_docs/fake/SpecialList/replaceRange.html @@ -159,7 +159,7 @@
class SpecialList
end - start. An empty range (with end == start) is valid.

This method does not work on fixed-length lists, even when replacement has the same number of elements as the replaced range. In that case use -setRange instead.

+setRange instead.

diff --git a/testing/test_package_docs/fake/SpecialList/take.html b/testing/test_package_docs/fake/SpecialList/take.html index a1d33b78f4..475c6fa972 100644 --- a/testing/test_package_docs/fake/SpecialList/take.html +++ b/testing/test_package_docs/fake/SpecialList/take.html @@ -150,7 +150,7 @@
class SpecialList

Returns a lazy iterable of the count first elements of this iterable.

The returned Iterable may contain fewer than count elements, if this contains fewer than count elements.

-

The elements can be computed by stepping through iterator until count +

The elements can be computed by stepping through iterator until count elements have been seen.

The count must not be negative.

diff --git a/testing/test_package_docs/fake/SpecialList/takeWhile.html b/testing/test_package_docs/fake/SpecialList/takeWhile.html index b954062bab..6dea876f3c 100644 --- a/testing/test_package_docs/fake/SpecialList/takeWhile.html +++ b/testing/test_package_docs/fake/SpecialList/takeWhile.html @@ -150,7 +150,7 @@
class SpecialList

Returns a lazy iterable of the leading elements satisfying test.

The filtering happens lazily. Every new iterator of the returned iterable starts iterating over the elements of this.

-

The elements can be computed by stepping through iterator until an +

The elements can be computed by stepping through iterator until an element is found where test(element) is false. At that point, the returned iterable stops (its moveNext() returns false).

diff --git a/testing/test_package_docs/fake/SpecialList/where.html b/testing/test_package_docs/fake/SpecialList/where.html index 8da978107d..c56a098ff3 100644 --- a/testing/test_package_docs/fake/SpecialList/where.html +++ b/testing/test_package_docs/fake/SpecialList/where.html @@ -150,7 +150,7 @@
class SpecialList

Returns a new lazy Iterable with all elements that satisfy the predicate test.

The matching elements have the same order in the returned iterable -as they have in iterator.

+as they have in iterator.

This method returns a view of the mapped elements. As long as the returned Iterable is not iterated over, the supplied function test will not be invoked.