Skip to content

Merge from head into the nnbd branch once more #2815

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 11 commits into from
Sep 28, 2021
24 changes: 23 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,33 @@ jobs:
job: sdk-analyzer

steps:
- name: Store date
id: date
run: echo "::set-output name=today::$(date +'%Y-%m-%d')"
shell: bash
- name: Cache clean flutter
uses: actions/cache@v2
if: matrix.job == 'flutter'
env:
# Increment version to invalidate bad/obsolete caches.
cache-name: cache-grinder-flutter-v1
with:
path: ~/.dartdoc_grinder
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ steps.date.outputs.today }}
- name: Cache .pub-cache
uses: actions/cache@v2
if: matrix.job == 'flutter'
env:
# Increment version to invalidate bad/obsolete caches.
cache-name: cache-dart-pub-v1
with:
path: ~/.pub-cache
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ steps.date.outputs.today }}
- name: Configure git
if: runner.os == 'Windows'
run: git config --global core.autocrlf input
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
- uses: dart-lang/setup-dart@v1.2
with:
sdk: ${{ matrix.sdk }}
- name: Install dependencies
Expand Down
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ analyzer:
todo: ignore
unused_import: warning
unused_shown_name: warning
language:
strict-raw-types: true
exclude:
- 'doc/**'
- 'lib/src/third_party/pkg/**'
Expand Down
2 changes: 2 additions & 0 deletions analysis_options_presubmit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ analyzer:
deprecated_member_use_from_same_package: ignore
### Temporary presubmit ignore for NNBD migration
import_of_legacy_library_into_null_safe: ignore
language:
strict-raw-types: true
exclude:
- 'doc/**'
- 'lib/src/third_party/pkg/**'
Expand Down
12 changes: 1 addition & 11 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'dart:io' show Platform, exitCode, stderr;
import 'package:analyzer/file_system/file_system.dart';
import 'package:dartdoc/options.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/generator/empty_generator.dart';
import 'package:dartdoc/src/generator/generator.dart';
import 'package:dartdoc/src/generator/html_generator.dart';
Expand Down Expand Up @@ -529,17 +530,6 @@ class Dartdoc {
}
}

/// This class is returned if dartdoc fails in an expected way (for instance, if
/// there is an analysis error in the library).
class DartdocFailure {
final String message;

DartdocFailure(this.message);

@override
String toString() => message;
}

