summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
index 4a21d88..52683b5 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/java/JavaWriter.java
@@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.List;
+import java.util.Optional;
import static org.zwobble.hobgoblin.compiler.output.CodeWriter.writeWithSeparator;
@@ -416,11 +417,7 @@ public class JavaWriter implements AutoCloseable {
private void writeEnhancedForStatement(JavaEnhancedForStatement enhancedForStatement) throws IOException {
this.writer.write("for (");
- if (enhancedForStatement.elementType().isPresent()) {
- this.writeTypeRef(enhancedForStatement.elementType().get());
- } else {
- this.writer.write("var");
- }
+ writeLocalVariableType(enhancedForStatement.elementType());
this.writer.write(" ");
this.writeIdentifier(enhancedForStatement.elementName());
@@ -445,11 +442,7 @@ public class JavaWriter implements AutoCloseable {
}
private void writeLocalVariableDeclaration(JavaLocalVariableDeclaration localVariableDeclaration) throws IOException {
- if (localVariableDeclaration.type().isPresent()) {
- this.writeTypeRef(localVariableDeclaration.type().get());
- } else {
- this.writer.write("var");
- }
+ writeLocalVariableType(localVariableDeclaration.type());
this.writer.write(" ");
this.writeIdentifier(localVariableDeclaration.name());
@@ -458,6 +451,14 @@ public class JavaWriter implements AutoCloseable {
this.writer.write(";");
}
+ private void writeLocalVariableType(Optional<JavaTypeRef> type) throws IOException {
+ if (type.isPresent()) {
+ this.writeTypeRef(type.get());
+ } else {
+ this.writer.write("var");
+ }
+ }
+
private void writeReturnStatement(JavaReturn returnStatement) throws IOException {
this.writer.write("return ");
writeTopLevelExpression(returnStatement.value());