Skip to content

Commit 1e0223e

Browse files
jakemac53Commit Queue
authored and
Commit Queue
committed
Clean up VariableDeclaration and MemberDeclaration APIs.
- Adds hasInitializer and hasConst to VariableDeclaration. - Renames isStatic to hasStatic to be consistent with other members. - Improves serialization tests by randomizing some values, which should help to catch ordering errors in serialization. Change-Id: I44199b1b058444510b9fa55afe0611187b90fc95 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352540 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Morgan :) <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]> Auto-Submit: Jake Macdonald <[email protected]>
1 parent 5394052 commit 1e0223e

File tree

11 files changed

+201
-141
lines changed

11 files changed

+201
-141
lines changed

pkg/_fe_analyzer_shared/lib/src/macros/api/introspection.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ abstract interface class MemberDeclaration implements Declaration {
119119
/// The type that defines this member.
120120
Identifier get definingType;
121121

122-
/// Whether or not this is a static member.
123-
bool get isStatic;
122+
/// Whether or not member has the `static` keyword.
123+
bool get hasStatic;
124124
}
125125

126126
/// Marker interface for a declaration that defines a new type in the program.
@@ -288,12 +288,18 @@ abstract interface class ConstructorDeclaration implements MethodDeclaration {
288288

289289
/// Variable introspection information.
290290
abstract interface class VariableDeclaration implements Declaration {
291+
/// Whether this variable has a `const` modifier.
292+
bool get hasConst;
293+
291294
/// Whether this variable has an `external` modifier.
292295
bool get hasExternal;
293296

294297
/// Whether this variable has a `final` modifier.
295298
bool get hasFinal;
296299

300+
/// Whether this variable has an initializer at its declaration.
301+
bool get hasInitializer;
302+
297303
/// Whether this variable has a `late` modifier.
298304
bool get hasLate;
299305

pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,15 @@ List<DeclarationCode> _buildVariableAugmentations(
532532
augmentations.add(new DeclarationCode.fromParts([
533533
if (declaration is FieldDeclaration) ' ',
534534
'augment ',
535-
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
535+
if (declaration is FieldDeclaration && declaration.hasStatic) 'static ',
536536
getter,
537537
]));
538538
}
539539
if (setter != null) {
540540
augmentations.add(new DeclarationCode.fromParts([
541541
if (declaration is FieldDeclaration) ' ',
542542
'augment ',
543-
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
543+
if (declaration is FieldDeclaration && declaration.hasStatic) 'static ',
544544
setter,
545545
]));
546546
}
@@ -549,7 +549,7 @@ List<DeclarationCode> _buildVariableAugmentations(
549549
if (initializerDocComments != null) initializerDocComments,
550550
if (declaration is FieldDeclaration) ' ',
551551
'augment ',
552-
if (declaration is FieldDeclaration && declaration.isStatic) 'static ',
552+
if (declaration is FieldDeclaration && declaration.hasStatic) 'static ',
553553
if (declaration.hasFinal) 'final ',
554554
declaration.type.code,
555555
' ',
@@ -581,7 +581,7 @@ DeclarationCode _buildFunctionAugmentation(
581581
declaration.definingType.name,
582582
if (declaration.identifier.name.isNotEmpty) '.',
583583
] else ...[
584-
if (declaration is MethodDeclaration && declaration.isStatic) 'static ',
584+
if (declaration is MethodDeclaration && declaration.hasStatic) 'static ',
585585
declaration.returnType.code,
586586
' ',
587587
if (declaration.isOperator) 'operator ',

pkg/_fe_analyzer_shared/lib/src/macros/executor/introspection_impls.dart

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
612612
RemoteInstanceKind get kind => RemoteInstanceKind.methodDeclaration;
613613

614614
@override
615-
final bool isStatic;
615+
final bool hasStatic;
616616

617617
MethodDeclarationImpl({
618618
// Declaration fields.
@@ -632,15 +632,15 @@ class MethodDeclarationImpl extends FunctionDeclarationImpl
632632
required super.typeParameters,
633633
// Method fields.
634634
required this.definingType,
635-
required this.isStatic,
635+
required this.hasStatic,
636636
});
637637

638638
@override
639639
void serializeUncached(Serializer serializer, {bool isConstructor = false}) {
640640
super.serializeUncached(serializer, isConstructor: isConstructor);
641641

642642
definingType.serialize(serializer);
643-
if (!isConstructor) serializer.addBool(isStatic);
643+
if (!isConstructor) serializer.addBool(hasStatic);
644644
}
645645
}
646646

@@ -673,7 +673,7 @@ class ConstructorDeclarationImpl extends MethodDeclarationImpl
673673
isGetter: false,
674674
isOperator: false,
675675
isSetter: false,
676-
isStatic: true,
676+
hasStatic: true,
677677
);
678678

679679
@override
@@ -687,12 +687,18 @@ class ConstructorDeclarationImpl extends MethodDeclarationImpl
687687

688688
class VariableDeclarationImpl extends DeclarationImpl
689689
implements VariableDeclaration {
690+
@override
691+
final bool hasConst;
692+
690693
@override
691694
final bool hasExternal;
692695

693696
@override
694697
final bool hasFinal;
695698

699+
@override
700+
final bool hasInitializer;
701+
696702
@override
697703
final bool hasLate;
698704

@@ -707,8 +713,10 @@ class VariableDeclarationImpl extends DeclarationImpl
707713
required super.identifier,
708714
required super.library,
709715
required super.metadata,
716+
required this.hasConst,
710717
required this.hasExternal,
711718
required this.hasFinal,
719+
required this.hasInitializer,
712720
required this.hasLate,
713721
required this.type,
714722
});
@@ -718,8 +726,10 @@ class VariableDeclarationImpl extends DeclarationImpl
718726
super.serializeUncached(serializer);
719727

720728
serializer
729+
..addBool(hasConst)
721730
..addBool(hasExternal)
722731
..addBool(hasFinal)
732+
..addBool(hasInitializer)
723733
..addBool(hasLate);
724734
type.serialize(serializer);
725735
}
@@ -734,7 +744,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
734744
final bool hasAbstract;
735745

