@@ -53,8 +53,13 @@ void applyCheckElementTextReplacements() {
53
53
* actual text with the given [expected] one.
54
54
*/
55
55
void checkElementText (LibraryElement library, String expected,
56
- {bool withOffsets: false }) {
57
- var writer = new _ElementWriter (withOffsets: withOffsets);
56
+ {bool withOffsets: false ,
57
+ bool withSyntheticAccessors: false ,
58
+ bool withSyntheticFields: false }) {
59
+ var writer = new _ElementWriter (
60
+ withOffsets: withOffsets,
61
+ withSyntheticAccessors: withSyntheticAccessors,
62
+ withSyntheticFields: withSyntheticFields);
58
63
writer.writeLibraryElement (library);
59
64
60
65
String actualText = writer.buffer.toString ();
@@ -117,14 +122,21 @@ void checkElementText(LibraryElement library, String expected,
117
122
class _ElementWriter {
118
123
final bool withOffsets;
119
124
final bool withConstElements;
125
+ final bool withSyntheticAccessors;
126
+ final bool withSyntheticFields;
120
127
final StringBuffer buffer = new StringBuffer ();
121
128
122
- _ElementWriter ({this .withOffsets: false , this .withConstElements: true });
129
+ _ElementWriter (
130
+ {this .withOffsets: false ,
131
+ this .withConstElements: true ,
132
+ this .withSyntheticAccessors,
133
+ this .withSyntheticFields: false });
123
134
124
135
bool isDynamicType (DartType type) => type is DynamicTypeImpl ;
125
136
126
- bool isEnumElement (Element e) {
127
- return e is ClassElement && e.isEnum;
137
+ bool isEnumField (Element e) {
138
+ Element enclosing = e.enclosingElement;
139
+ return enclosing is ClassElement && enclosing.isEnum;
128
140
}
129
141
130
142
void newLineIfNotEmpty () {
@@ -175,7 +187,7 @@ class _ElementWriter {
175
187
176
188
buffer.writeln (' {' );
177
189
178
- e.fields.forEach (writeFieldElement );
190
+ e.fields.forEach (writePropertyInducingElement );
179
191
e.accessors.forEach (writePropertyAccessorElement);
180
192
181
193
if (e.isEnum) {
@@ -410,22 +422,6 @@ class _ElementWriter {
410
422
}
411
423
}
412
424
413
- void writeFieldElement (FieldElement e) {
414
- if (e.isSynthetic && ! isEnumElement (e.enclosingElement)) {
415
- return ;
416
- }
417
-
418
- writeDocumentation (e, ' ' );
419
- writeMetadata (e, ' ' , '\n ' );
420
-
421
- buffer.write (' ' );
422
-
423
- writeIf (e.isStatic, 'static ' );
424
- writeIf (e is FieldElementImpl && e.isCovariant, 'covariant ' );
425
-
426
- writePropertyInducingElement (e);
427
- }
428
-
429
425
void writeFunctionElement (FunctionElement e) {
430
426
writeIf (e.isExternal, 'external ' );
431
427
@@ -623,7 +619,7 @@ class _ElementWriter {
623
619
}
624
620
625
621
void writePropertyAccessorElement (PropertyAccessorElement e) {
626
- if (e.isSynthetic) {
622
+ if (e.isSynthetic && ! withSyntheticAccessors ) {
627
623
return ;
628
624
}
629
625
@@ -633,10 +629,12 @@ class _ElementWriter {
633
629
634
630
buffer.write (' ' );
635
631
632
+ writeIf (e.isSynthetic, 'synthetic ' );
636
633
writeIf (e.isStatic, 'static ' );
637
634
} else {
638
635
writeDocumentation (e);
639
636
writeMetadata (e, '' , '\n ' );
637
+ writeIf (e.isSynthetic, 'synthetic ' );
640
638
}
641
639
642
640
writeIf (e.isExternal, 'external ' );
@@ -669,9 +667,27 @@ class _ElementWriter {
669
667
}
670
668
671
669
void writePropertyInducingElement (PropertyInducingElement e) {
670
+ if (e.isSynthetic && ! withSyntheticFields && ! isEnumField (e)) {
671
+ return ;
672
+ }
673
+
672
674
DartType type = e.type;
673
675
expect (type, isNotNull);
674
676
677
+ if (e.enclosingElement is ClassElement ) {
678
+ writeDocumentation (e, ' ' );
679
+ writeMetadata (e, ' ' , '\n ' );
680
+
681
+ buffer.write (' ' );
682
+
683
+ writeIf (e.isSynthetic, 'synthetic ' );
684
+ writeIf (e.isStatic, 'static ' );
685
+ writeIf (e is FieldElementImpl && e.isCovariant, 'covariant ' );
686
+ } else {
687
+ writeDocumentation (e);
688
+ writeMetadata (e, '' , '\n ' );
689
+ }
690
+
675
691
writeIf (e.isFinal, 'final ' );
676
692
writeIf (e.isConst, 'const ' );
677
693
writeType2 (type);
@@ -693,15 +709,6 @@ class _ElementWriter {
693
709
buffer.writeln (';' );
694
710
}
695
711
696
- void writeTopLevelVariableElement (TopLevelVariableElement e) {
697
- if (e.isSynthetic) {
698
- return ;
699
- }
700
- writeDocumentation (e);
701
- writeMetadata (e, '' , '\n ' );
702
- writePropertyInducingElement (e);
703
- }
704
-
705
712
void writeType (DartType type) {
706
713
if (type is InterfaceType ) {
707
714
buffer.write (type.element.name);
@@ -739,7 +746,7 @@ class _ElementWriter {
739
746
e.functionTypeAliases.forEach (writeFunctionTypeAliasElement);
740
747
e.enums.forEach (writeClassElement);
741
748
e.types.forEach (writeClassElement);
742
- e.topLevelVariables.forEach (writeTopLevelVariableElement );
749
+ e.topLevelVariables.forEach (writePropertyInducingElement );
743
750
e.accessors.forEach (writePropertyAccessorElement);
744
751
e.functions.forEach (writeFunctionElement);
745
752
}
0 commit comments