| 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 /** | 5 /** |
| 6 * Tools for Java code generation. | 6 * Tools for Java code generation. |
| 7 */ | 7 */ |
| 8 library CodegenJava; | 8 library CodegenJava; |
| 9 | 9 |
| 10 import 'dart:io'; | |
| 11 | |
| 12 import 'api.dart'; | 10 import 'api.dart'; |
| 13 import 'codegen_tools.dart'; | 11 import 'codegen_tools.dart'; |
| 12 import 'from_html.dart'; |
| 14 import 'to_html.dart'; | 13 import 'to_html.dart'; |
| 15 | 14 |
| 16 /** | 15 /** |
| 17 * Common code for all Java code generation. | 16 * Common code for all Java code generation. |
| 18 */ | 17 */ |
| 19 class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { | 18 class CodegenJavaVisitor extends HierarchicalApiVisitor with CodeGenerator { |
| 20 _CodegenJavaState _state; | 19 _CodegenJavaState _state; |
| 21 | 20 |
| 22 /** | 21 /** |
| 23 * Variable names which must be changed in order to avoid conflict with | 22 * Variable names which must be changed in order to avoid conflict with |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 */ | 144 */ |
| 146 Map<String, String> publicMethods = <String, String>{}; | 145 Map<String, String> publicMethods = <String, String>{}; |
| 147 | 146 |
| 148 /** | 147 /** |
| 149 * Temporary storage for private methods. | 148 * Temporary storage for private methods. |
| 150 */ | 149 */ |
| 151 Map<String, String> privateMethods = <String, String>{}; | 150 Map<String, String> privateMethods = <String, String>{}; |
| 152 } | 151 } |
| 153 | 152 |
| 154 /** | 153 /** |
| 155 * Use [visitor] to create Java code and output it to [path]. | 154 * Create a [GeneratedFile] that creates Java code and outputs it to [path]. |
| 155 * [path] uses Posix-style path separators regardless of the OS. |
| 156 */ | 156 */ |
| 157 void createJavaCode(String path, CodegenJavaVisitor visitor) { | 157 GeneratedFile javaGeneratedFile(String path, CodegenJavaVisitor createVisitor(Ap
i api)) { |
| 158 String code = visitor.collectCode(visitor.visitApi); | 158 return new GeneratedFile(path, () { |
| 159 File outputFile = new File(path); | 159 CodegenJavaVisitor visitor = createVisitor(readApi()); |
| 160 outputFile.writeAsStringSync(code); | 160 return visitor.collectCode(visitor.visitApi); |
| 161 }); |
| 161 } | 162 } |
| OLD | NEW |