aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/couscous/ast
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-13 14:27:28 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-13 14:27:28 +0000
commit0102779512e4475a32c95f0d84d704bcef7d38fe (patch)
treeb09286a8624ea3fc05fff0d4c767aacf47b293d4 /src/main/java/org/zwobble/couscous/ast
parentf31e1bc8ecd4a2323da72e7e78819d0f733bb27d (diff)
Tidy up reading of class bodies
Diffstat (limited to 'src/main/java/org/zwobble/couscous/ast')
-rw-r--r--src/main/java/org/zwobble/couscous/ast/sugar/TypeDeclarationBody.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/couscous/ast/sugar/TypeDeclarationBody.java b/src/main/java/org/zwobble/couscous/ast/sugar/TypeDeclarationBody.java
new file mode 100644
index 0000000..666d777
--- /dev/null
+++ b/src/main/java/org/zwobble/couscous/ast/sugar/TypeDeclarationBody.java
@@ -0,0 +1,82 @@
+package org.zwobble.couscous.ast.sugar;
+
+import com.google.common.collect.ImmutableList;
+import org.zwobble.couscous.ast.*;
+
+import java.util.List;
+
+public class TypeDeclarationBody {
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+ private final ImmutableList.Builder<FieldDeclarationNode> fields = ImmutableList.builder();
+ private final ImmutableList.Builder<StatementNode> staticConstructor = ImmutableList.builder();
+ private ConstructorNode constructor = ConstructorNode.DEFAULT;
+ private final ImmutableList.Builder<MethodNode> methods = ImmutableList.builder();
+
+ private Builder() {
+ }
+
+ public void field(FieldDeclarationNode field) {
+ fields.add(field);
+ }
+
+ public void addStaticInitializer(List<StatementNode> statements) {
+ staticConstructor.addAll(statements);
+ }
+
+ public void addStaticInitializer(StatementNode statement) {
+ staticConstructor.add(statement);
+ }
+
+ public void constructor(ConstructorNode constructor) {
+ this.constructor = constructor;
+ }
+
+ public void addMethod(MethodNode method) {
+ this.methods.add(method);
+ }
+
+ public TypeDeclarationBody build() {
+ return new TypeDeclarationBody(
+ fields.build(),
+ staticConstructor.build(),
+ constructor,
+ methods.build());
+ }
+ }
+
+ private final List<FieldDeclarationNode> fields;
+ private final List<StatementNode> staticConstructor;
+ private final ConstructorNode constructor;
+ private final List<MethodNode> methods;
+
+ public TypeDeclarationBody(
+ List<FieldDeclarationNode> fields,
+ List<StatementNode> staticConstructor, ConstructorNode constructor,
+ List<MethodNode> methods)
+ {
+ this.fields = fields;
+ this.staticConstructor = staticConstructor;
+ this.constructor = constructor;
+ this.methods = methods;
+ }
+
+ public List<FieldDeclarationNode> getFields() {
+ return fields;
+ }
+
+ public List<StatementNode> getStaticConstructor() {
+ return staticConstructor;
+ }
+
+ public ConstructorNode getConstructor() {
+ return constructor;
+ }
+
+ public List<MethodNode> getMethods() {
+ return methods;
+ }
+}