@@ -233,26 +233,68 @@ MemberBuilder lookupExtensionMemberBuilder(
233233
234234/// Returns a textual representation of the constant [node] to be used in
235235/// testing.
236- String constantToText (Constant node, {bool isNonNullableByDefault: false }) {
236+ String constantToText (Constant node,
237+ {TypeRepresentation typeRepresentation: TypeRepresentation .legacy}) {
237238 StringBuffer sb = new StringBuffer ();
238- new ConstantToTextVisitor (sb, isNonNullableByDefault ).visit (node);
239+ new ConstantToTextVisitor (sb, typeRepresentation ).visit (node);
239240 return sb.toString ();
240241}
241242
243+ enum TypeRepresentation {
244+ legacy,
245+ explicit,
246+ implicitUndetermined,
247+ nonNullableByDefault,
248+ }
249+
242250/// Returns a textual representation of the type [node] to be used in
243251/// testing.
244- String typeToText (DartType node, {bool isNonNullableByDefault: false }) {
252+ String typeToText (DartType node,
253+ [TypeRepresentation typeRepresentation = TypeRepresentation .legacy]) {
254+ StringBuffer sb = new StringBuffer ();
255+ new DartTypeToTextVisitor (sb, typeRepresentation).visit (node);
256+ return sb.toString ();
257+ }
258+
259+ Set <Class > computeAllSuperclasses (Class node) {
260+ Set <Class > set = < Class > {};
261+ _getAllSuperclasses (node, set );
262+ return set ;
263+ }
264+
265+ void _getAllSuperclasses (Class node, Set <Class > set ) {
266+ if (set .add (node)) {
267+ if (node.supertype != null ) {
268+ _getAllSuperclasses (node.supertype.classNode, set );
269+ }
270+ if (node.mixedInType != null ) {
271+ _getAllSuperclasses (node.mixedInType.classNode, set );
272+ }
273+ for (Supertype interface in node.implementedTypes) {
274+ _getAllSuperclasses (interface .classNode, set );
275+ }
276+ }
277+ }
278+
279+ String supertypeToText (Supertype node,
280+ [TypeRepresentation typeRepresentation = TypeRepresentation .legacy]) {
245281 StringBuffer sb = new StringBuffer ();
246- new DartTypeToTextVisitor (sb, isNonNullableByDefault).visit (node);
282+ sb.write (node.classNode.name);
283+ if (node.typeArguments.isNotEmpty) {
284+ sb.write ('<' );
285+ new DartTypeToTextVisitor (sb, typeRepresentation)
286+ .visitList (node.typeArguments);
287+ sb.write ('>' );
288+ }
247289 return sb.toString ();
248290}
249291
250292class ConstantToTextVisitor implements ConstantVisitor <void > {
251293 final StringBuffer sb;
252294 final DartTypeToTextVisitor typeToText;
253295
254- ConstantToTextVisitor (this .sb, bool isNonNullableByDefault )
255- : typeToText = new DartTypeToTextVisitor (sb, isNonNullableByDefault );
296+ ConstantToTextVisitor (this .sb, TypeRepresentation typeRepresentation )
297+ : typeToText = new DartTypeToTextVisitor (sb, typeRepresentation );
256298
257299 void visit (Constant node) => node.accept (this );
258300
@@ -375,9 +417,9 @@ class ConstantToTextVisitor implements ConstantVisitor<void> {
375417
376418class DartTypeToTextVisitor implements DartTypeVisitor <void > {
377419 final StringBuffer sb;
378- final bool isNonNullableByDefault ;
420+ final TypeRepresentation typeRepresentation ;
379421
380- DartTypeToTextVisitor (this .sb, this .isNonNullableByDefault );
422+ DartTypeToTextVisitor (this .sb, this .typeRepresentation );
381423
382424 void visit (DartType node) => node.accept (this );
383425
@@ -421,8 +463,7 @@ class DartTypeToTextVisitor implements DartTypeVisitor<void> {
421463 sb.write ('>' );
422464 }
423465 if (! isNull (node)) {
424- sb.write (nullabilityToText (node.nullability,
425- isNonNullableByDefault: isNonNullableByDefault));
466+ sb.write (nullabilityToText (node.nullability, typeRepresentation));
426467 }
427468 }
428469
@@ -454,16 +495,14 @@ class DartTypeToTextVisitor implements DartTypeVisitor<void> {
454495 sb.write ('}' );
455496 }
456497 sb.write (')' );
457- sb.write (nullabilityToText (node.nullability,
458- isNonNullableByDefault: isNonNullableByDefault));
498+ sb.write (nullabilityToText (node.nullability, typeRepresentation));
459499 sb.write ('->' );
460500 visit (node.returnType);
461501 }
462502
463503 void visitTypeParameterType (TypeParameterType node) {
464504 sb.write (node.parameter.name);
465- sb.write (nullabilityToText (node.nullability,
466- isNonNullableByDefault: isNonNullableByDefault));
505+ sb.write (nullabilityToText (node.nullability, typeRepresentation));
467506 if (node.promotedBound != null ) {
468507 sb.write (' & ' );
469508 visit (node.promotedBound);
@@ -477,8 +516,7 @@ class DartTypeToTextVisitor implements DartTypeVisitor<void> {
477516 visitList (node.typeArguments);
478517 sb.write ('>' );
479518 }
480- sb.write (nullabilityToText (node.nullability,
481- isNonNullableByDefault: isNonNullableByDefault));
519+ sb.write (nullabilityToText (node.nullability, typeRepresentation));
482520 }
483521}
484522
@@ -546,8 +584,12 @@ String typeVariableBuilderToText(TypeVariableBuilder typeVariable) {
546584}
547585
548586/// Returns a textual representation of [errors] to be used in testing.
549- String errorsToText (List <FormattedMessage > errors) {
550- return errors.map ((m) => m.message).join (',' );
587+ String errorsToText (List <FormattedMessage > errors, {bool useCodes: false }) {
588+ if (useCodes) {
589+ return errors.map ((m) => m.code).join (',' );
590+ } else {
591+ return errors.map ((m) => m.message).join (',' );
592+ }
551593}
552594
553595/// Returns a textual representation of [descriptor] to be used in testing.
@@ -588,18 +630,39 @@ String extensionMethodDescriptorToText(ExtensionMemberDescriptor descriptor) {
588630}
589631
590632/// Returns a textual representation of [nullability] to be used in testing.
591- String nullabilityToText (Nullability nullability,
592- {bool isNonNullableByDefault}) {
593- assert (isNonNullableByDefault != null );
633+ String nullabilityToText (
634+ Nullability nullability, TypeRepresentation typeRepresentation) {
594635 switch (nullability) {
595636 case Nullability .nonNullable:
596- return isNonNullableByDefault ? '' : '!' ;
637+ switch (typeRepresentation) {
638+ case TypeRepresentation .explicit:
639+ case TypeRepresentation .legacy:
640+ case TypeRepresentation .implicitUndetermined:
641+ return '!' ;
642+ case TypeRepresentation .nonNullableByDefault:
643+ return '' ;
644+ }
645+ break ;
597646 case Nullability .nullable:
598647 return '?' ;
599648 case Nullability .undetermined:
600- return '%' ;
649+ switch (typeRepresentation) {
650+ case TypeRepresentation .implicitUndetermined:
651+ return '' ;
652+ default :
653+ return '%' ;
654+ }
655+ break ;
601656 case Nullability .legacy:
602- return isNonNullableByDefault ? '*' : '' ;
657+ switch (typeRepresentation) {
658+ case TypeRepresentation .legacy:
659+ return '' ;
660+ case TypeRepresentation .explicit:
661+ case TypeRepresentation .nonNullableByDefault:
662+ case TypeRepresentation .implicitUndetermined:
663+ return '*' ;
664+ }
665+ break ;
603666 }
604667 throw new UnsupportedError ('Unexpected nullability: $nullability .' );
605668}
0 commit comments