Skip to content

Commit c57f879

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate getExportedElement()
Change-Id: I987a14f465541d727aa32716bc77dd0702f1746c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399023 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 6123e0e commit c57f879

File tree

5 files changed

+12
-25
lines changed

5 files changed

+12
-25
lines changed

pkg/analysis_server/lib/src/services/correction/dart/import_library.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ImportLibrary extends MultiCorrectionProducer {
227227
if (libraryElement == null) {
228228
continue;
229229
}
230-
var element = getExportedElement2(libraryElement, name);
230+
var element = getExportedElement(libraryElement, name);
231231
if (element == null) {
232232
continue;
233233
}

pkg/analysis_server/lib/src/services/correction/namespace.dart

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@ import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/element/element.dart';
77
import 'package:analyzer/dart/element/element2.dart';
88
import 'package:analyzer/src/dart/resolver/scope.dart';
9-
import 'package:analyzer/src/utilities/extensions/element.dart';
109

11-
/// Returns the [Element] exported from the given [LibraryElement].
12-
Element? getExportedElement(LibraryElement? library, String name) {
10+
/// Returns the [Element2] exported from the given [LibraryElement2].
11+
Element2? getExportedElement(LibraryElement2? library, String name) {
1312
if (library == null) {
1413
return null;
1514
}
16-
return _getExportNamespaceForLibrary(library)[name];
17-
}
18-
19-
/// Returns the [Element] exported from the given [LibraryElement].
20-
Element2? getExportedElement2(LibraryElement2? library, String name) {
21-
if (library == null) {
22-
return null;
23-
}
24-
return _getExportNamespaceForLibrary(
25-
library as LibraryElement,
26-
)[name].asElement2;
15+
var namespace = NamespaceBuilder().createExportNamespaceForLibrary(library);
16+
return namespace.definedNames2[name];
2717
}
2818

2919
/// Return the [LibraryImportElement] that is referenced by [prefixNode], or
@@ -48,12 +38,6 @@ LibraryImport? getImportElement2(SimpleIdentifier prefixNode) {
4838
return _getImportElementInfo2(prefixNode);
4939
}
5040

51-
/// Returns the export namespace of the given [LibraryElement].
52-
Map<String, Element> _getExportNamespaceForLibrary(LibraryElement library) {
53-
var namespace = NamespaceBuilder().createExportNamespaceForLibrary(library);
54-
return namespace.definedNames;
55-
}
56-
5741
/// Return the [LibraryImportElement] that declared [prefix] and imports [element].
5842
///
5943
/// [libraryElement] - the [LibraryElement] where reference is.

pkg/analyzer/lib/src/dart/resolver/scope.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:analyzer/src/dart/ast/ast.dart';
1111
import 'package:analyzer/src/dart/element/element.dart';
1212
import 'package:analyzer/src/dart/element/type.dart';
1313
import 'package:analyzer/src/generated/engine.dart';
14+
import 'package:analyzer/src/utilities/extensions/element.dart';
1415

1516
/// The scope defined by a block.
1617
class BlockScope {
@@ -179,8 +180,8 @@ class NamespaceBuilder {
179180

180181
/// Create a namespace representing the export namespace of the given
181182
/// [library].
182-
Namespace createExportNamespaceForLibrary(LibraryElement library) {
183-
Map<String, Element> exportedNames = _getExportMapping(library);
183+
Namespace createExportNamespaceForLibrary(LibraryElement2 library) {
184+
Map<String, Element> exportedNames = _getExportMapping(library.asElement);
184185
return Namespace(exportedNames);
185186
}
186187

pkg/analyzer/lib/src/error/dead_code_verifier.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:analyzer/src/dart/element/type_system.dart';
1515
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
1616
import 'package:analyzer/src/dart/resolver/scope.dart';
1717
import 'package:analyzer/src/error/codes.dart';
18+
import 'package:analyzer/src/utilities/extensions/element.dart';
1819

1920
typedef _CatchClausesVerifierReporter = void Function(
2021
CatchClause first,
@@ -132,7 +133,7 @@ class DeadCodeVerifier extends RecursiveAstVisitor<void> {
132133
/// [library].
133134
void _checkCombinator(LibraryElement library, Combinator combinator) {
134135
Namespace namespace =
135-
NamespaceBuilder().createExportNamespaceForLibrary(library);
136+
NamespaceBuilder().createExportNamespaceForLibrary(library.asElement2);
136137
NodeList<SimpleIdentifier> names;
137138
ErrorCode warningCode;
138139
if (combinator is HideCombinator) {

pkg/analyzer/lib/src/generated/element_resolver.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/src/dart/resolver/scope.dart';
1414
import 'package:analyzer/src/error/codes.dart';
1515
import 'package:analyzer/src/generated/resolver.dart';
1616
import 'package:analyzer/src/generated/super_context.dart';
17+
import 'package:analyzer/src/utilities/extensions/element.dart';
1718

1819
/// An object used by instances of [ResolverVisitor] to resolve references
1920
/// within the AST structure to the elements being referenced. The requirements
@@ -468,7 +469,7 @@ class ElementResolver {
468469
return;
469470
}
470471
Namespace namespace =
471-
NamespaceBuilder().createExportNamespaceForLibrary(library);
472+
NamespaceBuilder().createExportNamespaceForLibrary(library.asElement2);
472473
for (Combinator combinator in combinators) {
473474
NodeList<SimpleIdentifier> names;
474475
if (combinator is HideCombinator) {

0 commit comments

Comments
 (0)