Skip to content

Commit

Permalink
Elements. Migrate test/end2end/model_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
keertip committed Jan 27, 2025
1 parent 114c006 commit acdbe88
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 30 deletions.
21 changes: 9 additions & 12 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.

29 changes: 29 additions & 0 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6396,6 +6396,34 @@ class _Renderer_DocumentationComment
);
},
),
'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']!,
);
},
),
'elementDocumentation': Property(
getValue: (CT_ c) => c.elementDocumentation,
renderVariable:
Expand Down Expand Up @@ -25793,6 +25821,7 @@ const _invisibleGetters = {
'documentationFrom',
'documentationLocal',
'element',
'element2',
'elementDocumentation',
'hasDocumentationComment',
'hasNodoc',
Expand Down
7 changes: 7 additions & 0 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
library;

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
// ignore: implementation_imports
import 'package:analyzer/src/utilities/extensions/element.dart';
import 'package:args/args.dart';
import 'package:crypto/crypto.dart' as crypto;
import 'package:dartdoc/src/model/documentable.dart';
Expand Down Expand Up @@ -45,6 +48,10 @@ mixin DocumentationComment
@override
Element get element;

Element2 get element2 => element.asElement2!;



List<DocumentationComment>? _documentationFrom;

@override
Expand Down
1 change: 1 addition & 0 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ abstract class ModelElement
@override
Element get element;

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

@override
Expand Down
36 changes: 20 additions & 16 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

// ignore_for_file: non_constant_identifier_names

// 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';
import 'package:analyzer/source/line_info.dart';
import 'package:async/async.dart';
Expand Down Expand Up @@ -181,9 +179,9 @@ void main() async {
'Verify annotations and their type arguments render on type parameters '
'for typedefs',
skip: 'dart-lang/sdk#46064', () {
expect((F.aliasedType as FunctionType).typeFormals.first.metadata,
expect((F.aliasedType as FunctionType).typeParameters.first.metadata2,
isNotEmpty);
expect((F.aliasedType as FunctionType).parameters.first.metadata,
expect((F.aliasedType as FunctionType).formalParameters.first.metadata2,
isNotEmpty);
// TODO(jcollins-g): add rendering verification once we have data from
// analyzer.
Expand Down Expand Up @@ -234,7 +232,7 @@ void main() async {
void expectTypedefs(Typedef t, String modelTypeToString,
Iterable<String> genericParameters) {
expect(t.modelType.toString(), equals(modelTypeToString));
expect(t.element.typeParameters.map((p) => p.toString()),
expect(t.element2.typeParameters2.map((p) => p.toString()),
orderedEquals(genericParameters));
}

Expand Down Expand Up @@ -909,18 +907,24 @@ void main() async {
});

test('can import other libraries with unusual URIs', () {
final importLists = fakeLibrary.element2.fragments
.map((fragment) => fragment.libraryImports2);
final exportLists = fakeLibrary.element2.fragments
.map((fragment) => fragment.libraryExports2);
final fakeLibraryImportedExported = <Library>{
for (final l in <LibraryElement>{
...fakeLibrary.element.definingCompilationUnit.libraryImports
for (final l in <LibraryElement2>{
...importLists
.expand((imports) => imports)
.map((import) => import.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library),
...fakeLibrary.element.definingCompilationUnit.libraryExports
.map((import) => import.uri)
.map((uri) => uri.library2),
...exportLists
.expand((exports) => exports)
.map((export) => export.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library)
.map((uri) => uri.library2)
})
packageGraph.getModelForElement(l) as Library
packageGraph.getModelForElement2(l) as Library
};
expect(fakeLibraryImportedExported.any((l) => l.name == 'import_unusual'),
isTrue);
Expand Down Expand Up @@ -1182,7 +1186,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] ??
.countedWarnings2[doAwesomeStuff.element2] ??
{};
expect(
doAwesomeStuffWarnings,
Expand Down Expand Up @@ -1682,7 +1686,7 @@ void main() async {
fakeLibrary.classes.wherePublic.named('MIEEMixinWithOverride');
var problematicOperator =
MIEEMixinWithOverride.inheritedOperators.named('operator []=');
expect(problematicOperator.element.enclosingElement3.name,
expect(problematicOperator.element2.enclosingElement2?.name3,
equals('_MIEEPrivateOverride'));
expect(problematicOperator.canonicalModelElement!.enclosingElement!.name,
equals('MIEEMixinWithOverride'));
Expand Down Expand Up @@ -3572,7 +3576,7 @@ String? topLevelFunction(int param1, bool param2, Cool coolBeans,
test('inheritance of docs from SDK works for getter/setter combos', () {
expect(
ExtraSpecialListLength
.getter!.documentationFrom.first.element.library!.name,
.getter!.documentationFrom.first.element2.library2!.name3,
equals('dart.core'));
expect(ExtraSpecialListLength.oneLineDoc == '', isFalse);
});
Expand Down

0 comments on commit acdbe88

Please sign in to comment.