Skip to content

Commit 5e86e84

Browse files
authored
Merge pull request #2815 from jcollins-g/nnbd-mainmerge-0928
Merge from head into the nnbd branch once more
2 parents 229174c + 0cd18cf commit 5e86e84

32 files changed

+215
-105
lines changed

.github/workflows/test.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,33 @@ jobs:
3838
job: sdk-analyzer
3939

4040
steps:
41+
- name: Store date
42+
id: date
43+
run: echo "::set-output name=today::$(date +'%Y-%m-%d')"
44+
shell: bash
45+
- name: Cache clean flutter
46+
uses: actions/cache@v2
47+
if: matrix.job == 'flutter'
48+
env:
49+
# Increment version to invalidate bad/obsolete caches.
50+
cache-name: cache-grinder-flutter-v1
51+
with:
52+
path: ~/.dartdoc_grinder
53+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ steps.date.outputs.today }}
54+
- name: Cache .pub-cache
55+
uses: actions/cache@v2
56+
if: matrix.job == 'flutter'
57+
env:
58+
# Increment version to invalidate bad/obsolete caches.
59+
cache-name: cache-dart-pub-v1
60+
with:
61+
path: ~/.pub-cache
62+
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ steps.date.outputs.today }}
4163
- name: Configure git
4264
if: runner.os == 'Windows'
4365
run: git config --global core.autocrlf input
4466
- uses: actions/checkout@v2
45-
- uses: dart-lang/setup-dart@v1.0
67+
- uses: dart-lang/setup-dart@v1.2
4668
with:
4769
sdk: ${{ matrix.sdk }}
4870
- name: Install dependencies

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ analyzer:
77
todo: ignore
88
unused_import: warning
99
unused_shown_name: warning
10+
language:
11+
strict-raw-types: true
1012
exclude:
1113
- 'doc/**'
1214
- 'lib/src/third_party/pkg/**'

analysis_options_presubmit.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ analyzer:
1212
deprecated_member_use_from_same_package: ignore
1313
### Temporary presubmit ignore for NNBD migration
1414
import_of_legacy_library_into_null_safe: ignore
15+
language:
16+
strict-raw-types: true
1517
exclude:
1618
- 'doc/**'
1719
- 'lib/src/third_party/pkg/**'

lib/dartdoc.dart

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'dart:io' show Platform, exitCode, stderr;
1717
import 'package:analyzer/file_system/file_system.dart';
1818
import 'package:dartdoc/options.dart';
1919
import 'package:dartdoc/src/dartdoc_options.dart';
20+
import 'package:dartdoc/src/failure.dart';
2021
import 'package:dartdoc/src/generator/empty_generator.dart';
2122
import 'package:dartdoc/src/generator/generator.dart';
2223
import 'package:dartdoc/src/generator/html_generator.dart';
@@ -529,17 +530,6 @@ class Dartdoc {
529530
}
530531
}
531532

