Permalink
Browse files

Improve generix parameter handling on routes

  • Loading branch information...
ctruchi committed Sep 13, 2014
1 parent bea3aad commit c2a5fc66c81222add29cac255338db5682a08c34
@@ -19,14 +19,19 @@ static String getTypeExpressionFor(String type) {
Matcher matcher = PARAMETERIZED_TYPE_PATTERN.matcher(type);
if (matcher.matches()) {
String rawType = matcher.group(1);
List<String> pTypes = new ArrayList<>();
for (String pType : Splitter.on(",").trimResults().split(matcher.group(2))) {
pTypes.add(getTypeExpressionFor(pType));
}
return "Types.newParameterizedType(" + rawType + ".class, " + Joiner.on(", ").join(pTypes) + ")";
return "Types.newParameterizedType(" + rawType + ".class, " + getTypeExpressionFor(matcher.group(2)) + ")";
} else {
return type + ".class";
if (type.contains(",")) {
List<String> pTypes = new ArrayList<>();
for (String pType : Splitter.on(",").trimResults().split(type)) {
pTypes.add(getTypeExpressionFor(pType));
}
return Joiner.on(", ").join(pTypes);
} else {
return type + ".class";
}
}
}
}
@@ -1,6 +1,5 @@
package restx.annotations.processor;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -20,5 +19,9 @@ public void should_produce_type_expression() throws Exception {
.isEqualTo("Types.newParameterizedType(java.util.Map.class, java.lang.String.class, java.lang.Integer.class)");
assertThat(TypeHelper.getTypeExpressionFor("java.util.List<java.util.List<java.lang.String>>"))
.isEqualTo("Types.newParameterizedType(java.util.List.class, Types.newParameterizedType(java.util.List.class, java.lang.String.class))");
assertThat(TypeHelper.getTypeExpressionFor("java.util.List<java.util.Map<java.lang.String, java.lang.Integer>>"))
.isEqualTo("Types.newParameterizedType(java.util.List.class, Types.newParameterizedType(java.util.Map.class, java.lang.String.class, java.lang.Integer.class))");
assertThat(TypeHelper.getTypeExpressionFor("java.util.List<java.util.Map<java.util.Set<java.lang.String>, java.lang.Integer>>"))
.isEqualTo("Types.newParameterizedType(java.util.List.class, Types.newParameterizedType(java.util.Map.class, Types.newParameterizedType(java.util.Set.class, java.lang.String.class), java.lang.Integer.class))");
}
}

0 comments on commit c2a5fc6

Please sign in to comment.