Skip to content
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

Elements. Migrate test/typedefs_test.dart #3964

Merged
merged 2 commits into from
Jan 16, 2025
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
18 changes: 10 additions & 8 deletions lib/resources/docs.dart.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/resources/docs.dart.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
library;

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
Expand Down Expand Up @@ -209,6 +210,8 @@ class ParameterizedElementType extends DefinedElementType with Rendered {
mixin Aliased implements ElementType {
Element get typeAliasElement => type.alias!.element;

Element2 get typeAliasElement2 => type.alias!.element2;

@override
String get name => typeAliasElement.name!;

Expand Down
41 changes: 39 additions & 2 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20231,13 +20231,13 @@ class _Renderer_PackageTemplateData extends RendererBase<PackageTemplateData> {
}
}

String renderIndex(PackageTemplateData context, Template template) {
String renderSearchPage(PackageTemplateData context, Template template) {
var buffer = StringBuffer();
_render_PackageTemplateData(context, template.ast, template, buffer);
return buffer.toString();
}

String renderSearchPage(PackageTemplateData context, Template template) {
String renderIndex(PackageTemplateData context, Template template) {
var buffer = StringBuffer();
_render_PackageTemplateData(context, template.ast, template, buffer);
return buffer.toString();
Expand Down Expand Up @@ -24813,6 +24813,34 @@ class _Renderer_Typedef extends RendererBase<Typedef> {
);
},
),
'element2': Property(
getValue: (CT_ c) => c.element2,
renderVariable:
(CT_ c, Property<CT_> self, List<String> remainingNames) =>
self.renderSimpleVariable(
c,
remainingNames,
'TypeAliasElement2',
),

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['TypeAliasElement2']!,
);
},
),
'enclosingElement': Property(
getValue: (CT_ c) => c.enclosingElement,
renderVariable: (
Expand Down Expand Up @@ -26309,6 +26337,15 @@ const _invisibleGetters = {
'name',
'runtimeType',
},
'TypeAliasElement2': {
'aliasedElement2',
'aliasedType',
'enclosingElement2',
'firstFragment',
'hashCode',
'name',
'runtimeType',
},
'TypeParameterElement': {
'bound',
'declaration',
Expand Down
5 changes: 5 additions & 0 deletions lib/src/model/typedef.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// 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/type.dart';
// ignore: implementation_imports
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/kind.dart';
Expand All @@ -16,6 +19,8 @@ abstract class Typedef extends ModelElement
@override
final TypeAliasElement element;

TypeAliasElement2 get element2 => element.asElement2 as TypeAliasElement2;

Typedef(this.element, super.library, super.packageGraph);

DartType get aliasedType => element.aliasedType;
Expand Down
6 changes: 2 additions & 4 deletions test/typedefs_test.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/type.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -256,7 +254,7 @@ R<int> f(int a, String b) {

expect(
fFunc.modelType.returnType,
isA<AliasedUndefinedElementType>().having((e) => e.typeAliasElement,
'typeAliasElement', equals(rTypedef.element)));
isA<AliasedUndefinedElementType>().having((e) => e.typeAliasElement2,
'typeAliasElement', equals(rTypedef.element2)));
}
}
Loading