Skip to content

Commit 3cb8548

Browse files
authored
Update analyzer, fix checked mode runs for flutter, and unpin bots. (#1606)
* First part fixed, but now need to refactor _findRefElementInLibrary to return ModelElements * Fix checked mode and bring things up to parity for analysis driver * Add tests * Reenable -c and dartfmt * Update test package docs * Fix URL
1 parent ccf8b91 commit 3cb8548

File tree

108 files changed

+3482
-55
lines changed

Some content is hidden

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

108 files changed

+3482
-55
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: dart
22
sudo: false
33
dart:
4-
- "dev/release/2.0.0-dev.22.0"
4+
- "dev/raw/latest"
55
env:
66
- DARTDOC_BOT=main
77
# TODO(devoncarew): add angulardart support

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
install:
6-
- 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
6+
- ps: wget https://storage.googleapis.com/dart-archive/channels/dev/raw/latest/sdk/dartsdk-windows-x64-release.zip -OutFile dart-sdk.zip
77
- cmd: echo "Unzipping dart-sdk..."
88
- cmd: 7z x dart-sdk.zip -o"C:\tools" -y > nul
99
- set PATH=%PATH%;C:\tools\dart-sdk\bin

lib/src/markdown_processor.dart

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ library dartdoc.markdown_processor;
88
import 'dart:convert';
99
import 'dart:math';
1010

11-
import 'package:analyzer/dart/ast/ast.dart';
11+
import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
1212
import 'package:analyzer/dart/element/element.dart';
13-
import 'package:analyzer/src/dart/element/member.dart' show Member;
1413
import 'package:dartdoc/src/model_utils.dart';
1514
import 'package:html/parser.dart' show parse;
1615
import 'package:markdown/markdown.dart' as md;
@@ -254,46 +253,42 @@ MatchingLinkResult _getMatchingLinkElement(
254253
return new MatchingLinkResult(null, null, warn: false);
255254
}
256255

257-
Element refElement;
256+
ModelElement refModelElement;
258257

259258
// Try expensive not-scoped lookup.
260-
if (refElement == null) {
259+
if (refModelElement == null) {
261260
Class preferredClass = _getPreferredClass(element);
262-
refElement =
261+
refModelElement =
263262
_findRefElementInLibrary(codeRef, element, commentRefs, preferredClass);
264263
}
265264

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

276280
// Did not find it anywhere.
277-
if (refElement == null) {
281+
if (refModelElement == null) {
278282
// TODO(jcollins-g): remove squelching of non-canonical warnings here
279283
// once we no longer process full markdown for
280284
// oneLineDocs (#1417)
281285
return new MatchingLinkResult(null, null, warn: element.isCanonical);
282286
}
283287

284288
// Ignore all parameters.
285-
if (refElement is ParameterElement || refElement is TypeParameterElement)
289+
if (refModelElement is Parameter || refModelElement is TypeParameter)
286290
return new MatchingLinkResult(null, null, warn: false);
287291

288-
Library refLibrary = element.package.findOrCreateLibraryFor(refElement);
289-
Element searchElement = refElement;
290-
if (searchElement is Member)
291-
searchElement = Package.getBasestElement(refElement);
292-
293-
final Class preferredClass = _getPreferredClass(element);
294-
ModelElement refModelElement = element.package.findCanonicalModelElementFor(
295-
searchElement,
296-
preferredClass: preferredClass);
297292
// There have been places in the code which helpfully cache entities
298293
// regardless of what package they are associated with. This assert
299294
// will protect us from reintroducing that.
@@ -302,23 +297,8 @@ MatchingLinkResult _getMatchingLinkElement(
302297
return new MatchingLinkResult(refModelElement, null);
303298
}
304299
// From this point on, we haven't been able to find a canonical ModelElement.
305-
// So in this case, just find any ModelElement we can.
306-
Accessor getter;
307-
Accessor setter;
308-
if (searchElement is FieldElement) {
309-
// TODO(jcollins-g): consolidate field element construction with inheritance
310-
// checking.
311-
if (searchElement.getter != null) {
312-
getter = new ModelElement.from(searchElement.getter, refLibrary);
313-
}
314-
if (searchElement.setter != null) {
315-
setter = new ModelElement.from(searchElement.setter, refLibrary);
316-
}
317-
}
318-
refModelElement = new ModelElement.from(searchElement, refLibrary,
319-
getter: getter, setter: setter);
320300
if (!refModelElement.isCanonical) {
321-
if (refLibrary.isPublicAndPackageDocumented) {
301+
if (refModelElement.library.isPublicAndPackageDocumented) {
322302
refModelElement
323303
.warn(PackageWarning.noCanonicalFound, referredFrom: [element]);
324304
}
@@ -393,7 +373,7 @@ Map<String, Set<ModelElement>> _findRefElementCache;
393373
// TODO(jcollins-g): Subcomponents of this function shouldn't be adding nulls to results, strip the
394374
// removes out that are gratuitous and debug the individual pieces.
395375
// TODO(jcollins-g): A complex package winds up spending a lot of cycles in here. Optimize.
396-
Element _findRefElementInLibrary(String codeRef, Warnable element,
376+
ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
397377
List<CommentReference> commentRefs, Class preferredClass) {
398378
assert(element != null);
399379
assert(element.package.allLibrariesAdded);
@@ -507,10 +487,17 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
507487
if (results.isEmpty &&
508488
codeRefChomped.contains('.') &&
509489
_findRefElementCache.containsKey(codeRefChomped)) {
510-
for (final modelElement in _findRefElementCache[codeRefChomped]) {
490+
for (final ModelElement modelElement
491+
in _findRefElementCache[codeRefChomped]) {
511492
if (!_ConsiderIfConstructor(codeRef, modelElement)) continue;
493+
// For fully qualified matches, the original preferredClass passed
494+
// might make no sense. Instead, use the enclosing class from the
495+
// element in [_findRefElementCache], because that element's enclosing
496+
// class will be preferred from [codeRefChomped]'s perspective.
512497
results.add(package.findCanonicalModelElementFor(modelElement.element,
513-
preferredClass: preferredClass));
498+
preferredClass: modelElement.enclosingElement is Class
499+
? modelElement.enclosingElement
500+
: null));
514501
}
515502
}
516503
results.remove(null);
@@ -563,8 +550,6 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
563550
}
564551
results.remove(null);
565552

566-
Element result;
567-
568553
if (results.length > 1) {
569554
// If this name could refer to a class or a constructor, prefer the class.
570555
if (results.any((r) => r is Class)) {
@@ -626,11 +611,12 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
626611
}
627612
}
628613

614+
ModelElement result;
629615
// TODO(jcollins-g): further disambiguations based on package information?
630616
if (results.isEmpty) {
631617
result = null;
632618
} else if (results.length == 1) {
633-
result = results.first.element;
619+
result = results.first;
634620
} else {
635621
// Squelch ambiguous doc reference warnings for parameters, because we
636622
// don't link those anyway.
@@ -639,7 +625,7 @@ Element _findRefElementInLibrary(String codeRef, Warnable element,
639625
message:
640626
"[$codeRef] => ${results.map((r) => "'${r.fullyQualifiedName}'").join(", ")}");
641627
}
642-
result = results.first.element;
628+
result = results.first;
643629
}
644630
return result;
645631
}

pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: analyzer
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "0.31.1"
10+
version: "0.31.2-alpha.0"
1111
args:
1212
dependency: "direct main"
1313
description:
@@ -91,7 +91,7 @@ packages:
9191
name: front_end
9292
url: "https://pub.dartlang.org"
9393
source: hosted
94-
version: "0.1.0-alpha.9"
94+
version: "0.1.0-alpha.10"
9595
glob:
9696
dependency: transitive
9797
description:
@@ -161,7 +161,7 @@ packages:
161161
name: kernel
162162
url: "https://pub.dartlang.org"
163163
source: hosted
164-
version: "0.3.0-alpha.9"
164+
version: "0.3.0-alpha.10"
165165
logging:
166166
dependency: "direct main"
167167
description:
@@ -371,7 +371,7 @@ packages:
371371
name: test
372372
url: "https://pub.dartlang.org"
373373
source: hosted
374-
version: "0.12.30+2"
374+
version: "0.12.30+3"
375375
tuple:
376376
dependency: "direct main"
377377
description:

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ homepage: https://github.com/dart-lang/dartdoc
99
environment:
1010
sdk: '>=1.23.0-dev.11.5 <2.0.0'
1111
dependencies:
12-
analyzer: 0.31.1
12+
analyzer: '0.31.2-alpha.0'
1313
args: '>=0.13.0 <2.0.0'
1414
collection: ^1.2.0
15-
front_end: ^0.1.0-alpha.9
15+
front_end: ^0.1.0-alpha.10
1616
html: '>=0.12.1 <0.14.0'
1717
# We don't use http_parser directly; this dep exists to ensure that we get at
1818
# least version 3.0.3 to work around an issue with 3.0.2.

test/model_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,23 @@ void main() {
690690
'<p>link to method from class <a href="ex/Apple/m.html">Apple.m</a></p>'));
691691
});
692692

