Skip to content

Commit 8386371

Browse files
keertipCommit Queue
authored andcommitted
Migrate NotImportedCompletionPass.
Change-Id: I15c18b941833688745416f69b271f8598505c673 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397981 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]>
1 parent e01bbdf commit 8386371

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

pkg/analysis_server/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ lib/src/services/completion/dart/completion_manager.dart
3131
lib/src/services/completion/dart/declaration_helper.dart
3232
lib/src/services/completion/dart/identifier_helper.dart
3333
lib/src/services/completion/dart/in_scope_completion_pass.dart
34-
lib/src/services/completion/dart/not_imported_completion_pass.dart
3534
lib/src/services/completion/dart/visibility_tracker.dart
3635
lib/src/services/correction/dart/add_extension_override.dart
3736
lib/src/services/correction/dart/create_extension_member.dart

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,28 +459,29 @@ class DeclarationHelper {
459459

460460
/// Adds suggestions for any constructors that are visible within the not yet
461461
/// imported [library].
462-
void addNotImportedConstructors(LibraryElement library) {
462+
void addNotImportedConstructors(LibraryElement2 library) {
463463
var importData = ImportData(
464-
libraryUri: library.source.uri,
464+
libraryUri: library.uri,
465465
prefix: null,
466466
isNotImported: true,
467467
);
468-
_addConstructors(library, importData);
468+
_addConstructors(library.asElement as LibraryElement, importData);
469469
}
470470

471471
/// Add members from all the applicable extensions that are visible in the
472472
/// not yet imported [library] that are applicable for the given [type].
473473
void addNotImportedExtensionMethods({
474-
required LibraryElement library,
474+
required LibraryElement2 library,
475475
required DartType type,
476476
required Set<String> excludedGetters,
477477
required bool includeMethods,
478478
required bool includeSetters,
479479
}) {
480+
var libraryElement = library.asElement as LibraryElement;
480481
var applicableExtensions = library.exportNamespace.definedNames.values
481482
.whereType<ExtensionElement>()
482483
.applicableTo(
483-
targetLibrary: library,
484+
targetLibrary: libraryElement,
484485
// Ignore nullability, consistent with non-extension members.
485486
targetType:
486487
type.isDartCoreNull
@@ -489,7 +490,7 @@ class DeclarationHelper {
489490
strictCasts: false,
490491
);
491492
var importData = ImportData(
492-
libraryUri: library.source.uri,
493+
libraryUri: library.uri,
493494
prefix: null,
494495
isNotImported: true,
495496
);
@@ -503,14 +504,14 @@ class DeclarationHelper {
503504

504505
/// Adds suggestions for any top-level declarations that are visible within
505506
/// the not yet imported [library].
506-
void addNotImportedTopLevelDeclarations(LibraryElement library) {
507+
void addNotImportedTopLevelDeclarations(LibraryElement2 library) {
507508
var importData = ImportData(
508-
libraryUri: library.source.uri,
509+
libraryUri: library.uri,
509510
prefix: null,
510511
isNotImported: true,
511512
);
512513
_addExternalTopLevelDeclarations(
513-
library: library,
514+
library: library.asElement as LibraryElement,
514515
namespace: library.exportNamespace,
515516
importData: importData,
516517
);

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'package:analysis_server/src/services/completion/dart/completion_state.da
88
import 'package:analysis_server/src/services/completion/dart/declaration_helper.dart';
99
import 'package:analysis_server/src/services/completion/dart/suggestion_collector.dart';
1010
import 'package:analyzer/dart/analysis/results.dart';
11-
import 'package:analyzer/dart/element/element.dart';
11+
import 'package:analyzer/dart/element/element2.dart';
1212
import 'package:analyzer/dart/element/type.dart';
1313
import 'package:analyzer/src/dart/analysis/file_state.dart';
1414
import 'package:analyzer/src/dart/analysis/file_state_filter.dart';
@@ -26,7 +26,7 @@ class ConstructorsOperation extends NotImportedOperation {
2626
: _declarationHelper = declarationHelper;
2727

2828
/// Compute any candidate suggestions for elements in the [library].
29-
void computeSuggestionsIn(LibraryElement library) {
29+
void computeSuggestionsIn(LibraryElement2 library) {
3030
_declarationHelper.addNotImportedConstructors(library);
3131
}
3232
}
@@ -62,7 +62,7 @@ class InstanceExtensionMembersOperation extends NotImportedOperation {
6262
_includeSetters = includeSetters;
6363

6464
/// Compute any candidate suggestions for elements in the [library].
65-
void computeSuggestionsIn(LibraryElement library) {
65+
void computeSuggestionsIn(LibraryElement2 library) {
6666
_declarationHelper.addNotImportedExtensionMethods(
6767
library: library,
6868
type: _type,
@@ -137,8 +137,8 @@ class NotImportedCompletionPass {
137137
continue;
138138
}
139139

140-
var library = request.libraryElement;
141-
var element = elementResult.element;
140+
var library = request.libraryElement2;
141+
var element = elementResult.element2;
142142
if (element == library) {
143143
// Don't suggest elements from the library in which completion is being
144144
// requested. They've already been suggested.
@@ -166,7 +166,7 @@ class NotImportedCompletionPass {
166166
}
167167

168168
var exportNamespace = element.exportNamespace;
169-
var exportElements = exportNamespace.definedNames.values.toList();
169+
var exportElements = exportNamespace.definedNames2.values.toList();
170170

171171
performance.run('staticMembers', (_) {
172172
operation.computeSuggestionsIn(
@@ -198,9 +198,9 @@ class StaticMembersOperation extends NotImportedOperation {
198198

199199
/// Compute any candidate suggestions for elements in the [library].
200200
void computeSuggestionsIn(
201-
LibraryElement library,
202-
List<Element> exportElements,
203-
Set<Element> importedElements,
201+
LibraryElement2 library,
202+
List<Element2> exportElements,
203+
Set<Element2> importedElements,
204204
) {
205205
// TODO(brianwilkerson): Determine whether we need the element parameters.
206206
_declarationHelper.addNotImportedTopLevelDeclarations(library);
@@ -211,19 +211,21 @@ class StaticMembersOperation extends NotImportedOperation {
211211
class _ImportSummary {
212212
/// The elements that are imported from libraries that are only partially
213213
/// imported.
214-
Set<Element> importedElements = Set<Element>.identity();
214+
Set<Element2> importedElements = Set<Element2>.identity();
215215

216216
/// The libraries that are imported in their entirety.
217-
Set<LibraryElement> importedLibraries = Set<LibraryElement>.identity();
218-
219-
_ImportSummary(LibraryElement library) {
220-
for (var import in library.definingCompilationUnit.libraryImports) {
221-
var importedLibrary = import.importedLibrary;
222-
if (importedLibrary != null) {
223-
if (import.combinators.isEmpty) {
224-
importedLibraries.add(importedLibrary);
225-
} else {
226-
importedElements.addAll(import.namespace.definedNames.values);
217+
Set<LibraryElement2> importedLibraries = Set<LibraryElement2>.identity();
218+
219+
_ImportSummary(LibraryElement2 library) {
220+
for (var fragment in library.fragments) {
221+
for (var import in fragment.libraryImports2) {
222+
var importedLibrary = import.importedLibrary2;
223+
if (importedLibrary != null) {
224+
if (import.combinators.isEmpty) {
225+
importedLibraries.add(importedLibrary);
226+
} else {
227+
importedElements.addAll(import.namespace.definedNames2.values);
228+
}
227229
}
228230
}
229231
}

0 commit comments

Comments
 (0)