aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/backends/python
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-10-25 19:18:09 +0000
committerMichael Williamson <mike@zwobble.org>2015-10-25 19:34:44 +0000
commit368f2dd010defaf5f4b6deb70f45285cee8f244d (patch)
tree55494f85341f23dd1e588fa070ef863ef7cfdef5 /src/main/java/org/zwobble/couscous/backends/python
parent060ae04a695df6abac7445df3c5394b59da40f41 (diff)
Remove lombok
Diffstat (limited to 'src/main/java/org/zwobble/couscous/backends/python')
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java190
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/PythonCompiler.java43
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java80
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonAssignmentNode.java58
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonAttributeAccessNode.java58
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonBooleanLiteralNode.java42
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonCallNode.java60
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonClassNode.java67
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonConditionalExpressionNode.java70
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonFunctionDefinitionNode.java76
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonGetSliceNode.java59
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportAliasNode.java44
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportNode.java59
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonIntegerLiteralNode.java43
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonModuleNode.java48
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonReturnNode.java45
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonStringLiteralNode.java46
-rw-r--r--src/main/java/org/zwobble/couscous/backends/python/ast/PythonVariableReferenceNode.java46
18 files changed, 821 insertions, 313 deletions
diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java b/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java
index cc2b116..01e62c1 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/PythonCodeGenerator.java
@@ -1,10 +1,10 @@
package org.zwobble.couscous.backends.python;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-
import org.zwobble.couscous.ast.AssignmentNode;
import org.zwobble.couscous.ast.ClassNode;
import org.zwobble.couscous.ast.ConstructorCallNode;
@@ -28,6 +28,7 @@ import org.zwobble.couscous.ast.visitors.NodeVisitorWithEmptyDefaults;
import org.zwobble.couscous.ast.visitors.NodeVisitors;
import org.zwobble.couscous.ast.visitors.StatementNodeMapper;
import org.zwobble.couscous.backends.python.ast.PythonBlock;
+import org.zwobble.couscous.backends.python.ast.PythonClassNode;
import org.zwobble.couscous.backends.python.ast.PythonExpressionNode;
import org.zwobble.couscous.backends.python.ast.PythonFunctionDefinitionNode;
import org.zwobble.couscous.backends.python.ast.PythonImportNode;
@@ -40,13 +41,11 @@ import org.zwobble.couscous.values.PrimitiveValue;
import org.zwobble.couscous.values.PrimitiveValueVisitor;
import org.zwobble.couscous.values.StringValue;
import org.zwobble.couscous.values.UnitValue;
-
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
-
import static com.google.common.collect.Iterators.singletonIterator;
import static java.util.Arrays.asList;
import static org.zwobble.couscous.backends.python.ast.PythonAssignmentNode.pythonAssignment;
@@ -64,54 +63,38 @@ import static org.zwobble.couscous.backends.python.ast.PythonReturnNode.pythonRe
import static org.zwobble.couscous.backends.python.ast.PythonStringLiteralNode.pythonStringLiteral;
import static org.zwobble.couscous.backends.python.ast.PythonVariableReferenceNode.pythonVariableReference;
-import lombok.val;
-
public class PythonCodeGenerator {
+
+
public static PythonModuleNode generateCode(ClassNode classNode) {
- val imports = generateImports(classNode).iterator();
-
- val constructor = generateConstructor(classNode.getConstructor());
-
- val pythonMethods = Iterables.transform(
- classNode.getMethods(),
- PythonCodeGenerator::generateFunction);
-
-
- val pythonBody = Iterables.concat(
- asList(constructor),
- pythonMethods);
-
- val pythonClass = pythonClass(
- classNode.getSimpleName(),
- ImmutableList.copyOf(pythonBody));
-
- return pythonModule(ImmutableList.copyOf(Iterators.concat(
- imports,
- singletonIterator(pythonClass))));
+ Iterator<org.zwobble.couscous.backends.python.ast.PythonImportNode> imports = generateImports(classNode).iterator();
+ PythonFunctionDefinitionNode constructor = generateConstructor(classNode.getConstructor());
+ Iterable<PythonFunctionDefinitionNode> pythonMethods = Iterables.transform(classNode.getMethods(), PythonCodeGenerator::generateFunction);
+ Iterable<PythonStatementNode> pythonBody = Iterables.concat(asList(constructor), pythonMethods);
+ PythonClassNode pythonClass = pythonClass(classNode.getSimpleName(), ImmutableList.copyOf(pythonBody));
+ return pythonModule(ImmutableList.copyOf(Iterators.concat(imports, singletonIterator(pythonClass))));
}
-
+
private static Stream<PythonImportNode> generateImports(ClassNode classNode) {
- val classes = findReferencedClasses(classNode);
- return classes.stream()
- .map(name -> pythonImport(
- Strings.repeat(".", packageDepth(classNode) + 1) + name.getQualifiedName(),
- asList(pythonImportAlias(name.getSimpleName()))));
+ final java.util.Set<org.zwobble.couscous.ast.TypeName> classes = findReferencedClasses(classNode);
+ return classes.stream().map(name -> pythonImport(Strings.repeat(".", packageDepth(classNode) + 1) + name.getQualifiedName(), asList(pythonImportAlias(name.getSimpleName()))));
}
private static int packageDepth(ClassNode classNode) {
int depth = 0;
- val qualifiedName = classNode.getName().getQualifiedName();
+ final java.lang.String qualifiedName = classNode.getName().getQualifiedName();
for (int index = 0; index < qualifiedName.length(); index++) {
if (qualifiedName.charAt(index) == '.') {
- depth += 1;
+ depth += 1;
}
}
return depth;
}
private static Set<TypeName> findReferencedClasses(ClassNode classNode) {
- val imports = ImmutableSet.<TypeName>builder();
- NodeVisitors.visitAll(classNode, new NodeVisitorWithEmptyDefaults() {
+ ImmutableSet.Builder<TypeName> imports = ImmutableSet.builder();
+ NodeVisitors.visitAll(classNode, new NodeVisitorWithEmptyDefaults(){
+
@Override
public void visit(StaticMethodCallNode staticMethodCall) {
imports.add(staticMethodCall.getClassName());
@@ -126,22 +109,23 @@ public class PythonCodeGenerator {
}
public static PythonExpressionNode generateCode(PrimitiveValue value) {
- return value.accept(new PrimitiveValueVisitor<PythonExpressionNode>() {
+ return value.accept(new PrimitiveValueVisitor<PythonExpressionNode>(){
+
@Override
public PythonExpressionNode visit(IntegerValue value) {
return pythonIntegerLiteral(value.getValue());
}
-
+
@Override
public PythonExpressionNode visit(StringValue value) {
return pythonStringLiteral(value.getValue());
}
-
+
@Override
public PythonExpressionNode visit(BooleanValue value) {
return pythonBooleanLiteral(value.getValue());
}
-
+
@Override
public PythonExpressionNode visit(UnitValue unitValue) {
throw new UnsupportedOperationException();
@@ -149,45 +133,18 @@ public class PythonCodeGenerator {
});
}
- private static PythonFunctionDefinitionNode generateConstructor(
- ConstructorNode constructor) {
- val explicitArgumentNames = Iterables.transform(
- constructor.getArguments(),
- argument -> argument.getName());
-
- val argumentNames = Iterables.concat(
- asList("self"),
- explicitArgumentNames);
-
- val pythonBody = constructor.getBody()
- .stream()
- .map(PythonCodeGenerator::generateStatement)
- .collect(Collectors.toList());
-
- return pythonFunctionDefinition(
- "__init__",
- ImmutableList.copyOf(argumentNames),
- new PythonBlock(pythonBody));
+ private static PythonFunctionDefinitionNode generateConstructor(ConstructorNode constructor) {
+ Iterable<String> explicitArgumentNames = Iterables.transform(constructor.getArguments(), argument -> argument.getName());
+ Iterable<String> argumentNames = Iterables.concat(asList("self"), explicitArgumentNames);
+ List<PythonStatementNode> pythonBody = constructor.getBody().stream().map(PythonCodeGenerator::generateStatement).collect(Collectors.toList());
+ return pythonFunctionDefinition("__init__", ImmutableList.copyOf(argumentNames), new PythonBlock(pythonBody));
}
private static PythonFunctionDefinitionNode generateFunction(MethodNode method) {
- val explicitArgumentNames = Iterables.transform(
- method.getArguments(),
- argument -> argument.getName());
-
- val argumentNames = Iterables.concat(
- method.isStatic() ? asList() : asList("self"),
- explicitArgumentNames);
-
- val pythonBody = method.getBody()
- .stream()
- .map(PythonCodeGenerator::generateStatement)
- .collect(Collectors.toList());
-
- return pythonFunctionDefinition(
- method.getName(),
- ImmutableList.copyOf(argumentNames),
- new PythonBlock(pythonBody));
+ Iterable<String> explicitArgumentNames = Iterables.transform(method.getArguments(), argument -> argument.getName());
+ Iterable<String> argumentNames = Iterables.concat(method.isStatic() ? asList() : asList("self"), explicitArgumentNames);
+ List<PythonStatementNode> pythonBody = method.getBody().stream().map(PythonCodeGenerator::generateStatement).collect(Collectors.toList());
+ return pythonFunctionDefinition(method.getName(), ImmutableList.copyOf(argumentNames), new PythonBlock(pythonBody));
}
private static PythonStatementNode generateStatement(StatementNode statement) {
@@ -195,28 +152,26 @@ public class PythonCodeGenerator {
}
private static class StatementGenerator implements StatementNodeMapper<PythonStatementNode> {
+
+
@Override
public PythonStatementNode visit(ReturnNode returnNode) {
return pythonReturn(generateExpression(returnNode.getValue()));
}
-
+
@Override
public PythonStatementNode visit(ExpressionStatementNode expressionStatement) {
if (expressionStatement.getExpression() instanceof AssignmentNode) {
- val assignment = (AssignmentNode) expressionStatement.getExpression();
- return pythonAssignment(
- assignment.getTarget().accept(EXPRESSION_GENERATOR),
- generateExpression(assignment.getValue()));
+ final org.zwobble.couscous.ast.AssignmentNode assignment = (AssignmentNode)expressionStatement.getExpression();
+ return pythonAssignment(assignment.getTarget().accept(EXPRESSION_GENERATOR), generateExpression(assignment.getValue()));
} else {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException();
}
}
-
+
@Override
public PythonStatementNode visit(LocalVariableDeclarationNode declaration) {
- return pythonAssignment(
- pythonVariableReference(declaration.getDeclaration().getName()),
- generateExpression(declaration.getInitialValue()));
+ return pythonAssignment(pythonVariableReference(declaration.getDeclaration().getName()), generateExpression(declaration.getInitialValue()));
}
}
@@ -225,89 +180,74 @@ public class PythonCodeGenerator {
}
private static List<PythonExpressionNode> generateExpressions(Iterable<ExpressionNode> expressions) {
- return ImmutableList.copyOf(
- Iterables.transform(expressions, PythonCodeGenerator::generateExpression));
+ return ImmutableList.copyOf(Iterables.transform(expressions, PythonCodeGenerator::generateExpression));
}
-
private static final ExpressionGenerator EXPRESSION_GENERATOR = new ExpressionGenerator();
private static class ExpressionGenerator implements ExpressionNodeMapper<PythonExpressionNode> {
+
+
@Override
public PythonExpressionNode visit(LiteralNode literal) {
return generateCode(literal.getValue());
}
-
+
@Override
public PythonVariableReferenceNode visit(VariableReferenceNode variableReference) {
return pythonVariableReference(variableReference.getReferent().getName());
}
-
+
@Override
public PythonExpressionNode visit(ThisReferenceNode reference) {
return pythonVariableReference("self");
}
-
+
@Override
public PythonExpressionNode visit(AssignmentNode assignment) {
throw new UnsupportedOperationException();
}
-
+
@Override
public PythonExpressionNode visit(TernaryConditionalNode ternaryConditional) {
- return pythonConditionalExpression(
- generateExpression(ternaryConditional.getCondition()),
- generateExpression(ternaryConditional.getIfTrue()),
- generateExpression(ternaryConditional.getIfFalse()));
+ return pythonConditionalExpression(generateExpression(ternaryConditional.getCondition()), generateExpression(ternaryConditional.getIfTrue()), generateExpression(ternaryConditional.getIfFalse()));
}
-
+
@Override
public PythonExpressionNode visit(MethodCallNode methodCall) {
- val receiver = generateExpression(methodCall.getReceiver());
- val arguments = generateExpressions(methodCall.getArguments());
+ final org.zwobble.couscous.backends.python.ast.PythonExpressionNode receiver = generateExpression(methodCall.getReceiver());
+ final java.util.List<org.zwobble.couscous.backends.python.ast.PythonExpressionNode> arguments = generateExpressions(methodCall.getArguments());
if (isPrimitive(methodCall.getReceiver())) {
- val primitiveMethodGenerator = PrimitiveMethods.getPrimitiveMethod(
- methodCall.getReceiver().getType(),
- methodCall.getMethodName()).get();
+ final org.zwobble.couscous.backends.python.PrimitiveMethods.PrimitiveMethodGenerator primitiveMethodGenerator = PrimitiveMethods.getPrimitiveMethod(methodCall.getReceiver().getType(), methodCall.getMethodName()).get();
return primitiveMethodGenerator.generate(receiver, arguments);
} else {
- return pythonCall(
- pythonAttributeAccess(receiver, methodCall.getMethodName()),
- arguments);
+ return pythonCall(pythonAttributeAccess(receiver, methodCall.getMethodName()), arguments);
}
}
-
+
@Override
public PythonExpressionNode visit(StaticMethodCallNode staticMethodCall) {
- val className = staticMethodCall.getClassName();
- val classReference = pythonVariableReference(className.getSimpleName());
-
- val methodReference = pythonAttributeAccess(
- classReference,
- staticMethodCall.getMethodName());
-
- val arguments = generateExpressions(staticMethodCall.getArguments());
-
+ final org.zwobble.couscous.ast.TypeName className = staticMethodCall.getClassName();
+ final org.zwobble.couscous.backends.python.ast.PythonVariableReferenceNode classReference = pythonVariableReference(className.getSimpleName());
+ final org.zwobble.couscous.backends.python.ast.PythonAttributeAccessNode methodReference = pythonAttributeAccess(classReference, staticMethodCall.getMethodName());
+ final java.util.List<org.zwobble.couscous.backends.python.ast.PythonExpressionNode> arguments = generateExpressions(staticMethodCall.getArguments());
return pythonCall(methodReference, arguments);
}
-
+
@Override
public PythonExpressionNode visit(ConstructorCallNode call) {
- val className = call.getType();
- val classReference = pythonVariableReference(className.getSimpleName());
- val arguments = generateExpressions(call.getArguments());
-
+ final org.zwobble.couscous.ast.TypeName className = call.getType();
+ final org.zwobble.couscous.backends.python.ast.PythonVariableReferenceNode classReference = pythonVariableReference(className.getSimpleName());
+ final java.util.List<org.zwobble.couscous.backends.python.ast.PythonExpressionNode> arguments = generateExpressions(call.getArguments());
return pythonCall(classReference, arguments);
}
-
+
@Override
public PythonExpressionNode visit(FieldAccessNode fieldAccess) {
- return pythonAttributeAccess(
- generateExpression(fieldAccess.getLeft()),
- fieldAccess.getFieldName());
+ return pythonAttributeAccess(generateExpression(fieldAccess.getLeft()), fieldAccess.getFieldName());
}
}
private static boolean isPrimitive(ExpressionNode value) {
return PrimitiveMethods.isPrimitive(value.getType());
}
-}
+} \ No newline at end of file
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
diff --git a/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java b/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java
index 249d9fa..1674e1f 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/PythonSerializer.java
@@ -2,7 +2,6 @@ package org.zwobble.couscous.backends.python;
import java.util.List;
import java.util.function.Consumer;
-
import org.zwobble.couscous.backends.python.ast.PythonAssignmentNode;
import org.zwobble.couscous.backends.python.ast.PythonAttributeAccessNode;
import org.zwobble.couscous.backends.python.ast.PythonBlock;
@@ -19,19 +18,17 @@ import org.zwobble.couscous.backends.python.ast.PythonModuleNode;
import org.zwobble.couscous.backends.python.ast.PythonNode;
import org.zwobble.couscous.backends.python.ast.PythonPassNode;
import org.zwobble.couscous.backends.python.ast.PythonReturnNode;
+import org.zwobble.couscous.backends.python.ast.PythonStatementNode;
import org.zwobble.couscous.backends.python.ast.PythonStringLiteralNode;
import org.zwobble.couscous.backends.python.ast.PythonVariableReferenceNode;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
import org.zwobble.couscous.util.Action;
-
import static com.google.common.collect.Iterables.skip;
-import lombok.val;
-
public class PythonSerializer implements PythonNodeVisitor {
public static String serialize(PythonNode node) {
- val writer = new PythonWriter();
- val serializer = new PythonSerializer(writer);
+ PythonWriter writer = new PythonWriter();
+ PythonSerializer serializer = new PythonSerializer(writer);
serializer.write(node);
return writer.asString();
}
@@ -50,22 +47,22 @@ public class PythonSerializer implements PythonNodeVisitor {
public void visit(PythonIntegerLiteralNode integerLiteral) {
writer.writeInteger(integerLiteral.getValue());
}
-
+
@Override
public void visit(PythonStringLiteralNode stringLiteral) {
writer.writeStringLiteral(stringLiteral.getValue());
}
-
+
@Override
public void visit(PythonBooleanLiteralNode booleanLiteral) {
writer.writeKeyword(booleanLiteral.getValue() ? "True" : "False");
}
-
+
@Override
public void visit(PythonVariableReferenceNode reference) {
writer.writeIdentifier(reference.getName());
}
-
+
@Override
public void visit(PythonConditionalExpressionNode conditional) {
writeParenthesised(conditional.getTrueValue());
@@ -78,14 +75,14 @@ public class PythonSerializer implements PythonNodeVisitor {
writer.writeSpace();
writeParenthesised(conditional.getFalseValue());
}
-
+
@Override
public void visit(PythonAttributeAccessNode attributeAccess) {
writeParenthesised(attributeAccess.getLeft());
writer.writeSymbol(".");
writer.writeIdentifier(attributeAccess.getAttributeName());
}
-
+
@Override
public void visit(PythonCallNode call) {
writeParenthesised(call.getCallee());
@@ -96,7 +93,7 @@ public class PythonSerializer implements PythonNodeVisitor {
});
writer.writeSymbol(")");
}
-
+
@Override
public void visit(PythonGetSliceNode getSlice) {
writeParenthesised(getSlice.getReceiver());
@@ -106,7 +103,7 @@ public class PythonSerializer implements PythonNodeVisitor {
});
writer.writeSymbol("]");
}
-
+
@Override
public void visit(PythonReturnNode pythonReturn) {
writer.writeStatement(() -> {
@@ -115,14 +112,14 @@ public class PythonSerializer implements PythonNodeVisitor {
write(pythonReturn.getValue());
});
}
-
+
@Override
public void visit(PythonPassNode pass) {
writer.writeStatement(() -> {
- writer.writeKeyword("pass");
+ writer.writeKeyword("pass");
});
}
-
+
@Override
public void visit(PythonClassNode pythonClass) {
writer.writeStatement(() -> {
@@ -135,7 +132,7 @@ public class PythonSerializer implements PythonNodeVisitor {
writeBlock(pythonClass.getBody());
});
}
-
+
@Override
public void visit(PythonFunctionDefinitionNode functionDefinition) {
writer.writeStatement(() -> {
@@ -148,7 +145,7 @@ public class PythonSerializer implements PythonNodeVisitor {
writeBlock(functionDefinition.getBody());
});
}
-
+
@Override
public void visit(PythonAssignmentNode assignment) {
writer.writeStatement(() -> {
@@ -157,10 +154,9 @@ public class PythonSerializer implements PythonNodeVisitor {
writer.writeSymbol("=");
writer.writeSpace();
write(assignment.getValue());
-
});
}
-
+
@Override
public void visit(PythonImportNode importNode) {
writer.writeStatement(() -> {
@@ -170,38 +166,32 @@ public class PythonSerializer implements PythonNodeVisitor {
writer.writeSpace();
writer.writeKeyword("import");
writer.writeSpace();
- writeWithSeparator(
- importNode.getAliases(),
- alias -> {
- writer.writeIdentifier(alias.getName());
- },
- () -> {
- writer.writeSymbol(",");
- writer.writeSpace();
- });
+ writeWithSeparator(importNode.getAliases(), alias -> {
+ writer.writeIdentifier(alias.getName());
+ }, () -> {
+ writer.writeSymbol(",");
+ writer.writeSpace();
+ });
});
}
-
+
private void writeParenthesised(PythonExpressionNode expression) {
writer.writeSymbol("(");
write(expression);
writer.writeSymbol(")");
}
-
+
private void writeArgumentNames(PythonFunctionDefinitionNode functionDefinition) {
- writeWithSeparator(
- functionDefinition.getArgumentNames(),
- writer::writeIdentifier,
- () -> {
- writer.writeSymbol(",");
- writer.writeSpace();
- });
+ writeWithSeparator(functionDefinition.getArgumentNames(), writer::writeIdentifier, () -> {
+ writer.writeSymbol(",");
+ writer.writeSpace();
+ });
}
-
+
private <T> void writeWithSeparator(List<T> values, Consumer<T> writeValue, Action separator) {
if (!values.isEmpty()) {
writeValue.accept(values.get(0));
- for (val value : skip(values, 1)) {
+ for (T value : skip(values, 1)) {
separator.run();
writeValue.accept(value);
}
@@ -210,16 +200,16 @@ public class PythonSerializer implements PythonNodeVisitor {
@Override
public void visit(PythonModuleNode module) {
- for (val statement : module.getStatements()) {
+ for (PythonStatementNode statement : module.getStatements()) {
write(statement);
}
}
-
+
private void writeBlock(PythonBlock body) {
writer.startBlock();
- for (val statement : body) {
+ for (PythonStatementNode statement : body) {
write(statement);
}
writer.endBlock();
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAssignmentNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAssignmentNode.java
index 9c5b20a..37ca7b7 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAssignmentNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAssignmentNode.java
@@ -2,15 +2,59 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonAssignment")
-public class PythonAssignmentNode implements PythonStatementNode {
- PythonExpressionNode target;
- PythonExpressionNode value;
+public final class PythonAssignmentNode implements PythonStatementNode {
+ private final PythonExpressionNode target;
+ private final PythonExpressionNode value;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonAssignmentNode(final PythonExpressionNode target, final PythonExpressionNode value) {
+ this.target = target;
+ this.value = value;
+ }
+
+ public static PythonAssignmentNode pythonAssignment(final PythonExpressionNode target, final PythonExpressionNode value) {
+ return new PythonAssignmentNode(target, value);
+ }
+
+ public PythonExpressionNode getTarget() {
+ return this.target;
+ }
+
+ public PythonExpressionNode getValue() {
+ return this.value;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonAssignmentNode)) return false;
+ final PythonAssignmentNode other = (PythonAssignmentNode)o;
+ final java.lang.Object this$target = this.getTarget();
+ final java.lang.Object other$target = other.getTarget();
+ if (this$target == null ? other$target != null : !this$target.equals(other$target)) return false;
+ final java.lang.Object this$value = this.getValue();
+ final java.lang.Object other$value = other.getValue();
+ if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $target = this.getTarget();
+ result = result * PRIME + ($target == null ? 43 : $target.hashCode());
+ final java.lang.Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 43 : $value.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonAssignmentNode(target=" + this.getTarget() + ", value=" + this.getValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAttributeAccessNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAttributeAccessNode.java
index ccd795f..bb46af3 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAttributeAccessNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonAttributeAccessNode.java
@@ -2,15 +2,59 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonAttributeAccess")
-public class PythonAttributeAccessNode implements PythonExpressionNode {
- PythonExpressionNode left;
- String attributeName;
+public final class PythonAttributeAccessNode implements PythonExpressionNode {
+ private final PythonExpressionNode left;
+ private final String attributeName;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonAttributeAccessNode(final PythonExpressionNode left, final String attributeName) {
+ this.left = left;
+ this.attributeName = attributeName;
+ }
+
+ public static PythonAttributeAccessNode pythonAttributeAccess(final PythonExpressionNode left, final String attributeName) {
+ return new PythonAttributeAccessNode(left, attributeName);
+ }
+
+ public PythonExpressionNode getLeft() {
+ return this.left;
+ }
+
+ public String getAttributeName() {
+ return this.attributeName;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonAttributeAccessNode)) return false;
+ final PythonAttributeAccessNode other = (PythonAttributeAccessNode)o;
+ final java.lang.Object this$left = this.getLeft();
+ final java.lang.Object other$left = other.getLeft();
+ if (this$left == null ? other$left != null : !this$left.equals(other$left)) return false;
+ final java.lang.Object this$attributeName = this.getAttributeName();
+ final java.lang.Object other$attributeName = other.getAttributeName();
+ if (this$attributeName == null ? other$attributeName != null : !this$attributeName.equals(other$attributeName)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $left = this.getLeft();
+ result = result * PRIME + ($left == null ? 43 : $left.hashCode());
+ final java.lang.Object $attributeName = this.getAttributeName();
+ result = result * PRIME + ($attributeName == null ? 43 : $attributeName.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonAttributeAccessNode(left=" + this.getLeft() + ", attributeName=" + this.getAttributeName() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonBooleanLiteralNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonBooleanLiteralNode.java
index 349ab4b..3f3d9a0 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonBooleanLiteralNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonBooleanLiteralNode.java
@@ -2,14 +2,8 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.Value;
-
-@Value(staticConstructor="pythonBooleanLiteral")
-public class PythonBooleanLiteralNode implements PythonExpressionNode {
- @Getter(value = AccessLevel.NONE)
- boolean value;
+public final class PythonBooleanLiteralNode implements PythonExpressionNode {
+ private final boolean value;
public boolean getValue() {
return value;
@@ -19,4 +13,34 @@ public class PythonBooleanLiteralNode implements PythonExpressionNode {
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonBooleanLiteralNode(final boolean value) {
+ this.value = value;
+ }
+
+ public static PythonBooleanLiteralNode pythonBooleanLiteral(final boolean value) {
+ return new PythonBooleanLiteralNode(value);
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonBooleanLiteralNode)) return false;
+ final PythonBooleanLiteralNode other = (PythonBooleanLiteralNode)o;
+ if (this.getValue() != other.getValue()) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + (this.getValue() ? 79 : 97);
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonBooleanLiteralNode(value=" + this.getValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonCallNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonCallNode.java
index 92c8b20..6cc5b11 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonCallNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonCallNode.java
@@ -1,19 +1,61 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonCall")
-public class PythonCallNode implements PythonExpressionNode {
- PythonExpressionNode callee;
- List<PythonExpressionNode> arguments;
-
+public final class PythonCallNode implements PythonExpressionNode {
+ private final PythonExpressionNode callee;
+ private final List<PythonExpressionNode> arguments;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonCallNode(final PythonExpressionNode callee, final List<PythonExpressionNode> arguments) {
+ this.callee = callee;
+ this.arguments = arguments;
+ }
+
+ public static PythonCallNode pythonCall(final PythonExpressionNode callee, final List<PythonExpressionNode> arguments) {
+ return new PythonCallNode(callee, arguments);
+ }
+
+ public PythonExpressionNode getCallee() {
+ return this.callee;
+ }
+
+ public List<PythonExpressionNode> getArguments() {
+ return this.arguments;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonCallNode)) return false;
+ final PythonCallNode other = (PythonCallNode)o;
+ final java.lang.Object this$callee = this.getCallee();
+ final java.lang.Object other$callee = other.getCallee();
+ if (this$callee == null ? other$callee != null : !this$callee.equals(other$callee)) return false;
+ final java.lang.Object this$arguments = this.getArguments();
+ final java.lang.Object other$arguments = other.getArguments();
+ if (this$arguments == null ? other$arguments != null : !this$arguments.equals(other$arguments)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $callee = this.getCallee();
+ result = result * PRIME + ($callee == null ? 43 : $callee.hashCode());
+ final java.lang.Object $arguments = this.getArguments();
+ result = result * PRIME + ($arguments == null ? 43 : $arguments.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonCallNode(callee=" + this.getCallee() + ", arguments=" + this.getArguments() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonClassNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonClassNode.java
index 3ed7eba..8fe2ffe 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonClassNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonClassNode.java
@@ -1,15 +1,11 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-
import com.google.common.collect.ImmutableList;
-import lombok.Value;
-
-@Value(staticConstructor="pythonClass")
-public class PythonClassNode implements PythonStatementNode {
+public final class PythonClassNode implements PythonStatementNode {
+
public static Builder builder(String name) {
return new Builder(name);
}
@@ -17,7 +13,7 @@ public class PythonClassNode implements PythonStatementNode {
public static class Builder {
private final String name;
private final ImmutableList.Builder<PythonStatementNode> statements;
-
+
public Builder(String name) {
this.name = name;
this.statements = ImmutableList.builder();
@@ -26,7 +22,7 @@ public class PythonClassNode implements PythonStatementNode {
public PythonClassNode build() {
return new PythonClassNode(name, new PythonBlock(statements.build()));
}
-
+
public Builder statement(PythonStatementNode statement) {
statements.add(statement);
return this;
@@ -36,13 +32,58 @@ public class PythonClassNode implements PythonStatementNode {
public static PythonClassNode pythonClass(String name, List<? extends PythonStatementNode> body) {
return new PythonClassNode(name, new PythonBlock(body));
}
-
- String name;
- PythonBlock body;
+ private final String name;
+ private final PythonBlock body;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-
-}
+
+ private PythonClassNode(final String name, final PythonBlock body) {
+ this.name = name;
+ this.body = body;
+ }
+
+ public static PythonClassNode pythonClass(final String name, final PythonBlock body) {
+ return new PythonClassNode(name, body);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public PythonBlock getBody() {
+ return this.body;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonClassNode)) return false;
+ final PythonClassNode other = (PythonClassNode)o;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ final java.lang.Object this$body = this.getBody();
+ final java.lang.Object other$body = other.getBody();
+ if (this$body == null ? other$body != null : !this$body.equals(other$body)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
+ final java.lang.Object $body = this.getBody();
+ result = result * PRIME + ($body == null ? 43 : $body.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonClassNode(name=" + this.getName() + ", body=" + this.getBody() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonConditionalExpressionNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonConditionalExpressionNode.java
index e39dce1..13f5e99 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonConditionalExpressionNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonConditionalExpressionNode.java
@@ -2,16 +2,70 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonConditionalExpression")
-public class PythonConditionalExpressionNode implements PythonExpressionNode {
- PythonExpressionNode condition;
- PythonExpressionNode trueValue;
- PythonExpressionNode falseValue;
+public final class PythonConditionalExpressionNode implements PythonExpressionNode {
+ private final PythonExpressionNode condition;
+ private final PythonExpressionNode trueValue;
+ private final PythonExpressionNode falseValue;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonConditionalExpressionNode(final PythonExpressionNode condition, final PythonExpressionNode trueValue, final PythonExpressionNode falseValue) {
+ this.condition = condition;
+ this.trueValue = trueValue;
+ this.falseValue = falseValue;
+ }
+
+ public static PythonConditionalExpressionNode pythonConditionalExpression(final PythonExpressionNode condition, final PythonExpressionNode trueValue, final PythonExpressionNode falseValue) {
+ return new PythonConditionalExpressionNode(condition, trueValue, falseValue);
+ }
+
+ public PythonExpressionNode getCondition() {
+ return this.condition;
+ }
+
+ public PythonExpressionNode getTrueValue() {
+ return this.trueValue;
+ }
+
+ public PythonExpressionNode getFalseValue() {
+ return this.falseValue;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonConditionalExpressionNode)) return false;
+ final PythonConditionalExpressionNode other = (PythonConditionalExpressionNode)o;
+ final java.lang.Object this$condition = this.getCondition();
+ final java.lang.Object other$condition = other.getCondition();
+ if (this$condition == null ? other$condition != null : !this$condition.equals(other$condition)) return false;
+ final java.lang.Object this$trueValue = this.getTrueValue();
+ final java.lang.Object other$trueValue = other.getTrueValue();
+ if (this$trueValue == null ? other$trueValue != null : !this$trueValue.equals(other$trueValue)) return false;
+ final java.lang.Object this$falseValue = this.getFalseValue();
+ final java.lang.Object other$falseValue = other.getFalseValue();
+ if (this$falseValue == null ? other$falseValue != null : !this$falseValue.equals(other$falseValue)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $condition = this.getCondition();
+ result = result * PRIME + ($condition == null ? 43 : $condition.hashCode());
+ final java.lang.Object $trueValue = this.getTrueValue();
+ result = result * PRIME + ($trueValue == null ? 43 : $trueValue.hashCode());
+ final java.lang.Object $falseValue = this.getFalseValue();
+ result = result * PRIME + ($falseValue == null ? 43 : $falseValue.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonConditionalExpressionNode(condition=" + this.getCondition() + ", trueValue=" + this.getTrueValue() + ", falseValue=" + this.getFalseValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonFunctionDefinitionNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonFunctionDefinitionNode.java
index a7983d6..8c50ebd 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonFunctionDefinitionNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonFunctionDefinitionNode.java
@@ -1,15 +1,11 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-
import com.google.common.collect.ImmutableList;
-import lombok.Value;
-
-@Value(staticConstructor="pythonFunctionDefinition")
-public class PythonFunctionDefinitionNode implements PythonStatementNode {
+public final class PythonFunctionDefinitionNode implements PythonStatementNode {
+
public static Builder builder(String name) {
return new Builder(name);
}
@@ -24,7 +20,7 @@ public class PythonFunctionDefinitionNode implements PythonStatementNode {
this.argumentNames = ImmutableList.builder();
this.body = ImmutableList.builder();
}
-
+
public Builder argument(String argumentName) {
argumentNames.add(argumentName);
return this;
@@ -34,13 +30,69 @@ public class PythonFunctionDefinitionNode implements PythonStatementNode {
return pythonFunctionDefinition(name, argumentNames.build(), new PythonBlock(body.build()));
}
}
-
- String name;
- List<String> argumentNames;
- PythonBlock body;
+ private final String name;
+ private final List<String> argumentNames;
+ private final PythonBlock body;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonFunctionDefinitionNode(final String name, final List<String> argumentNames, final PythonBlock body) {
+ this.name = name;
+ this.argumentNames = argumentNames;
+ this.body = body;
+ }
+
+ public static PythonFunctionDefinitionNode pythonFunctionDefinition(final String name, final List<String> argumentNames, final PythonBlock body) {
+ return new PythonFunctionDefinitionNode(name, argumentNames, body);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public List<String> getArgumentNames() {
+ return this.argumentNames;
+ }
+
+ public PythonBlock getBody() {
+ return this.body;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonFunctionDefinitionNode)) return false;
+ final PythonFunctionDefinitionNode other = (PythonFunctionDefinitionNode)o;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ final java.lang.Object this$argumentNames = this.getArgumentNames();
+ final java.lang.Object other$argumentNames = other.getArgumentNames();
+ if (this$argumentNames == null ? other$argumentNames != null : !this$argumentNames.equals(other$argumentNames)) return false;
+ final java.lang.Object this$body = this.getBody();
+ final java.lang.Object other$body = other.getBody();
+ if (this$body == null ? other$body != null : !this$body.equals(other$body)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
+ final java.lang.Object $argumentNames = this.getArgumentNames();
+ result = result * PRIME + ($argumentNames == null ? 43 : $argumentNames.hashCode());
+ final java.lang.Object $body = this.getBody();
+ result = result * PRIME + ($body == null ? 43 : $body.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonFunctionDefinitionNode(name=" + this.getName() + ", argumentNames=" + this.getArgumentNames() + ", body=" + this.getBody() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonGetSliceNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonGetSliceNode.java
index 27c191e..2298086 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonGetSliceNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonGetSliceNode.java
@@ -1,18 +1,61 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonGetSlice")
-public class PythonGetSliceNode implements PythonExpressionNode {
- PythonExpressionNode receiver;
- List<PythonExpressionNode> arguments;
+public final class PythonGetSliceNode implements PythonExpressionNode {
+ private final PythonExpressionNode receiver;
+ private final List<PythonExpressionNode> arguments;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonGetSliceNode(final PythonExpressionNode receiver, final List<PythonExpressionNode> arguments) {
+ this.receiver = receiver;
+ this.arguments = arguments;
+ }
+
+ public static PythonGetSliceNode pythonGetSlice(final PythonExpressionNode receiver, final List<PythonExpressionNode> arguments) {
+ return new PythonGetSliceNode(receiver, arguments);
+ }
+
+ public PythonExpressionNode getReceiver() {
+ return this.receiver;
+ }
+
+ public List<PythonExpressionNode> getArguments() {
+ return this.arguments;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonGetSliceNode)) return false;
+ final PythonGetSliceNode other = (PythonGetSliceNode)o;
+ final java.lang.Object this$receiver = this.getReceiver();
+ final java.lang.Object other$receiver = other.getReceiver();
+ if (this$receiver == null ? other$receiver != null : !this$receiver.equals(other$receiver)) return false;
+ final java.lang.Object this$arguments = this.getArguments();
+ final java.lang.Object other$arguments = other.getArguments();
+ if (this$arguments == null ? other$arguments != null : !this$arguments.equals(other$arguments)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $receiver = this.getReceiver();
+ result = result * PRIME + ($receiver == null ? 43 : $receiver.hashCode());
+ final java.lang.Object $arguments = this.getArguments();
+ result = result * PRIME + ($arguments == null ? 43 : $arguments.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonGetSliceNode(receiver=" + this.getReceiver() + ", arguments=" + this.getArguments() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportAliasNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportAliasNode.java
index 9fb531a..783eb4e 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportAliasNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportAliasNode.java
@@ -1,8 +1,42 @@
package org.zwobble.couscous.backends.python.ast;
-import lombok.Value;
+public final class PythonImportAliasNode {
+ private final String name;
-@Value(staticConstructor="pythonImportAlias")
-public class PythonImportAliasNode {
- String name;
-}
+ private PythonImportAliasNode(final String name) {
+ this.name = name;
+ }
+
+ public static PythonImportAliasNode pythonImportAlias(final String name) {
+ return new PythonImportAliasNode(name);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonImportAliasNode)) return false;
+ final PythonImportAliasNode other = (PythonImportAliasNode)o;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonImportAliasNode(name=" + this.getName() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportNode.java
index c639829..4916cf7 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonImportNode.java
@@ -1,18 +1,61 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonImport")
-public class PythonImportNode implements PythonStatementNode {
- String moduleName;
- List<PythonImportAliasNode> aliases;
+public final class PythonImportNode implements PythonStatementNode {
+ private final String moduleName;
+ private final List<PythonImportAliasNode> aliases;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonImportNode(final String moduleName, final List<PythonImportAliasNode> aliases) {
+ this.moduleName = moduleName;
+ this.aliases = aliases;
+ }
+
+ public static PythonImportNode pythonImport(final String moduleName, final List<PythonImportAliasNode> aliases) {
+ return new PythonImportNode(moduleName, aliases);
+ }
+
+ public String getModuleName() {
+ return this.moduleName;
+ }
+
+ public List<PythonImportAliasNode> getAliases() {
+ return this.aliases;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonImportNode)) return false;
+ final PythonImportNode other = (PythonImportNode)o;
+ final java.lang.Object this$moduleName = this.getModuleName();
+ final java.lang.Object other$moduleName = other.getModuleName();
+ if (this$moduleName == null ? other$moduleName != null : !this$moduleName.equals(other$moduleName)) return false;
+ final java.lang.Object this$aliases = this.getAliases();
+ final java.lang.Object other$aliases = other.getAliases();
+ if (this$aliases == null ? other$aliases != null : !this$aliases.equals(other$aliases)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $moduleName = this.getModuleName();
+ result = result * PRIME + ($moduleName == null ? 43 : $moduleName.hashCode());
+ final java.lang.Object $aliases = this.getAliases();
+ result = result * PRIME + ($aliases == null ? 43 : $aliases.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonImportNode(moduleName=" + this.getModuleName() + ", aliases=" + this.getAliases() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonIntegerLiteralNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonIntegerLiteralNode.java
index 1c273d7..459ad6d 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonIntegerLiteralNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonIntegerLiteralNode.java
@@ -2,14 +2,45 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonIntegerLiteral")
-public class PythonIntegerLiteralNode implements PythonExpressionNode {
- int value;
+public final class PythonIntegerLiteralNode implements PythonExpressionNode {
+ private final int value;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonIntegerLiteralNode(final int value) {
+ this.value = value;
+ }
+
+ public static PythonIntegerLiteralNode pythonIntegerLiteral(final int value) {
+ return new PythonIntegerLiteralNode(value);
+ }
+
+ public int getValue() {
+ return this.value;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonIntegerLiteralNode)) return false;
+ final PythonIntegerLiteralNode other = (PythonIntegerLiteralNode)o;
+ if (this.getValue() != other.getValue()) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ result = result * PRIME + this.getValue();
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonIntegerLiteralNode(value=" + this.getValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonModuleNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonModuleNode.java
index b3fd728..a95b6c5 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonModuleNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonModuleNode.java
@@ -1,18 +1,50 @@
package org.zwobble.couscous.backends.python.ast;
import java.util.List;
-
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonModule")
-public class PythonModuleNode implements PythonNode {
- List<PythonStatementNode> statements;
+public final class PythonModuleNode implements PythonNode {
+ private final List<PythonStatementNode> statements;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-
-}
+
+ private PythonModuleNode(final List<PythonStatementNode> statements) {
+ this.statements = statements;
+ }
+
+ public static PythonModuleNode pythonModule(final List<PythonStatementNode> statements) {
+ return new PythonModuleNode(statements);
+ }
+
+ public List<PythonStatementNode> getStatements() {
+ return this.statements;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonModuleNode)) return false;
+ final PythonModuleNode other = (PythonModuleNode)o;
+ final java.lang.Object this$statements = this.getStatements();
+ final java.lang.Object other$statements = other.getStatements();
+ if (this$statements == null ? other$statements != null : !this$statements.equals(other$statements)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $statements = this.getStatements();
+ result = result * PRIME + ($statements == null ? 43 : $statements.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonModuleNode(statements=" + this.getStatements() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonReturnNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonReturnNode.java
index adb4168..1967dd3 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonReturnNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonReturnNode.java
@@ -2,15 +2,48 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonReturn")
-public class PythonReturnNode implements PythonStatementNode {
- PythonExpressionNode value;
+public final class PythonReturnNode implements PythonStatementNode {
+ private final PythonExpressionNode value;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+ private PythonReturnNode(final PythonExpressionNode value) {
+ this.value = value;
+ }
+
+ public static PythonReturnNode pythonReturn(final PythonExpressionNode value) {
+ return new PythonReturnNode(value);
+ }
+
+ public PythonExpressionNode getValue() {
+ return this.value;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonReturnNode)) return false;
+ final PythonReturnNode other = (PythonReturnNode)o;
+ final java.lang.Object this$value = this.getValue();
+ final java.lang.Object other$value = other.getValue();
+ if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 43 : $value.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonReturnNode(value=" + this.getValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonStringLiteralNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonStringLiteralNode.java
index bd35621..3907555 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonStringLiteralNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonStringLiteralNode.java
@@ -2,14 +2,48 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonStringLiteral")
-public class PythonStringLiteralNode implements PythonExpressionNode {
- String value;
+public final class PythonStringLiteralNode implements PythonExpressionNode {
+ private final String value;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonStringLiteralNode(final String value) {
+ this.value = value;
+ }
+
+ public static PythonStringLiteralNode pythonStringLiteral(final String value) {
+ return new PythonStringLiteralNode(value);
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonStringLiteralNode)) return false;
+ final PythonStringLiteralNode other = (PythonStringLiteralNode)o;
+ final java.lang.Object this$value = this.getValue();
+ final java.lang.Object other$value = other.getValue();
+ if (this$value == null ? other$value != null : !this$value.equals(other$value)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $value = this.getValue();
+ result = result * PRIME + ($value == null ? 43 : $value.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonStringLiteralNode(value=" + this.getValue() + ")";
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonVariableReferenceNode.java b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonVariableReferenceNode.java
index a67da73..4edad3e 100644
--- a/src/main/java/org/zwobble/couscous/backends/python/ast/PythonVariableReferenceNode.java
+++ b/src/main/java/org/zwobble/couscous/backends/python/ast/PythonVariableReferenceNode.java
@@ -2,14 +2,48 @@ package org.zwobble.couscous.backends.python.ast;
import org.zwobble.couscous.backends.python.ast.visitors.PythonNodeVisitor;
-import lombok.Value;
-
-@Value(staticConstructor="pythonVariableReference")
-public class PythonVariableReferenceNode implements PythonExpressionNode {
- String name;
+public final class PythonVariableReferenceNode implements PythonExpressionNode {
+ private final String name;
@Override
public void accept(PythonNodeVisitor visitor) {
visitor.visit(this);
}
-}
+
+ private PythonVariableReferenceNode(final String name) {
+ this.name = name;
+ }
+
+ public static PythonVariableReferenceNode pythonVariableReference(final String name) {
+ return new PythonVariableReferenceNode(name);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ @java.lang.Override
+ public boolean equals(final java.lang.Object o) {
+ if (o == this) return true;
+ if (!(o instanceof PythonVariableReferenceNode)) return false;
+ final PythonVariableReferenceNode other = (PythonVariableReferenceNode)o;
+ final java.lang.Object this$name = this.getName();
+ final java.lang.Object other$name = other.getName();
+ if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ return true;
+ }
+
+ @java.lang.Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final java.lang.Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
+ return result;
+ }
+
+ @java.lang.Override
+ public java.lang.String toString() {
+ return "PythonVariableReferenceNode(name=" + this.getName() + ")";
+ }
+} \ No newline at end of file