Skip to content

Replace getBasestElement() with Element.declaration #2106

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
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
4 changes: 1 addition & 3 deletions lib/src/model/accessor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ class ContainerAccessor extends Accessor with ContainerMember, Inheritable {
? t.getGetter(element.name)
: t.getSetter(element.name);
if (accessor != null) {
if (accessor is Member) {
accessor = PackageGraph.getBasestElement(accessor);
}
accessor = accessor.declaration;
Class parentClass =
ModelElement.fromElement(t.element, packageGraph);
List<Field> possibleFields = [];
Expand Down
6 changes: 1 addition & 5 deletions lib/src/model/inheritable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/element/member.dart' show Member;
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/special_elements.dart';

Expand Down Expand Up @@ -41,10 +40,7 @@ mixin Inheritable on ContainerMember {
@override
Container computeCanonicalEnclosingContainer() {
if (isInherited) {
Element searchElement = element;
searchElement = searchElement is Member
? PackageGraph.getBasestElement(searchElement)
: searchElement;
Element searchElement = element.declaration;
// TODO(jcollins-g): generate warning if an inherited element's definition
// is in an intermediate non-canonical class in the inheritance chain?
Class previous;
Expand Down
3 changes: 1 addition & 2 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ abstract class ModelElement extends Canonicalization
// TODO(jcollins-g): Refactor object model to instantiate 'ModelMembers'
// for members?
if (e is Member) {
var basest = PackageGraph.getBasestElement(e);
originalMember = e;
e = basest;
e = e.declaration;
}
Tuple3<Element, Library, Container> key =
Tuple3(e, library, enclosingContainer);
Expand Down
12 changes: 1 addition & 11 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/element/member.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
Expand Down Expand Up @@ -672,15 +671,6 @@ class PackageGraph {
return _canonicalLibraryFor[e];
}

// TODO(jcollins-g): Revise when dart-lang/sdk#29600 is fixed.
static Element getBasestElement(Element possibleMember) {
Element element = possibleMember;
while (element is Member) {
element = (element as Member).declaration;
}
return element;
}

/// Tries to find a canonical ModelElement for this element. If we know
/// this element is related to a particular class, pass preferredClass to
/// disambiguate.
Expand Down Expand Up @@ -715,7 +705,7 @@ class PackageGraph {
// TODO(jcollins-g): The data structures should be changed to eliminate guesswork
// with member elements.
if (e is ClassMemberElement || e is PropertyAccessorElement) {
if (e is Member) e = getBasestElement(e);
e = e.declaration;
Set<ModelElement> candidates = Set();
Tuple2<Element, Library> iKey = Tuple2(e, lib);
Tuple4<Element, Library, Class, ModelElement> key =
Expand Down