/// The results of a [Dartdoc.generateDocs] call.
class DartdocResults {
final PackageMeta packageMeta;
Expand Down
19 changes: 13 additions & 6 deletions lib/src/comment_references/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,22 @@ class StringTrie {
/// Does [this] node represent a valid entry in the trie?
bool valid = false;

/// Greedily match on the string trie. Returns the index of the first
/// non-operator character if valid, otherwise -1.
int match(String toMatch, [int index = 0]) {
if (index < 0 || index >= toMatch.length) return valid ? index : 1;
/// Greedily match on the string trie starting at the given index. Returns
/// the index of the first non-operator character if a match is valid,
/// otherwise -1.
int match(String toMatch, [int index = 0, int lastValid = -1]) {
if (index < 0 || index > toMatch.length) {
return lastValid;
}
if (index == toMatch.length) {
return valid ? index : lastValid;
}
var matchChar = toMatch.codeUnitAt(index);
if (children.containsKey(matchChar)) {
return children[matchChar].match(toMatch, index + 1);
lastValid = valid ? index : lastValid;
return children[matchChar].match(toMatch, index + 1, lastValid);
}
return valid ? index : -1;
return valid ? index : lastValid;
}

void addWord(String toAdd) {
Expand Down
20 changes: 12 additions & 8 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import 'dart:io' show Platform, stdout;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:args/args.dart';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/experiment_options.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/io_utils.dart';
import 'package:dartdoc/src/package_meta.dart';
import 'package:dartdoc/src/source_linker.dart';
import 'package:dartdoc/src/tool_definition.dart';
import 'package:dartdoc/src/tool_runner.dart';
Expand Down Expand Up @@ -335,7 +336,7 @@ class _OptionValueWithContext<T> {
///
/// Use via implementations [DartdocOptionSet], [DartdocOptionArgFile],
/// [DartdocOptionArgOnly], and [DartdocOptionFileOnly].
abstract class DartdocOption<T> {
abstract class DartdocOption<T extends Object?> {
/// This is the value returned if we couldn't find one otherwise.
final T? defaultsTo;

Expand Down Expand Up @@ -457,7 +458,7 @@ abstract class DartdocOption<T> {

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

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

Choose a reason for hiding this comment

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

+1 thanks for filing a bug!

dynamic valueAtCurrent() => valueAt(_directoryCurrent);

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

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

/// Apply the function [visit] to [this] and all children.
void traverse(void Function(DartdocOption option) visit) {
Expand Down
16 changes: 16 additions & 0 deletions lib/src/failure.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/// A class representing a failure during dartdoc execution.
///
/// An instance of this is returned if dartdoc fails in an expected way (for
/// instance, if there is an analysis error in the library).
class DartdocFailure {
final String message;

DartdocFailure(this.message);

@override
String toString() => message;
}
6 changes: 4 additions & 2 deletions lib/src/generator/dartdoc_generator_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// @dart=2.9

import 'package:analyzer/file_system/file_system.dart';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/options.dart';
import 'package:dartdoc/src/generator/generator.dart';
import 'package:dartdoc/src/generator/generator_frontend.dart';
import 'package:dartdoc/src/generator/generator_utils.dart' as generator_util;
import 'package:dartdoc/src/generator/template_data.dart';
import 'package:dartdoc/src/generator/templates.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/version.dart';
import 'package:dartdoc/src/warnings.dart';
import 'package:path/path.dart' as path show Context;

Expand Down Expand Up @@ -41,7 +43,7 @@ class DartdocGeneratorBackendOptions implements TemplateOptions {
DartdocGeneratorBackendOptions.fromContext(
DartdocGeneratorOptionContext context)
: relCanonicalPrefix = context.relCanonicalPrefix,
toolVersion = dartdocVersion,
toolVersion = packageVersion,
favicon = context.favicon,
prettyIndexJson = context.prettyIndexJson,
useBaseHref = context.useBaseHref,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/generator/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
library dartdoc.templates;

import 'package:analyzer/file_system/file_system.dart';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/options.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/generator/resource_loader.dart';
import 'package:dartdoc/src/generator/template_data.dart';
import 'package:dartdoc/src/generator/templates.aot_renderers_for_html.dart'
Expand All @@ -42,6 +43,7 @@ import 'package:dartdoc/src/generator/templates.runtime_renderers.dart'
import 'package:dartdoc/src/model/annotation.dart';
import 'package:dartdoc/src/model/feature_set.dart';
import 'package:dartdoc/src/model/language_feature.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/mustachio/annotations.dart';
import 'package:dartdoc/src/mustachio/renderer_base.dart';
import 'package:meta/meta.dart';
Expand Down
4 changes: 3 additions & 1 deletion lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
// ignore_for_file: camel_case_types, deprecated_member_use_from_same_package
// ignore_for_file: unused_import
// @dart=2.9
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/generator/template_data.dart';
import 'package:dartdoc/src/model/annotation.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/extension_target.dart';
import 'package:dartdoc/src/model/feature.dart';
import 'package:dartdoc/src/model/feature_set.dart';
import 'package:dartdoc/src/model/language_feature.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/mustachio/parser.dart';
import 'package:dartdoc/src/mustachio/renderer_base.dart';
import 'package:dartdoc/src/warnings.dart';
Expand Down Expand Up @@ -4229,6 +4230,7 @@ class _Renderer_Enum extends RendererBase<Enum> {
CT_,
() => {
..._Renderer_InheritingContainer.propertyMap<CT_>(),
..._Renderer_TypeImplementing.propertyMap<CT_>(),
'inheritanceChain': Property(
getValue: (CT_ c) => c.inheritanceChain,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/io_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _TaskQueueItem<T> {
/// the number of simultaneous tasks.
///
/// The tasks return results of type T.
class TaskQueue<T> {
class TaskQueue<T extends Object> {
/// Creates a task queue with a maximum number of simultaneous jobs.
/// The [maxJobs] parameter defaults to the number of CPU cores on the
/// system.
Expand Down
7 changes: 6 additions & 1 deletion lib/src/model/comment_referable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import 'dart:core';

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/model/accessor.dart';
import 'package:dartdoc/src/model/container.dart';
import 'package:dartdoc/src/model/library.dart';
import 'package:dartdoc/src/model/model_element.dart';
import 'package:dartdoc/src/model/nameable.dart';
import 'package:dartdoc/src/model/package_graph.dart';
import 'package:meta/meta.dart';

class ReferenceChildrenLookup {
Expand Down
10 changes: 8 additions & 2 deletions lib/src/model/enum.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/enum_field_renderer.dart';
import 'package:dartdoc/src/special_elements.dart';

class Enum extends InheritingContainer {
class Enum extends InheritingContainer with TypeImplementing {
Enum(ClassElement element, Library library, PackageGraph packageGraph)
: super(element, library, packageGraph);

List<InheritingContainer> _inheritanceChain;

@override
List<InheritingContainer> get inheritanceChain {
if (_inheritanceChain == null) {
Expand All @@ -25,6 +25,12 @@ class Enum extends InheritingContainer {
in superChain.map((e) => (e.modelElement as InheritingContainer))) {
_inheritanceChain.addAll(c.inheritanceChain);
}

_inheritanceChain.addAll(interfaces.expand(
(e) => (e.modelElement as InheritingContainer).inheritanceChain));

assert(_inheritanceChain
.contains(packageGraph.specialClasses[SpecialClass.enumClass]));
}
return _inheritanceChain.toList(growable: false);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:dartdoc/dartdoc.dart' show DartdocFailure;
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/logging.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:dartdoc/dartdoc.dart' show DartdocFailure;
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:glob/glob.dart';
import 'package:path/path.dart' as path;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mustachio/annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Renderer {
final Symbol name;

/// The type of the context type, specified as the [Context] type argument.
final Context context;
final Context<Object> context;

/// The unparsed, string form of the URI of the _standard_ HTML template.
///
Expand Down
13 changes: 4 additions & 9 deletions lib/src/mustachio/renderer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class Template {
}

/// The base class for a generated Mustache renderer.
abstract class RendererBase<T> {
abstract class RendererBase<T extends Object?> {
/// The context object which this renderer can render.
final T context;

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

/// The current template being rendered.
///
Expand Down Expand Up @@ -289,13 +289,8 @@ abstract class RendererBase<T> {
}

String renderSimple(
Object context,
List<MustachioNode> ast,
Template template,
StringSink sink, {
required RendererBase<Object> parent,
required Set<String> getters,
}) {
Object context, List<MustachioNode> ast, Template template, StringSink sink,
{required RendererBase<Object> parent, required Set<String> getters}) {
var renderer = SimpleRenderer(context, parent, template, sink, getters);
renderer.renderBlock(ast);
return renderer.sink.toString();
Expand Down
3 changes: 2 additions & 1 deletion lib/src/package_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/physical_file_system.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';
Expand Down
4 changes: 1 addition & 3 deletions lib/src/render/element_type_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.9

import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/render/parameter_renderer.dart';

abstract class ElementTypeRenderer<T extends ElementType> {
Expand Down
Loading