Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Unified Diff: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart

Issue 625413002: Remove special list behavior in analysis server protocol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/search/type_hierarchy_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« no previous file with comments | « pkg/analysis_server/test/search/type_hierarchy_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698