Skip to content

Commit b92cd2c

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Deprecate DartType.displayName, use getDisplayString() instead.
We call it with `withNullability: false` almost everywhere. My attempt to update all places turned out to be a long chain of changes. So, instead I will make decisions and updates in separate CLs, starting with ErrorReporter. R=brianwilkerson@google.com, paulberry@google.com Change-Id: I9d72475577ba2934bed1c06a4808ab620e92a20e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127441 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 0939101 commit b92cd2c

File tree

25 files changed

+118
-80
lines changed

25 files changed

+118
-80
lines changed

pkg/analysis_server/lib/src/computer/computer_signature.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DartUnitSignatureComputer {
8181
? ParameterKind.OPTIONAL
8282
: param.isPositional ? ParameterKind.REQUIRED : ParameterKind.NAMED,
8383
param.displayName,
84-
param.type.displayName,
84+
param.type.getDisplayString(withNullability: false),
8585
defaultValue: param.defaultValueCode);
8686
}
8787
}

pkg/analysis_server/lib/src/protocol_server.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ String getReturnTypeString(engine.Element element) {
6666
}
6767
} else if (element is engine.VariableElement) {
6868
engine.DartType type = element.type;
69-
return type != null ? type.displayName : 'dynamic';
69+
return type != null
70+
? type.getDisplayString(withNullability: false)
71+
: 'dynamic';
7072
} else if (element is engine.FunctionTypeAliasElement) {
7173
return element.function.returnType.toString();
7274
} else {

pkg/analysis_server/lib/src/services/completion/dart/arglist_contributor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ArgListContributor extends DartCompletionContributor {
171171
void _addNamedParameterSuggestion(List<String> namedArgs,
172172
ParameterElement parameter, bool appendColon, bool appendComma) {
173173
String name = parameter.name;
174-
String type = parameter.type?.displayName;
174+
String type = parameter.type?.getDisplayString(withNullability: false);
175175
if (name != null && name.isNotEmpty && !namedArgs.contains(name)) {
176176
String completion = name;
177177
if (appendColon) {

pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ CompletionSuggestion createSuggestion(Element element,
6363
element.parameters.map((ParameterElement parameter) {
6464
DartType paramType = parameter.type;
6565
// Gracefully degrade if type not resolved yet
66-
return paramType != null ? paramType.displayName : 'var';
66+
return paramType != null
67+
? paramType.getDisplayString(withNullability: false)
68+
: 'var';
6769
}).toList();
6870

6971
Iterable<ParameterElement> requiredParameters = element.parameters

pkg/analysis_server/lib/src/services/completion/postfix/postfix_completion.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class PostfixCompletionProcessor {
505505
if (astNode is ThrowExpression) {
506506
ThrowExpression expr = astNode;
507507
var type = expr.expression.staticType;
508-
return type.displayName;
508+
return type.getDisplayString(withNullability: false);
509509
}
510510
return 'Exception';
511511
}

pkg/analysis_server/lib/src/services/completion/token_details/token_detail_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class TokenDetailBuilder {
116116
} else if (type is InterfaceType) {
117117
Element element = type.element;
118118
if (element == null || element.isSynthetic) {
119-
buffer.write(type.displayName);
119+
buffer.write(type.getDisplayString(withNullability: false));
120120
} else {
121121
// String uri = element.library.source.uri.toString();
122122
String name = element.name;
@@ -134,7 +134,7 @@ class TokenDetailBuilder {
134134
}
135135
} else {
136136
// Handle `void` and `dynamic`.
137-
buffer.write(type.displayName);
137+
buffer.write(type.getDisplayString(withNullability: false));
138138
}
139139
}
140140
}

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,13 @@ class FixProcessor extends BaseProcessor {
13251325
});
13261326
});
13271327
_addFixFromBuilder(
1328-
changeBuilder, DartFixKind.CHANGE_TYPE_ANNOTATION,
1329-
args: [typeNode.type, newType.displayName]);
1328+
changeBuilder,
1329+
DartFixKind.CHANGE_TYPE_ANNOTATION,
1330+
args: [
1331+
typeNode.type,
1332+
newType.getDisplayString(withNullability: false),
1333+
],
1334+
);
13301335
}
13311336
}
13321337
}

pkg/analysis_server/lib/src/services/correction/util.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,16 @@ CompilationUnitElement getCompilationUnitElement(Element element) {
184184

185185
String getDefaultValueCode(DartType type) {
186186
if (type != null) {
187-
String typeName = type.displayName;
188-
if (typeName == "bool") {
187+
if (type.isDartCoreBool) {
189188
return "false";
190189
}
191-
if (typeName == "int") {
190+
if (type.isDartCoreInt) {
192191
return "0";
193192
}
194-
if (typeName == "double") {
193+
if (type.isDartCoreDouble) {
195194
return "0.0";
196195
}
197-
if (typeName == "String") {
196+
if (type.isDartCoreString) {
198197
return "''";
199198
}
200199
}
@@ -1327,7 +1326,7 @@ class CorrectionUtils {
13271326
return _invertCondition0(expression.unParenthesized);
13281327
}
13291328
DartType type = expression.staticType;
1330-
if (type.displayName == "bool") {
1329+
if (type.isDartCoreBool) {
13311330
return _InvertedCondition._simple("!${getNodeText(expression)}");
13321331
}
13331332
return _InvertedCondition._simple(getNodeText(expression));

pkg/analyzer/lib/dart/element/type.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ abstract class DartType {
3232
///
3333
/// Clients should not depend on the content of the returned value as it will
3434
/// be changed if doing so would improve the UX.
35+
@deprecated
3536
String get displayName;
3637

3738
/// Return the element representing the declaration of this type, or `null` if

pkg/analyzer/lib/error/listener.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class ErrorReporter {
206206
return buffer.toString();
207207
}
208208
}
209-
return type.displayName;
209+
return type.getDisplayString(withNullability: false);
210210
}
211211

212212
Map<String, List<_TypeToConvert>> typeGroups = {};

0 commit comments

Comments
 (0)