mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:50:11 +00:00
library scope extensions
Change-Id: I060ddd02145d949b0becf7d2fb20f2ca01401766 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108461 Commit-Queue: Phil Quitslund <pquitslund@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
9503969664
commit
f939ad3964
|
@ -559,6 +559,8 @@ class LibraryImportScope extends Scope {
|
|||
* A scope containing all of the names defined in a given library.
|
||||
*/
|
||||
class LibraryScope extends EnclosedScope {
|
||||
List<ExtensionElement> _extensions = <ExtensionElement>[];
|
||||
|
||||
/**
|
||||
* Initialize a newly created scope representing the names defined in the
|
||||
* [definingLibrary].
|
||||
|
@ -576,6 +578,9 @@ class LibraryScope extends EnclosedScope {
|
|||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<ExtensionElement> get extensions => _extensions;
|
||||
|
||||
/**
|
||||
* Add to this scope all of the public top-level names that are defined in the
|
||||
* given [compilationUnit].
|
||||
|
@ -589,6 +594,7 @@ class LibraryScope extends EnclosedScope {
|
|||
}
|
||||
for (ExtensionElement element in compilationUnit.extensions) {
|
||||
define(element);
|
||||
_extensions.add(element);
|
||||
}
|
||||
for (FunctionElement element in compilationUnit.functions) {
|
||||
define(element);
|
||||
|
@ -982,6 +988,12 @@ abstract class Scope {
|
|||
*/
|
||||
Scope get enclosingScope => null;
|
||||
|
||||
/**
|
||||
* The list of extensions defined in this scope.
|
||||
*/
|
||||
List<ExtensionElement> get extensions =>
|
||||
enclosingScope == null ? <ExtensionElement>[] : enclosingScope.extensions;
|
||||
|
||||
/**
|
||||
* Add the given [element] to this scope. If there is already an element with
|
||||
* the given name defined in this scope, then the original element will
|
||||
|
|
|
@ -336,6 +336,22 @@ class LibraryScopeTest extends ResolverTestCase {
|
|||
AstTestFactory.identifier3(importedTypeName), definingLibrary),
|
||||
importedType);
|
||||
}
|
||||
|
||||
void test_extensions() {
|
||||
SimpleIdentifier identifier = AstTestFactory.identifier3('test_extension');
|
||||
ExtensionElement extension = ExtensionElementImpl.forNode(identifier);
|
||||
|
||||
CompilationUnitElementImpl compilationUnit =
|
||||
ElementFactory.compilationUnit('/test.dart');
|
||||
compilationUnit.extensions = <ExtensionElement>[extension];
|
||||
|
||||
String libraryName = 'lib';
|
||||
LibraryElementImpl library = new LibraryElementImpl(
|
||||
null, null, libraryName, 0, libraryName.length, false);
|
||||
library.definingCompilationUnit = compilationUnit;
|
||||
|
||||
expect(LibraryScope(library).extensions, contains(extension));
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
|
|
Loading…
Reference in a new issue