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

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

Issue 1083223003: Fix additional cases where analysis server might send null, violating protocol. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
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 9087e57550fb4e8c2ac5936d72b13971d047d826..7fad5a21e118bdf11ce5158f5a9193aa7a15fb3c 100644
--- a/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
+++ b/pkg/analysis_server/tool/spec/codegen_dart_protocol.dart
@@ -16,6 +16,13 @@ import 'implied_types.dart';
import 'to_html.dart';
/**
+ * Translate spec_input.html into protocol_matchers.dart.
+ */
+main() {
+ target.generate();
+}
+
+/**
* Special flags that need to be inserted into the declaration of the Element
* class.
*/
@@ -35,13 +42,6 @@ final GeneratedFile target = new GeneratedFile(
});
/**
- * Translate spec_input.html into protocol_matchers.dart.
- */
-main() {
- target.generate();
-}
-
-/**
* Callback type used to represent arbitrary code generation.
*/
typedef void CodegenCallback();
@@ -383,10 +383,29 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
if (field.value != null) {
continue;
}
+ writeln('${dartType(field.type)} _${field.name};');
+ writeln();
+ }
+ for (TypeObjectField field in type.fields) {
+ if (field.value != null) {
+ continue;
+ }
docComment(toHtmlVisitor.collectHtml(() {
toHtmlVisitor.translateHtml(field.html);
}));
- writeln('${dartType(field.type)} ${field.name};');
+ writeln('${dartType(field.type)} get ${field.name} => _${field.name};');
+ writeln();
+ docComment(toHtmlVisitor.collectHtml(() {
+ toHtmlVisitor.translateHtml(field.html);
+ }));
+ writeln('void set ${field.name}(${dartType(field.type)} value) {');
+ indent(() {
+ if (!field.optional) {
+ writeln('assert(value != null);');
+ }
+ writeln('this._${field.name} = value;');
+ });
+ writeln('}');
writeln();
}
emitObjectConstructor(type, className);
@@ -437,7 +456,8 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
if (field.value != null) {
continue;
}
- String arg = 'this.${field.name}';
+ String arg = '${dartType(field.type)} ${field.name}';
+ String setValueFromArg = 'this.${field.name} = ${field.name};';
if (isOptionalConstructorArg(className, field)) {
optionalArgs.add(arg);
if (!field.optional) {
@@ -448,7 +468,12 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
extraInitCode.add(() {
writeln('if (${field.name} == null) {');
indent(() {
- writeln('${field.name} = <${dartType(fieldType.itemType)}>[];');
+ writeln(
+ 'this.${field.name} = <${dartType(fieldType.itemType)}>[];');
+ });
+ writeln('} else {');
+ indent(() {
+ writeln(setValueFromArg);
});
writeln('}');
});
@@ -456,9 +481,16 @@ class CodegenProtocolVisitor extends DartCodegenVisitor with CodeGenerator {
throw new Exception(
"Don't know how to create default field value.");
}
+ } else {
+ extraInitCode.add(() {
+ writeln(setValueFromArg);
+ });
}
} else {
args.add(arg);
+ extraInitCode.add(() {
+ writeln(setValueFromArg);
+ });
}
}
if (optionalArgs.isNotEmpty) {

Powered by Google App Engine
This is Rietveld 408576698