Index: pkg/analysis_server/tool/spec/codegen_matchers.dart |
diff --git a/pkg/analysis_server/tool/spec/codegen_matchers.dart b/pkg/analysis_server/tool/spec/codegen_matchers.dart |
index 02261da8389bae04730c92316bd16bae5c79c7cd..30a6e142f562b08665ec5d2aaf80cb37c8204469 100644 |
--- a/pkg/analysis_server/tool/spec/codegen_matchers.dart |
+++ b/pkg/analysis_server/tool/spec/codegen_matchers.dart |
@@ -15,6 +15,19 @@ import 'from_html.dart'; |
import 'implied_types.dart'; |
import 'to_html.dart'; |
+final GeneratedFile target = |
+ new GeneratedFile('../../test/integration/protocol_matchers.dart', () { |
+ CodegenMatchersVisitor visitor = new CodegenMatchersVisitor(readApi()); |
+ return visitor.collectCode(visitor.visitApi); |
+}); |
+ |
+/** |
+ * Translate spec_input.html into protocol_matchers.dart. |
+ */ |
+main() { |
+ target.generate(); |
+} |
+ |
class CodegenMatchersVisitor extends HierarchicalApiVisitor with CodeGenerator { |
/** |
* Visitor used to produce doc comments. |
@@ -56,6 +69,36 @@ class CodegenMatchersVisitor extends HierarchicalApiVisitor with CodeGenerator { |
writeln(); |
} |
+ /** |
+ * Generate a map describing the given set of fields, for use as the |
+ * 'requiredFields' or 'optionalFields' argument to the [MatchesJsonObject] |
+ * constructor. |
+ */ |
+ void outputObjectFields(Iterable<TypeObjectField> fields) { |
+ if (fields.isEmpty) { |
+ write('null'); |
+ return; |
+ } |
+ writeln('{'); |
+ indent(() { |
+ bool commaNeeded = false; |
+ for (TypeObjectField field in fields) { |
+ if (commaNeeded) { |
+ writeln(','); |
+ } |
+ write('${JSON.encode(field.name)}: '); |
+ if (field.value != null) { |
+ write('equals(${JSON.encode(field.value)})'); |
+ } else { |
+ visitTypeDecl(field.type); |
+ } |
+ commaNeeded = true; |
+ } |
+ writeln(); |
+ }); |
+ write('}'); |
+ } |
+ |
@override |
visitApi() { |
outputHeader(); |
@@ -113,11 +156,11 @@ class CodegenMatchersVisitor extends HierarchicalApiVisitor with CodeGenerator { |
writeln('new LazyMatcher(() => new MatchesJsonObject('); |
indent(() { |
write('${JSON.encode(context)}, '); |
- Iterable<TypeObjectField> requiredFields = typeObject.fields.where( |
- (TypeObjectField field) => !field.optional); |
+ Iterable<TypeObjectField> requiredFields = |
+ typeObject.fields.where((TypeObjectField field) => !field.optional); |
outputObjectFields(requiredFields); |
- List<TypeObjectField> optionalFields = typeObject.fields.where( |
- (TypeObjectField field) => field.optional).toList(); |
+ List<TypeObjectField> optionalFields = |
+ typeObject.fields.where((TypeObjectField field) => field.optional).toList(); |
if (optionalFields.isNotEmpty) { |
write(', optionalFields: '); |
outputObjectFields(optionalFields); |
@@ -126,36 +169,6 @@ class CodegenMatchersVisitor extends HierarchicalApiVisitor with CodeGenerator { |
write('))'); |
} |
- /** |
- * Generate a map describing the given set of fields, for use as the |
- * 'requiredFields' or 'optionalFields' argument to the [MatchesJsonObject] |
- * constructor. |
- */ |
- void outputObjectFields(Iterable<TypeObjectField> fields) { |
- if (fields.isEmpty) { |
- write('null'); |
- return; |
- } |
- writeln('{'); |
- indent(() { |
- bool commaNeeded = false; |
- for (TypeObjectField field in fields) { |
- if (commaNeeded) { |
- writeln(','); |
- } |
- write('${JSON.encode(field.name)}: '); |
- if (field.value != null) { |
- write('equals(${JSON.encode(field.value)})'); |
- } else { |
- visitTypeDecl(field.type); |
- } |
- commaNeeded = true; |
- } |
- writeln(); |
- }); |
- write('}'); |
- } |
- |
@override |
void visitTypeReference(TypeReference typeReference) { |
String typeName = typeReference.typeName; |
@@ -179,16 +192,3 @@ class CodegenMatchersVisitor extends HierarchicalApiVisitor with CodeGenerator { |
write('])'); |
} |
} |
- |
-final GeneratedFile target = new GeneratedFile( |
- '../../test/integration/protocol_matchers.dart', () { |
- CodegenMatchersVisitor visitor = new CodegenMatchersVisitor(readApi()); |
- return visitor.collectCode(visitor.visitApi); |
-}); |
- |
-/** |
- * Translate spec_input.html into protocol_matchers.dart. |
- */ |
-main() { |
- target.generate(); |
-} |