|
|
|
@ -57,7 +57,7 @@ import org.springframework.util.Assert; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class ConstructorReference extends SpelNodeImpl { |
|
|
|
public class ConstructorReference extends SpelNodeImpl { |
|
|
|
|
|
|
|
|
|
|
|
private boolean isArrayConstructor = false; |
|
|
|
private final boolean isArrayConstructor; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private SpelNodeImpl[] dimensions; |
|
|
|
private SpelNodeImpl[] dimensions; |
|
|
|
@ -234,6 +234,7 @@ public class ConstructorReference extends SpelNodeImpl { |
|
|
|
FormatHelper.formatClassNameForMessage( |
|
|
|
FormatHelper.formatClassNameForMessage( |
|
|
|
intendedArrayType != null ? intendedArrayType.getClass() : null)); |
|
|
|
intendedArrayType != null ? intendedArrayType.getClass() : null)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String type = (String) intendedArrayType; |
|
|
|
String type = (String) intendedArrayType; |
|
|
|
Class<?> componentType; |
|
|
|
Class<?> componentType; |
|
|
|
TypeCode arrayTypeCode = TypeCode.forName(type); |
|
|
|
TypeCode arrayTypeCode = TypeCode.forName(type); |
|
|
|
@ -243,7 +244,8 @@ public class ConstructorReference extends SpelNodeImpl { |
|
|
|
else { |
|
|
|
else { |
|
|
|
componentType = arrayTypeCode.getType(); |
|
|
|
componentType = arrayTypeCode.getType(); |
|
|
|
} |
|
|
|
} |
|
|
|
Object newArray; |
|
|
|
|
|
|
|
|
|
|
|
Object newArray = null; |
|
|
|
if (!hasInitializer()) { |
|
|
|
if (!hasInitializer()) { |
|
|
|
// Confirm all dimensions were specified (for example [3][][5] is missing the 2nd dimension)
|
|
|
|
// Confirm all dimensions were specified (for example [3][][5] is missing the 2nd dimension)
|
|
|
|
if (this.dimensions != null) { |
|
|
|
if (this.dimensions != null) { |
|
|
|
@ -252,23 +254,22 @@ public class ConstructorReference extends SpelNodeImpl { |
|
|
|
throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION); |
|
|
|
throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); |
|
|
|
TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); |
|
|
|
if (this.dimensions.length == 1) { |
|
|
|
|
|
|
|
// Shortcut for 1-dimensional
|
|
|
|
// Shortcut for 1 dimensional
|
|
|
|
TypedValue o = this.dimensions[0].getTypedValue(state); |
|
|
|
if (this.dimensions.length == 1) { |
|
|
|
int arraySize = ExpressionUtils.toInt(typeConverter, o); |
|
|
|
TypedValue o = this.dimensions[0].getTypedValue(state); |
|
|
|
newArray = Array.newInstance(componentType, arraySize); |
|
|
|
int arraySize = ExpressionUtils.toInt(typeConverter, o); |
|
|
|
} |
|
|
|
newArray = Array.newInstance(componentType, arraySize); |
|
|
|
else { |
|
|
|
} |
|
|
|
// Multi-dimensional - hold onto your hat!
|
|
|
|
else { |
|
|
|
int[] dims = new int[this.dimensions.length]; |
|
|
|
// Multi-dimensional - hold onto your hat!
|
|
|
|
for (int d = 0; d < this.dimensions.length; d++) { |
|
|
|
int[] dims = new int[this.dimensions.length]; |
|
|
|
TypedValue o = this.dimensions[d].getTypedValue(state); |
|
|
|
for (int d = 0; d < this.dimensions.length; d++) { |
|
|
|
dims[d] = ExpressionUtils.toInt(typeConverter, o); |
|
|
|
TypedValue o = this.dimensions[d].getTypedValue(state); |
|
|
|
} |
|
|
|
dims[d] = ExpressionUtils.toInt(typeConverter, o); |
|
|
|
newArray = Array.newInstance(componentType, dims); |
|
|
|
} |
|
|
|
} |
|
|
|
newArray = Array.newInstance(componentType, dims); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
|