Skip to content

Commit

Permalink
Use DartType.getDisplayString() instead of toString().
Browse files Browse the repository at this point in the history
Change-Id: I982a4fff312593e6788afcbc9200a83793fefb97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134464
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Feb 5, 2020
1 parent 738ad28 commit 34893fa
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/analysis_server/lib/src/protocol_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ String getReturnTypeString(engine.Element element) {
if (element.kind == engine.ElementKind.SETTER) {
return null;
} else {
return element.returnType?.toString();
return element.returnType?.getDisplayString(withNullability: false);
}
} else if (element is engine.VariableElement) {
engine.DartType type = element.type;
return type != null
? type.getDisplayString(withNullability: false)
: 'dynamic';
} else if (element is engine.FunctionTypeAliasElement) {
return element.function.returnType.toString();
var returnType = element.function.returnType;
return returnType.getDisplayString(withNullability: false);
} else {
return null;
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/analysis_server/lib/src/search/type_hierarchy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ class TypeHierarchyComputer {
{
String displayName;
if (typeArguments != null && typeArguments.isNotEmpty) {
displayName =
classElement.displayName + '<' + typeArguments.join(', ') + '>';
var typeArgumentsStr = typeArguments
.map((type) => type.getDisplayString(withNullability: false))
.join(', ');
displayName = classElement.displayName + '<' + typeArgumentsStr + '>';
}
ExecutableElement memberElement = _findMemberElement(classElement);
item = TypeHierarchyItem(convertElement(classElement),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ String nameForType(SimpleIdentifier identifier, TypeAnnotation declaredType) {
if (type == null) {
return DYNAMIC;
}
return type.toString();
return type.getDisplayString(withNullability: false);
}

/// TODO(pq): fix to use getDefaultStringParameterValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ class FixProcessor extends BaseProcessor {
changeBuilder,
DartFixKind.CHANGE_TYPE_ANNOTATION,
args: [
typeNode.type,
typeNode.type.getDisplayString(withNullability: false),
newType.getDisplayString(withNullability: false),
],
);
Expand Down

0 comments on commit 34893fa

Please sign in to comment.