Skip to content

Commit

Permalink
Support for generic arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechhabarta committed Apr 24, 2017
1 parent 68de040 commit 9ea922c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public Result processType(Type javaType, Context context) {
return new Result(new TsType.GenericReferenceType(context.getSymbol(javaClass), tsTypeArguments), discoveredClasses);
}
}
if (javaType instanceof GenericArrayType) {
final GenericArrayType genericArrayType = (GenericArrayType) javaType;
final Result result = context.processType(genericArrayType.getGenericComponentType());
return new Result(new TsType.BasicArrayType(result.getTsType()), result.getDiscoveredClasses());
}
if (javaType instanceof TypeVariable) {
final TypeVariable<?> typeVariable = (TypeVariable<?>) javaType;
return new Result(new TsType.GenericVariableType(typeVariable.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ public void testGenericsWithoutTypeArgument() {
assertEquals(expected, output.trim());
}

@Test
public void testGenericArray() {
final Settings settings = TestUtils.settings();
final String output = new TypeScriptGenerator(settings).generateTypeScript(Input.from(TableGA.class));
final String expected =
"interface TableGA<T> {\n" +
" rows: T[];\n" +
"}";
assertEquals(expected, output.trim());
}

class A<U,V> {
public A<String, String> x;
public A<A<String, B>, List<String>> y;
Expand Down Expand Up @@ -157,4 +168,8 @@ class Page2 {
public Table someTable;
}

class TableGA<T> {
public T[] rows;
}

}

0 comments on commit 9ea922c

Please sign in to comment.