mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:47:36 +00:00
Address some feedback on a previous CL
Change-Id: I2e0f59fb2d22677efa58720d0bd6e73ac65daa22 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350980 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
ff23e8074f
commit
070485c19d
|
@ -364,30 +364,27 @@ class DeclarationHelper {
|
|||
case EnumElement():
|
||||
var augmented = element.augmented;
|
||||
_addStaticMembers(
|
||||
accessors: [...element.accessors, ...?augmented?.accessors],
|
||||
accessors: augmented?.accessors ?? element.accessors,
|
||||
constructors: const [],
|
||||
containingElement: element,
|
||||
fields: [...element.fields, ...?augmented?.fields],
|
||||
methods: [...element.methods, ...?augmented?.methods]);
|
||||
fields: augmented?.fields ?? element.fields,
|
||||
methods: augmented?.methods ?? element.methods);
|
||||
case ExtensionElement():
|
||||
var augmented = element.augmented;
|
||||
_addStaticMembers(
|
||||
accessors: [...element.accessors, ...?augmented?.accessors],
|
||||
accessors: augmented?.accessors ?? element.accessors,
|
||||
constructors: const [],
|
||||
containingElement: element,
|
||||
fields: [...element.fields, ...?augmented?.fields],
|
||||
methods: [...element.methods, ...?augmented?.methods]);
|
||||
fields: augmented?.fields ?? element.fields,
|
||||
methods: augmented?.methods ?? element.methods);
|
||||
case InterfaceElement():
|
||||
var augmented = element.augmented;
|
||||
_addStaticMembers(
|
||||
accessors: [...element.accessors, ...?augmented?.accessors],
|
||||
constructors: [
|
||||
...element.constructors,
|
||||
...?augmented?.constructors
|
||||
],
|
||||
accessors: augmented?.accessors ?? element.accessors,
|
||||
constructors: augmented?.constructors ?? element.constructors,
|
||||
containingElement: element,
|
||||
fields: [...element.fields, ...?augmented?.fields],
|
||||
methods: [...element.methods, ...?augmented?.methods]);
|
||||
fields: augmented?.fields ?? element.fields,
|
||||
methods: augmented?.methods ?? element.methods);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -775,6 +772,8 @@ class DeclarationHelper {
|
|||
|
||||
/// Adds suggestions for the [members] of the [containingElement].
|
||||
void _addMembers(Element containingElement, NodeList<ClassMember> members) {
|
||||
// TODO(brianwilkerson): Replace this method with methods similar to
|
||||
// `_addMembersOfClass`.
|
||||
for (var member in members) {
|
||||
switch (member) {
|
||||
case ConstructorDeclaration():
|
||||
|
@ -832,7 +831,7 @@ class DeclarationHelper {
|
|||
var classElement = parent.declaredElement;
|
||||
if (classElement != null) {
|
||||
if (!mustBeType) {
|
||||
_addMembers(classElement, parent.members);
|
||||
_addMembersOfClass(classElement);
|
||||
}
|
||||
_suggestTypeParameters(classElement.typeParameters);
|
||||
}
|
||||
|
@ -890,6 +889,27 @@ class DeclarationHelper {
|
|||
}
|
||||
}
|
||||
|
||||
/// Adds suggestions for the [members] of the [containingElement].
|
||||
void _addMembersOfClass(ClassElement classElement) {
|
||||
// Add any immediate members from augmentations.
|
||||
var augmented = classElement.augmented;
|
||||
for (var accessor in augmented?.accessors ?? classElement.accessors) {
|
||||
if (!accessor.isSynthetic && (!mustBeStatic || accessor.isStatic)) {
|
||||
_suggestProperty(accessor, classElement);
|
||||
}
|
||||
}
|
||||
for (var field in augmented?.fields ?? classElement.fields) {
|
||||
if (!field.isSynthetic && (!mustBeStatic || field.isStatic)) {
|
||||
_suggestField(field, classElement);
|
||||
}
|
||||
}
|
||||
for (var method in augmented?.methods ?? classElement.methods) {
|
||||
if (!mustBeStatic || method.isStatic) {
|
||||
_suggestMethod(method, classElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds suggestions for the instance members declared on `Object`.
|
||||
void _addMembersOfDartCoreObject() {
|
||||
_addInstanceMembers(
|
||||
|
|
|
@ -11,7 +11,13 @@
|
|||
mixin TestMacros {
|
||||
/// Return the declaration of a macro that will add a member to a library.
|
||||
///
|
||||
/// The text of the member is provided as an argument to the macro.
|
||||
/// The text of the member to be declared is provided as an argument to the
|
||||
/// macro that is returned. For example, the following can be used to generate
|
||||
/// a top level function in the library containing the class `C`:
|
||||
/// ```dart
|
||||
/// @DeclareInLibrary('void generatedTopLevelFunction() {}')
|
||||
/// class C {}
|
||||
/// ```
|
||||
String declareInLibraryMacro() {
|
||||
return '''
|
||||
macro class DeclareInLibrary
|
||||
|
@ -41,7 +47,15 @@ macro class DeclareInLibrary
|
|||
|
||||
/// Return the declaration of a macro that will add a member to a type.
|
||||
///
|
||||
/// The text of the member is provided as an argument to the macro.
|
||||
/// The text of the member to be declared is provided as an argument to the
|
||||
/// macro that is returned. For example, the following can be used to generate
|
||||
/// a method in the class `C`:
|
||||
/// ```dart
|
||||
/// @DeclareInType(' void generatedMethod() {}')
|
||||
/// class C {}
|
||||
/// ```
|
||||
/// (Adding the indent makes the content of the generated code look nicer, but
|
||||
/// isn't required.)
|
||||
String declareInTypeMacro() {
|
||||
return '''
|
||||
macro class DeclareInType
|
||||
|
|
|
@ -1475,7 +1475,14 @@ abstract class InstanceElement
|
|||
@experimental
|
||||
InstanceElement? get augmentationTarget;
|
||||
|
||||
/// The result of applying augmentations.
|
||||
/// The result of merging augmentations.
|
||||
///
|
||||
/// Returns `null` if this element is an augmentation and there is no base
|
||||
/// element from which a merge can be performed.
|
||||
///
|
||||
/// If a non-null instance is returned it will include the members of
|
||||
/// the base element and its augmentations as specified by the merge
|
||||
/// operations.
|
||||
@experimental
|
||||
AugmentedInstanceElement? get augmented;
|
||||
|
||||
|
|
Loading…
Reference in a new issue