Skip to content

Fix void as a type parameter by rewriting most of element_type.dart #1629

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

Merged
merged 18 commits into from
Mar 13, 2018
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
392 changes: 277 additions & 115 deletions lib/src/element_type.dart

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions lib/src/markdown_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'dart:math';

import 'package:analyzer/dart/ast/ast.dart' hide TypeParameter;
import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model_utils.dart';
import 'package:html/parser.dart' show parse;
import 'package:markdown/markdown.dart' as md;
Expand Down Expand Up @@ -422,7 +423,7 @@ ModelElement _findRefElementInLibrary(String codeRef, Warnable element,
// Maybe this ModelElement has type parameters, and this is one of them.
if (results.isEmpty) {
if (element is TypeParameters) {
results.addAll((element as TypeParameters).typeParameters.where((p) =>
results.addAll(element.typeParameters.where((p) =>
p.name == codeRefChomped || codeRefChomped.startsWith("${p.name}.")));
}
}
Expand Down Expand Up @@ -644,8 +645,9 @@ void _getResultsForClass(Class tryClass, String codeRefChomped,
// Otherwise, search the class.
if ((tryClass.modelType.typeArguments.map((e) => e.name))
.contains(codeRefChomped)) {
results.add(tryClass.modelType.typeArguments
.firstWhere((e) => e.name == codeRefChomped)
results.add((tryClass.modelType.typeArguments.firstWhere(
(e) => e.name == codeRefChomped && e is DefinedElementType)
as DefinedElementType)
.element);
} else {
// People like to use 'this' in docrefs too.
Expand All @@ -655,14 +657,12 @@ void _getResultsForClass(Class tryClass, String codeRefChomped,
// TODO(jcollins-g): get rid of reimplementation of identifier resolution
// or integrate into ModelElement in a simpler way.
List<Class> superChain = [tryClass];
superChain
.addAll(tryClass.interfaces.map((t) => t.returnElement as Class));
superChain.addAll(tryClass.interfaces.map((t) => t.element as Class));
// This seems duplicitous with our caller, but the preferredClass
// hint matters with findCanonicalModelElementFor.
// TODO(jcollins-g): This makes our caller ~O(n^2) vs length of superChain.
// Fortunately superChains are short, but optimize this if it matters.
superChain
.addAll(tryClass.superChain.map((t) => t.returnElement as Class));
superChain.addAll(tryClass.superChain.map((t) => t.element as Class));
List<String> codeRefParts = codeRefChomped.split('.');
for (final c in superChain) {
// TODO(jcollins-g): add a hash-map-enabled lookup function to Class?
Expand Down
Loading