| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Helper methods for converting a [Mirror] to a [String]. | 5 /// Helper methods for converting a [Mirror] to a [String]. |
| 6 library test.stringify; | 6 library test.stringify; |
| 7 | 7 |
| 8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
| 9 | 9 |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (method.isSynthetic) buffer.write(', synthetic'); | 109 if (method.isSynthetic) buffer.write(', synthetic'); |
| 110 if (method.isStatic) buffer.write(', static'); | 110 if (method.isStatic) buffer.write(', static'); |
| 111 if (method.isGetter) buffer.write(', getter'); | 111 if (method.isGetter) buffer.write(', getter'); |
| 112 if (method.isSetter) buffer.write(', setter'); | 112 if (method.isSetter) buffer.write(', setter'); |
| 113 if (method.isConstructor) buffer.write(', constructor'); | 113 if (method.isConstructor) buffer.write(', constructor'); |
| 114 return 'Method($buffer)'; | 114 return 'Method($buffer)'; |
| 115 } | 115 } |
| 116 | 116 |
| 117 stringifyDependencies(LibraryMirror l) { | 117 stringifyDependencies(LibraryMirror l) { |
| 118 n(s) => s is Symbol ? MirrorSystem.getName(s) : s; | 118 n(s) => s is Symbol ? MirrorSystem.getName(s) : s; |
| 119 compareDep(a, b) => | 119 compareDep(a, b) { |
| 120 n(a.targetLibrary.simpleName).compareTo(n(b.targetLibrary.simpleName)); | 120 if (a.targetLibrary == b.targetLibrary) { |
| 121 if ((a.prefix != null) && (b.prefix != null)) { |
| 122 return n(a.prefix).compareTo(n(b.prefix)); |
| 123 } |
| 124 return a.prefix == null ? 1 : -1; |
| 125 } |
| 126 return n(a.targetLibrary.simpleName).compareTo(n(b.targetLibrary.simpleNam
e)); |
| 127 } |
| 121 compareCom(a, b) => n(a.identifier).compareTo(n(b.identifier)); | 128 compareCom(a, b) => n(a.identifier).compareTo(n(b.identifier)); |
| 122 compareFirst(a, b) => a[0].compareTo(b[0]); | 129 compareFirst(a, b) => a[0].compareTo(b[0]); |
| 123 sortBy(c, p) => new List.from(c)..sort(p); | 130 sortBy(c, p) => new List.from(c)..sort(p); |
| 124 | 131 |
| 125 var buffer = new StringBuffer(); | 132 var buffer = new StringBuffer(); |
| 126 sortBy(l.libraryDependencies, compareDep).forEach((dep) { | 133 sortBy(l.libraryDependencies, compareDep).forEach((dep) { |
| 127 if (dep.isImport) buffer.write('import '); | 134 if (dep.isImport) buffer.write('import '); |
| 128 if (dep.isExport) buffer.write('export '); | 135 if (dep.isExport) buffer.write('export '); |
| 129 buffer.write(n(dep.targetLibrary.simpleName)); | 136 buffer.write(n(dep.targetLibrary.simpleName)); |
| 137 if (dep.isDeferred) buffer.write(' deferred'); |
| 130 if (dep.prefix != null) buffer.write(' as ${n(dep.prefix)}'); | 138 if (dep.prefix != null) buffer.write(' as ${n(dep.prefix)}'); |
| 131 buffer.write('\n'); | 139 buffer.write('\n'); |
| 132 | 140 |
| 133 List flattenedCombinators = new List(); | 141 List flattenedCombinators = new List(); |
| 134 dep.combinators.forEach((com) { | 142 dep.combinators.forEach((com) { |
| 135 com.identifiers.forEach((ident) { | 143 com.identifiers.forEach((ident) { |
| 136 flattenedCombinators.add([n(ident), com.isShow, com.isHide]); | 144 flattenedCombinators.add([n(ident), com.isShow, com.isHide]); |
| 137 }); | 145 }); |
| 138 }); | 146 }); |
| 139 sortBy(flattenedCombinators, compareFirst).forEach((triple) { | 147 sortBy(flattenedCombinators, compareFirst).forEach((triple) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 168 Expect.stringEquals(expected, stringify(actual), reason); | 176 Expect.stringEquals(expected, stringify(actual), reason); |
| 169 } | 177 } |
| 170 | 178 |
| 171 compareSymbols(Symbol a, Symbol b) { | 179 compareSymbols(Symbol a, Symbol b) { |
| 172 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); | 180 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); |
| 173 } | 181 } |
| 174 | 182 |
| 175 simpleNames(Iterable<Mirror> i) => i.map((e) => e.simpleName); | 183 simpleNames(Iterable<Mirror> i) => i.map((e) => e.simpleName); |
| 176 | 184 |
| 177 sort(Iterable<Symbol> symbols) => symbols.toList()..sort(compareSymbols); | 185 sort(Iterable<Symbol> symbols) => symbols.toList()..sort(compareSymbols); |
| OLD | NEW |