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
84 changes: 84 additions & 0 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,34 @@ class _Renderer_Category extends RendererBase<Category> {
);
},
),
'element2': Property(
getValue: (CT_ c) => c.element2,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'Element2',
),

isNullValue: (CT_ c) => c.element2 == null,

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

isNullValue: (CT_ c) => c.element2 == null,

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

isNullValue: (CT_ c) => c.element2 == null,

renderValue: (
CT_ c,
RendererBase<CT_> r,
List<MustachioNode> ast,
StringSink sink,
) {
renderSimple(
c.element2,
ast,
r.template,
sink,
parent: r,
getters: _invisibleGetters['Element2']!,
);
},
),
},
)
as Map<String, Property<CT_>>;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/model/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ignore_for_file: analyzer_use_new_elements

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
Expand Down Expand Up @@ -82,6 +83,9 @@ class Category
@override
Element? get element => null;

@override
Element2? get element2 => null;

@override
String get name => _categoryDefinition.displayName;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/constructor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Constructor extends ModelElement with ContainerMember, TypeParameters {
@override
bool get isPublic {
if (!super.isPublic) return false;
if (element.hasPrivateName) return false;
if (element2.hasPrivateName) return false;
var class_ = element.enclosingElement3;
// Enums cannot be explicitly constructed or extended.
if (class_ is EnumElement) return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Library extends ModelElement
final LibraryElement element;

@override
LibraryElement2 get element2 => element.asElement2;
LibraryElement2 get element2 => element.asElement2;

/// The set of [Element]s declared directly in this library.
final Set<Element> _localElements;
Expand Down Expand Up @@ -315,8 +315,8 @@ class Library extends ModelElement
String get packageName => packageMeta?.name ?? '';

/// The real packageMeta, as opposed to the package we are documenting with.
late final PackageMeta? packageMeta =
packageGraph.packageMetaProvider.fromElement(element.asElement2, config.sdkDir);
late final PackageMeta? packageMeta = packageGraph.packageMetaProvider
.fromElement(element.asElement2, config.sdkDir);

late final List<Class> classesAndExceptions = [
..._localElementsOfType<ClassElement, Class>(),
Expand Down
8 changes: 5 additions & 3 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ abstract class ModelElement
TypeAliasElement(aliasedType: FunctionType()) =>
FunctionTypedef(e, library, packageGraph),
TypeAliasElement()
when e.aliasedType.documentableElement2.asElement is InterfaceElement =>
when e.aliasedType.documentableElement2.asElement
is InterfaceElement =>
ClassTypedef(e, library, packageGraph),
TypeAliasElement() => GeneralizedTypedef(e, library, packageGraph),
MethodElement(isOperator: true) when enclosingContainer == null =>
Expand Down Expand Up @@ -438,7 +439,7 @@ abstract class ModelElement
}
}

return !element.hasPrivateName && !hasNodoc;
return !element2.hasPrivateName && !hasNodoc;
}();

