for (int i = 0; i < dimensions.length; i++) {
if (dimensions[i] == null) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION);
}
}
TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();
// Shortcut for 1 dimensional
if (dimensions.length == 1) {
TypedValue o = dimensions[0].getTypedValue(state);
int arraySize = ExpressionUtils.toInt(typeConverter, o);
newArray = Array.newInstance(componentType, arraySize);
} else {
// Multi-dimensional - hold onto your hat!
int[] dims = new int[dimensions.length];
for (int d = 0; d < dimensions.length; d++) {
TypedValue o = dimensions[d].getTypedValue(state);
dims[d] = ExpressionUtils.toInt(typeConverter, o);
}
newArray = Array.newInstance(componentType, dims);
}
} else {
// There is an initializer
if (dimensions.length > 1) {
// There is an initializer but this is a multi-dimensional array (e.g. new int[][]{{1,2},{3,4}}) - this
// is not currently supported
throw new SpelEvaluationException(getStartPosition(),
SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED);
}
TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter();
InlineList initializer = (InlineList) getChild(1);
// If a dimension was specified, check it matches the initializer length
if (dimensions[0] != null) {
TypedValue dValue = dimensions[0].getTypedValue(state);
int i = ExpressionUtils.toInt(typeConverter, dValue);