| 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 7a59bc725b2694f61bb81a74c43625124263c382..02b38ac9024efe0a01ffe8224de4de661cc7b3ec 100644
|
| --- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| +++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
|
| @@ -620,15 +620,22 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
|
| String arg = 'this.${field.name}';
|
| if (isOptionalConstructorArg(className, field)) {
|
| optionalArgs.add(arg);
|
| - TypeDecl fieldType = field.type;
|
| - if (fieldType is TypeList) {
|
| - extraInitCode.add(() {
|
| - writeln('if (${field.name} == null) {');
|
| - indent(() {
|
| - writeln('${field.name} = <${dartType(fieldType.itemType)}>[];');
|
| + if (!field.optional) {
|
| + // Optional constructor arg, but non-optional field. If no arg is
|
| + // given, the constructor should populate with the empty list.
|
| + TypeDecl fieldType = field.type;
|
| + if (fieldType is TypeList) {
|
| + extraInitCode.add(() {
|
| + writeln('if (${field.name} == null) {');
|
| + indent(() {
|
| + writeln('${field.name} = <${dartType(fieldType.itemType)}>[];');
|
| + });
|
| + writeln('}');
|
| });
|
| - writeln('}');
|
| - });
|
| + } else {
|
| + throw new Exception(
|
| + "Don't know how to create default field value.");
|
| + }
|
| }
|
| } else {
|
| args.add(arg);
|
| @@ -681,13 +688,7 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
|
| String fieldToJson = toJsonCode(field.type).asSnippet(field.name);
|
| String populateField = 'result[$fieldNameString] = $fieldToJson;';
|
| if (field.optional) {
|
| - String condition;
|
| - if (field.type is TypeList) {
|
| - condition = '${field.name}.isNotEmpty';
|
| - } else {
|
| - condition = '${field.name} != null';
|
| - }
|
| - writeln('if ($condition) {');
|
| + writeln('if (${field.name} != null) {');
|
| indent(() {
|
| writeln(populateField);
|
| });
|
| @@ -1049,12 +1050,6 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
|
| "throw jsonDecoder.missingKey(jsonPath, $fieldNameString);");
|
| });
|
| writeln('}');
|
| - } else if (fieldType is TypeList) {
|
| - writeln(' else {');
|
| - indent(() {
|
| - writeln('${field.name} = <${dartType(fieldType.itemType)}>[];');
|
| - });
|
| - writeln('}');
|
| } else {
|
| writeln();
|
| }
|
|
|