public <T> Template<T> buildTemplate(Type arrayType) {
Type baseType;
Class<?> baseClass;
int dim = 1;
if (arrayType instanceof GenericArrayType) {
GenericArrayType type = (GenericArrayType) arrayType;
baseType = type.getGenericComponentType();
while (baseType instanceof GenericArrayType) {
baseType = ((GenericArrayType) baseType).getGenericComponentType();
dim += 1;
}
if (baseType instanceof ParameterizedType) {
baseClass = (Class<?>) ((ParameterizedType) baseType).getRawType();
} else {
baseClass = (Class<?>) baseType;
}
} else {
Class<?> type = (Class<?>) arrayType;
baseClass = type.getComponentType();
while (baseClass.isArray()) {
baseClass = baseClass.getComponentType();
dim += 1;
}
baseType = baseClass;