From 9ea922c2ec51e8174a714730bb7ef2553c6165a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Habarta?= Date: Mon, 24 Apr 2017 17:43:06 +0200 Subject: [PATCH] Support for generic arrays --- .../generator/DefaultTypeProcessor.java | 5 +++++ .../typescript/generator/GenericsTest.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/DefaultTypeProcessor.java b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/DefaultTypeProcessor.java index d2512e5e4..15a365417 100644 --- a/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/DefaultTypeProcessor.java +++ b/typescript-generator-core/src/main/java/cz/habarta/typescript/generator/DefaultTypeProcessor.java @@ -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())); diff --git a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java index d7de2cc9e..b59468d80 100644 --- a/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java +++ b/typescript-generator-core/src/test/java/cz/habarta/typescript/generator/GenericsTest.java @@ -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 {\n" + + " rows: T[];\n" + + "}"; + assertEquals(expected, output.trim()); + } + class A { public A x; public A, List> y; @@ -157,4 +168,8 @@ class Page2 { public Table someTable; } + class TableGA { + public T[] rows; + } + }