blob: a519a547d7fcff8bb4bdf0433074c81905769060 [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// 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.
import 'package:analyzer/dart/element/element.dart';
import 'package:dartdoc/src/element_type.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/type_parameters_renderer.dart';
class TypeParameter extends ModelElement with HasNoPage {
final TypeParameterElement element;
TypeParameter(this.element, super.library, super.packageGraph);
ModelElement get enclosingElement =>
modelBuilder.from(element.enclosingElement!, library);
/// [TypeParameter]s don't have documentation pages, and don't link to the
/// element on which they are declared.
// TODO(srawlins): But shouldn't they link to the element on which they are
// declared?
String? get href => null;
Kind get kind => Kind.typeParameter;
ElementType? get boundType {
var bound = element.bound;
return bound == null ? null : modelBuilder.typeFrom(bound, library);
bool get hasParameters => false;
String get name => element.bound != null
? '${} extends ${boundType!.nameWithGenerics}'
String? _linkedName;
String get linkedName {
_linkedName ??= element.bound != null
? '${} extends ${boundType!.linkedName}'
return _linkedName!;
late final Map<String, CommentReferable> referenceChildren = () {
var boundType = this.boundType;
if (boundType == null) return const <String, CommentReferable>{};
return { boundType};
Iterable<CommentReferable> get referenceParents => [enclosingElement];
String get referenceName =>;
/// A mixin for [ModelElement]s which have type parameters.
mixin TypeParameters implements ModelElement {
String get nameWithGenerics => '$name$genericParameters';
String get nameWithLinkedGenerics => '$name$linkedGenericParameters';
bool get hasGenericParameters => typeParameters.isNotEmpty;
String get genericParameters =>
String get linkedGenericParameters =>
List<TypeParameter> get typeParameters;
TypeParametersRenderer get _typeParametersRenderer =>