Skip to content

Commit

Permalink
Elements. Migrate test/typedefs_test.dart (#3964)
Browse files Browse the repository at this point in the history
* Elements. Migrate test/typedefs_test.dart

* Rebuild generated file
  • Loading branch information
keertip authored Jan 16, 2025
1 parent 456dd6e commit ea99b16
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 16 deletions.
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)));
}
}

0 comments on commit ea99b16

Please sign in to comment.