Skip to content

Commit 8c270c4

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Add ElementDirective super-interface.
It is necessary to support source_gen with annotated directives, e.g. to support `package:checks` code generator. Change-Id: Ia6cf97ce7cf9a44158afb5e019805e13ffdbc96e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402424 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Samuel Rawlins <srawlins@google.com>
1 parent d3fed40 commit 8c270c4

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

pkg/analyzer/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.2.0-dev
2+
* Add `ElementDirective` as superinterface for `LibraryExport`, `LibraryImport`,
3+
and `PartInclude`. It implements `Annotatable`.
4+
15
## 7.1.0
26
* New APIs for element model with fragments.
37

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,17 @@ abstract class Element2 {
524524
void visitChildren2<T>(ElementVisitor2<T> visitor);
525525
}
526526

527+
/// A directive within a library fragment.
528+
///
529+
/// Clients may not extend, implement or mix-in this class.
530+
sealed class ElementDirective implements Annotatable {
531+
/// The library fragment that contains this object.
532+
LibraryFragment get libraryFragment;
533+
534+
/// The interpretation of the URI specified in the directive.
535+
DirectiveUri get uri;
536+
}
537+
527538
/// An object that can be used to visit an element structure.
528539
///
529540
/// Clients may not extend, implement or mix-in this class. There are classes
@@ -1619,7 +1630,7 @@ abstract class LibraryElement2 implements Element2, Annotatable {
16191630
/// An `export` directive within a library fragment.
16201631
///
16211632
/// Clients may not extend, implement or mix-in this class.
1622-
abstract class LibraryExport implements Annotatable {
1633+
abstract class LibraryExport implements ElementDirective {
16231634
/// The combinators that were specified as part of the `export` directive.
16241635
///
16251636
/// The combinators are in the order in which they were specified.
@@ -1630,9 +1641,6 @@ abstract class LibraryExport implements Annotatable {
16301641

16311642
/// The offset of the `export` keyword.
16321643
int get exportKeywordOffset;
1633-
1634-
/// The interpretation of the URI specified in the directive.
1635-
DirectiveUri get uri;
16361644
}
16371645

16381646
/// The portion of a [LibraryElement2] coming from a single compilation unit.
@@ -1718,7 +1726,7 @@ abstract class LibraryFragment implements Fragment, Annotatable {
17181726
/// An `import` directive within a library fragment.
17191727
///
17201728
/// Clients may not extend, implement or mix-in this class.
1721-
abstract class LibraryImport implements Annotatable {
1729+
abstract class LibraryImport implements ElementDirective {
17221730
/// The combinators that were specified as part of the `import` directive.
17231731
///
17241732
/// The combinators are in the order in which they were specified.
@@ -1737,19 +1745,13 @@ abstract class LibraryImport implements Annotatable {
17371745
/// an implicit import of `dart:core`.
17381746
bool get isSynthetic;
17391747

1740-
/// The library fragment that contains this object.
1741-
LibraryFragment? get libraryFragment;
1742-
17431748
/// The [Namespace] that this directive contributes to the containing library.
17441749
Namespace get namespace;
17451750

17461751
/// The prefix fragment that was specified as part of the import directive.
17471752
///
17481753
/// Returns `null` if there was no prefix specified.
17491754
PrefixFragment? get prefix2;
1750-
1751-
/// The interpretation of the URI specified in the directive.
1752-
DirectiveUri get uri;
17531755
}
17541756

17551757
/// An element that can be (but is not required to be) defined within a method
@@ -2090,9 +2092,9 @@ abstract class MultiplyDefinedFragment implements Fragment {
20902092
/// A 'part' directive within a library fragment.
20912093
///
20922094
/// Clients may not extend, implement or mix-in this class.
2093-
abstract class PartInclude {
2094-
/// The interpretation of the URI specified in the directive.
2095-
DirectiveUri get uri;
2095+
abstract class PartInclude implements ElementDirective {
2096+
/// The [LibraryFragment], if [uri] is a [DirectiveUriWithUnit].
2097+
LibraryFragment? get includedFragment;
20962098
}
20972099

20982100
/// A pattern variable.

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7251,6 +7251,9 @@ class LibraryExportElementImpl extends _ExistingElementImpl
72517251
@override
72527252
ElementKind get kind => ElementKind.EXPORT;
72537253

7254+
@override
7255+
LibraryFragment get libraryFragment => enclosingElement3;
7256+
72547257
@override
72557258
T? accept<T>(ElementVisitor<T> visitor) {
72567259
return visitor.visitLibraryExportElement(this);
@@ -7321,7 +7324,7 @@ class LibraryImportElementImpl extends _ExistingElementImpl
73217324
LibraryElementImpl get library2 => super.library2 as LibraryElementImpl;
73227325

73237326
@override
7324-
LibraryFragment? get libraryFragment => enclosingElement3;
7327+
LibraryFragment get libraryFragment => enclosingElement3;
73257328

73267329
@override
73277330
Namespace get namespace {
@@ -9265,9 +9268,20 @@ class PartElementImpl extends _ExistingElementImpl
92659268
@override
92669269
String get identifier => 'part';
92679270

9271+
@override
9272+
LibraryFragment? get includedFragment {
9273+
if (uri case DirectiveUriWithUnit uri) {
9274+
return uri.libraryFragment;
9275+
}
9276+
return null;
9277+
}
9278+
92689279
@override
92699280
ElementKind get kind => ElementKind.PART;
92709281

9282+
@override
9283+
LibraryFragment get libraryFragment => enclosingUnit;
9284+
92719285
@override
92729286
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitPartElement(this);
92739287

pkg/analyzer/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: analyzer
2-
version: 7.1.0
2+
version: 7.2.0-dev
33
description: >-
44
This package provides a library that performs static analysis of Dart code.
55
repository: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer

0 commit comments

Comments
 (0)