@@ -64,6 +64,11 @@ class DynamicTypeImpl extends TypeImpl {
64
64
@override
65
65
bool operator == (Object object) => identical (object, this );
66
66
67
+ @override
68
+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
69
+ buffer.write ('dynamic' );
70
+ }
71
+
67
72
@override
68
73
DartType replaceTopAndBottom (TypeProvider typeProvider,
69
74
{bool isCovariant = true }) {
@@ -142,50 +147,6 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
142
147
@override
143
148
List <TypeParameterElement > get boundTypeParameters => typeFormals;
144
149
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
-
189
150
@override
190
151
FunctionTypedElement get element {
191
152
var element = super .element;
@@ -294,7 +255,7 @@ class FunctionTypeImpl extends TypeImpl implements FunctionType {
294
255
}
295
256
296
257
@override
297
- void appendTo (StringBuffer buffer, {bool withNullability = false }) {
258
+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
298
259
// TODO(paulberry): eliminate code duplication with
299
260
// _ElementWriter.writeType. See issue #35818.
300
261
if (typeFormals.isNotEmpty) {
@@ -944,39 +905,6 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
944
905
return _constructors;
945
906
}
946
907
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
-
980
908
@override
981
909
ClassElement get element => super .element;
982
910
@@ -1175,8 +1103,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
1175
1103
}
1176
1104
1177
1105
@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);
1180
1108
int argumentCount = typeArguments.length;
1181
1109
if (argumentCount > 0 ) {
1182
1110
buffer.write ("<" );
@@ -1902,6 +1830,14 @@ class NeverTypeImpl extends TypeImpl {
1902
1830
@override
1903
1831
bool operator == (Object object) => identical (object, this );
1904
1832
1833
+ @override
1834
+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
1835
+ buffer.write ('Never' );
1836
+ if (withNullability) {
1837
+ _appendNullability (buffer);
1838
+ }
1839
+ }
1840
+
1905
1841
@override
1906
1842
DartType replaceTopAndBottom (TypeProvider typeProvider,
1907
1843
{bool isCovariant = true }) {
@@ -1963,7 +1899,9 @@ abstract class TypeImpl implements DartType {
1963
1899
TypeImpl (this ._element, this .name);
1964
1900
1965
1901
@override
1966
- String get displayName => name;
1902
+ String get displayName {
1903
+ return getDisplayString (withNullability: false );
1904
+ }
1967
1905
1968
1906
@override
1969
1907
Element get element => _element;
@@ -2028,15 +1966,13 @@ abstract class TypeImpl implements DartType {
2028
1966
/**
2029
1967
* Append a textual representation of this type to the given [buffer] .
2030
1968
*/
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 ();
2040
1976
}
2041
1977
2042
1978
/// Replaces all covariant occurrences of `dynamic` , `Object` , and `void` with
@@ -2061,9 +1997,7 @@ abstract class TypeImpl implements DartType {
2061
1997
2062
1998
@override
2063
1999
String toString ({bool withNullability = false }) {
2064
- StringBuffer buffer = new StringBuffer ();
2065
- appendTo (buffer, withNullability: withNullability);
2066
- return buffer.toString ();
2000
+ return getDisplayString (withNullability: withNullability);
2067
2001
}
2068
2002
2069
2003
/**
@@ -2081,11 +2015,6 @@ abstract class TypeImpl implements DartType {
2081
2015
TypeImpl withNullability (NullabilitySuffix nullabilitySuffix);
2082
2016
2083
2017
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
- }
2089
2018
switch (nullabilitySuffix) {
2090
2019
case NullabilitySuffix .question:
2091
2020
buffer.write ('?' );
@@ -2181,6 +2110,14 @@ class TypeParameterTypeImpl extends TypeImpl implements TypeParameterType {
2181
2110
other.nullabilitySuffix == nullabilitySuffix;
2182
2111
}
2183
2112
2113
+ @override
2114
+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
2115
+ buffer.write (element.name);
2116
+ if (withNullability) {
2117
+ _appendNullability (buffer);
2118
+ }
2119
+ }
2120
+
2184
2121
@override
2185
2122
DartType replaceTopAndBottom (TypeProvider typeProvider,
2186
2123
{bool isCovariant = true }) {
@@ -2319,6 +2256,11 @@ class VoidTypeImpl extends TypeImpl implements VoidType {
2319
2256
@override
2320
2257
bool operator == (Object object) => identical (object, this );
2321
2258
2259
+ @override
2260
+ void appendTo (StringBuffer buffer, {@required bool withNullability}) {
2261
+ buffer.write ('void' );
2262
+ }
2263
+
2322
2264
@override
2323
2265
DartType replaceTopAndBottom (TypeProvider typeProvider,
2324
2266
{bool isCovariant = true }) {
0 commit comments