| 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 'package:html5lib/dom.dart' as dom; | 10 import 'package:html5lib/dom.dart' as dom; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 * opening brace. | 89 * opening brace. |
| 90 */ | 90 */ |
| 91 void makeClass(String header, void callback()) { | 91 void makeClass(String header, void callback()) { |
| 92 _CodegenJavaState oldState = _state; | 92 _CodegenJavaState oldState = _state; |
| 93 try { | 93 try { |
| 94 _state = new _CodegenJavaState(); | 94 _state = new _CodegenJavaState(); |
| 95 callback(); | 95 callback(); |
| 96 writeln('$header {'); | 96 writeln('$header {'); |
| 97 indent(() { | 97 indent(() { |
| 98 // fields | 98 // fields |
| 99 List<String> allFields = _valuesSortedByKey(_state.privateFields).toList
(); | 99 List<String> allFields = |
| 100 _valuesSortedByKey(_state.privateFields).toList(); |
| 100 for (String field in allFields) { | 101 for (String field in allFields) { |
| 101 writeln(); | 102 writeln(); |
| 102 write(field); | 103 write(field); |
| 103 } | 104 } |
| 104 | 105 |
| 105 // constructors | 106 // constructors |
| 106 List<String> allConstructors = _valuesSortedByKey(_state.constructors).t
oList(); | 107 List<String> allConstructors = |
| 108 _valuesSortedByKey(_state.constructors).toList(); |
| 107 for (String constructor in allConstructors) { | 109 for (String constructor in allConstructors) { |
| 108 writeln(); | 110 writeln(); |
| 109 write(constructor); | 111 write(constructor); |
| 110 } | 112 } |
| 111 | 113 |
| 112 // methods | 114 // methods |
| 113 List<String> allMethods = _valuesSortedByKey(_state.publicMethods).toLis
t(); | 115 List<String> allMethods = |
| 116 _valuesSortedByKey(_state.publicMethods).toList(); |
| 114 allMethods.addAll(_valuesSortedByKey(_state.privateMethods)); | 117 allMethods.addAll(_valuesSortedByKey(_state.privateMethods)); |
| 115 for (String method in allMethods) { | 118 for (String method in allMethods) { |
| 116 writeln(); | 119 writeln(); |
| 117 write(method); | 120 write(method); |
| 118 } | 121 } |
| 119 }); | 122 }); |
| 120 writeln('}'); | 123 writeln('}'); |
| 121 } finally { | 124 } finally { |
| 122 _state = oldState; | 125 _state = oldState; |
| 123 } | 126 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 /** | 236 /** |
| 234 * Temporary storage for constructors. | 237 * Temporary storage for constructors. |
| 235 */ | 238 */ |
| 236 Map<String, String> constructors = <String, String>{}; | 239 Map<String, String> constructors = <String, String>{}; |
| 237 } | 240 } |
| 238 | 241 |
| 239 /** | 242 /** |
| 240 * Create a [GeneratedFile] that creates Java code and outputs it to [path]. | 243 * Create a [GeneratedFile] that creates Java code and outputs it to [path]. |
| 241 * [path] uses Posix-style path separators regardless of the OS. | 244 * [path] uses Posix-style path separators regardless of the OS. |
| 242 */ | 245 */ |
| 243 GeneratedFile javaGeneratedFile(String path, CodegenJavaVisitor createVisitor(Ap
i api)) { | 246 GeneratedFile javaGeneratedFile(String path, CodegenJavaVisitor |
| 247 createVisitor(Api api)) { |
| 244 return new GeneratedFile(path, () { | 248 return new GeneratedFile(path, () { |
| 245 CodegenJavaVisitor visitor = createVisitor(readApi()); | 249 CodegenJavaVisitor visitor = createVisitor(readApi()); |
| 246 return visitor.collectCode(visitor.visitApi); | 250 return visitor.collectCode(visitor.visitApi); |
| 247 }); | 251 }); |
| 248 } | 252 } |
| OLD | NEW |