From 22f5765125eea28ae158bab4d9e96ae6472b73d4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 18 Mar 2016 20:22:39 +0000 Subject: Remove duplication of primitive types --- .../java/org/zwobble/couscous/ast/LiteralNode.java | 18 +++++++++--------- .../org/zwobble/couscous/values/PrimitiveValue.java | 3 ++- .../java/org/zwobble/couscous/values/TypeValue.java | 8 ++++++-- 3 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/zwobble/couscous/ast/LiteralNode.java b/src/main/java/org/zwobble/couscous/ast/LiteralNode.java index f0e9af5..46a141e 100644 --- a/src/main/java/org/zwobble/couscous/ast/LiteralNode.java +++ b/src/main/java/org/zwobble/couscous/ast/LiteralNode.java @@ -1,13 +1,13 @@ package org.zwobble.couscous.ast; -import org.zwobble.couscous.types.ParameterizedType; -import org.zwobble.couscous.types.ScalarType; -import org.zwobble.couscous.types.Type; import org.zwobble.couscous.ast.visitors.ExpressionNodeMapper; import org.zwobble.couscous.ast.visitors.NodeTransformer; -import org.zwobble.couscous.values.*; +import org.zwobble.couscous.types.ScalarType; +import org.zwobble.couscous.types.Type; +import org.zwobble.couscous.values.PrimitiveValue; +import org.zwobble.couscous.values.PrimitiveValues; +import org.zwobble.couscous.values.TypeValue; -import static org.zwobble.couscous.util.ExtraLists.list; import static org.zwobble.couscous.values.PrimitiveValues.value; public class LiteralNode implements ExpressionNode { @@ -18,19 +18,19 @@ public class LiteralNode implements ExpressionNode { } public static LiteralNode literal(String value) { - return new LiteralNode(value(value), StringValue.REF); + return literal(value(value)); } public static LiteralNode literal(int value) { - return new LiteralNode(value(value), IntegerValue.REF); + return literal(value(value)); } public static LiteralNode literal(boolean value) { - return new LiteralNode(value(value), BooleanValue.REF); + return literal(value(value)); } public static LiteralNode literal(ScalarType type) { - return new LiteralNode(value(type), new ParameterizedType(ObjectValues.CLASS, list(type))); + return literal(value(type)); } public static LiteralNode of(PrimitiveValue value, Type type) { diff --git a/src/main/java/org/zwobble/couscous/values/PrimitiveValue.java b/src/main/java/org/zwobble/couscous/values/PrimitiveValue.java index 0075a30..2fb4137 100644 --- a/src/main/java/org/zwobble/couscous/values/PrimitiveValue.java +++ b/src/main/java/org/zwobble/couscous/values/PrimitiveValue.java @@ -1,10 +1,11 @@ package org.zwobble.couscous.values; import org.zwobble.couscous.types.ScalarType; +import org.zwobble.couscous.types.Type; public interface PrimitiveValue { T accept(Visitor visitor); - ScalarType getType(); + Type getType(); interface Visitor { T visitInteger(int value); diff --git a/src/main/java/org/zwobble/couscous/values/TypeValue.java b/src/main/java/org/zwobble/couscous/values/TypeValue.java index cc8b026..4a3b13d 100644 --- a/src/main/java/org/zwobble/couscous/values/TypeValue.java +++ b/src/main/java/org/zwobble/couscous/values/TypeValue.java @@ -1,6 +1,10 @@ package org.zwobble.couscous.values; +import org.zwobble.couscous.types.ParameterizedType; import org.zwobble.couscous.types.ScalarType; +import org.zwobble.couscous.types.Type; + +import static org.zwobble.couscous.util.ExtraLists.list; public class TypeValue implements PrimitiveValue { private final ScalarType value; @@ -19,8 +23,8 @@ public class TypeValue implements PrimitiveValue { } @Override - public ScalarType getType() { - return ObjectValues.CLASS; + public Type getType() { + return new ParameterizedType(ObjectValues.CLASS, list(value)); } @Override -- cgit v1.2.3