vm_service: Remove unnecessary '?' from dynamic types

Also update the generator:

* Remove same unnecessary '?'
* Update MemberType.name, TypeRef.ref to be non-nullable

Bug: https://github.com/dart-lang/sdk/issues/45165
Change-Id: I438e9ce1e02faac9417a7d2d4ace143f2cf6feb3
TEST=Just the regular trybots.
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190722
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Sam Rawlins 2021-03-11 20:14:41 +00:00 committed by commit-bot@chromium.org
parent 54b2948461
commit 5aca96546b
2 changed files with 25 additions and 21 deletions

View file

@ -2703,7 +2703,7 @@ class BoundField {
FieldRef? decl;
/// [value] can be one of [InstanceRef] or [Sentinel].
dynamic? value;
dynamic value;
BoundField({
required this.decl,
@ -2747,7 +2747,7 @@ class BoundVariable extends Response {
String? name;
/// [value] can be one of [InstanceRef], [TypeArgumentsRef] or [Sentinel].
dynamic? value;
dynamic value;
/// The token position where this variable was declared.
int? declarationTokenPos;
@ -2822,7 +2822,7 @@ class Breakpoint extends Obj {
/// a breakpoint is not resolved.
///
/// [location] can be one of [SourceLocation] or [UnresolvedSourceLocation].
dynamic? location;
dynamic location;
Breakpoint({
required this.breakpointNumber,
@ -3331,7 +3331,7 @@ class ContextElement {
json == null ? null : ContextElement._fromJson(json);
/// [value] can be one of [InstanceRef] or [Sentinel].
dynamic? value;
dynamic value;
ContextElement({
required this.value,
@ -4052,7 +4052,7 @@ class Field extends Obj implements FieldRef {
///
/// [staticValue] can be one of [InstanceRef] or [Sentinel].
@optional
dynamic? staticValue;
dynamic staticValue;
/// The location of this field in the source code.
@optional
@ -4082,7 +4082,7 @@ class Field extends Obj implements FieldRef {
isFinal = json['final'] ?? false;
isStatic = json['static'] ?? false;
staticValue = createServiceObject(
json['staticValue'], const ['InstanceRef', 'Sentinel']) as dynamic?;
json['staticValue'], const ['InstanceRef', 'Sentinel']) as dynamic;
location = createServiceObject(json['location'], const ['SourceLocation'])
as SourceLocation?;
}
@ -4276,7 +4276,7 @@ class FuncRef extends ObjRef {
/// The owner of this function, which can be a Library, Class, or a Function.
///
/// [owner] can be one of [LibraryRef], [ClassRef] or [FuncRef].
dynamic? owner;
dynamic owner;
/// Is this function static?
bool? isStatic;
@ -4338,7 +4338,7 @@ class Func extends Obj implements FuncRef {
/// The owner of this function, which can be a Library, Class, or a Function.
///
/// [owner] can be one of [LibraryRef], [ClassRef] or [FuncRef].
dynamic? owner;
dynamic owner;
/// Is this function static?
bool? isStatic;
@ -5788,10 +5788,10 @@ class MapAssociation {
json == null ? null : MapAssociation._fromJson(json);
/// [key] can be one of [InstanceRef] or [Sentinel].
dynamic? key;
dynamic key;
/// [value] can be one of [InstanceRef] or [Sentinel].
dynamic? value;
dynamic value;
MapAssociation({
required this.key,
@ -6241,7 +6241,7 @@ class ProfileFunction {
String? resolvedUrl;
/// The function captured during profiling.
dynamic? function;
dynamic function;
ProfileFunction({
required this.kind,

View file

@ -1200,7 +1200,7 @@ class Method extends Member {
gen.write('Future<${returnType.name}> ${name}(');
bool startedOptional = false;
gen.write(args.map((MethodArg arg) {
String? typeName;
String typeName;
if (api.isEnumName(arg.type.name)) {
if (arg.type.isArray) {
typeName = typeName = '/*${arg.type}*/ List<String>';
@ -1268,7 +1268,7 @@ class MemberType extends Member {
}
}
String? get name {
String get name {
if (types.isEmpty) return '';
if (types.length == 1) return types.first.ref;
if (isReturnType) return 'Response';
@ -1286,7 +1286,7 @@ class MemberType extends Member {
bool get isArray => types.length == 1 && types.first.isArray;
void generate(DartGenerator gen) => gen.write(name!);
void generate(DartGenerator gen) => gen.write(name);
}
class TypeRef {
@ -1296,7 +1296,7 @@ class TypeRef {
TypeRef(this.name);
String? get ref {
String get ref {
if (arrayDepth == 2) {
return 'List<List<${name}>>';
} else if (arrayDepth == 1) {
@ -1304,7 +1304,7 @@ class TypeRef {
} else if (genericTypes != null) {
return '$name<${genericTypes!.join(', ')}>';
} else {
return name!.startsWith('_') ? name!.substring(1) : name;
return name!.startsWith('_') ? name!.substring(1) : name!;
}
}
@ -1340,7 +1340,7 @@ class TypeRef {
name == 'double' ||
name == 'ByteData');
String toString() => ref!;
String toString() => ref;
}
class MethodArg extends Member {
@ -1639,9 +1639,11 @@ class Type extends Member {
}
} else {
String typesList = _typeRefListToString(field.type.types);
String nullable =
field.optional && field.type.name != 'dynamic' ? '?' : '';
gen.writeln("${field.generatableName} = "
"createServiceObject(json['${field.name}']${field.optional ? '' : '!'}, "
"$typesList) as ${field.type.name}${field.optional ? '?' : ''};");
"$typesList) as ${field.type.name}$nullable;");
}
});
if (fields.isNotEmpty) {
@ -1851,8 +1853,8 @@ void _parseTokenPosTable() {
gen.writeln('}');
} else {
String assertMethodName = 'assert' +
type.name!.substring(0, 1).toUpperCase() +
type.name!.substring(1);
type.name.substring(0, 1).toUpperCase() +
type.name.substring(1);
gen.writeln('$assertMethodName(obj.${field.generatableName}!);');
}
}
@ -1943,7 +1945,9 @@ class TypeField extends Member {
{
String? typeName =
api.isEnumName(type.name) ? '/*${type.name}*/ String' : type.name;
typeName = '$typeName?';
if (typeName != 'dynamic') {
typeName = '$typeName?';
}
gen.writeStatement('${typeName} ${generatableName};');
if (parent.fields.any((field) => field.hasDocs)) gen.writeln();
}