@override
Expand Down Expand Up @@ -508,7 +509,7 @@ abstract class ModelElement
/// A public, documented library which exports this [ModelElement], ideally in
/// [library]'s package.
late final Library? canonicalLibrary = () {
if (element.hasPrivateName) {
if (element2.hasPrivateName) {
// Privately named elements can never have a canonical library.
return null;
}
Expand Down Expand Up @@ -558,6 +559,7 @@ abstract class ModelElement
@override
Element get element;

@override
Element2 get element2 => element.asElement2!;

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/nameable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mixin Nameable {
enclosingContainer: enclosingContainer,
);

/// Returns the [ModelElement] for [element], instantiating it if needed.
/// Returns the [ModelElement] for [element], instantiating it if needed.
///
/// A convenience method for [ModelElement.for_], see its documentation.
ModelElement getModelFor2(
Expand All @@ -91,7 +91,7 @@ mixin Nameable {
ModelElement getModelForElement(Element element) =>
ModelElement.forElement(element, packageGraph);

/// Returns the [ModelElement] for [element], instantiating it if needed.
/// Returns the [ModelElement] for [element], instantiating it if needed.
///
/// A convenience method for [ModelElement.forElement], see its
/// documentation.
Expand Down
4 changes: 4 additions & 0 deletions lib/src/model/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// ignore_for_file: analyzer_use_new_elements

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/io_utils.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
Expand Down Expand Up @@ -378,6 +379,9 @@ class Package extends LibraryContainer
@override
Element? get element => null;

@override
Element2? get element2 => null;

@override
List<String> get containerOrder => config.packageOrder;

Expand Down
12 changes: 5 additions & 7 deletions lib/src/model_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// 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 'dart:io' show Platform;

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:dartdoc/src/failure.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:glob/glob.dart';
Expand Down Expand Up @@ -54,9 +52,9 @@ Iterable<T> filterHasCanonical<T extends ModelElement>(
return maybeHasCanonicalItems.where((me) => me.canonicalModelElement != null);
}

extension ElementExtension on Element {
extension ElementExtension on Element2 {
bool get hasPrivateName {
final name = this.name;
final name = name3;
if (name == null) return false;

if (name.startsWith('_')) {
Expand All @@ -67,8 +65,8 @@ extension ElementExtension on Element {

// GenericFunctionTypeElements have the name we care about in the enclosing
// element.
if (self is GenericFunctionTypeElement) {
var enclosingElementName = self.enclosingElement3?.name;
if (self is GenericFunctionTypeElement2) {
var enclosingElementName = self.enclosingElement2?.name3;
if (enclosingElementName != null &&
enclosingElementName.startsWith('_')) {
return true;
Expand Down
1 change: 0 additions & 1 deletion lib/src/type_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';

extension DartTypeExtension on DartType {

/// The static element associataed with this type, where documentable, and
/// `null` otherwise.
///
Expand Down
19 changes: 6 additions & 13 deletions lib/src/warnings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'dart:math' as math;
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/file_system/file_system.dart';
// ignore: implementation_imports
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:collection/collection.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/logging.dart';
Expand Down Expand Up @@ -102,6 +100,8 @@ List<DartdocOption<Object?>> createPackageWarningOptions(
mixin Warnable implements CommentReferable, Documentable, Locatable {
Element? get element;

Element2? get element2;

void warn(
PackageWarning kind, {
String? message,
Expand Down Expand Up @@ -481,7 +481,7 @@ class PackageWarningOptions {
}

class PackageWarningCounter {
final Map<Element?, Map<PackageWarning, Set<String>>> _countedWarnings = {};
final Map<Element2?, Map<PackageWarning, Set<String>>> _countedWarnings = {};
final _items = <Jsonable>[];
final _displayedWarningCounts = <PackageWarning, int>{};
final PackageGraph packageGraph;
Expand All @@ -496,17 +496,10 @@ class PackageWarningCounter {
/// The total amount of warnings this package has experienced.
int get warningCount => _warningCount;

/// An unmodifiable map view of all counted warnings related by their element,
/// warning type, and message.
UnmodifiableMapView<Element?, Map<PackageWarning, Set<String>>>
get countedWarnings => UnmodifiableMapView(_countedWarnings);

/// An unmodifiable map view of all counted warnings related by their element,
/// warning type, and message.
UnmodifiableMapView<Element2?, Map<PackageWarning, Set<String>>>
get countedWarnings2 => UnmodifiableMapView(_countedWarnings.map((key,
value) =>
MapEntry(key?.asElement2, value)));
get countedWarnings => UnmodifiableMapView(_countedWarnings);

PackageWarningCounter(this.packageGraph);

Expand Down Expand Up @@ -558,7 +551,7 @@ class PackageWarningCounter {
if (element == null) {
return false;
}
final warning = _countedWarnings[element.element];
final warning = _countedWarnings[element.element2];
if (warning != null) {
final messages = warning[kind];
return messages != null &&
Expand Down Expand Up @@ -587,7 +580,7 @@ class PackageWarningCounter {
}
var elementName = element == null ? '<global>' : element.fullyQualifiedName;
_countedWarnings
.putIfAbsent(element?.element, () => {})
.putIfAbsent(element?.element2, () => {})
.putIfAbsent(kind, () => {})
.add(message);
_writeWarning(
Expand Down
4 changes: 2 additions & 2 deletions test/documentation_comment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DocumentationCommentTest extends DartdocTestBase {
late ModelElement libraryModel;

void expectNoWarnings() {
expect(packageGraph.packageWarningCounter.countedWarnings2, isEmpty);
expect(packageGraph.packageWarningCounter.countedWarnings, isEmpty);
expect(packageGraph.packageWarningCounter.hasWarnings, isFalse);
}

Expand Down Expand Up @@ -861,7 +861,7 @@ class _HasWarning extends Matcher {
Map<Object?, Object?> matchState, bool verbose) {
if (actual is ModelElement) {
var warnings = actual
.packageGraph.packageWarningCounter.countedWarnings2[actual.element2];
.packageGraph.packageWarningCounter.countedWarnings[actual.element2];
if (warnings == null) {
return mismatchDescription.add('has no warnings');
}
Expand Down
2 changes: 1 addition & 1 deletion test/end2end/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void main() {
await buildDartdoc(['--allow-tools'], testPackageToolError, tempDir);
var results = await dartdoc.generateDocsBase();
var p = results.packageGraph;
var unresolvedToolErrors = p.packageWarningCounter.countedWarnings2.values
var unresolvedToolErrors = p.packageWarningCounter.countedWarnings.values
.map((e) => e[PackageWarning.toolError] ?? {})
.expand((element) => element);

Expand Down
2 changes: 1 addition & 1 deletion test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ void main() async {
contains(
'<a href="%%__HTMLBASE_dartdoc_internal__%%reexport_two/BaseReexported/action.html">ExtendedBaseReexported.action</a></p>'));
var doAwesomeStuffWarnings = packageGraph.packageWarningCounter
.countedWarnings[doAwesomeStuff.element] ??
.countedWarnings[doAwesomeStuff.element2] ??
{};
expect(
doAwesomeStuffWarnings,
Expand Down
2 changes: 1 addition & 1 deletion test/mustachio/builder_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,4 @@ Future<LibraryElement2> resolveGeneratedLibrary2(String libraryPath) async {
}

return libraryResult.element2;
}
}
3 changes: 1 addition & 2 deletions tool/mustachio/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ Future<void> build(
var typeProvider = library.typeProvider;
var typeSystem = library.typeSystem;
var rendererSpecs = <RendererSpec>{};
for (var renderer in library.metadata2
.annotations
for (var renderer in library.metadata2.annotations
.where((e) => e.element2!.enclosingElement2!.name3 == 'Renderer')) {
rendererSpecs.add(_buildRendererSpec(renderer));
}
Expand Down
4 changes: 2 additions & 2 deletions tool/mustachio/codegen_aot_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ Future<String> _redirectingMethod(
_AotCompiler compiler, _AotCompiler lubCompiler) async {
var buffer = StringBuffer()..write('String ${compiler._rendererName}');

buffer.writeTypeParameters(
compiler._usedContextStack.expand((c) => c.type.element3.typeParameters2));
buffer.writeTypeParameters(compiler._usedContextStack
.expand((c) => c.type.element3.typeParameters2));
buffer.write('(');

for (var context in compiler._usedContextStack) {
Expand Down
Loading
Loading