Skip to content

Commit b263206

Browse files
committed
fix issue #159, toInterdaceJavaType and toParameterJavaType methods added
1 parent 207cdc8 commit b263206

File tree

8 files changed

+83
-22
lines changed

8 files changed

+83
-22
lines changed

src/java/boa/compiler/visitors/CodeGeneratingVisitor.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void visit(final VarDeclStatement n) {
182182
final ST st = stg.getInstanceOf("VarDecl");
183183

184184
st.add("id", n.getId().getToken());
185-
st.add("type", n.type.toJavaType());
185+
st.add("type", n.type.toInterfaceJavaType());
186186

187187
if (n.isStatic())
188188
st.add("isstatic", true);
@@ -291,11 +291,8 @@ public void visit(final TupleType n) {
291291
fields.add("f" + fieldCount);
292292
}
293293
fieldCount++;
294-
fieldTypes.add(c.getType().type.toBoxedJavaType());
295-
if(c.getType().type instanceof BoaSet)
296-
initializeTypes.add(c.getType().type.toBoxedJavaType().replace("Set", "LinkedHashSet"));
297-
else
298-
initializeTypes.add(c.getType().type.toBoxedJavaType());
294+
fieldTypes.add(c.getType().type.toInterfaceJavaType());
295+
initializeTypes.add(c.getType().type.toBoxedJavaType());
299296
}
300297

301298
st.add("name", tupType.toJavaType());
@@ -1850,19 +1847,7 @@ public void visit(final FixPType n) {
18501847
/** {@inheritDoc} */
18511848
@Override
18521849
public void visit(final MapType n) {
1853-
final ST st = stg.getInstanceOf("MapType");
1854-
1855-
n.env.setNeedsBoxing(true);
1856-
1857-
n.getIndex().accept(this);
1858-
st.add("key", code.removeLast());
1859-
1860-
n.getValue().accept(this);
1861-
st.add("value", code.removeLast());
1862-
1863-
n.env.setNeedsBoxing(false);
1864-
1865-
code.add(st.render().replaceAll("LinkedHashSet", "Set"));
1850+
code.add(n.type.toJavaType());
18661851
}
18671852

18681853
/** {@inheritDoc} */

src/java/boa/types/BoaFloat.java

+12
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,18 @@ public String toBoxedJavaType() {
6969
return "Double";
7070
}
7171

72+
/** {@inheritDoc} */
73+
@Override
74+
public String toInterfaceJavaType() {
75+
return toJavaType();
76+
}
77+
78+
/** {@inheritDoc} */
79+
@Override
80+
public String toParameterJavaType() {
81+
return toBoxedJavaType();
82+
}
83+
7284
/** {@inheritDoc} */
7385
@Override
7486
public String toString() {

src/java/boa/types/BoaInt.java

+12
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,16 @@ public String toJavaType() {
6565
public String toBoxedJavaType() {
6666
return "Long";
6767
}
68+
69+
/** {@inheritDoc} */
70+
@Override
71+
public String toInterfaceJavaType() {
72+
return toJavaType();
73+
}
74+
75+
/** {@inheritDoc} */
76+
@Override
77+
public String toParameterJavaType() {
78+
return toBoxedJavaType();
79+
}
6880
}

src/java/boa/types/BoaMap.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ public String toString() {
148148
/** {@inheritDoc} */
149149
@Override
150150
public String toJavaType() {
151-
return "java.util.HashMap<" + this.indexType.toBoxedJavaType() + ", " + this.valueType.toBoxedJavaType() + ">";
151+
return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">";
152+
}
153+
154+
/** {@inheritDoc} */
155+
@Override
156+
public String toInterfaceJavaType() {
157+
return "java.util.HashMap<" + this.indexType.toParameterJavaType() + ", " + this.valueType.toParameterJavaType() + ">";
152158
}
153159

154160
/** {@inheritDoc} */

src/java/boa/types/BoaProtoMap.java

+12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ public String toJavaType() {
7575
return getEnumClass().getName().replace('$', '.');
7676
}
7777

78+
/** {@inheritDoc} */
79+
@Override
80+
public String toInterfaceJavaType() {
81+
return toJavaType();
82+
}
83+
84+
/** {@inheritDoc} */
85+
@Override
86+
public String toParameterJavaType() {
87+
return toJavaType();
88+
}
89+
7890
/** {@inheritDoc} */
7991
@Override
8092
public String toString() {

src/java/boa/types/BoaSet.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,19 @@ public String toString() {
124124
/** {@inheritDoc} */
125125
@Override
126126
public String toJavaType() {
127-
return "java.util.Set<" + this.type.toBoxedJavaType() + ">";
127+
return "java.util.LinkedHashSet<" + this.type.toParameterJavaType() + ">";
128+
}
129+
130+
/** {@inheritDoc} */
131+
@Override
132+
public String toInterfaceJavaType() {
133+
return "java.util.Set<" + this.type.toParameterJavaType() + ">";
134+
}
135+
136+
/** {@inheritDoc} */
137+
@Override
138+
public String toParameterJavaType() {
139+
return "java.util.Set<" + this.type.toParameterJavaType() + ">";
128140
}
129141

130142
/** {@inheritDoc} */

src/java/boa/types/BoaStack.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public String toString() {
124124
/** {@inheritDoc} */
125125
@Override
126126
public String toJavaType() {
127-
return "java.util.Stack<" + this.type.toBoxedJavaType() + ">";
127+
return "java.util.Stack<" + this.type.toParameterJavaType() + ">";
128128
}
129129

130130
/** {@inheritDoc} */

src/java/boa/types/BoaType.java

+22
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,28 @@ public String toBoxedJavaType() {
111111
return toJavaType();
112112
}
113113

114+
/**
115+
* Returns a string representation of the interface Java equivalent of this Boa
116+
* type.
117+
*
118+
* @return A String containing the name of the interface Java type equivalent to this
119+
* Boa type
120+
*/
121+
public String toInterfaceJavaType() {
122+
return toBoxedJavaType();
123+
}
124+
125+
/**
126+
* Returns a string representation of the parameter Java equivalent of this Boa
127+
* type.
128+
*
129+
* @return A String containing the name of the parameter Java type equivalent to this
130+
* Boa type
131+
*/
132+
public String toParameterJavaType() {
133+
return toBoxedJavaType();
134+
}
135+
114136
/**
115137
* Takes a type name and returns one suitable for use as an identifier.
116138
*

0 commit comments

Comments
 (0)