@@ -64,6 +64,11 @@ class DynamicTypeImpl extends TypeImpl {
6464 @override
6565 bool operator == (Object object) => identical (object, this );
6666
67+ @override
68+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
69+ buffer.write ('dynamic' );
70+ }
71+
6772 @override
6873 DartType replaceTopAndBottom (TypeProvider typeProvider,
6974 {bool isCovariant = true }) {
@@ -142,50 +147,6 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
142147 @override
143148 List <TypeParameterElement > get boundTypeParameters => typeFormals;
144149
145- @override
146- String get displayName {
147- if (name == null || name.isEmpty) {
148- // Function types have an empty name when they are defined implicitly by
149- // either a closure or as part of a parameter declaration.
150- StringBuffer buffer = new StringBuffer ();
151- appendTo (buffer);
152- if (nullabilitySuffix == NullabilitySuffix .question) {
153- buffer.write ('?' );
154- }
155- return buffer.toString ();
156- }
157-
158- List <DartType > typeArguments = this .typeArguments;
159-
160- bool allTypeArgumentsAreDynamic () {
161- for (DartType type in typeArguments) {
162- if (type != null && ! type.isDynamic) {
163- return false ;
164- }
165- }
166- return true ;
167- }
168-
169- StringBuffer buffer = new StringBuffer ();
170- buffer.write (name);
171- // If there is at least one non-dynamic type, then list them out.
172- if (! allTypeArgumentsAreDynamic ()) {
173- buffer.write ("<" );
174- for (int i = 0 ; i < typeArguments.length; i++ ) {
175- if (i != 0 ) {
176- buffer.write (", " );
177- }
178- DartType typeArg = typeArguments[i];
179- buffer.write (typeArg.displayName);
180- }
181- buffer.write (">" );
182- }
183- if (nullabilitySuffix == NullabilitySuffix .question) {
184- buffer.write ('?' );
185- }
186- return buffer.toString ();
187- }
188-
189150 @override
190151 FunctionTypedElement get element {
191152 var element = super .element;
@@ -294,7 +255,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
294255 }
295256
296257 @override
297- void appendTo (StringBuffer buffer, {bool withNullability = false }) {
258+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
298259 // TODO(paulberry): eliminate code duplication with
299260 // _ElementWriter.writeType. See issue #35818.
300261 if (typeFormals.isNotEmpty) {
@@ -944,39 +905,6 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
944905 return _constructors;
945906 }
946907
947- @override
948- String get displayName {
949- List <DartType > typeArguments = this .typeArguments;
950-
951- bool allTypeArgumentsAreDynamic () {
952- for (DartType type in typeArguments) {
953- if (type != null && ! type.isDynamic) {
954- return false ;
955- }
956- }
957- return true ;
958- }
959-
960- StringBuffer buffer = new StringBuffer ();
961- buffer.write (name);
962- // If there is at least one non-dynamic type, then list them out.
963- if (! allTypeArgumentsAreDynamic ()) {
964- buffer.write ("<" );
965- for (int i = 0 ; i < typeArguments.length; i++ ) {
966- if (i != 0 ) {
967- buffer.write (", " );
968- }
969- DartType typeArg = typeArguments[i];
970- buffer.write (typeArg.displayName);
971- }
972- buffer.write (">" );
973- }
974- if (nullabilitySuffix == NullabilitySuffix .question) {
975- buffer.write ('?' );
976- }
977- return buffer.toString ();
978- }
979-
980908 @override
981909 ClassElement get element => super .element;
982910
@@ -1175,8 +1103,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
11751103 }
11761104
11771105 @override
1178- void appendTo (StringBuffer buffer, {bool withNullability = false }) {
1179- buffer.write (name);
1106+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
1107+ buffer.write (element. name);
11801108 int argumentCount = typeArguments.length;
11811109 if (argumentCount > 0 ) {
11821110 buffer.write ("<" );
@@ -1902,6 +1830,14 @@ class NeverTypeImpl extends TypeImpl {
19021830 @override
19031831 bool operator == (Object object) => identical (object, this );
19041832
1833+ @override
1834+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
1835+ buffer.write ('Never' );
1836+ if (withNullability) {
1837+ _appendNullability (buffer);
1838+ }
1839+ }
1840+
19051841 @override
19061842 DartType replaceTopAndBottom (TypeProvider typeProvider,
19071843 {bool isCovariant = true }) {
@@ -1963,7 +1899,9 @@ abstract class TypeImpl implements DartType {
19631899 TypeImpl (this ._element, this .name);
19641900
19651901 @override
1966- String get displayName => name;
1902+ String get displayName {
1903+ return getDisplayString (withNullability: false );
1904+ }
19671905
19681906 @override
19691907 Element get element => _element;
@@ -2028,15 +1966,13 @@ abstract class TypeImpl implements DartType {
20281966 /**
20291967 * Append a textual representation of this type to the given [buffer] .
20301968 */
2031- void appendTo (StringBuffer buffer, {bool withNullability = false }) {
2032- if (name == null ) {
2033- buffer.write ("<unnamed type>" );
2034- } else {
2035- buffer.write (name);
2036- }
2037- if (withNullability) {
2038- _appendNullability (buffer);
2039- }
1969+ void appendTo (StringBuffer buffer, {@required bool withNullability});
1970+
1971+ @override
1972+ String getDisplayString ({bool withNullability = false }) {
1973+ var buffer = StringBuffer ();
1974+ appendTo (buffer, withNullability: withNullability);
1975+ return buffer.toString ();
20401976 }
20411977
20421978 /// Replaces all covariant occurrences of `dynamic` , `Object` , and `void` with
@@ -2061,9 +1997,7 @@ abstract class TypeImpl implements DartType {
20611997
20621998 @override
20631999 String toString ({bool withNullability = false }) {
2064- StringBuffer buffer = new StringBuffer ();
2065- appendTo (buffer, withNullability: withNullability);
2066- return buffer.toString ();
2000+ return getDisplayString (withNullability: withNullability);
20672001 }
20682002
20692003 /**
@@ -2081,11 +2015,6 @@ abstract class TypeImpl implements DartType {
20812015 TypeImpl withNullability (NullabilitySuffix nullabilitySuffix);
20822016
20832017 void _appendNullability (StringBuffer buffer) {
2084- if (isDynamic || isVoid) {
2085- // These types don't have nullability variations, so don't append
2086- // anything.
2087- return ;
2088- }
20892018 switch (nullabilitySuffix) {
20902019 case NullabilitySuffix .question:
20912020 buffer.write ('?' );
@@ -2181,6 +2110,14 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
21812110 other.nullabilitySuffix == nullabilitySuffix;
21822111 }
21832112
2113+ @override
2114+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
2115+ buffer.write (element.name);
2116+ if (withNullability) {
2117+ _appendNullability (buffer);
2118+ }
2119+ }
2120+
21842121 @override
21852122 DartType replaceTopAndBottom (TypeProvider typeProvider,
21862123 {bool isCovariant = true }) {
@@ -2319,6 +2256,11 @@ class VoidTypeImpl extends TypeImpl implements VoidType {
23192256 @override
23202257 bool operator == (Object object) => identical (object, this );
23212258
2259+ @override
2260+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
2261+ buffer.write ('void' );
2262+ }
2263+
23222264 @override
23232265 DartType replaceTopAndBottom (TypeProvider typeProvider,
23242266 {bool isCovariant = true }) {
0 commit comments