Skip to content

Commit

Permalink
fix issue #159, toInterdaceJavaType and toParameterJavaType methods a…
Browse files Browse the repository at this point in the history
…dded
  • Loading branch information
CheShianHung committed Jan 22, 2018
1 parent 207cdc8 commit b263206
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 22 deletions.
23 changes: 4 additions & 19 deletions src/java/boa/compiler/visitors/CodeGeneratingVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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} */
Expand Down
12 changes: 12 additions & 0 deletions src/java/boa/types/BoaFloat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions src/java/boa/types/BoaInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 7 additions & 1 deletion src/java/boa/types/BoaMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
12 changes: 12 additions & 0 deletions src/java/boa/types/BoaProtoMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 13 additions & 1 deletion src/java/boa/types/BoaSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
2 changes: 1 addition & 1 deletion src/java/boa/types/BoaStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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} */
Expand Down
22 changes: 22 additions & 0 deletions src/java/boa/types/BoaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit b263206

Please sign in to comment.