From 20dc1e124d606cf4298d5112b6d3c4f6c74e9b68 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 9 Mar 2016 18:11:17 +0000 Subject: Introduce Type interface --- .../org/zwobble/couscous/ast/ClassNodeBuilder.java | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/main/java/org/zwobble/couscous/ast/ClassNodeBuilder.java') diff --git a/src/main/java/org/zwobble/couscous/ast/ClassNodeBuilder.java b/src/main/java/org/zwobble/couscous/ast/ClassNodeBuilder.java index 282df33..9dc5098 100644 --- a/src/main/java/org/zwobble/couscous/ast/ClassNodeBuilder.java +++ b/src/main/java/org/zwobble/couscous/ast/ClassNodeBuilder.java @@ -3,6 +3,8 @@ package org.zwobble.couscous.ast; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.zwobble.couscous.ast.identifiers.Identifier; +import org.zwobble.couscous.ast.types.ScalarType; +import org.zwobble.couscous.ast.types.Type; import org.zwobble.couscous.values.UnitValue; import java.util.List; @@ -15,15 +17,15 @@ import static org.zwobble.couscous.ast.VariableDeclaration.var; import static org.zwobble.couscous.util.ExtraLists.list; public class ClassNodeBuilder { - private final TypeName name; - private final ImmutableSet.Builder superTypes; + private final ScalarType name; + private final ImmutableSet.Builder superTypes; private final ImmutableList.Builder typeParameters; private final ImmutableList.Builder fields; private List staticConstructor; private Optional constructor; private final ImmutableList.Builder methods; - public ClassNodeBuilder(TypeName name) { + public ClassNodeBuilder(ScalarType name) { this.name = name; this.typeParameters = ImmutableList.builder(); this.superTypes = ImmutableSet.builder(); @@ -34,7 +36,7 @@ public class ClassNodeBuilder { } public ClassNodeBuilder(String name) { - this(TypeName.of(name)); + this(ScalarType.of(name)); } public ClassNodeBuilder addTypeParameter(String name) { @@ -43,15 +45,15 @@ public class ClassNodeBuilder { } public ClassNodeBuilder addSuperType(String type) { - this.superTypes.add(TypeName.of(type)); + this.superTypes.add(ScalarType.of(type)); return this; } - public ClassNodeBuilder staticField(String name, TypeName type) { + public ClassNodeBuilder staticField(String name, ScalarType type) { return field(FieldDeclarationNode.staticField(name, type)); } - public ClassNodeBuilder field(String name, TypeName type) { + public ClassNodeBuilder field(String name, ScalarType type) { return field(FieldDeclarationNode.field(name, type)); } @@ -132,7 +134,7 @@ public class ClassNodeBuilder { private final Function, T> build; private final ImmutableList.Builder annotations; private final ImmutableList.Builder arguments; - private TypeName returnType = UnitValue.REF; + private ScalarType returnType = UnitValue.REF; private final ImmutableList.Builder statements; public MethodBuilder(Function, T> build) { @@ -142,7 +144,7 @@ public class ClassNodeBuilder { this.statements = ImmutableList.builder(); } - public MethodBuilder annotation(TypeName type) { + public MethodBuilder annotation(ScalarType type) { annotations.add(AnnotationNode.annotation(type)); return this; } @@ -151,12 +153,12 @@ public class ClassNodeBuilder { return ThisReferenceNode.thisReference(name); } - public MethodBuilder argument(Identifier id, String name, TypeName type) { + public MethodBuilder argument(Identifier id, String name, ScalarType type) { arguments.add(formalArg(var(id, name, type))); return this; } - public MethodBuilder returns(TypeName returnType) { + public MethodBuilder returns(ScalarType returnType) { this.returnType = returnType; return this; } -- cgit v1.2.3