Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit e68b563

Browse files
committed
Merge pull request spring-projects#53 from aclement/SPR-9203
* SPR-9203: Eliminate trailing whitespace in SpEL classes Support [] array ref syntax in SpEL T() construct
2 parents 0e8f5d8 + de2d808 commit e68b563

File tree

3 files changed

+142
-81
lines changed

3 files changed

+142
-81
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java

+31-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,19 +16,28 @@
1616

1717
package org.springframework.expression.spel.ast;
1818

19+
import java.lang.reflect.Array;
20+
1921
import org.springframework.expression.EvaluationException;
2022
import org.springframework.expression.TypedValue;
2123
import org.springframework.expression.spel.ExpressionState;
2224

2325
/**
2426
* Represents a reference to a type, for example "T(String)" or "T(com.somewhere.Foo)"
25-
*
27+
*
2628
* @author Andy Clement
2729
*/
2830
public class TypeReference extends SpelNodeImpl {
2931

32+
private int dimensions;
33+
3034
public TypeReference(int pos,SpelNodeImpl qualifiedId) {
35+
this(pos,qualifiedId,0);
36+
}
37+
38+
public TypeReference(int pos,SpelNodeImpl qualifiedId,int dims) {
3139
super(pos,qualifiedId);
40+
this.dimensions = dims;
3241
}
3342

3443
@Override
@@ -39,19 +48,36 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
3948
TypeCode tc = TypeCode.valueOf(typename.toUpperCase());
4049
if (tc != TypeCode.OBJECT) {
4150
// it is a primitive type
42-
return new TypedValue(tc.getType());
51+
Class<?> clazz = tc.getType();
52+
clazz = makeArrayIfNecessary(clazz);
53+
return new TypedValue(clazz);
4354
}
4455
}
45-
return new TypedValue(state.findType(typename));
56+
Class<?> clazz = state.findType(typename);
57+
clazz = makeArrayIfNecessary(clazz);
58+
return new TypedValue(clazz);
59+
}
60+
61+
private Class makeArrayIfNecessary(Class clazz) {
62+
if (dimensions!=0) {
63+
for (int i=0;i<dimensions;i++) {
64+
Object o = Array.newInstance(clazz, 0);
65+
clazz = o.getClass();
66+
}
67+
}
68+
return clazz;
4669
}
4770

4871
@Override
4972
public String toStringAST() {
5073
StringBuilder sb = new StringBuilder();
5174
sb.append("T(");
5275
sb.append(getChild(0).toStringAST());
76+
for (int d=0;d<dimensions;d++) {
77+
sb.append("[]");
78+
}
5379
sb.append(")");
5480
return sb.toString();
5581
}
56-
82+
5783
}

0 commit comments

Comments
 (0)