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

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

Issue 499073002: Make certain generated constructor parameters optional. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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/services/correction/change_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 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);
« no previous file with comments | « pkg/analysis_server/test/services/correction/change_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698