Skip to content

Commit 95105e9

Browse files
authored
Remove use of ElementImpl2 (#4042)
This simplifies the code and reduces use of private API.
1 parent 1a08646 commit 95105e9

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/src/model/canonicalization.dart

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:analyzer/dart/element/element2.dart';
6-
// ignore: implementation_imports
7-
import 'package:analyzer/src/dart/element/element.dart';
86
import 'package:dartdoc/src/model/model.dart';
97
import 'package:dartdoc/src/warnings.dart';
108

@@ -86,22 +84,16 @@ final class _Canonicalization {
8684
}
8785
}
8886

89-
// Copied from package analyzer ElementLocationImpl.fromElement.
9087
String _getElementLocation(Element2 element) {
9188
var components = <String>[];
9289
Element2? ancestor = element;
9390
while (ancestor != null) {
94-
if (ancestor is! ElementImpl2) {
95-
if (ancestor is LibraryElement2) {
96-
components.insert(0, ancestor.identifier);
97-
} else {
98-
throw Exception('${ancestor.runtimeType} is not an ElementImpl2');
99-
}
100-
ancestor = ancestor.enclosingElement2;
101-
} else {
91+
if (ancestor is LibraryElement2) {
10292
components.insert(0, ancestor.identifier);
103-
ancestor = ancestor.enclosingElement2;
93+
} else {
94+
components.insert(0, ancestor.name3!);
10495
}
96+
ancestor = ancestor.enclosingElement2;
10597
}
10698
var buffer = StringBuffer();
10799
var length = components.length;

0 commit comments

Comments
 (0)