| 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.constants.constructors; | 5 library dart2js.constants.constructors; |
| 6 | 6 |
| 7 import '../dart_types.dart'; | 7 import '../dart_types.dart'; |
| 8 import '../elements/elements.dart' show FieldElement; | 8 import '../elements/elements.dart' show FieldElement; |
| 9 import '../universe/call_structure.dart' show CallStructure; | 9 import '../universe/call_structure.dart' show CallStructure; |
| 10 import '../util/util.dart'; | 10 import '../util/util.dart'; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return type == other.type && | 92 return type == other.type && |
| 93 superConstructorInvocation == other.superConstructorInvocation && | 93 superConstructorInvocation == other.superConstructorInvocation && |
| 94 mapEquals(defaultValues, other.defaultValues) && | 94 mapEquals(defaultValues, other.defaultValues) && |
| 95 mapEquals(fieldMap, other.fieldMap); | 95 mapEquals(fieldMap, other.fieldMap); |
| 96 } | 96 } |
| 97 | 97 |
| 98 String toString() { | 98 String toString() { |
| 99 StringBuffer sb = new StringBuffer(); | 99 StringBuffer sb = new StringBuffer(); |
| 100 sb.write("{'type': $type"); | 100 sb.write("{'type': $type"); |
| 101 defaultValues.forEach((key, ConstantExpression expression) { | 101 defaultValues.forEach((key, ConstantExpression expression) { |
| 102 sb.write(",\n 'default:${key}': ${expression.getText()}"); | 102 sb.write(",\n 'default:${key}': ${expression.toDartText()}"); |
| 103 }); | 103 }); |
| 104 fieldMap.forEach((FieldElement field, ConstantExpression expression) { | 104 fieldMap.forEach((FieldElement field, ConstantExpression expression) { |
| 105 sb.write(",\n 'field:${field}': ${expression.getText()}"); | 105 sb.write(",\n 'field:${field}': ${expression.toDartText()}"); |
| 106 }); | 106 }); |
| 107 if (superConstructorInvocation != null) { | 107 if (superConstructorInvocation != null) { |
| 108 sb.write(",\n 'constructor: ${superConstructorInvocation.getText()}"); | 108 sb.write(",\n 'constructor: ${superConstructorInvocation.toDartText()}"); |
| 109 } | 109 } |
| 110 sb.write("}"); | 110 sb.write("}"); |
| 111 return sb.toString(); | 111 return sb.toString(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 static bool mapEquals(Map map1, Map map2) { | 114 static bool mapEquals(Map map1, Map map2) { |
| 115 if (map1.length != map1.length) return false; | 115 if (map1.length != map1.length) return false; |
| 116 for (var key in map1.keys) { | 116 for (var key in map1.keys) { |
| 117 if (map1[key] != map2[key]) { | 117 if (map1[key] != map2[key]) { |
| 118 return false; | 118 return false; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (other is! RedirectingGenerativeConstantConstructor) return false; | 182 if (other is! RedirectingGenerativeConstantConstructor) return false; |
| 183 return thisConstructorInvocation == other.thisConstructorInvocation && | 183 return thisConstructorInvocation == other.thisConstructorInvocation && |
| 184 GenerativeConstantConstructor.mapEquals( | 184 GenerativeConstantConstructor.mapEquals( |
| 185 defaultValues, other.defaultValues); | 185 defaultValues, other.defaultValues); |
| 186 } | 186 } |
| 187 | 187 |
| 188 String toString() { | 188 String toString() { |
| 189 StringBuffer sb = new StringBuffer(); | 189 StringBuffer sb = new StringBuffer(); |
| 190 sb.write("{'type': ${thisConstructorInvocation.type}"); | 190 sb.write("{'type': ${thisConstructorInvocation.type}"); |
| 191 defaultValues.forEach((key, ConstantExpression expression) { | 191 defaultValues.forEach((key, ConstantExpression expression) { |
| 192 sb.write(",\n 'default:${key}': ${expression.getText()}"); | 192 sb.write(",\n 'default:${key}': ${expression.toDartText()}"); |
| 193 }); | 193 }); |
| 194 sb.write(",\n 'constructor': ${thisConstructorInvocation.getText()}"); | 194 sb.write(",\n 'constructor': ${thisConstructorInvocation.toDartText()}"); |
| 195 sb.write("}"); | 195 sb.write("}"); |
| 196 return sb.toString(); | 196 return sb.toString(); |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 | 199 |
| 200 /// A redirecting factory constant constructor. | 200 /// A redirecting factory constant constructor. |
| 201 class RedirectingFactoryConstantConstructor implements ConstantConstructor { | 201 class RedirectingFactoryConstantConstructor implements ConstantConstructor { |
| 202 final ConstructedConstantExpression targetConstructorInvocation; | 202 final ConstructedConstantExpression targetConstructorInvocation; |
| 203 | 203 |
| 204 RedirectingFactoryConstantConstructor(this.targetConstructorInvocation); | 204 RedirectingFactoryConstantConstructor(this.targetConstructorInvocation); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 230 | 230 |
| 231 bool operator ==(other) { | 231 bool operator ==(other) { |
| 232 if (identical(this, other)) return true; | 232 if (identical(this, other)) return true; |
| 233 if (other is! RedirectingFactoryConstantConstructor) return false; | 233 if (other is! RedirectingFactoryConstantConstructor) return false; |
| 234 return targetConstructorInvocation == other.targetConstructorInvocation; | 234 return targetConstructorInvocation == other.targetConstructorInvocation; |
| 235 } | 235 } |
| 236 | 236 |
| 237 String toString() { | 237 String toString() { |
| 238 StringBuffer sb = new StringBuffer(); | 238 StringBuffer sb = new StringBuffer(); |
| 239 sb.write("{"); | 239 sb.write("{"); |
| 240 sb.write("'constructor': ${targetConstructorInvocation.getText()}"); | 240 sb.write("'constructor': ${targetConstructorInvocation.toDartText()}"); |
| 241 sb.write("}"); | 241 sb.write("}"); |
| 242 return sb.toString(); | 242 return sb.toString(); |
| 243 } | 243 } |
| 244 } | 244 } |
| OLD | NEW |