| 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'; | 10 import 'dart:io'; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 String typeName = resolvedType.typeName; | 95 String typeName = resolvedType.typeName; |
| 96 if (_typeRenames.containsKey(typeName)) { | 96 if (_typeRenames.containsKey(typeName)) { |
| 97 return _typeRenames[typeName]; | 97 return _typeRenames[typeName]; |
| 98 } else { | 98 } else { |
| 99 return typeName; | 99 return typeName; |
| 100 } | 100 } |
| 101 } else if (type is TypeList) { | 101 } else if (type is TypeList) { |
| 102 return 'List<${javaType(type.itemType)}>'; | 102 return 'List<${javaType(type.itemType)}>'; |
| 103 } else if (type is TypeMap) { | 103 } else if (type is TypeMap) { |
| 104 return 'Map<${javaType(type.keyType)}, ${javaType(type.valueType)}>'; | 104 return 'Map<${javaType(type.keyType)}, ${javaType(type.valueType)}>'; |
| 105 } else if (type is TypeUnion) { |
| 106 return 'Object'; |
| 105 } else { | 107 } else { |
| 106 throw new Exception("Can't make type buildable"); | 108 throw new Exception("Can't make type buildable"); |
| 107 } | 109 } |
| 108 } | 110 } |
| 109 | 111 |
| 110 /** | 112 /** |
| 111 * Return a suitable representation of [name] as the name of a Java variable. | 113 * Return a suitable representation of [name] as the name of a Java variable. |
| 112 */ | 114 */ |
| 113 String javaName(String name) { | 115 String javaName(String name) { |
| 114 if (_variableRenames.containsKey(name)) { | 116 if (_variableRenames.containsKey(name)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 154 } |
| 153 | 155 |
| 154 /** | 156 /** |
| 155 * Use [visitor] to create Java code and output it to [path]. | 157 * Use [visitor] to create Java code and output it to [path]. |
| 156 */ | 158 */ |
| 157 void createJavaCode(String path, CodegenJavaVisitor visitor) { | 159 void createJavaCode(String path, CodegenJavaVisitor visitor) { |
| 158 String code = visitor.collectCode(visitor.visitApi); | 160 String code = visitor.collectCode(visitor.visitApi); |
| 159 File outputFile = new File(path); | 161 File outputFile = new File(path); |
| 160 outputFile.writeAsStringSync(code); | 162 outputFile.writeAsStringSync(code); |
| 161 } | 163 } |
| OLD | NEW |