532-
/// This class is returned if dartdoc fails in an expected way (for instance, if
533-
/// there is an analysis error in the library).
534-
class DartdocFailure {
535-
final String message;
536-
537-
DartdocFailure(this.message);
538-
539-
@override
540-
String toString() => message;
541-
}
542-
543533
/// The results of a [Dartdoc.generateDocs] call.
544534
class DartdocResults {
545535
final PackageMeta packageMeta;

lib/src/comment_references/parser.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,22 @@ class StringTrie {
3939
/// Does [this] node represent a valid entry in the trie?
4040
bool valid = false;
4141

42-
/// Greedily match on the string trie. Returns the index of the first
43-
/// non-operator character if valid, otherwise -1.
44-
int match(String toMatch, [int index = 0]) {
45-
if (index < 0 || index >= toMatch.length) return valid ? index : 1;
42+
/// Greedily match on the string trie starting at the given index. Returns
43+
/// the index of the first non-operator character if a match is valid,
44+
/// otherwise -1.
45+
int match(String toMatch, [int index = 0, int lastValid = -1]) {
46+
if (index < 0 || index > toMatch.length) {
47+
return lastValid;
48+
}
49+
if (index == toMatch.length) {
50+
return valid ? index : lastValid;
51+
}
4652
var matchChar = toMatch.codeUnitAt(index);
4753
if (children.containsKey(matchChar)) {
48-
return children[matchChar].match(toMatch, index + 1);
54+
lastValid = valid ? index : lastValid;
55+
return children[matchChar].match(toMatch, index + 1, lastValid);
4956
}
50-
return valid ? index : -1;
57+
return valid ? index : lastValid;
5158
}
5259

5360
void addWord(String toAdd) {

lib/src/dartdoc_options.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import 'dart:io' show Platform, stdout;
2020
import 'package:analyzer/dart/element/element.dart';
2121
import 'package:analyzer/file_system/file_system.dart';
2222
import 'package:args/args.dart';
23-
import 'package:dartdoc/dartdoc.dart';
2423
import 'package:dartdoc/src/experiment_options.dart';
24+
import 'package:dartdoc/src/failure.dart';
2525
import 'package:dartdoc/src/io_utils.dart';
26+
import 'package:dartdoc/src/package_meta.dart';
2627
import 'package:dartdoc/src/source_linker.dart';
2728
import 'package:dartdoc/src/tool_definition.dart';
2829
import 'package:dartdoc/src/tool_runner.dart';
@@ -335,7 +336,7 @@ class _OptionValueWithContext<T> {
335336
///
336337
/// Use via implementations [DartdocOptionSet], [DartdocOptionArgFile],
337338
/// [DartdocOptionArgOnly], and [DartdocOptionFileOnly].
338-
abstract class DartdocOption<T> {
339+
abstract class DartdocOption<T extends Object?> {
339340
/// This is the value returned if we couldn't find one otherwise.
340341
final T? defaultsTo;
341342

@@ -457,7 +458,7 @@ abstract class DartdocOption<T> {
457458

458459
/// The [DartdocOptionRoot] containing this object.
459460
DartdocOptionRoot get root {
460-
DartdocOption p = this;
461+
DartdocOption<dynamic> p = this;
461462
while (p is! DartdocOptionRoot) {
462463
p = p.parent;
463464
}
@@ -467,7 +468,7 @@ abstract class DartdocOption<T> {
467468
/// All object names starting at the root.
468469
Iterable<String> get keys {
469470
var keyList = <String>[];
470-
DartdocOption option = this;
471+
DartdocOption<dynamic> option = this;
471472
while (option is! DartdocOptionRoot) {
472473
keyList.add(option.name);
473474
option = option.parent;
@@ -490,10 +491,12 @@ abstract class DartdocOption<T> {
490491
/// type. If [mustExist] is true, will throw [DartdocFileMissing] for command
491492
/// line parameters and file paths in config files that don't point to
492493
/// corresponding files or directories.
493-
T? valueAt(Folder dir);
494+
// TODO(jcollins-g): use of dynamic. https://github.com/dart-lang/dartdoc/issues/2814
495+
dynamic valueAt(Folder dir);
494496

495497
/// Calls [valueAt] with the working directory at the start of the program.
496-
T? valueAtCurrent() => valueAt(_directoryCurrent);
498+
// TODO(jcollins-g): use of dynamic. https://github.com/dart-lang/dartdoc/issues/2814
499+
dynamic valueAtCurrent() => valueAt(_directoryCurrent);
497500

498501
late final Folder _directoryCurrent =
499502
resourceProvider.getFolder(_directoryCurrentPath);
@@ -523,8 +526,9 @@ abstract class DartdocOption<T> {
523526
return _children[name]!;
524527
}
525528

526-
/// Get the immediate child of this node named [name] as a [DartdocOption<U>].
527-
DartdocOption<U> getAs<U>(String name) => _children[name] as DartdocOption<U>;
529+
/// Get the immediate child of this node named [name] and its value at [dir].
530+
U getValueAs<U extends Object?>(String name, Folder dir) =>
531+
_children[name]?.valueAt(dir) as U;
528532

529533
/// Apply the function [visit] to [this] and all children.
530534
void traverse(void Function(DartdocOption option) visit) {

lib/src/failure.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// A class representing a failure during dartdoc execution.
6+
///
7+
/// An instance of this is returned if dartdoc fails in an expected way (for
8+
/// instance, if there is an analysis error in the library).
9+
class DartdocFailure {
10+
final String message;
11+
12+
DartdocFailure(this.message);
13+
14+
@override
15+
String toString() => message;
16+
}

lib/src/generator/dartdoc_generator_backend.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
// @dart=2.9
66

77
import 'package:analyzer/file_system/file_system.dart';
8-
import 'package:dartdoc/dartdoc.dart';
98
import 'package:dartdoc/options.dart';
9+
import 'package:dartdoc/src/generator/generator.dart';
1010
import 'package:dartdoc/src/generator/generator_frontend.dart';
1111
import 'package:dartdoc/src/generator/generator_utils.dart' as generator_util;
1212
import 'package:dartdoc/src/generator/template_data.dart';
1313
import 'package:dartdoc/src/generator/templates.dart';
14+
import 'package:dartdoc/src/model/model.dart';
15+
import 'package:dartdoc/src/version.dart';
1416
import 'package:dartdoc/src/warnings.dart';
1517
import 'package:path/path.dart' as path show Context;
1618

@@ -41,7 +43,7 @@ class DartdocGeneratorBackendOptions implements TemplateOptions {
4143
DartdocGeneratorBackendOptions.fromContext(
4244
DartdocGeneratorOptionContext context)
4345
: relCanonicalPrefix = context.relCanonicalPrefix,
44-
toolVersion = dartdocVersion,
46+
toolVersion = packageVersion,
4547
favicon = context.favicon,
4648
prettyIndexJson = context.prettyIndexJson,
4749
useBaseHref = context.useBaseHref,

lib/src/generator/templates.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
library dartdoc.templates;
3030

3131
import 'package:analyzer/file_system/file_system.dart';
32-
import 'package:dartdoc/dartdoc.dart';
3332
import 'package:dartdoc/options.dart';
33+
import 'package:dartdoc/src/element_type.dart';
34+
import 'package:dartdoc/src/failure.dart';
3435
import 'package:dartdoc/src/generator/resource_loader.dart';
3536
import 'package:dartdoc/src/generator/template_data.dart';
3637
import 'package:dartdoc/src/generator/templates.aot_renderers_for_html.dart'
@@ -42,6 +43,7 @@ import 'package:dartdoc/src/generator/templates.runtime_renderers.dart'
4243
import 'package:dartdoc/src/model/annotation.dart';
4344
import 'package:dartdoc/src/model/feature_set.dart';
4445
import 'package:dartdoc/src/model/language_feature.dart';
46+
import 'package:dartdoc/src/model/model.dart';
4547
import 'package:dartdoc/src/mustachio/annotations.dart';
4648
import 'package:dartdoc/src/mustachio/renderer_base.dart';
4749
import 'package:meta/meta.dart';

lib/src/generator/templates.runtime_renderers.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
// ignore_for_file: camel_case_types, deprecated_member_use_from_same_package
77
// ignore_for_file: unused_import
88
// @dart=2.9
9-
import 'package:dartdoc/dartdoc.dart';
9+
import 'package:dartdoc/src/element_type.dart';
1010
import 'package:dartdoc/src/generator/template_data.dart';
1111
import 'package:dartdoc/src/model/annotation.dart';
1212
import 'package:dartdoc/src/model/comment_referable.dart';
1313
import 'package:dartdoc/src/model/extension_target.dart';
1414
import 'package:dartdoc/src/model/feature.dart';
1515
import 'package:dartdoc/src/model/feature_set.dart';
1616
import 'package:dartdoc/src/model/language_feature.dart';
17+
import 'package:dartdoc/src/model/model.dart';
1718
import 'package:dartdoc/src/mustachio/parser.dart';
1819
import 'package:dartdoc/src/mustachio/renderer_base.dart';
1920
import 'package:dartdoc/src/warnings.dart';
@@ -4229,6 +4230,7 @@ class _Renderer_Enum extends RendererBase<Enum> {
42294230
CT_,
42304231
() => {
42314232
..._Renderer_InheritingContainer.propertyMap<CT_>(),
4233+
..._Renderer_TypeImplementing.propertyMap<CT_>(),
42324234
'inheritanceChain': Property(
42334235
getValue: (CT_ c) => c.inheritanceChain,
42344236
renderVariable: (CT_ c, Property<CT_> self,

lib/src/io_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class _TaskQueueItem<T> {
145145
/// the number of simultaneous tasks.
146146
///
147147
/// The tasks return results of type T.
148-
class TaskQueue<T> {
148+
class TaskQueue<T extends Object> {
149149
/// Creates a task queue with a maximum number of simultaneous jobs.
150150
/// The [maxJobs] parameter defaults to the number of CPU cores on the
151151
/// system.

lib/src/model/comment_referable.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import 'dart:core';
1313

1414
import 'package:analyzer/dart/element/element.dart';
1515
import 'package:analyzer/dart/element/scope.dart';
16-
import 'package:dartdoc/dartdoc.dart';
16+
import 'package:dartdoc/src/model/accessor.dart';
17+
import 'package:dartdoc/src/model/container.dart';
18+
import 'package:dartdoc/src/model/library.dart';
19+
import 'package:dartdoc/src/model/model_element.dart';
20+
import 'package:dartdoc/src/model/nameable.dart';
21+
import 'package:dartdoc/src/model/package_graph.dart';
1722
import 'package:meta/meta.dart';
1823

1924
class ReferenceChildrenLookup {

lib/src/model/enum.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import 'package:analyzer/dart/element/element.dart';
99
import 'package:dartdoc/src/model/model.dart';
1010
import 'package:dartdoc/src/render/enum_field_renderer.dart';
11+
import 'package:dartdoc/src/special_elements.dart';
1112

12-
class Enum extends InheritingContainer {
13+
class Enum extends InheritingContainer with TypeImplementing {
1314
Enum(ClassElement element, Library library, PackageGraph packageGraph)
1415
: super(element, library, packageGraph);
1516

1617
List<InheritingContainer> _inheritanceChain;
17-
1818
@override
1919
List<InheritingContainer> get inheritanceChain {
2020
if (_inheritanceChain == null) {
@@ -25,6 +25,12 @@ class Enum extends InheritingContainer {
2525
in superChain.map((e) => (e.modelElement as InheritingContainer))) {
2626
_inheritanceChain.addAll(c.inheritanceChain);
2727
}
28+
29+
_inheritanceChain.addAll(interfaces.expand(
30+
(e) => (e.modelElement as InheritingContainer).inheritanceChain));
31+
32+
assert(_inheritanceChain
33+
.contains(packageGraph.specialClasses[SpecialClass.enumClass]));
2834
}
2935
return _inheritanceChain.toList(growable: false);
3036
}

lib/src/model/package_graph.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import 'package:analyzer/file_system/file_system.dart';
1212
import 'package:analyzer/src/generated/sdk.dart';
1313
import 'package:analyzer/src/generated/source.dart';
1414
import 'package:analyzer/src/generated/source_io.dart';
15-
import 'package:dartdoc/dartdoc.dart' show DartdocFailure;
1615
import 'package:dartdoc/src/dartdoc_options.dart';
16+
import 'package:dartdoc/src/failure.dart';
1717
import 'package:dartdoc/src/logging.dart';
1818
import 'package:dartdoc/src/model/comment_referable.dart';
1919
import 'package:dartdoc/src/model/model.dart';

lib/src/model_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:analyzer/dart/ast/ast.dart';
1313
import 'package:analyzer/dart/element/element.dart';
1414
import 'package:analyzer/file_system/file_system.dart';
1515
import 'package:analyzer/src/dart/ast/utilities.dart';
16-
import 'package:dartdoc/dartdoc.dart' show DartdocFailure;
16+
import 'package:dartdoc/src/failure.dart';
1717
import 'package:dartdoc/src/model/model.dart';
1818
import 'package:glob/glob.dart';
1919
import 'package:path/path.dart' as path;

lib/src/mustachio/annotations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Renderer {
2020
final Symbol name;
2121

2222
/// The type of the context type, specified as the [Context] type argument.
23-
final Context context;
23+
final Context<Object> context;
2424

2525
/// The unparsed, string form of the URI of the _standard_ HTML template.
2626
///

lib/src/mustachio/renderer_base.dart

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ class Template {
132132
}
133133

134134
/// The base class for a generated Mustache renderer.
135-
abstract class RendererBase<T> {
135+
abstract class RendererBase<T extends Object?> {
136136
/// The context object which this renderer can render.
137137
final T context;
138138

139139
/// The renderer of the parent context, if any, otherwise `null`.
140-
final RendererBase? parent;
140+
final RendererBase<Object?>? parent;
141141

142142
/// The current template being rendered.
143143
///
@@ -289,13 +289,8 @@ abstract class RendererBase<T> {
289289
}
290290

291291
String renderSimple(
292-
Object context,
293-
List<MustachioNode> ast,
294-
Template template,
295-
StringSink sink, {
296-
required RendererBase<Object> parent,
297-
required Set<String> getters,
298-
}) {
292+
Object context, List<MustachioNode> ast, Template template, StringSink sink,
293+
{required RendererBase<Object> parent, required Set<String> getters}) {
299294
var renderer = SimpleRenderer(context, parent, template, sink, getters);
300295
renderer.renderBlock(ast);
301296
return renderer.sink.toString();

lib/src/package_meta.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import 'package:analyzer/dart/element/element.dart';
1111
import 'package:analyzer/file_system/file_system.dart';
1212
import 'package:analyzer/file_system/physical_file_system.dart';
1313
import 'package:analyzer/src/generated/sdk.dart';
14-
import 'package:dartdoc/dartdoc.dart';
14+
import 'package:dartdoc/src/dartdoc_options.dart';
15+
import 'package:dartdoc/src/failure.dart';
1516
import 'package:meta/meta.dart';
1617
import 'package:path/path.dart' as p;
1718
import 'package:yaml/yaml.dart';

lib/src/render/element_type_renderer.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// @dart=2.9
6-
7-
import 'package:dartdoc/dartdoc.dart';
5+
import 'package:dartdoc/src/element_type.dart';
86
import 'package:dartdoc/src/render/parameter_renderer.dart';
97

108
abstract class ElementTypeRenderer<T extends ElementType> {

0 commit comments

Comments
 (0)