1
1
/*
2
- * Copyright 2002-2009 the original author or authors.
2
+ * Copyright 2002-2012 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .expression .spel .ast ;
18
18
19
+ import java .lang .reflect .Array ;
20
+
19
21
import org .springframework .expression .EvaluationException ;
20
22
import org .springframework .expression .TypedValue ;
21
23
import org .springframework .expression .spel .ExpressionState ;
22
24
23
25
/**
24
26
* Represents a reference to a type, for example "T(String)" or "T(com.somewhere.Foo)"
25
- *
27
+ *
26
28
* @author Andy Clement
27
29
*/
28
30
public class TypeReference extends SpelNodeImpl {
29
31
32
+ private int dimensions ;
33
+
30
34
public TypeReference (int pos ,SpelNodeImpl qualifiedId ) {
35
+ this (pos ,qualifiedId ,0 );
36
+ }
37
+
38
+ public TypeReference (int pos ,SpelNodeImpl qualifiedId ,int dims ) {
31
39
super (pos ,qualifiedId );
40
+ this .dimensions = dims ;
32
41
}
33
42
34
43
@ Override
@@ -39,19 +48,36 @@ public TypedValue getValueInternal(ExpressionState state) throws EvaluationExcep
39
48
TypeCode tc = TypeCode .valueOf (typename .toUpperCase ());
40
49
if (tc != TypeCode .OBJECT ) {
41
50
// 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 );
43
54
}
44
55
}
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 ;
46
69
}
47
70
48
71
@ Override
49
72
public String toStringAST () {
50
73
StringBuilder sb = new StringBuilder ();
51
74
sb .append ("T(" );
52
75
sb .append (getChild (0 ).toStringAST ());
76
+ for (int d =0 ;d <dimensions ;d ++) {
77
+ sb .append ("[]" );
78
+ }
53
79
sb .append (")" );
54
80
return sb .toString ();
55
81
}
56
-
82
+
57
83
}
0 commit comments