736746
@override
737-
final bool isStatic;
747+
final bool hasStatic;
738748

739749
FieldDeclarationImpl({
740750
// Declaration fields.
@@ -743,14 +753,16 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
743753
required super.library,
744754
required super.metadata,
745755
// Variable fields.
756+
required super.hasConst,
746757
required super.hasExternal,
747758
required super.hasFinal,
759+
required super.hasInitializer,
748760
required super.hasLate,
749761
required super.type,
750762
// Field fields.
751763
required this.definingType,
752764
required this.hasAbstract,
753-
required this.isStatic,
765+
required this.hasStatic,
754766
});
755767

756768
@override
@@ -763,7 +775,7 @@ class FieldDeclarationImpl extends VariableDeclarationImpl
763775
definingType.serialize(serializer);
764776
serializer
765777
..addBool(hasAbstract)
766-
..addBool(isStatic);
778+
..addBool(hasStatic);
767779
}
768780
}
769781

pkg/_fe_analyzer_shared/lib/src/macros/executor/serialization_extensions.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ extension DeserializerExtensions on Deserializer {
229229
returnType: RemoteInstance.deserialize(this),
230230
typeParameters: (this..moveNext())._expectRemoteInstanceList(),
231231
definingType: RemoteInstance.deserialize(this),
232-
isStatic: (this..moveNext()).expectBool(),
232+
hasStatic: (this..moveNext()).expectBool(),
233233
);
234234

235235
ConstructorDeclarationImpl _expectConstructorDeclaration(int id) =>
@@ -254,25 +254,32 @@ extension DeserializerExtensions on Deserializer {
254254
identifier: expectRemoteInstance(),
255255
library: RemoteInstance.deserialize(this),
256256
metadata: (this..moveNext())._expectRemoteInstanceList(),
257+
hasConst: (this..moveNext()).expectBool(),
257258
hasExternal: (this..moveNext()).expectBool(),
258259
hasFinal: (this..moveNext()).expectBool(),
260+
hasInitializer: (this..moveNext()).expectBool(),
259261
hasLate: (this..moveNext()).expectBool(),
260262
type: RemoteInstance.deserialize(this),
261263
);
262264

263265
FieldDeclarationImpl _expectFieldDeclaration(int id) =>
264266
new FieldDeclarationImpl(
265267
id: id,
268+
// Declaration fields.
266269
identifier: expectRemoteInstance(),
267270
library: RemoteInstance.deserialize(this),
268271
metadata: (this..moveNext())._expectRemoteInstanceList(),
272+
// VariableDeclaration fields
273+
hasConst: (this..moveNext()).expectBool(),
269274
hasExternal: (this..moveNext()).expectBool(),
270275
hasFinal: (this..moveNext()).expectBool(),
276+
hasInitializer: (this..moveNext()).expectBool(),
271277
hasLate: (this..moveNext()).expectBool(),
272278
type: RemoteInstance.deserialize(this),
279+
// FieldDeclaration fields
273280
definingType: RemoteInstance.deserialize(this),
274281
hasAbstract: (this..moveNext()).expectBool(),
275-
isStatic: (this..moveNext()).expectBool(),
282+
hasStatic: (this..moveNext()).expectBool(),
276283
);
277284

278285
ClassDeclarationImpl _expectClassDeclaration(int id) =>

pkg/_fe_analyzer_shared/test/macros/executor/augmentation_library_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,12 @@ void main() {
393393
metadata: [],
394394
definingType: myEnum.identifier,
395395
hasAbstract: false,
396+
hasConst: false,
396397
hasExternal: false,
397398
hasFinal: true,
399+
hasInitializer: false,
398400
hasLate: false,
399-
isStatic: false,
401+
hasStatic: false,
400402
type: NamedTypeAnnotationImpl(
401403
id: RemoteInstance.uniqueId,
402404
isNullable: false,
@@ -470,7 +472,7 @@ void main() {
470472
metadata: [],
471473
definingType: myExtension.identifier,
472474
hasExternal: false,
473-
isStatic: false,
475+
hasStatic: false,
474476
returnType: NamedTypeAnnotationImpl(
475477
id: RemoteInstance.uniqueId,
476478
isNullable: false,

0 commit comments

Comments
 (0)