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

Unified Diff: pkg/smoke/lib/codegen/generator.dart

Issue 208583003: Fix string literals and add support for static methods in smoke. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minor fix - inlcude name for static method too Created 6 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/smoke/lib/codegen/recorder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/smoke/lib/codegen/generator.dart
diff --git a/pkg/smoke/lib/codegen/generator.dart b/pkg/smoke/lib/codegen/generator.dart
index 6269abe9ff6baa2e4f4ab0e73882157f1d0182b2..42c5455763b5e45ebe5532ecae0b434a1392214d 100644
--- a/pkg/smoke/lib/codegen/generator.dart
+++ b/pkg/smoke/lib/codegen/generator.dart
@@ -43,6 +43,9 @@ class SmokeCodeGenerator {
final Map<TypeIdentifier, Map<String, _DeclarationCode>> _declarations =
new SplayTreeMap();
+ /// Static methods used on each type.
+ final Map<TypeIdentifier, Set<String>> _staticMethods = new SplayTreeMap();
+
/// Names that are used both as strings and symbols.
final Set<String> _names = new SplayTreeSet();
@@ -58,6 +61,14 @@ class SmokeCodeGenerator {
/// Register that [name] might be needed as a symbol.
void addSymbol(String name) { _names.add(name); }
+ /// Register that `cls.name` is used as a static method in the code.
+ void addStaticMethod(TypeIdentifier cls, String name) {
+ var methods = _staticMethods.putIfAbsent(cls,
+ () => new SplayTreeSet<String>());
+ _addLibrary(cls.importUrl);
+ methods.add(name);
+ }
+
int _mixins = 0;
/// Creates a new type to represent a mixin. Use [comment] to help users
@@ -208,8 +219,29 @@ class SmokeCodeGenerator {
args['declarations'] = declarations;
}
+ if (_staticMethods.isNotEmpty) {
+ var methods = [];
+ _staticMethods.forEach((type, members) {
+ var className = type.asCode(_libraryPrefix);
+ final sb = new StringBuffer()
+ ..write(className)
+ ..write(': ');
+ if (members.isEmpty) {
+ sb.write('const {}');
+ } else {
+ sb.write('{\n');
+ for (var name in members) {
+ sb.write('$spaces #$name: $className.$name,\n');
+ }
+ sb.write('$spaces }');
+ }
+ methods.add(sb.toString());
+ });
+ args['staticMethods'] = methods;
+ }
+
if (_names.isNotEmpty) {
- args['names'] = _names.map((n) => "#$n: '$n'");
+ args['names'] = _names.map((n) => "#$n: r'$n'");
}
buffer..write(spaces)
« no previous file with comments | « no previous file | pkg/smoke/lib/codegen/recorder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698