693+
test(
694+
'code references to privately defined elements in public classes work properly',
695+
() {
696+
Method notAMethodFromPrivateClass = fakeLibrary.allClasses
697+
.firstWhere((Class c) => c.name == 'ReferringClass')
698+
.allPublicInstanceMethods
699+
.firstWhere((Method m) => m.name == 'notAMethodFromPrivateClass');
700+
expect(
701+
notAMethodFromPrivateClass.documentationAsHtml,
702+
contains(
703+
'<a href="fake/InheritingClassOne/aMethod.html">fake.InheritingClassOne.aMethod</a>'));
704+
expect(
705+
notAMethodFromPrivateClass.documentationAsHtml,
706+
contains(
707+
'<a href="fake/InheritingClassTwo/aMethod.html">fake.InheritingClassTwo.aMethod</a>'));
708+
});
709+
693710
test('legacy code blocks render correctly', () {
694711
expect(
695712
testingCodeSyntaxInOneLiners.oneLineDoc,

testing/test_package/lib/fake.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,21 @@ class OperatorReferenceClass {
687687
return false;
688688
}
689689
}
690+
691+
class _PrivateClassDefiningSomething {
692+
bool aMethod() {
693+
return false;
694+
}
695+
}
696+
697+
class InheritingClassOne extends _PrivateClassDefiningSomething {}
698+
class InheritingClassTwo extends _PrivateClassDefiningSomething {}
699+
700+
class ReferringClass {
701+
/// Here I am referring by full names, to [fake.InheritingClassOne.aMethod],
702+
/// and to [fake.InheritingClassTwo.aMethod]. With luck, both of these
703+
/// two resolve correctly.
704+
bool notAMethodFromPrivateClass() {
705+
return false;
706+
}
707+
}

testing/test_package_docs/fake/AClassUsingASuperMixin-class.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ <h5>fake library</h5>
5858
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
5959
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
6060
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
61+
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
62+
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
6163
<li><a href="fake/Interface-class.html">Interface</a></li>
6264
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
6365
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
6466
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
6567
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
6668
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
69+
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
6770
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
6871
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
6972
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>

testing/test_package_docs/fake/AMixinCallingSuper-class.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ <h5>fake library</h5>
5858
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
5959
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
6060
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
61+
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
62+
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
6163
<li><a href="fake/Interface-class.html">Interface</a></li>
6264
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
6365
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
6466
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
6567
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
6668
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
69+
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
6770
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
6871
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
6972
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>

testing/test_package_docs/fake/Annotation-class.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ <h5>fake library</h5>
5858
<li><a href="fake/ImplementingThingy-class.html">ImplementingThingy</a></li>
5959
<li><a href="fake/ImplementingThingy2-class.html">ImplementingThingy2</a></li>
6060
<li><a href="fake/ImplicitProperties-class.html">ImplicitProperties</a></li>
61+
<li><a href="fake/InheritingClassOne-class.html">InheritingClassOne</a></li>
62+
<li><a href="fake/InheritingClassTwo-class.html">InheritingClassTwo</a></li>
6163
<li><a href="fake/Interface-class.html">Interface</a></li>
6264
<li><a href="fake/LongFirstLine-class.html">LongFirstLine</a></li>
6365
<li><a href="fake/MixMeIn-class.html">MixMeIn</a></li>
6466
<li><a href="fake/NotAMixin-class.html">NotAMixin</a></li>
6567
<li><a href="fake/OperatorReferenceClass-class.html">OperatorReferenceClass</a></li>
6668
<li><a href="fake/OtherGenericsThing-class.html">OtherGenericsThing</a></li>
69+
<li><a href="fake/ReferringClass-class.html">ReferringClass</a></li>
6770
<li><a href="fake/SpecialList-class.html">SpecialList</a></li>
6871
<li><a href="fake/SubForDocComments-class.html">SubForDocComments</a></li>
6972
<li><a class="deprecated" href="fake/SuperAwesomeClass-class.html">SuperAwesomeClass</a></li>

0 commit comments

Comments
 (0)