Skip to content

Update analyzer, fix checked mode runs for flutter, and unpin bots. #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: dart
sudo: false
dart:
- "dev/release/2.0.0-dev.22.0"
- "dev/raw/latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just dev here!

Copy link
Contributor Author

@jcollins-g jcollins-g Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually looking for raw here. Not all versions that we actually wind up using in internal rolls, etc, get published to release right away, and I'd like to have the bots go red on a problem ahead of that.

env:
- DARTDOC_BOT=main
# TODO(devoncarew): add angulardart support
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# BSD-style license that can be found in the LICENSE file.

install:
- ps: wget https://gsdview.appspot.com/dart-archive/channels/dev/raw/2.0.0-dev.22.0/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip
- ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/latest/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip
- cmd: echo "Unzipping dart-sdk..."
- cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul
- set PATH=%PATH%;C:\tools\dart-sdk\bin
Expand Down
78 changes: 32 additions & 46 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ library dartdoc.markdown_processor;
import 'dart:convert';
import 'dart:math';

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart' show Member;
import 'package:dartdoc/src/model_utils.dart';
import 'package:html/parser.dart' show parse;
import 'package:markdown/markdown.dart' as md;
Expand Down Expand Up @@ -254,46 +253,42 @@ MatchingLinkResult _getMatchingLinkElement(
return new MatchingLinkResult(null, null, warn: false);
}

Element refElement;
ModelElement refModelElement;

// Try expensive not-scoped lookup.
if (refElement == null) {
if (refModelElement == null) {
Class preferredClass = _getPreferredClass(element);
refElement =
refModelElement =
_findRefElementInLibrary(codeRef, element, commentRefs, preferredClass);
}

// This is faster but does not take canonicalization into account; try
// only as a last resort. TODO(jcollins-g): make analyzer comment references
// dartdoc-canonicalization-aware?
if (refElement == null) {
refElement = _getRefElementFromCommentRefs(commentRefs, codeRef);
// This is faster but does not know about libraries without imports in the
// current context; try only as a last resort.
// TODO(jcollins-g): make analyzer comment references dartdoc-canonicalization-aware?
if (refModelElement == null) {
Element refElement = _getRefElementFromCommentRefs(commentRefs, codeRef);
if (refElement != null) {
refModelElement = new ModelElement.fromElement(
_getRefElementFromCommentRefs(commentRefs, codeRef), element.package);
refModelElement =
refModelElement.canonicalModelElement ?? refModelElement;
}
} else {
assert(refElement is! PropertyAccessorElement);
assert(refElement is! PrefixElement);
assert(refModelElement is! Accessor);
}

// Did not find it anywhere.
if (refElement == null) {
if (refModelElement == 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.
if (refElement is ParameterElement || refElement is TypeParameterElement)
if (refModelElement is Parameter || refModelElement is TypeParameter)
return new MatchingLinkResult(null, null, warn: false);

Library refLibrary = element.package.findOrCreateLibraryFor(refElement);
Element searchElement = refElement;
if (searchElement is Member)
searchElement = Package.getBasestElement(refElement);

final Class preferredClass = _getPreferredClass(element);
ModelElement refModelElement = element.package.findCanonicalModelElementFor(
searchElement,
preferredClass: preferredClass);
// There have been places in the code which helpfully cache entities
// regardless of what package they are associated with. This assert
// will protect us from reintroducing that.
Expand All @@ -302,23 +297,8 @@ MatchingLinkResult _getMatchingLinkElement(
return new MatchingLinkResult(refModelElement, null);
}
// From this point on, we haven't been able to find a canonical ModelElement.
// So in this case, just find any ModelElement we can.
Accessor getter;
Accessor setter;
if (searchElement is FieldElement) {
// TODO(jcollins-g): consolidate field element construction with inheritance
// checking.
if (searchElement.getter != null) {
getter = new ModelElement.from(searchElement.getter, refLibrary);
}
if (searchElement.setter != null) {
setter = new ModelElement.from(searchElement.setter, refLibrary);
}
}
refModelElement = new ModelElement.from(searchElement, refLibrary,
getter: getter, setter: setter);
if (!refModelElement.isCanonical) {
if (refLibrary.isPublicAndPackageDocumented) {
if (refModelElement.library.isPublicAndPackageDocumented) {
refModelElement
.warn(PackageWarning.noCanonicalFound, referredFrom: [element]);
}
Expand Down Expand Up @@ -393,7 +373,7 @@ Map<String, Set<ModelElement>> _findRefElementCache;
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
// removes out that are gratuitous and debug the individual pieces.
// TODO(jcollins-g): A complex package winds up spending a lot of cycles in here. Optimize.
Element _findRefElementInLibrary(String codeRef, Warnable element,
ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
List<CommentReference> commentRefs, Class preferredClass) {
assert(element != null);
assert(element.package.allLibrariesAdded);
Expand Down Expand Up @@ -507,10 +487,17 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
if (results.isEmpty &&
codeRefChomped.contains('.') &&
_findRefElementCache.containsKey(codeRefChomped)) {
for (final modelElement in _findRefElementCache[codeRefChomped]) {
for (final ModelElement modelElement
in _findRefElementCache[codeRefChomped]) {
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
// For fully qualified matches, the original preferredClass passed
// might make no sense. Instead, use the enclosing class from the
// element in [_findRefElementCache], because that element's enclosing
// class will be preferred from [codeRefChomped]'s perspective.
results.add(package.findCanonicalModelElementFor(modelElement.element,
preferredClass: preferredClass));
preferredClass: modelElement.enclosingElement is Class
? modelElement.enclosingElement
: null));
}
}
results.remove(null);
Expand Down Expand Up @@ -563,8 +550,6 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
}
results.remove(null);

Element result;

if (results.length > 1) {
// If this name could refer to a class or a constructor, prefer the class.
if (results.any((r) => r is Class)) {
Expand Down Expand Up @@ -626,11 +611,12 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
}
}

ModelElement result;
// TODO(jcollins-g): further disambiguations based on package information?
if (results.isEmpty) {
result = null;
} else if (results.length == 1) {
result = results.first.element;
result = results.first;
} else {
// Squelch ambiguous doc reference warnings for parameters, because we
// don't link those anyway.
Expand All @@ -639,7 +625,7 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
message:
"[$codeRef] => ${results.map((r) => "'${r.fullyQualifiedName}'").join(", ")}");
}
result = results.first.element;
result = results.first;
}
return result;
}
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.31.1"
version: "0.31.2-alpha.0"
args:
dependency: "direct main"
description:
Expand Down Expand Up @@ -91,7 +91,7 @@ packages:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0-alpha.9"
version: "0.1.0-alpha.10"
glob:
dependency: transitive
description:
Expand Down Expand Up @@ -161,7 +161,7 @@ packages:
name: kernel
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0-alpha.9"
version: "0.3.0-alpha.10"
logging:
dependency: "direct main"
description:
Expand Down Expand Up @@ -371,7 +371,7 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.30+2"
version: "0.12.30+3"
tuple:
dependency: "direct main"
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ homepage: https://github.com/dart-lang/dartdoc
environment:
sdk: '>=1.23.0-dev.11.5 <2.0.0'
dependencies:
analyzer: 0.31.1
analyzer: '0.31.2-alpha.0'
args: '>=0.13.0 <2.0.0'
collection: ^1.2.0
front_end: ^0.1.0-alpha.9
front_end: ^0.1.0-alpha.10
html: '>=0.12.1 <0.14.0'
# We don't use http_parser directly; this dep exists to ensure that we get at
# least version 3.0.3 to work around an issue with 3.0.2.
Expand Down
17 changes: 17 additions & 0 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,23 @@ void main() {
'<p>link to method from class <a href="ex/Apple/m.html">Apple.m</a></p>'));
});

