Skip to content

Commit ce8b3ba

Browse files
committed
Fix using Java array types as @JsProperty
Fix #12
1 parent a61bfb5 commit ce8b3ba

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

core/src/main/java/com/axellience/vuegwt/core/generation/GenerationUtil.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.gwt.resources.client.ClientBundle;
77
import com.google.gwt.resources.client.ClientBundle.Source;
88
import com.squareup.javapoet.AnnotationSpec;
9+
import com.squareup.javapoet.ArrayTypeName;
910
import com.squareup.javapoet.ClassName;
1011
import com.squareup.javapoet.CodeBlock;
1112
import com.squareup.javapoet.FieldSpec;
@@ -27,6 +28,8 @@
2728
import java.io.IOException;
2829
import java.io.Writer;
2930
import java.lang.annotation.Annotation;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
3033

3134
/**
3235
* @author Adrien Baron
@@ -172,6 +175,24 @@ public static TypeName stringTypeToTypeName(String type)
172175
if (type.equals("Double") || type.equals("java.lang.Double"))
173176
return TypeName.DOUBLE.box();
174177

175-
return ClassName.bestGuess(type);
178+
// Manage array types
179+
Pattern arrayEnding = Pattern.compile("\\[\\]");
180+
Matcher matcher = arrayEnding.matcher(type);
181+
int arrayCount = 0;
182+
while (matcher.find())
183+
arrayCount++;
184+
185+
if (arrayCount > 0)
186+
{
187+
type = type.substring(0, type.length() - arrayCount * 2);
188+
}
189+
190+
TypeName typeName = ClassName.bestGuess(type);
191+
for (int i = 0; i < arrayCount; i++)
192+
{
193+
typeName = ArrayTypeName.of(typeName);
194+
}
195+
196+
return typeName;
176197
}
177198
}

0 commit comments

Comments
 (0)