Skip to content

Commit

Permalink
Merge pull request #118 from ctruchi/master
Browse files Browse the repository at this point in the history
Improve generics parameter handling on routes
  • Loading branch information
xhanin committed Feb 23, 2015
2 parents 1b07017 + c2a5fc6 commit 742bcd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

}
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 742bcd5

Please sign in to comment.