OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.serialization.json; | 5 library dart2js.serialization.json; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'keys.dart'; | 8 import 'keys.dart'; |
9 import 'serialization.dart'; | 9 import 'serialization.dart'; |
10 import 'values.dart'; | 10 import 'values.dart'; |
11 | 11 |
12 /// Serialization encoder for JSON. | 12 /// Serialization encoder for JSON. |
13 class JsonSerializationEncoder implements SerializationEncoder { | 13 class JsonSerializationEncoder implements SerializationEncoder { |
14 const JsonSerializationEncoder(); | 14 const JsonSerializationEncoder(); |
15 | 15 |
16 String encode(ObjectValue objectValue) { | 16 String encode(ObjectValue objectValue) { |
17 return new JsonEncoder.withIndent(' ').convert( | 17 return new JsonEncoder.withIndent(' ') |
18 const JsonValueEncoder().convert(objectValue)); | 18 .convert(const JsonValueEncoder().convert(objectValue)); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 /// Serialization decoder for JSON. | 22 /// Serialization decoder for JSON. |
23 class JsonSerializationDecoder implements SerializationDecoder { | 23 class JsonSerializationDecoder implements SerializationDecoder { |
24 const JsonSerializationDecoder(); | 24 const JsonSerializationDecoder(); |
25 | 25 |
26 Map decode(String text) => JSON.decode(text); | 26 Map decode(String text) => JSON.decode(text); |
27 | 27 |
28 /// Returns the name of the [key] which used for to store a [Key] into a | 28 /// Returns the name of the [key] which used for to store a [Key] into a |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 @override | 114 @override |
115 void visitConstant(ConstantValue value, String indentation) { | 115 void visitConstant(ConstantValue value, String indentation) { |
116 buffer.write('Constant(${value.id}):${value.constant.getText()}'); | 116 buffer.write('Constant(${value.id}):${value.constant.getText()}'); |
117 } | 117 } |
118 | 118 |
119 @override | 119 @override |
120 void visitDouble(DoubleValue value, String indentation) { | 120 void visitDouble(DoubleValue value, String indentation) { |
121 buffer.write(value.value); | 121 buffer.write(value.value); |
122 } | 122 } |
| 123 |
123 @override | 124 @override |
124 void visitElement(ElementValue value, String indentation) { | 125 void visitElement(ElementValue value, String indentation) { |
125 buffer.write('Element(${value.id}):${value.element}'); | 126 buffer.write('Element(${value.id}):${value.element}'); |
126 } | 127 } |
127 | 128 |
128 @override | 129 @override |
129 void visitEnum(EnumValue value, String indentation) { | 130 void visitEnum(EnumValue value, String indentation) { |
130 buffer.write(value.value); | 131 buffer.write(value.value); |
131 } | 132 } |
132 | 133 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 203 |
203 @override | 204 @override |
204 void visitType(TypeValue value, String indentation) { | 205 void visitType(TypeValue value, String indentation) { |
205 buffer.write('Type(${value.id}):${value.type}'); | 206 buffer.write('Type(${value.id}):${value.type}'); |
206 } | 207 } |
207 | 208 |
208 @override | 209 @override |
209 void visitUri(UriValue value, String indentation) { | 210 void visitUri(UriValue value, String indentation) { |
210 buffer.write('Uri(${value.value})'); | 211 buffer.write('Uri(${value.value})'); |
211 } | 212 } |
212 } | 213 } |
OLD | NEW |