Skip to content

Commit 951d966

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate BestPracticesVerifier.
Change-Id: Ib2ac5ed4cd5a82fc2b880a5a56465d04ebbbbf43 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409383 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
1 parent 4a62cfa commit 951d966

File tree

3 files changed

+298
-237
lines changed

3 files changed

+298
-237
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,32 @@ extension DartTypeExtension on DartType {
2222
}
2323

2424
extension Element2Extension on Element2 {
25+
/// Return `true` if this element, the enclosing class (if there is one), or
26+
/// the enclosing library, has been annotated with the `@doNotStore`
27+
/// annotation.
28+
bool get hasOrInheritsDoNotStore {
29+
if (this case Annotatable annotatable) {
30+
if (annotatable.metadata2.hasDoNotStore) {
31+
return true;
32+
}
33+
}
34+
35+
var ancestor = enclosingElement2;
36+
if (ancestor is InterfaceElement2) {
37+
if (ancestor.metadata2.hasDoNotStore) {
38+
return true;
39+
}
40+
ancestor = ancestor.enclosingElement2;
41+
} else if (ancestor is ExtensionElement2) {
42+
if (ancestor.metadata2.hasDoNotStore) {
43+
return true;
44+
}
45+
ancestor = ancestor.enclosingElement2;
46+
}
47+
48+
return ancestor is LibraryElement2 && ancestor.metadata2.hasDoNotStore;
49+
}
50+
2551
/// Return `true` if this element is an instance member of a class or mixin.
2652
///
2753
/// Only [MethodElement2]s, [GetterElement]s, and [SetterElement]s are

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ class NamespaceBuilder {
180180
return Namespace(exportedNames);
181181
}
182182

183+
/// Create a namespace representing the export namespace of the given
184+
/// [export].
185+
Namespace createExportNamespaceForDirective2(LibraryExport export) {
186+
var exportedLibrary = export.exportedLibrary2;
187+
if (exportedLibrary == null) {
188+
//
189+
// The exported library will be null if the URI does not reference a valid
190+
// library.
191+
//
192+
return Namespace.EMPTY;
193+
}
194+
Map<String, Element> exportedNames =
195+
_getExportMapping(exportedLibrary.asElement);
196+
exportedNames = _applyCombinators(exportedNames, export.combinators);
197+
return Namespace(exportedNames);
198+
}
199+
183200
/// Create a namespace representing the export namespace of the given
184201
/// [library].
185202
Namespace createExportNamespaceForLibrary(LibraryElement2 library) {

0 commit comments

Comments
 (0)