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 using code-generated data. | 5 /// Static implementation of smoke services using code-generated data. |
6 library smoke.static; | 6 library smoke.static; |
7 | 7 |
8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'package:smoke/smoke.dart'; | 10 import 'package:smoke/smoke.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 /// Static methods for each type. | 32 /// Static methods for each type. |
33 // TODO(sigmund): should we add static getters & setters too? | 33 // TODO(sigmund): should we add static getters & setters too? |
34 final Map<Type, Map<Symbol, Function>> staticMethods; | 34 final Map<Type, Map<Symbol, Function>> staticMethods; |
35 | 35 |
36 /// A map from symbol to strings. | 36 /// A map from symbol to strings. |
37 final Map<Symbol, String> names; | 37 final Map<Symbol, String> names; |
38 | 38 |
39 /// A map from strings to symbols (the reverse of [names]). | 39 /// A map from strings to symbols (the reverse of [names]). |
40 final Map<String, Symbol> _symbols = {}; | 40 final Map<String, Symbol> _symbols = {}; |
41 | 41 |
42 | |
43 /// Whether to check for missing declarations, otherwise, return default | 42 /// Whether to check for missing declarations, otherwise, return default |
44 /// values (for example a missing parent class can be treated as Object) | 43 /// values (for example a missing parent class can be treated as Object) |
45 final bool checkedMode; | 44 final bool checkedMode; |
46 | 45 |
47 StaticConfiguration({ | 46 StaticConfiguration({Map<Symbol, Getter> getters, Map<Symbol, Setter> setters, |
48 Map<Symbol, Getter> getters, | 47 Map<Type, Type> parents, Map<Type, Map<Symbol, Declaration>> declarations, |
49 Map<Symbol, Setter> setters, | 48 Map<Type, Map<Symbol, Function>> staticMethods, Map<Symbol, String> names, |
50 Map<Type, Type> parents, | |
51 Map<Type, Map<Symbol, Declaration>> declarations, | |
52 Map<Type, Map<Symbol, Function>> staticMethods, | |
53 Map<Symbol, String> names, | |
54 this.checkedMode: true}) | 49 this.checkedMode: true}) |
55 : getters = getters != null ? getters : {}, | 50 : getters = getters != null ? getters : {}, |
56 setters = setters != null ? setters : {}, | 51 setters = setters != null ? setters : {}, |
57 parents = parents != null ? parents : {}, | 52 parents = parents != null ? parents : {}, |
58 declarations = declarations != null ? declarations : {}, | 53 declarations = declarations != null ? declarations : {}, |
59 staticMethods = staticMethods != null ? staticMethods : {}, | 54 staticMethods = staticMethods != null ? staticMethods : {}, |
60 names = names != null ? names : {} { | 55 names = names != null ? names : {} { |
61 this.names.forEach((k, v) { _symbols[v] = k; }); | 56 this.names.forEach((k, v) { |
| 57 _symbols[v] = k; |
| 58 }); |
62 } | 59 } |
63 | 60 |
64 void addAll(StaticConfiguration other) { | 61 void addAll(StaticConfiguration other) { |
65 getters.addAll(other.getters); | 62 getters.addAll(other.getters); |
66 setters.addAll(other.setters); | 63 setters.addAll(other.setters); |
67 parents.addAll(other.parents); | 64 parents.addAll(other.parents); |
68 _nestedAddAll(declarations, other.declarations); | 65 _nestedAddAll(declarations, other.declarations); |
69 _nestedAddAll(staticMethods, other.staticMethods); | 66 _nestedAddAll(staticMethods, other.staticMethods); |
70 names.addAll(other.names); | 67 names.addAll(other.names); |
71 other.names.forEach((k, v) { _symbols[v] = k; }); | 68 other.names.forEach((k, v) { |
| 69 _symbols[v] = k; |
| 70 }); |
72 } | 71 } |
73 | 72 |
74 static _nestedAddAll(Map a, Map b) { | 73 static _nestedAddAll(Map a, Map b) { |
75 for (var key in b.keys) { | 74 for (var key in b.keys) { |
76 a.putIfAbsent(key, () => {}); | 75 a.putIfAbsent(key, () => {}); |
77 a[key].addAll(b[key]); | 76 a[key].addAll(b[key]); |
78 } | 77 } |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 final StaticConfiguration _configuration; | 271 final StaticConfiguration _configuration; |
273 Map<Symbol, String> get _names => _configuration.names; | 272 Map<Symbol, String> get _names => _configuration.names; |
274 Map<String, Symbol> get _symbols => _configuration._symbols; | 273 Map<String, Symbol> get _symbols => _configuration._symbols; |
275 | 274 |
276 GeneratedSymbolConverterService(this._configuration); | 275 GeneratedSymbolConverterService(this._configuration); |
277 | 276 |
278 String symbolToName(Symbol symbol) => _names[symbol]; | 277 String symbolToName(Symbol symbol) => _names[symbol]; |
279 Symbol nameToSymbol(String name) => _symbols[name]; | 278 Symbol nameToSymbol(String name) => _symbols[name]; |
280 } | 279 } |
281 | 280 |
282 | |
283 /// Exception thrown when trynig to access something that should be there, but | 281 /// Exception thrown when trynig to access something that should be there, but |
284 /// the code generator didn't include it. | 282 /// the code generator didn't include it. |
285 class MissingCodeException implements Exception { | 283 class MissingCodeException implements Exception { |
286 final String description; | 284 final String description; |
287 MissingCodeException(this.description); | 285 MissingCodeException(this.description); |
288 | 286 |
289 String toString() => 'Missing $description. ' | 287 String toString() => 'Missing $description. ' |
290 'Code generation for the smoke package seems incomplete.'; | 288 'Code generation for the smoke package seems incomplete.'; |
291 } | 289 } |
OLD | NEW |