| 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 /// Static implementation of smoke services that uses code-generated data and | 5 /// Static implementation of smoke services that uses code-generated data and |
| 6 /// verifies that the results match what we would get with a mirror-based | 6 /// verifies that the results match what we would get with a mirror-based |
| 7 /// implementation. | 7 /// implementation. |
| 8 library smoke.static_debug; | 8 library smoke.static_debug; |
| 9 | 9 |
| 10 export 'package:smoke/static.dart' show StaticConfiguration, Getter, Setter; | 10 export 'package:smoke/static.dart' show StaticConfiguration, Getter, Setter; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /// Implements [ObjectAccessorService] using a static configuration. | 25 /// Implements [ObjectAccessorService] using a static configuration. |
| 26 class _DebugObjectAccessorService implements ObjectAccessorService { | 26 class _DebugObjectAccessorService implements ObjectAccessorService { |
| 27 GeneratedObjectAccessorService _static; | 27 GeneratedObjectAccessorService _static; |
| 28 ReflectiveObjectAccessorService _mirrors; | 28 ReflectiveObjectAccessorService _mirrors; |
| 29 | 29 |
| 30 _DebugObjectAccessorService(StaticConfiguration configuration) | 30 _DebugObjectAccessorService(StaticConfiguration configuration) |
| 31 : _static = new GeneratedObjectAccessorService(configuration), | 31 : _static = new GeneratedObjectAccessorService(configuration), |
| 32 _mirrors = new ReflectiveObjectAccessorService(); | 32 _mirrors = new ReflectiveObjectAccessorService(); |
| 33 | 33 |
| 34 read(Object object, Symbol name) => | 34 read(Object object, Symbol name) => _check('read', [ |
| 35 _check('read', [object, name], | 35 object, |
| 36 _static.read(object, name), | 36 name |
| 37 _mirrors.read(object, name)); | 37 ], _static.read(object, name), _mirrors.read(object, name)); |
| 38 | 38 |
| 39 // Note: we can't verify operations with side-effects like write or invoke. | 39 // Note: we can't verify operations with side-effects like write or invoke. |
| 40 void write(Object object, Symbol name, value) => | 40 void write(Object object, Symbol name, value) => |
| 41 _static.write(object, name, value); | 41 _static.write(object, name, value); |
| 42 | 42 |
| 43 invoke(object, Symbol name, List args, {Map namedArgs, bool adjust: false}) => | 43 invoke(object, Symbol name, List args, {Map namedArgs, bool adjust: false}) => |
| 44 _static.invoke(object, name, args, namedArgs: namedArgs, adjust: adjust); | 44 _static.invoke(object, name, args, namedArgs: namedArgs, adjust: adjust); |
| 45 } | 45 } |
| 46 | 46 |
| 47 /// Implements [TypeInspectorService] using a static configuration. | 47 /// Implements [TypeInspectorService] using a static configuration. |
| 48 class _DebugTypeInspectorService implements TypeInspectorService { | 48 class _DebugTypeInspectorService implements TypeInspectorService { |
| 49 GeneratedTypeInspectorService _static; | 49 GeneratedTypeInspectorService _static; |
| 50 ReflectiveTypeInspectorService _mirrors; | 50 ReflectiveTypeInspectorService _mirrors; |
| 51 | 51 |
| 52 _DebugTypeInspectorService(StaticConfiguration configuration) | 52 _DebugTypeInspectorService(StaticConfiguration configuration) |
| 53 : _static = new GeneratedTypeInspectorService(configuration), | 53 : _static = new GeneratedTypeInspectorService(configuration), |
| 54 _mirrors = new ReflectiveTypeInspectorService(); | 54 _mirrors = new ReflectiveTypeInspectorService(); |
| 55 | 55 |
| 56 bool isSubclassOf(Type type, Type supertype) => | 56 bool isSubclassOf(Type type, Type supertype) => _check('isSubclassOf', [ |
| 57 _check('isSubclassOf', [type, supertype], | 57 type, |
| 58 _static.isSubclassOf(type, supertype), | 58 supertype |
| 59 _mirrors.isSubclassOf(type, supertype)); | 59 ], _static.isSubclassOf(type, supertype), |
| 60 _mirrors.isSubclassOf(type, supertype)); |
| 60 | 61 |
| 61 bool hasGetter(Type type, Symbol name) => | 62 bool hasGetter(Type type, Symbol name) => _check('hasGetter', [ |
| 62 _check('hasGetter', [type, name], | 63 type, |
| 63 _static.hasGetter(type, name), | 64 name |
| 64 _mirrors.hasGetter(type, name)); | 65 ], _static.hasGetter(type, name), _mirrors.hasGetter(type, name)); |
| 65 | 66 |
| 66 bool hasSetter(Type type, Symbol name) => | 67 bool hasSetter(Type type, Symbol name) => _check('hasSetter', [ |
| 67 _check('hasSetter', [type, name], | 68 type, |
| 68 _static.hasSetter(type, name), | 69 name |
| 69 _mirrors.hasSetter(type, name)); | 70 ], _static.hasSetter(type, name), _mirrors.hasSetter(type, name)); |
| 70 | 71 |
| 71 bool hasInstanceMethod(Type type, Symbol name) => | 72 bool hasInstanceMethod(Type type, Symbol name) => _check('hasInstanceMethod', |
| 72 _check('hasInstanceMethod', [type, name], | 73 [type, name], _static.hasInstanceMethod(type, name), |
| 73 _static.hasInstanceMethod(type, name), | 74 _mirrors.hasInstanceMethod(type, name)); |
| 74 _mirrors.hasInstanceMethod(type, name)); | |
| 75 | 75 |
| 76 bool hasStaticMethod(Type type, Symbol name) => | 76 bool hasStaticMethod(Type type, Symbol name) => _check('hasStaticMethod', [ |
| 77 _check('hasStaticMethod', [type, name], | 77 type, |
| 78 _static.hasStaticMethod(type, name), | 78 name |
| 79 _mirrors.hasStaticMethod(type, name)); | 79 ], _static.hasStaticMethod(type, name), _mirrors.hasStaticMethod(type, name)); |
| 80 | 80 |
| 81 Declaration getDeclaration(Type type, Symbol name) => | 81 Declaration getDeclaration(Type type, Symbol name) => _check('getDeclaration', |
| 82 _check('getDeclaration', [type, name], | 82 [ |
| 83 _static.getDeclaration(type, name), | 83 type, |
| 84 _mirrors.getDeclaration(type, name)); | 84 name |
| 85 ], _static.getDeclaration(type, name), _mirrors.getDeclaration(type, name)); |
| 85 | 86 |
| 86 List<Declaration> query(Type type, QueryOptions options) => | 87 List<Declaration> query(Type type, QueryOptions options) => _check('query', [ |
| 87 _check('query', [type, options], | 88 type, |
| 88 _static.query(type, options), | 89 options |
| 89 _mirrors.query(type, options)); | 90 ], _static.query(type, options), _mirrors.query(type, options)); |
| 90 } | 91 } |
| 91 | 92 |
| 92 /// Implements [SymbolConverterService] using a static configuration. | 93 /// Implements [SymbolConverterService] using a static configuration. |
| 93 class _DebugSymbolConverterService implements SymbolConverterService { | 94 class _DebugSymbolConverterService implements SymbolConverterService { |
| 94 GeneratedSymbolConverterService _static; | 95 GeneratedSymbolConverterService _static; |
| 95 ReflectiveSymbolConverterService _mirrors; | 96 ReflectiveSymbolConverterService _mirrors; |
| 96 | 97 |
| 97 _DebugSymbolConverterService(StaticConfiguration configuration) | 98 _DebugSymbolConverterService(StaticConfiguration configuration) |
| 98 : _static = new GeneratedSymbolConverterService(configuration), | 99 : _static = new GeneratedSymbolConverterService(configuration), |
| 99 _mirrors = new ReflectiveSymbolConverterService(); | 100 _mirrors = new ReflectiveSymbolConverterService(); |
| 100 | 101 |
| 101 String symbolToName(Symbol symbol) => | 102 String symbolToName(Symbol symbol) => _check('symbolToName', [symbol], |
| 102 _check('symbolToName', [symbol], | 103 _static.symbolToName(symbol), _mirrors.symbolToName(symbol)); |
| 103 _static.symbolToName(symbol), | |
| 104 _mirrors.symbolToName(symbol)); | |
| 105 | 104 |
| 106 Symbol nameToSymbol(String name) => | 105 Symbol nameToSymbol(String name) => _check('nameToSymbol', [name], |
| 107 _check('nameToSymbol', [name], | 106 _static.nameToSymbol(name), _mirrors.nameToSymbol(name)); |
| 108 _static.nameToSymbol(name), | |
| 109 _mirrors.nameToSymbol(name)); | |
| 110 } | 107 } |
| 111 | 108 |
| 112 _check(String operation, List arguments, staticResult, mirrorResult) { | 109 _check(String operation, List arguments, staticResult, mirrorResult) { |
| 113 if (staticResult == mirrorResult) return staticResult; | 110 if (staticResult == mirrorResult) return staticResult; |
| 114 if (staticResult is List && mirrorResult is List && | 111 if (staticResult is List && |
| 112 mirrorResult is List && |
| 115 compareLists(staticResult, mirrorResult, unordered: true)) { | 113 compareLists(staticResult, mirrorResult, unordered: true)) { |
| 116 return staticResult; | 114 return staticResult; |
| 117 } | 115 } |
| 118 print('warning: inconsistent result on $operation(${arguments.join(', ')})\n' | 116 print('warning: inconsistent result on $operation(${arguments.join(', ')})\n' |
| 119 'smoke.mirrors result: $mirrorResult\n' | 117 'smoke.mirrors result: $mirrorResult\n' |
| 120 'smoke.static result: $staticResult\n'); | 118 'smoke.static result: $staticResult\n'); |
| 121 return staticResult; | 119 return staticResult; |
| 122 } | 120 } |
| OLD | NEW |