blob: 673666f53d5d5dcfe913e4c3ae7b4a5e778cb979 [file] [log] [blame]
// Copyright (c) 2021, 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:analyzer/dart/element/scope.dart';
import 'package:dartdoc/src/model/comment_referable.dart';
import 'package:dartdoc/src/model/model.dart';
/// Represents a [PrefixElement] for dartdoc.
/// Like [Parameter], it doesn't have doc pages, but participates in lookups.
/// Forwards to its referenced library if referred to directly.
class Prefix extends ModelElement with HasNoPage implements EnclosedElement {
final PrefixElement element;
/// [library] is the library the prefix is defined in, not the [Library]
/// referred to by the [PrefixElement].
Prefix(this.element, super.library, super.packageGraph);
bool get isCanonical => false;
// TODO(jcollins-g): consider connecting PrefixElement to the imported library
// in analyzer?
late final Library associatedLibrary = modelBuilder.fromElement(library
.firstWhere((i) => i.prefix?.element == element)
.importedLibrary!) as Library;
Library? get canonicalModelElement => associatedLibrary.canonicalLibrary;
Scope get scope => element.scope;
ModelElement get enclosingElement => library;
String? get href => canonicalModelElement?.href;
Kind get kind => Kind.prefix;
Map<String, CommentReferable> get referenceChildren => {};
Iterable<CommentReferable> get referenceParents => [definingLibrary];