Skip to content

Commit 5dc7270

Browse files
authored
Fix void as a type parameter by rewriting most of element_type.dart (#1629)
* Beginnings of refactor, partially works * unit tests pass, integration tests fail * refactoring type arguments part 1 * getting closer. * closer! * Works! * pubspec.lock * new void tests pt 1 * void tests pt 2 * cleanup part 1 * cleanup part 2 * ModelFunctionAnonymous shift pt1 * cleanups * dartfmt and pub get * fix windows only analysis errors * stack depth reduction * Fix regression in typedef parameters
1 parent 06a7d43 commit 5dc7270

File tree

255 files changed

+8592
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+8592
-430
lines changed

lib/src/element_type.dart

Lines changed: 277 additions & 115 deletions
Large diffs are not rendered by default.

lib/src/markdown_processor.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'dart:math';
1010

1111
import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
1212
import 'package:analyzer/dart/element/element.dart';
13+
import 'package:dartdoc/src/element_type.dart';
1314
import 'package:dartdoc/src/model_utils.dart';
1415
import 'package:html/parser.dart' show parse;
1516
import 'package:markdown/markdown.dart' as md;
@@ -422,7 +423,7 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
422423
// Maybe this ModelElement has type parameters, and this is one of them.
423424
if (results.isEmpty) {
424425
if (element is TypeParameters) {
425-
results.addAll((element as TypeParameters).typeParameters.where((p) =>
426+
results.addAll(element.typeParameters.where((p) =>
426427
p.name == codeRefChomped || codeRefChomped.startsWith("${p.name}.")));
427428
}
428429
}
@@ -644,8 +645,9 @@ void _getResultsForClass(Class tryClass, String codeRefChomped,
644645
// Otherwise, search the class.
645646
if ((tryClass.modelType.typeArguments.map((e) => e.name))
646647
.contains(codeRefChomped)) {
647-
results.add(tryClass.modelType.typeArguments
648-
.firstWhere((e) => e.name == codeRefChomped)
648+
results.add((tryClass.modelType.typeArguments.firstWhere(
649+
(e) => e.name == codeRefChomped && e is DefinedElementType)
650+
as DefinedElementType)
649651
.element);
650652
} else {
651653
// People like to use 'this' in docrefs too.
@@ -655,14 +657,12 @@ void _getResultsForClass(Class tryClass, String codeRefChomped,
655657
// TODO(jcollins-g): get rid of reimplementation of identifier resolution
656658
// or integrate into ModelElement in a simpler way.
657659
List<Class> superChain = [tryClass];
658-
superChain
659-
.addAll(tryClass.interfaces.map((t) => t.returnElement as Class));
660+
superChain.addAll(tryClass.interfaces.map((t) => t.element as Class));
660661
// This seems duplicitous with our caller, but the preferredClass
661662
// hint matters with findCanonicalModelElementFor.
662663
// TODO(jcollins-g): This makes our caller ~O(n^2) vs length of superChain.
663664
// Fortunately superChains are short, but optimize this if it matters.
664-
superChain
665-
.addAll(tryClass.superChain.map((t) => t.returnElement as Class));
665+
superChain.addAll(tryClass.superChain.map((t) => t.element as Class));
666666
List<String> codeRefParts = codeRefChomped.split('.');
667667
for (final c in superChain) {
668668
// TODO(jcollins-g): add a hash-map-enabled lookup function to Class?

0 commit comments

Comments
 (0)