diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-10-25 19:18:09 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-10-25 19:34:44 +0000 |
| commit | 368f2dd010defaf5f4b6deb70f45285cee8f244d (patch) | |
| tree | 55494f85341f23dd1e588fa070ef863ef7cfdef5 /src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java | |
| parent | 060ae04a695df6abac7445df3c5394b59da40f41 (diff) | |
Remove lombok
Diffstat (limited to 'src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java b/src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java index 8787d81..c5ea3e3 100644 --- a/src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java +++ b/src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java @@ -5,62 +5,55 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; - import org.zwobble.couscous.ast.TypeName; import org.zwobble.couscous.ast.ClassNode; - import static java.util.Arrays.asList; import static org.zwobble.couscous.backends.python.PythonCodeGenerator.generateCode; import static org.zwobble.couscous.backends.python.PythonSerializer.serialize; -import lombok.SneakyThrows; -import lombok.val; - public class PythonCompiler { private final Path root; private final String packageName; - + public PythonCompiler(Path root, String packageName) { this.root = root; this.packageName = packageName; } public void compile(List<ClassNode> classes) { - for (val classNode : classes) { + for (ClassNode classNode : classes) { compileClass(classNode); } - writeClass(TypeName.of("java.lang.Integer"), - "class Integer(object):\n" + - " def parseInt(value):\n" + - " return int(value)" - ); + writeClass(TypeName.of("java.lang.Integer"), "class Integer(object):\n def parseInt(value):\n return int(value)"); } - + private Path pathForClass(TypeName className) { - return root - .resolve(packageName) + return root.resolve(packageName) .resolve(className.getQualifiedName().replace(".", File.separator) + ".py"); } - + private void compileClass(ClassNode classNode) { writeClass(classNode.getName(), serialize(generateCode(classNode))); } - - @SneakyThrows + private void writeClass(TypeName name, String contents) { - val path = pathForClass(name); - Files.createDirectories(path.getParent()); - createPythonPackages(path.getParent()); - Files.write(path, asList(contents)); + try { + final java.nio.file.Path path = pathForClass(name); + Files.createDirectories(path.getParent()); + createPythonPackages(path.getParent()); + Files.write(path, asList(contents)); + } catch (final java.lang.Throwable $ex) { + throw new RuntimeException($ex); + } } - + private void createPythonPackages(Path packagePath) throws IOException { while (packagePath.startsWith(root)) { - val packageFile = packagePath.resolve("__init__.py"); + final java.nio.file.Path packageFile = packagePath.resolve("__init__.py"); if (!packageFile.toFile().exists()) { Files.createFile(packageFile); } packagePath = packagePath.getParent(); } } -} +}
\ No newline at end of file |
