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

Side by Side Diff: pkg/analysis_server/tool/spec/codegen_matchers.dart

Issue 475143003: Fix code generated matchers to handle recursive objects. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/integration/protocol_matchers.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Code generation for the file "matchers.dart". 6 * Code generation for the file "matchers.dart".
7 */ 7 */
8 library codegen.matchers; 8 library codegen.matchers;
9 9
10 import 'dart:convert'; 10 import 'dart:convert';
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 visitTypeMap(TypeMap typeMap) { 129 visitTypeMap(TypeMap typeMap) {
130 write('isMapOf('); 130 write('isMapOf(');
131 visitTypeDecl(typeMap.keyType); 131 visitTypeDecl(typeMap.keyType);
132 write(', '); 132 write(', ');
133 visitTypeDecl(typeMap.valueType); 133 visitTypeDecl(typeMap.valueType);
134 write(')'); 134 write(')');
135 } 135 }
136 136
137 @override 137 @override
138 void visitTypeObject(TypeObject typeObject) { 138 void visitTypeObject(TypeObject typeObject) {
139 writeln('new MatchesJsonObject('); 139 writeln('new LazyMatcher(() => new MatchesJsonObject(');
140 indent(() { 140 indent(() {
141 write('${JSON.encode(context)}, '); 141 write('${JSON.encode(context)}, ');
142 Iterable<TypeObjectField> requiredFields = typeObject.fields.where( 142 Iterable<TypeObjectField> requiredFields = typeObject.fields.where(
143 (TypeObjectField field) => !field.optional); 143 (TypeObjectField field) => !field.optional);
144 outputObjectFields(requiredFields); 144 outputObjectFields(requiredFields);
145 List<TypeObjectField> optionalFields = typeObject.fields.where( 145 List<TypeObjectField> optionalFields = typeObject.fields.where(
146 (TypeObjectField field) => field.optional).toList(); 146 (TypeObjectField field) => field.optional).toList();
147 if (optionalFields.isNotEmpty) { 147 if (optionalFields.isNotEmpty) {
148 write(', optionalFields: '); 148 write(', optionalFields: ');
149 outputObjectFields(optionalFields); 149 outputObjectFields(optionalFields);
150 } 150 }
151 }); 151 });
152 write(')'); 152 write('))');
153 } 153 }
154 154
155 /** 155 /**
156 * Generate a map describing the given set of fields, for use as the 156 * Generate a map describing the given set of fields, for use as the
157 * 'requiredFields' or 'optionalFields' argument to the [MatchesJsonObject] 157 * 'requiredFields' or 'optionalFields' argument to the [MatchesJsonObject]
158 * constructor. 158 * constructor.
159 */ 159 */
160 void outputObjectFields(Iterable<TypeObjectField> fields) { 160 void outputObjectFields(Iterable<TypeObjectField> fields) {
161 if (fields.isEmpty) { 161 if (fields.isEmpty) {
162 write('null'); 162 write('null');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 CodegenMatchersVisitor visitor = new CodegenMatchersVisitor(readApi()); 207 CodegenMatchersVisitor visitor = new CodegenMatchersVisitor(readApi());
208 return visitor.collectCode(visitor.visitApi); 208 return visitor.collectCode(visitor.visitApi);
209 }); 209 });
210 210
211 /** 211 /**
212 * Translate spec_input.html into protocol_matchers.dart. 212 * Translate spec_input.html into protocol_matchers.dart.
213 */ 213 */
214 main() { 214 main() {
215 target.generate(); 215 target.generate();
216 } 216 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/integration/protocol_matchers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698