Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(354)

Side by Side Diff: pkg/unittest/lib/mirror_matchers.dart

Issue 63363003: Cascaded mirror removal revert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 * The mirror matchers library provides some additional matchers that 5 * The mirror matchers library provides some additional matchers that
6 * make use of dart:mirrors. 6 * make use of dart:mirrors.
7 * 7 *
8 * ## Installing ## 8 * ## Installing ##
9 * 9 *
10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml` 10 * Use [pub][] to install this package. Add the following to your `pubspec.yaml`
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class _HasProperty extends Matcher { 42 class _HasProperty extends Matcher {
43 final String _name; 43 final String _name;
44 final Matcher _matcher; 44 final Matcher _matcher;
45 45
46 const _HasProperty(this._name, [this._matcher]); 46 const _HasProperty(this._name, [this._matcher]);
47 47
48 bool matches(item, Map matchState) { 48 bool matches(item, Map matchState) {
49 var mirror = reflect(item); 49 var mirror = reflect(item);
50 var classMirror = mirror.type; 50 var classMirror = mirror.type;
51 var symbol = new Symbol(_name); 51 var symbol = new Symbol(_name);
52 bool hasGetter(classMirror, getterName) { 52 if (!classMirror.getters.containsKey(symbol)) {
53 var candidate = classMirror.declarations[getterName];
54 return candidate != null &&
55 candidate is MethodMirror &&
56 candidate.isGetter;
57 }
58 if (!hasGetter(classMirror, symbol)) {
59 addStateInfo(matchState, {'reason': 'has no property named "$_name"'}); 53 addStateInfo(matchState, {'reason': 'has no property named "$_name"'});
60 return false; 54 return false;
61 } 55 }
62 if (_matcher == null) return true; 56 if (_matcher == null) return true;
63 var result = mirror.getField(symbol); 57 var result = mirror.getField(symbol);
64 var resultMatches = _matcher.matches(result.reflectee, matchState); 58 var resultMatches = _matcher.matches(result.reflectee, matchState);
65 if (!resultMatches) { 59 if (!resultMatches) {
66 addStateInfo(matchState, {'value': result.reflectee}); 60 addStateInfo(matchState, {'value': result.reflectee});
67 } 61 }
68 return resultMatches; 62 return resultMatches;
(...skipping 18 matching lines...) Expand all
87 var innerDescription = new StringDescription(); 81 var innerDescription = new StringDescription();
88 _matcher.describeMismatch(matchState['value'], innerDescription, 82 _matcher.describeMismatch(matchState['value'], innerDescription,
89 matchState['state'], verbose); 83 matchState['state'], verbose);
90 if (innerDescription.length > 0) { 84 if (innerDescription.length > 0) {
91 mismatchDescription.add(' which ').add(innerDescription.toString()); 85 mismatchDescription.add(' which ').add(innerDescription.toString());
92 } 86 }
93 } 87 }
94 return mismatchDescription; 88 return mismatchDescription;
95 } 89 }
96 } 90 }
OLDNEW
« no previous file with comments | « pkg/serialization/lib/src/serialization_rule.dart ('k') | runtime/tests/vm/dart/mirrored_compilation_error_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698