test(
'code references to privately defined elements in public classes work properly',
() {
Method notAMethodFromPrivateClass = fakeLibrary.allClasses
.firstWhere((Class c) => c.name == 'ReferringClass')
.allPublicInstanceMethods
.firstWhere((Method m) => m.name == 'notAMethodFromPrivateClass');
expect(
notAMethodFromPrivateClass.documentationAsHtml,
contains(
'<a href="fake/InheritingClassOne/aMethod.html">fake.InheritingClassOne.aMethod</a>'));
expect(
notAMethodFromPrivateClass.documentationAsHtml,
contains(
'<a href="fake/InheritingClassTwo/aMethod.html">fake.InheritingClassTwo.aMethod</a>'));
});

test('legacy code blocks render correctly', () {
expect(
testingCodeSyntaxInOneLiners.oneLineDoc,
Expand Down
18 changes: 18 additions & 0 deletions testing/test_package/lib/fake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,21 @@ class OperatorReferenceClass {
return false;
}
}

class _PrivateClassDefiningSomething {
bool aMethod() {
return false;
}
}

class InheritingClassOne extends _PrivateClassDefiningSomething {}
class InheritingClassTwo extends _PrivateClassDefiningSomething {}

class ReferringClass {
/// Here I am referring by full names, to [fake.InheritingClassOne.aMethod],
/// and to [fake.InheritingClassTwo.aMethod]. With luck, both of these
/// two resolve correctly.
bool notAMethodFromPrivateClass() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/AMixinCallingSuper-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/Annotation-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/AnotherInterface-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/BaseForDocComments-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/BaseThingy-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package_docs/fake/BaseThingy2-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ <h5>fake library</h5>
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
<li><a href="fake/Interface-class.html">Interface</a></li>
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>
Expand Down
Loading