| Index: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| diff --git a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| index 47b7506b88ae29b6db9efa3dd3a64858b2615b47..674cb0de349737e5391efa72f8409a383f2a8aba 100644
|
| --- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| +++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| @@ -194,6 +194,16 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
|
| };
|
|
|
| /**
|
| + * Class members for which the constructor argument should be optional, even
|
| + * if the member is not an optional part of the protocol. For list types,
|
| + * the constructor will default the member to the empty list.
|
| + */
|
| + static const Map<String, List<String>> _optionalConstructorArguments = const {
|
| + 'SourceFileEdit': const ['edits'],
|
| + 'TypeHierarchyItem': const ['interfaces', 'mixins', 'subclasses']
|
| + };
|
| +
|
| + /**
|
| * Visitor used to produce doc comments.
|
| */
|
| final ToHtmlVisitor toHtmlVisitor;
|
| @@ -471,7 +481,7 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
|
| continue;
|
| }
|
| String arg = 'this.${field.name}';
|
| - if (field.optional) {
|
| + if (isOptionalConstructorArg(className, field)) {
|
| optionalArgs.add(arg);
|
| TypeDecl fieldType = field.type;
|
| if (fieldType is TypeList) {
|
| @@ -505,6 +515,20 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
|
| }
|
|
|
| /**
|
| + * True if the constructor argument for the given field should be optional.
|
| + */
|
| + bool isOptionalConstructorArg(String className, TypeObjectField field) {
|
| + if (field.optional) {
|
| + return true;
|
| + }
|
| + List<String> forceOptional = _optionalConstructorArguments[className];
|
| + if (forceOptional != null && forceOptional.contains(field.name)) {
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + /**
|
| * Emit the toJson() code for an object class.
|
| */
|
| void emitToJsonMember(TypeObject type) {
|
| @@ -812,7 +836,7 @@ class CodegenProtocolVisitor extends HierarchicalApiVisitor with CodeGenerator {
|
| writeln('}');
|
| continue;
|
| }
|
| - if (field.optional) {
|
| + if (isOptionalConstructorArg(className, field)) {
|
| optionalArgs.add('${field.name}: ${field.name}');
|
| } else {
|
| args.add(field.name);
|
|
|