Skip to content

Commit

Permalink
Elements. Migrate NamespaceBuilder.
Browse files Browse the repository at this point in the history
Change-Id: I3f51d6ad88528a7a7251a8c140795a442b04e5a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411460
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and Commit Queue committed Feb 22, 2025
1 parent 9c9fe8f commit fad65ac
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/src/dart/element/element.dart';
import 'package:analyzer/src/dart/resolver/scope.dart';

/// Returns the [Element2] exported from the given [LibraryElement2].
Element2? getExportedElement(LibraryElement2? library, String name) {
if (library == null) {
return null;
}
library as LibraryElementImpl;
var namespace = NamespaceBuilder().createExportNamespaceForLibrary(library);
return namespace.definedNames2[name];
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5269,7 +5269,7 @@ package:analyzer/src/dart/resolver/scope.dart:
Namespace (class extends Object):
EMPTY (static getter: Namespace)
EMPTY= (static setter: Namespace)
new (constructor: Namespace Function(Map<String, Element>))
new (constructor: Namespace Function(Map<String, Element2>))
definedNames (getter: Map<String, Element>)
definedNames2 (getter: Map<String, Element2>)
get (method: Element? Function(String))
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5955,7 +5955,7 @@ final class ExportDirectiveImpl extends NamespaceDirectiveImpl

@experimental
@override
LibraryExport? get libraryExport => element as LibraryExport?;
LibraryExportElementImpl? get libraryExport => element;

@override
ChildEntities get _childEntities => super._childEntities
Expand Down Expand Up @@ -9973,7 +9973,7 @@ final class ImportDirectiveImpl extends NamespaceDirectiveImpl

@experimental
@override
LibraryImport? get libraryImport => element as LibraryImport?;
LibraryImportElementImpl? get libraryImport => element;

@override
SimpleIdentifierImpl? get prefix => _prefix;
Expand Down
8 changes: 4 additions & 4 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7697,7 +7697,7 @@ class LibraryExportElementImpl extends _ExistingElementImpl
}

@override
LibraryElement2? get exportedLibrary2 => exportedLibrary;
LibraryElementImpl? get exportedLibrary2 => exportedLibrary;

@override
String get identifier => 'export@$nameOffset';
Expand Down Expand Up @@ -7769,7 +7769,7 @@ class LibraryImportElementImpl extends _ExistingElementImpl
}

@override
LibraryElement2? get importedLibrary2 => importedLibrary;
LibraryElementImpl? get importedLibrary2 => importedLibrary;

@override
ElementKind get kind => ElementKind.IMPORT;
Expand All @@ -7783,12 +7783,12 @@ class LibraryImportElementImpl extends _ExistingElementImpl
@override
Namespace get namespace {
var uri = this.uri;
if (uri is DirectiveUriWithLibrary) {
if (uri is DirectiveUriWithLibraryImpl) {
return _namespace ??=
NamespaceBuilder().createImportNamespaceForDirective(
importedLibrary: uri.library,
combinators: combinators,
prefix: prefix?.element,
prefix: prefix2,
);
}
return Namespace.EMPTY;
Expand Down
Loading

0 comments on commit fad65ac

Please sign in to comment.