| OLD | NEW |
| 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 library analyzer.test.enum_test; | 5 library analyzer.test.enum_test; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/element/element.dart'; | 10 import 'package:analyzer/src/dart/element/element.dart'; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 Map<String, C> result = <String, C>{}; | 129 Map<String, C> result = <String, C>{}; |
| 130 ClassMirror reflectedClass = reflectClass(C); | 130 ClassMirror reflectedClass = reflectClass(C); |
| 131 reflectedClass.staticMembers.forEach((Symbol symbol, MethodMirror method) { | 131 reflectedClass.staticMembers.forEach((Symbol symbol, MethodMirror method) { |
| 132 if (!method.isGetter) { | 132 if (!method.isGetter) { |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 String name = MirrorSystem.getName(symbol); | 135 String name = MirrorSystem.getName(symbol); |
| 136 if (_ignoreGetters.contains(name)) { | 136 if (_ignoreGetters.contains(name)) { |
| 137 return; | 137 return; |
| 138 } | 138 } |
| 139 C value = reflectedClass.getField(symbol).reflectee; | 139 C value = reflectedClass.getField(symbol).reflectee as C; |
| 140 result[name] = value; | 140 result[name] = value; |
| 141 }); | 141 }); |
| 142 return result; | 142 return result; |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Check invariants on the list of enum values accessible via the static | 146 * Check invariants on the list of enum values accessible via the static |
| 147 * getter "values". | 147 * getter "values". |
| 148 */ | 148 */ |
| 149 void check_explicit_values() { | 149 void check_explicit_values() { |
| 150 ClassMirror reflectedClass = reflectClass(C); | 150 ClassMirror reflectedClass = reflectClass(C); |
| 151 List<C> values = reflectedClass.getField(#values).reflectee; | 151 List<C> values = reflectedClass.getField(#values).reflectee as List<C>; |
| 152 Map<C, int> reverseMap = <C, int>{}; | 152 Map<C, int> reverseMap = <C, int>{}; |
| 153 | 153 |
| 154 // Check that "values" is a list of values of type C, with no duplicates. | 154 // Check that "values" is a list of values of type C, with no duplicates. |
| 155 expect(values, isList); | 155 expect(values, isList); |
| 156 for (int i = 0; i < values.length; i++) { | 156 for (int i = 0; i < values.length; i++) { |
| 157 C value = values[i]; | 157 C value = values[i]; |
| 158 expect(value, new isInstanceOf<C>(), reason: 'values[$i]'); | 158 expect(value, new isInstanceOf<C>(), reason: 'values[$i]'); |
| 159 if (reverseMap.containsKey(value)) { | 159 if (reverseMap.containsKey(value)) { |
| 160 fail('values[$i] and values[${reverseMap[value]}] both equal $value'); | 160 fail('values[$i] and values[${reverseMap[value]}] both equal $value'); |
| 161 } | 161 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 // Check that the set of ordinals runs from 0 to N-1, where N is the number | 202 // Check that the set of ordinals runs from 0 to N-1, where N is the number |
| 203 // of enumerated values. | 203 // of enumerated values. |
| 204 Set<int> expectedOrdinals = new Set<int>(); | 204 Set<int> expectedOrdinals = new Set<int>(); |
| 205 for (int i = 0; i < numValues; i++) { | 205 for (int i = 0; i < numValues; i++) { |
| 206 expectedOrdinals.add(i); | 206 expectedOrdinals.add(i); |
| 207 } | 207 } |
| 208 expect(ordinals.keys.toSet(), equals(expectedOrdinals)); | 208 expect(ordinals.keys.toSet(), equals(expectedOrdinals)); |
| 209 } | 209 } |
| 210 } | 210 } |
| OLD | NEW |