Skip to content

Commit b4e83da

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Update ElementDirective implementations to stop being fragments.
Change-Id: Id8ddd645e779a4b4d6173d0403fcbf925fa7a57c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425440 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 4d4f8f4 commit b4e83da

File tree

23 files changed

+401
-321
lines changed

23 files changed

+401
-321
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class _MergeCombinators extends ResolvedCorrectionProducer {
9595
Map<String, Element> namespace;
9696
Namespace? originalNamespace;
9797
switch (directive) {
98-
case ExportDirective(:LibraryExportElementImpl libraryExport):
98+
case ExportDirective(:LibraryExportImpl libraryExport):
9999
element = libraryExport.exportedLibrary2;
100100
if (element is! LibraryElementImpl) {
101101
return;
@@ -154,7 +154,7 @@ class _MergeCombinators extends ResolvedCorrectionProducer {
154154
});
155155
}
156156

157-
Namespace _currentNamespace(LibraryExportElementImpl libraryExport) {
157+
Namespace _currentNamespace(LibraryExportImpl libraryExport) {
158158
return namespaceBuilder.createExportNamespaceForDirective2(libraryExport);
159159
}
160160

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ testFineAfterLibraryAnalyzerHook;
110110
// TODO(scheglov): Clean up the list of implicitly analyzed files.
111111
class AnalysisDriver {
112112
/// The version of data format, should be incremented on every format change.
113-
static const int DATA_VERSION = 457;
113+
static const int DATA_VERSION = 458;
114114

115115
/// The number of exception contexts allowed to write. Once this field is
116116
/// zero, we stop writing any new exception contexts in this process.

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ class LibraryAnalyzer {
788788
);
789789
} else if (directive is LibraryDirectiveImpl) {
790790
if (fileKind == _library) {
791-
directive.element = _libraryElement;
791+
directive.element2 = _libraryElement;
792792
}
793793
} else if (directive is PartDirectiveImpl) {
794794
var index = partIndex++;
@@ -799,9 +799,6 @@ class LibraryAnalyzer {
799799
partElement: fileElement.parts[index],
800800
errorReporter: containerErrorReporter,
801801
);
802-
} else if (directive is PartOfDirectiveImpl) {
803-
// TODO(scheglov): this should be LibraryFragment.
804-
directive.element = _libraryElement;
805802
}
806803
}
807804

@@ -921,11 +918,11 @@ class LibraryAnalyzer {
921918

922919
void _resolveLibraryExportDirective({
923920
required ExportDirectiveImpl directive,
924-
required LibraryExportElementImpl element,
921+
required LibraryExportImpl element,
925922
required LibraryExportState state,
926923
required ErrorReporter errorReporter,
927924
}) {
928-
directive.element = element;
925+
directive.libraryExport = element;
929926
_resolveUriConfigurations(
930927
configurationNodes: directive.configurations,
931928
configurationUris: state.uris.configurations,
@@ -976,11 +973,11 @@ class LibraryAnalyzer {
976973

977974
void _resolveLibraryImportDirective({
978975
required ImportDirectiveImpl directive,
979-
required LibraryImportElementImpl element,
976+
required LibraryImportImpl element,
980977
required LibraryImportState state,
981978
required ErrorReporter errorReporter,
982979
}) {
983-
directive.element = element;
980+
directive.libraryImport = element;
984981
directive.prefix?.element = element.prefix2?.element;
985982
_resolveUriConfigurations(
986983
configurationNodes: directive.configurations,
@@ -997,10 +994,10 @@ class LibraryAnalyzer {
997994
required FileAnalysis enclosingFile,
998995
required PartDirectiveImpl? directive,
999996
required PartIncludeState partState,
1000-
required PartElementImpl partElement,
997+
required PartIncludeImpl partElement,
1001998
required ErrorReporter errorReporter,
1002999
}) {
1003-
directive?.element = partElement;
1000+
directive?.partInclude = partElement;
10041001

10051002
void reportOnDirectiveUri(
10061003
DiagnosticCode diagnosticCode, {

pkg/analyzer/lib/src/dart/analysis/search.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,8 @@ class Search {
466466
LibraryImport import,
467467
SearchedFiles searchedFiles,
468468
) async {
469-
var legacyElement = import as LibraryImportElementImpl;
470-
var legacyResults = await _searchReferences_Import(
471-
legacyElement,
472-
searchedFiles,
473-
);
469+
import as LibraryImportImpl;
470+
var legacyResults = await _searchReferences_Import(import, searchedFiles);
474471

475472
return legacyResults.map((match) {
476473
return LibraryFragmentSearchMatch(
@@ -836,16 +833,16 @@ class Search {
836833
}
837834

838835
Future<List<SearchResult>> _searchReferences_Import(
839-
LibraryImportElementImpl element,
836+
LibraryImportImpl element,
840837
SearchedFiles searchedFiles,
841838
) async {
842-
String path = element.source.fullName;
839+
String path = element.libraryFragment.source.fullName;
843840
if (!searchedFiles.add(path, this)) {
844841
return const <SearchResult>[];
845842
}
846843

847844
List<SearchResult> results = <SearchResult>[];
848-
LibraryElementImpl libraryElement = element.library;
845+
LibraryElementImpl libraryElement = element.libraryFragment.element;
849846
for (var unitElement in libraryElement.units) {
850847
String unitPath = unitElement.source.fullName;
851848
var unitResult = await _driver.getResolvedUnit(unitPath);
@@ -874,8 +871,7 @@ class Search {
874871
if (unitResult is ResolvedUnitResultImpl) {
875872
var unit = unitResult.unit;
876873
for (var directive in unit.directives) {
877-
if (directive is PartOfDirectiveImpl &&
878-
directive.element == element) {
874+
if (directive is PartOfDirectiveImpl) {
879875
var targetEntity = directive.libraryName ?? directive.uri;
880876
results.add(
881877
SearchResult._(

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,8 +5522,6 @@ final class DefaultFormalParameterImpl extends FormalParameterImpl
55225522
sealed class Directive implements AnnotatedNode {}
55235523

55245524
sealed class DirectiveImpl extends AnnotatedNodeImpl implements Directive {
5525-
FragmentImpl? element;
5526-
55275525
/// Initializes a newly create directive.
55285526
///
55295527
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -6522,6 +6520,9 @@ final class ExportDirectiveImpl extends NamespaceDirectiveImpl
65226520
@override
65236521
final Token exportKeyword;
65246522

6523+
@override
6524+
LibraryExportImpl? libraryExport;
6525+
65256526
/// Initializes a newly created export directive.
65266527
///
65276528
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -6541,12 +6542,6 @@ final class ExportDirectiveImpl extends NamespaceDirectiveImpl
65416542
@override
65426543
Token get firstTokenAfterCommentAndMetadata => exportKeyword;
65436544

6544-
@experimental
6545-
@override
6546-
LibraryExportElementImpl? get libraryExport {
6547-
return element as LibraryExportElementImpl?;
6548-
}
6549-
65506545
@override
65516546
ChildEntities get _childEntities =>
65526547
super._childEntities
@@ -10817,6 +10812,9 @@ final class ImportDirectiveImpl extends NamespaceDirectiveImpl
1081710812

1081810813
SimpleIdentifierImpl? _prefix;
1081910814

10815+
@override
10816+
LibraryImportImpl? libraryImport;
10817+
1082010818
/// Initializes a newly created import directive.
1082110819
///
1082210820
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -10846,12 +10844,6 @@ final class ImportDirectiveImpl extends NamespaceDirectiveImpl
1084610844
@override
1084710845
Token get firstTokenAfterCommentAndMetadata => importKeyword;
1084810846

10849-
@experimental
10850-
@override
10851-
LibraryImportElementImpl? get libraryImport {
10852-
return element as LibraryImportElementImpl?;
10853-
}
10854-
1085510847
@override
1085610848
SimpleIdentifierImpl? get prefix => _prefix;
1085710849

@@ -12078,6 +12070,9 @@ final class LibraryDirectiveImpl extends DirectiveImpl
1207812070
@override
1207912071
final Token semicolon;
1208012072

12073+
@override
12074+
LibraryElementImpl? element2;
12075+
1208112076
/// Initializes a newly created library directive.
1208212077
///
1208312078
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -12092,10 +12087,6 @@ final class LibraryDirectiveImpl extends DirectiveImpl
1209212087
_becomeParentOf(_name);
1209312088
}
1209412089

12095-
@experimental
12096-
@override
12097-
LibraryElementImpl? get element2 => element as LibraryElementImpl?;
12098-
1209912090
@override
1210012091
Token get endToken => semicolon;
1210112092

@@ -14963,6 +14954,9 @@ final class PartDirectiveImpl extends UriBasedDirectiveImpl
1496314954
@override
1496414955
final Token semicolon;
1496514956

14957+
@override
14958+
PartIncludeImpl? partInclude;
14959+
1496614960
/// Initializes a newly created part directive.
1496714961
///
1496814962
/// Either or both of the [comment] and [metadata] can be `null` if the
@@ -14984,10 +14978,6 @@ final class PartDirectiveImpl extends UriBasedDirectiveImpl
1498414978
@override
1498514979
Token get firstTokenAfterCommentAndMetadata => partKeyword;
1498614980

14987-
@experimental
14988-
@override
14989-
PartElementImpl? get partInclude => element as PartElementImpl?;
14990-
1499114981
@override
1499214982
ChildEntities get _childEntities =>
1499314983
super._childEntities

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ class ElementDisplayStringBuilder {
135135
}
136136
}
137137

138-
void writeExportElement(LibraryExportElementImpl element) {
139-
_write('export ');
140-
_writeDirectiveUri(element.uri);
141-
}
142-
143138
void writeExtensionElement(ExtensionFragmentImpl element) {
144139
if (element.isAugmentation) {
145140
_write('augment ');
@@ -210,11 +205,6 @@ class ElementDisplayStringBuilder {
210205
_writeFormalParameters(element.parameters, forElement: true);
211206
}
212207

213-
void writeImportElement(LibraryImportElementImpl element) {
214-
_write('import ');
215-
_writeDirectiveUri(element.uri);
216-
}
217-
218208
void writeInterfaceType(InterfaceType type) {
219209
if (_maybeWriteTypeAlias(type)) {
220210
return;
@@ -234,6 +224,16 @@ class ElementDisplayStringBuilder {
234224
_write('${element.source.uri}');
235225
}
236226

227+
void writeLibraryExport(LibraryExportImpl element) {
228+
_write('export ');
229+
_writeDirectiveUri(element.uri);
230+
}
231+
232+
void writeLibraryImport(LibraryImportImpl element) {
233+
_write('import ');
234+
_writeDirectiveUri(element.uri);
235+
}
236+
237237
void writeMixinElement(MixinFragmentImpl element) {
238238
if (element.isAugmentation) {
239239
_write('augment ');
@@ -253,7 +253,7 @@ class ElementDisplayStringBuilder {
253253
_writeNullability(type.nullabilitySuffix);
254254
}
255255

256-
void writePartElement(PartElementImpl element) {
256+
void writePartInclude(PartIncludeImpl element) {
257257
_write('part ');
258258
_writeDirectiveUri(element.uri);
259259
}
@@ -649,7 +649,7 @@ class ElementDisplayStringBuilder {
649649

650650
enum _WriteFormalParameterKind { requiredPositional, optionalPositional, named }
651651

652-
extension on LibraryImportElementImpl {
652+
extension on LibraryImportImpl {
653653
String get libraryName {
654654
if (uri case DirectiveUriWithRelativeUriString uri) {
655655
return uri.relativeUriString;

0 commit comments

Comments
 (0)