From b263206322373b2deeb1aa16f1ad695f2c4e7936 Mon Sep 17 00:00:00 2001 From: Che Shian Hung Date: Mon, 22 Jan 2018 08:45:15 -0500 Subject: [PATCH] fix issue #159, toInterdaceJavaType and toParameterJavaType methods added --- .../visitors/CodeGeneratingVisitor.java | 23 ++++--------------- src/java/boa/types/BoaFloat.java | 12 ++++++++++ src/java/boa/types/BoaInt.java | 12 ++++++++++ src/java/boa/types/BoaMap.java | 8 ++++++- src/java/boa/types/BoaProtoMap.java | 12 ++++++++++ src/java/boa/types/BoaSet.java | 14 ++++++++++- src/java/boa/types/BoaStack.java | 2 +- src/java/boa/types/BoaType.java | 22 ++++++++++++++++++ 8 files changed, 83 insertions(+), 22 deletions(-) diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index b8e75e39e..9ed83593a 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -182,7 +182,7 @@ public void visit(final VarDeclStatement n) { final ST st = stg.getInstanceOf("VarDecl"); st.add("id", n.getId().getToken()); - st.add("type", n.type.toJavaType()); + st.add("type", n.type.toInterfaceJavaType()); if (n.isStatic()) st.add("isstatic", true); @@ -291,11 +291,8 @@ public void visit(final TupleType n) { fields.add("f" + fieldCount); } fieldCount++; - fieldTypes.add(c.getType().type.toBoxedJavaType()); - if(c.getType().type instanceof BoaSet) - initializeTypes.add(c.getType().type.toBoxedJavaType().replace("Set", "LinkedHashSet")); - else - initializeTypes.add(c.getType().type.toBoxedJavaType()); + fieldTypes.add(c.getType().type.toInterfaceJavaType()); + initializeTypes.add(c.getType().type.toBoxedJavaType()); } st.add("name", tupType.toJavaType()); @@ -1850,19 +1847,7 @@ public void visit(final FixPType n) { /** {@inheritDoc} */ @Override public void visit(final MapType n) { - final ST st = stg.getInstanceOf("MapType"); - - n.env.setNeedsBoxing(true); - - n.getIndex().accept(this); - st.add("key", code.removeLast()); - - n.getValue().accept(this); - st.add("value", code.removeLast()); - - n.env.setNeedsBoxing(false); - - code.add(st.render().replaceAll("LinkedHashSet", "Set")); + code.add(n.type.toJavaType()); } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaFloat.java b/src/java/boa/types/BoaFloat.java index aad2a8b13..5661d6a67 100644 --- a/src/java/boa/types/BoaFloat.java +++ b/src/java/boa/types/BoaFloat.java @@ -69,6 +69,18 @@ public String toBoxedJavaType() { return "Double"; } + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toBoxedJavaType(); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaInt.java b/src/java/boa/types/BoaInt.java index ac4219322..5efe3419d 100644 --- a/src/java/boa/types/BoaInt.java +++ b/src/java/boa/types/BoaInt.java @@ -65,4 +65,16 @@ public String toJavaType() { public String toBoxedJavaType() { return "Long"; } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toBoxedJavaType(); + } } diff --git a/src/java/boa/types/BoaMap.java b/src/java/boa/types/BoaMap.java index 129f6afae..082fc2241 100644 --- a/src/java/boa/types/BoaMap.java +++ b/src/java/boa/types/BoaMap.java @@ -148,7 +148,13 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.HashMap<" + this.indexType.toBoxedJavaType() + ", " + this.valueType.toBoxedJavaType() + ">"; + return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaProtoMap.java b/src/java/boa/types/BoaProtoMap.java index 4bbab12c9..2cc8663e7 100644 --- a/src/java/boa/types/BoaProtoMap.java +++ b/src/java/boa/types/BoaProtoMap.java @@ -75,6 +75,18 @@ public String toJavaType() { return getEnumClass().getName().replace('$', '.'); } + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return toJavaType(); + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return toJavaType(); + } + /** {@inheritDoc} */ @Override public String toString() { diff --git a/src/java/boa/types/BoaSet.java b/src/java/boa/types/BoaSet.java index 66e2b8da6..967ac1368 100644 --- a/src/java/boa/types/BoaSet.java +++ b/src/java/boa/types/BoaSet.java @@ -124,7 +124,19 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Set<" + this.type.toBoxedJavaType() + ">"; + return "java.util.LinkedHashSet<" + this.type.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toInterfaceJavaType() { + return "java.util.Set<" + this.type.toParameterJavaType() + ">"; + } + + /** {@inheritDoc} */ + @Override + public String toParameterJavaType() { + return "java.util.Set<" + this.type.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaStack.java b/src/java/boa/types/BoaStack.java index 58b4696be..c5ff612f8 100644 --- a/src/java/boa/types/BoaStack.java +++ b/src/java/boa/types/BoaStack.java @@ -124,7 +124,7 @@ public String toString() { /** {@inheritDoc} */ @Override public String toJavaType() { - return "java.util.Stack<" + this.type.toBoxedJavaType() + ">"; + return "java.util.Stack<" + this.type.toParameterJavaType() + ">"; } /** {@inheritDoc} */ diff --git a/src/java/boa/types/BoaType.java b/src/java/boa/types/BoaType.java index cdc120b27..b53c39488 100644 --- a/src/java/boa/types/BoaType.java +++ b/src/java/boa/types/BoaType.java @@ -111,6 +111,28 @@ public String toBoxedJavaType() { return toJavaType(); } + /** + * Returns a string representation of the interface Java equivalent of this Boa + * type. + * + * @return A String containing the name of the interface Java type equivalent to this + * Boa type + */ + public String toInterfaceJavaType() { + return toBoxedJavaType(); + } + + /** + * Returns a string representation of the parameter Java equivalent of this Boa + * type. + * + * @return A String containing the name of the parameter Java type equivalent to this + * Boa type + */ + public String toParameterJavaType() { + return toBoxedJavaType(); + } + /** * Takes a type name and returns one suitable for use as an identifier. *