Skip to content
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
97 changes: 95 additions & 2 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4605,6 +4605,58 @@ class _Renderer_Container extends RendererBase<Container> {
);
},
),
'element': Property(
getValue: (CT_ c) => c.element,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'Element'),

isNullValue: (CT_ c) => false,

renderValue: (
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
renderSimple(
c.element,
ast,
r.template,
sink,
parent: r,
getters: _invisibleGetters['Element']!,
);
},
),
'element2': Property(
getValue: (CT_ c) => c.element2,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'Element2',
),

isNullValue: (CT_ c) => false,

renderValue: (
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
renderSimple(
c.element2,
ast,
r.template,
sink,
parent: r,
getters: _invisibleGetters['Element2']!,
);
},
),
'enclosingElement': Property(
getValue: (CT_ c) => c.enclosingElement,
renderVariable: (
Expand Down Expand Up @@ -11886,6 +11938,34 @@ class _Renderer_InheritingContainer extends RendererBase<InheritingContainer> {
);
},
),
'element2': Property(
getValue: (CT_ c) => c.element2,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'InterfaceElement2',
),

isNullValue: (CT_ c) => false,

renderValue: (
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
renderSimple(
c.element2,
ast,
r.template,
sink,
parent: r,
getters: _invisibleGetters['InterfaceElement2']!,
);
},
),
'enclosingElement': Property(
getValue: (CT_ c) => c.enclosingElement,
renderVariable: (
Expand Down Expand Up @@ -14312,7 +14392,7 @@ class _Renderer_LibraryContainer extends RendererBase<LibraryContainer> {
}
}

String renderLibrary(LibraryTemplateData context, Template template) {
String renderLibraryRedirect(LibraryTemplateData context, Template template) {
var buffer = StringBuffer();
_render_LibraryTemplateData(context, template.ast, template, buffer);
return buffer.toString();
Expand Down Expand Up @@ -14558,7 +14638,7 @@ class _Renderer_LibraryTemplateData extends RendererBase<LibraryTemplateData> {
}
}

String renderLibraryRedirect(LibraryTemplateData context, Template template) {
String renderLibrary(LibraryTemplateData context, Template template) {
var buffer = StringBuffer();
_render_LibraryTemplateData(context, template.ast, template, buffer);
return buffer.toString();
Expand Down Expand Up @@ -26508,6 +26588,19 @@ const _invisibleGetters = {
'thisType',
'unnamedConstructor',
},
'InterfaceElement2': {
'allSupertypes',
'constructors2',
'firstFragment',
'fragments',
'hashCode',
'interfaces',
'mixins',
'runtimeType',
'supertype',
'thisType',
'unnamedConstructor2',
},
'Iterable': {
'first',
'hashCode',
Expand Down
36 changes: 17 additions & 19 deletions lib/src/model/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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.

// ignore_for_file: analyzer_use_new_elements

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
// ignore: implementation_imports
Expand All @@ -20,10 +18,11 @@ import 'package:dartdoc/src/model/model.dart';
/// **inherited**: Filtered getters giving only inherited children.
class Class extends InheritingContainer with Constructable, MixedInTypes {
@override
final ClassElement element;
// ignore: analyzer_use_new_elements
ClassElement get element => element2.asElement;

@override
ClassElement2 get element2 => element.asElement2;
final ClassElement2 element2;

@override
late final List<ModelElement> allModelElements = [
Expand Down Expand Up @@ -51,10 +50,10 @@ class Class extends InheritingContainer with Constructable, MixedInTypes {
...interfaceElements.expandInheritanceChain,
];

Class(this.element, Library library, PackageGraph packageGraph)
Class(this.element2, Library library, PackageGraph packageGraph)
: super(library, packageGraph) {
if (element.name == 'Object' &&
library.element.name == 'dart.core' &&
if (element2.name3 == 'Object' &&
library.element2.name3 == 'dart.core' &&
package.name == 'Dart') {
packageGraph.objectClass = this;
}
Expand All @@ -64,32 +63,31 @@ class Class extends InheritingContainer with Constructable, MixedInTypes {
String get fileName => '$name-class.html';

@override
bool get isAbstract => element.isAbstract;
bool get isAbstract => element2.isAbstract;

@override
bool get isBase => element.isBase && !element.isSealed;
bool get isBase => element2.isBase && !element2.isSealed;

bool get isErrorOrException {
bool isError(InterfaceElement element) =>
element.library.isDartCore &&
(element.name == 'Exception' || element.name == 'Error');
bool isError(InterfaceElement2 e) =>
e.library2.isDartCore && (e.name3 == 'Exception' || e.name3 == 'Error');

final element = this.element;
if (isError(element)) return true;
return element.allSupertypes.map((t) => t.element).any(isError);
if (isError(element2)) return true;
return element2.allSupertypes.map((t) => t.element3).any(isError);
}

@override
bool get isFinal => element.isFinal && !element.isSealed;
bool get isFinal => element2.isFinal && !element2.isSealed;

@override
bool get isImplementableInterface => element.isInterface && !element.isSealed;
bool get isImplementableInterface =>
element2.isInterface && !element2.isSealed;

@override
bool get isMixinClass => element.isMixinClass;
bool get isMixinClass => element2.isMixinClass;

@override
bool get isSealed => element.isSealed;
bool get isSealed => element2.isSealed;

@override
Kind get kind => Kind.class_;
Expand Down
31 changes: 16 additions & 15 deletions lib/src/model/container.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) 2019, 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.
// ignore_for_file: analyzer_use_new_elements

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/scope.dart';
// ignore: implementation_imports
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/model_utils.dart' as model_utils;
Expand Down Expand Up @@ -33,27 +34,34 @@ abstract class Container extends ModelElement
with Categorization, TypeParameters {
Container(super.library, super.packageGraph);

@override
// ignore: analyzer_use_new_elements
Element get element => element2.asElement!;

@override
Element2 get element2;

// TODO(jcollins-g): Implement a ContainerScope that flattens supertypes?
@override
Scope? get scope => null;

@override
bool get hasParameters => false;

bool get isExtension => element is ExtensionElement;
bool get isExtension => element2 is ExtensionElement2;

/// Whether this is an enum.
bool get isEnum => element is EnumElement;
bool get isEnum => element2 is EnumElement2;

/// Whether this is an interface (e.g. class, enum, mixin, or extension type).
bool get isInterface => element is InterfaceElement;
bool get isInterface => element2 is InterfaceElement2;

/// Whether this is a mixin.
bool get isMixin => element is MixinElement;
bool get isMixin => element2 is MixinElement2;

/// Whether this container represents the Object class from 'dart:core'.
bool get isDartCoreObject =>
element.name == 'Object' && element.library?.name == 'dart.core';
element2.name3 == 'Object' && element2.library2?.name3 == 'dart.core';

/// The model elements of all of the members of this container, including
/// declared and inherited ones.
Expand Down Expand Up @@ -157,16 +165,9 @@ abstract class Container extends ModelElement

/// This container might be canonical for elements it does not contain.
/// See [Inheritable.canonicalEnclosingContainer].
bool containsElement(Element? element) => _allElements.contains(element);

/// This container might be canonical for elements it does not contain.
/// See [Inheritable.canonicalEnclosingContainer].
bool containsElement2(Element2? element) => _allElements2.contains(element);

late final Set<Element> _allElements =
allModelElements.map((e) => e.element).toSet();
bool containsElement(Element2? element) => _allElements.contains(element);

late final Set<Element2> _allElements2 =
late final Set<Element2> _allElements =
allModelElements.map((e) => e.element2).toSet();

bool get hasPublicStaticFields => staticFields.any((e) => e.isPublic);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/inheritable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mixin Inheritable on ContainerMember {
var reverseInheritance = _inheritance.reversed.toList();
for (var i = 0; i < reverseInheritance.length; i++) {
var container = reverseInheritance[i];
if (container.containsElement2(searchElement)) {
if (container.containsElement(searchElement)) {
var previousIsHiddenAndNotDefining = i > 0 &&
_isHiddenInterface(reverseInheritance[i - 1]) &&
container != definingEnclosingContainer;
Expand Down Expand Up @@ -95,7 +95,7 @@ mixin Inheritable on ContainerMember {
// starting from the ModelElement.
if (canonicalContainer != null) {
assert(canonicalContainer.isCanonical);
assert(canonicalContainer.containsElement2(searchElement));
assert(canonicalContainer.containsElement(searchElement));
found = canonicalContainer;
break;
}
Expand Down
Loading