Skip to content

Commit 1af77fa

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add PrefixElementExtension.asElement2 and PrefixElement2Extension.asElement.
Change-Id: I76ae659a487392ddcfffa45c7cf2178ee8ca1b85 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396623 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent cdd2700 commit 1af77fa

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

pkg/analysis_server/lib/src/services/completion/dart/declaration_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class DeclarationHelper {
340340
collector.addSuggestion(
341341
ImportPrefixSuggestion(
342342
libraryElement: importedLibrary.asElement2 as LibraryElement2,
343-
prefixElement: prefixElement.asElement2 as PrefixElement2,
343+
prefixElement: prefixElement.asElement2,
344344
matcherScore: matcherScore,
345345
),
346346
);

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9097,6 +9097,10 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 {
90979097
reference.element2 = this;
90989098
}
90999099

9100+
PrefixElementImpl get asElement {
9101+
return imports.first.prefix!.element;
9102+
}
9103+
91009104
@override
91019105
Null get enclosingElement2 => null;
91029106

pkg/analyzer/lib/src/utilities/extensions/element.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ extension Element2OrNullExtension on Element2? {
6868
return element2.asElement;
6969
case NeverElementImpl2():
7070
return NeverElementImpl.instance;
71-
case PrefixElementImpl():
72-
return self;
7371
case SetterElementImpl():
7472
return self.firstFragment as Element;
7573
case TopLevelFunctionElementImpl():
@@ -333,6 +331,18 @@ extension ParameterElementExtension on ParameterElement {
333331
}
334332
}
335333

334+
extension PrefixElement2Extension on PrefixElement2 {
335+
PrefixElement get asElement {
336+
return (this as PrefixElementImpl2).asElement;
337+
}
338+
}
339+
340+
extension PrefixElementExtension on PrefixElement {
341+
PrefixElement2 get asElement2 {
342+
return (this as PrefixElementImpl).element2;
343+
}
344+
}
345+
336346
extension TypeParameterElement2Extension on TypeParameterElement2 {
337347
TypeParameterElement get asElement {
338348
return firstFragment as TypeParameterElement;

0 commit comments

Comments
 (0)