Skip to content

Commit 8e1dd8d

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add PartInclude.partKeywordOffset
Bug: dart-lang/source_gen#769 Change-Id: I2316e3185326c2b9662a4cfa28dfc7b23a36e5c5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443903 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2586291 commit 8e1dd8d

19 files changed

+102
-5
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Add `documentationComment` to `Element` and `Fragment`.
55
* Add `metadata` to `Element` and `Fragment`.
66
* Add `metadata` to `ElementDirective`.
7+
* Add `partKeywordOffset` to `PartInclude`.
78
* Fix draining analysis events when used by `package:build`.
89
* Deprecate `LibraryElementResult.element2`, use `element` instead.
910
* Deprecate `ResolvedLibraryResult.element2`, use `element` instead.

pkg/analyzer/api.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,6 +4034,7 @@ package:analyzer/dart/element/element.dart:
40344034
PartInclude (class extends Object implements ElementDirective):
40354035
new (constructor: PartInclude Function())
40364036
includedFragment (getter: LibraryFragment?)
4037+
partKeywordOffset (getter: int)
40374038
PatternVariableElement (class extends Object implements LocalVariableElement):
40384039
new (constructor: PatternVariableElement Function())
40394040
firstFragment (getter: PatternVariableFragment)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3422,6 +3422,9 @@ sealed class NamespaceCombinator {
34223422
abstract class PartInclude implements ElementDirective {
34233423
/// The [LibraryFragment], if [uri] is a [DirectiveUriWithUnit].
34243424
LibraryFragment? get includedFragment;
3425+
3426+
/// The offset of the `part` keyword.
3427+
int get partKeywordOffset;
34253428
}
34263429

34273430
/// A pattern variable.

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

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

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ class FileState {
11611161
static UnlinkedPartDirective _serializePart(PartDirective node) {
11621162
return UnlinkedPartDirective(
11631163
configurations: _serializeConfigurations(node.configurations),
1164+
partKeywordOffset: node.partKeyword.offset,
11641165
uri: node.uri.stringValue,
11651166
);
11661167
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,20 @@ class UnlinkedNamespaceDirectiveConfiguration {
342342
}
343343

344344
class UnlinkedPartDirective extends UnlinkedConfigurableUriDirective {
345-
UnlinkedPartDirective({required super.configurations, required super.uri});
345+
final int partKeywordOffset;
346+
347+
UnlinkedPartDirective({
348+
required super.configurations,
349+
required this.partKeywordOffset,
350+
required super.uri,
351+
});
346352

347353
factory UnlinkedPartDirective.read(SummaryDataReader reader) {
348354
return UnlinkedPartDirective(
349355
configurations: reader.readTypedList(
350356
() => UnlinkedNamespaceDirectiveConfiguration.read(reader),
351357
),
358+
partKeywordOffset: reader.readUInt30(),
352359
uri: reader.readOptionalStringUtf8(),
353360
);
354361
}
@@ -359,6 +366,7 @@ class UnlinkedPartDirective extends UnlinkedConfigurableUriDirective {
359366
) {
360367
x.write(sink);
361368
});
369+
sink.writeUInt30(partKeywordOffset);
362370
sink.writeOptionalStringUtf8(uri);
363371
}
364372
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8391,7 +8391,10 @@ abstract class NonParameterVariableFragmentImpl extends VariableFragmentImpl {
83918391
}
83928392

83938393
class PartIncludeImpl extends ElementDirectiveImpl implements PartInclude {
8394-
PartIncludeImpl({required super.uri});
8394+
@override
8395+
int partKeywordOffset;
8396+
8397+
PartIncludeImpl({required super.uri, required this.partKeywordOffset});
83958398

83968399
@override
83978400
LibraryFragmentImpl? get includedFragment {

pkg/analyzer/lib/src/summary2/bundle_reader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ class LibraryReader {
10951095
}) {
10961096
var uri = _readDirectiveUri(containerUnit: containerUnit);
10971097

1098-
return PartIncludeImpl(uri: uri);
1098+
return PartIncludeImpl(partKeywordOffset: -1, uri: uri);
10991099
}
11001100

11011101
/// Read the reference of a non-local element.

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class InformativeDataApplier {
7272
unitElement.withoutLoadingResolution(() {
7373
_applyToImports(unitElement.libraryImports, unitInfo);
7474
_applyToExports(unitElement.libraryExports, unitInfo);
75+
_applyToPartIncludes(unitElement.parts, unitInfo);
7576
});
7677

7778
unitElement.deferConstantOffsets(unitInfo.libraryConstantOffsets, (
@@ -563,6 +564,12 @@ class InformativeDataApplier {
563564
});
564565
}
565566

567+
void _applyToPartIncludes(List<PartIncludeImpl> imports, _InfoUnit info) {
568+
forCorrespondingPairs(imports, info.parts, (element, info) {
569+
element.partKeywordOffset = info.nameOffset;
570+
});
571+
}
572+
566573
void _applyToTopLevelVariable(
567574
TopLevelVariableFragmentImpl element,
568575
_InfoTopLevelVariable info,

pkg/analyzer/lib/src/summary2/library_builder.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,10 @@ class LibraryBuilder {
712712
}
713713
}
714714

715-
return PartIncludeImpl(uri: directiveUri);
715+
return PartIncludeImpl(
716+
partKeywordOffset: state.unlinked.partKeywordOffset,
717+
uri: directiveUri,
718+
);
716719
}
717720

718721
/// We want to have stable references for `loadLibrary` function. But we

0 commit comments

Comments
 (0)