Skip to content

Support the Never type in dartdoc #2167

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 2 commits into from
Mar 25, 2020
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
4 changes: 3 additions & 1 deletion lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ abstract class ElementType extends Privacy {
factory ElementType.from(
DartType f, Library library, PackageGraph packageGraph,
[ElementType returnedFrom]) {
if (f.element == null || f.element.kind == ElementKind.DYNAMIC) {
if (f.element == null ||
f.element.kind == ElementKind.DYNAMIC ||
f.element.kind == ElementKind.NEVER) {
if (f is FunctionType) {
return FunctionTypeElementType(f, library, packageGraph, returnedFrom);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export 'model_element.dart';
export 'model_function.dart';
export 'model_node.dart';
export 'nameable.dart';
export 'never.dart';
export 'operator.dart';
export 'package.dart';
export 'package_builder.dart';
Expand Down
8 changes: 7 additions & 1 deletion lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ abstract class ModelElement extends Canonicalization
e is ParameterElement ||
e is TypeParameterElement ||
e is GenericFunctionTypeElementImpl ||
e.kind == ElementKind.DYNAMIC);
e.kind == ElementKind.DYNAMIC ||
e.kind == ElementKind.NEVER);

Member originalMember;
// TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers'
Expand All @@ -215,13 +216,17 @@ abstract class ModelElement extends Canonicalization
Tuple3(e, library, enclosingContainer);
ModelElement newModelElement;
if (e.kind != ElementKind.DYNAMIC &&
e.kind != ElementKind.NEVER &&
packageGraph.allConstructedModelElements.containsKey(key)) {
newModelElement = packageGraph.allConstructedModelElements[key];
assert(newModelElement.element is! MultiplyInheritedExecutableElement);
} else {
if (e.kind == ElementKind.DYNAMIC) {
newModelElement = Dynamic(e, packageGraph);
}
if (e.kind == ElementKind.NEVER) {
newModelElement = NeverType(e, packageGraph);
}
if (e is MultiplyInheritedExecutableElement) {
newModelElement = resolveMultiplyInheritedElement(
e, library, packageGraph, enclosingContainer);
Expand Down Expand Up @@ -1120,6 +1125,7 @@ abstract class ModelElement extends Canonicalization
// element associated with a ModelElement or there's an analysis bug.
assert(name.isNotEmpty ||
this.element?.kind == ElementKind.DYNAMIC ||
this.element?.kind == ElementKind.NEVER ||
this is ModelFunction);

if (href == null) {
Expand Down
33 changes: 33 additions & 0 deletions lib/src/model/never.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2020, 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.

import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/model/model.dart';

class NeverType extends ModelElement {
NeverType(Element element, PackageGraph packageGraph)
: super(element, null, packageGraph, null);

/// [never] is not a real object, and so we can't document it, so there
/// can be nothing canonical for it.
@override
ModelElement get canonicalModelElement => null;

@override
ModelElement get enclosingElement => throw UnsupportedError('');

/// And similiarly, even if someone references it directly it can have
/// no hyperlink.
@override
String get href => null;

@override
String get kind => 'Never';

@override
String get linkedName => 'Never';

@override
String get filePath => null;
}