|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2013 the original author or authors. |
| 2 | + * Copyright 2002-2014 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.
|
|
17 | 17 | package org.springframework.expression.spel.support;
|
18 | 18 |
|
19 | 19 | import java.lang.reflect.Method;
|
| 20 | +import java.lang.reflect.Modifier; |
20 | 21 | import java.util.ArrayList;
|
21 | 22 | import java.util.Arrays;
|
| 23 | +import java.util.Collection; |
22 | 24 | import java.util.Collections;
|
23 | 25 | import java.util.Comparator;
|
24 | 26 | import java.util.HashMap;
|
25 |
| -import java.util.HashSet; |
26 | 27 | import java.util.LinkedHashSet;
|
27 | 28 | import java.util.List;
|
28 | 29 | import java.util.Map;
|
@@ -107,7 +108,7 @@ public MethodExecutor resolve(EvaluationContext context, Object targetObject, St
|
107 | 108 | try {
|
108 | 109 | TypeConverter typeConverter = context.getTypeConverter();
|
109 | 110 | Class<?> type = (targetObject instanceof Class ? (Class<?>) targetObject : targetObject.getClass());
|
110 |
| - List<Method> methods = new ArrayList<Method>(Arrays.asList(getMethods(type, targetObject))); |
| 111 | + List<Method> methods = new ArrayList<Method>((getMethods(type, targetObject))); |
111 | 112 |
|
112 | 113 | // If a filter is registered for this type, call it
|
113 | 114 | MethodFilter filter = (this.filters != null ? this.filters.get(type) : null);
|
@@ -201,14 +202,22 @@ else if (matchRequiringConversion != null) {
|
201 | 202 | }
|
202 | 203 | }
|
203 | 204 |
|
204 |
| - private Method[] getMethods(Class<?> type, Object targetObject) { |
| 205 | + private Collection<Method> getMethods(Class<?> type, Object targetObject) { |
205 | 206 | if (targetObject instanceof Class) {
|
206 |
| - Set<Method> methods = new HashSet<Method>(); |
207 |
| - methods.addAll(Arrays.asList(getMethods(type))); |
208 |
| - methods.addAll(Arrays.asList(getMethods(targetObject.getClass()))); |
209 |
| - return methods.toArray(new Method[methods.size()]); |
| 207 | + Set<Method> result = new LinkedHashSet<Method>(); |
| 208 | + result.addAll(Arrays.asList(getMethods(targetObject.getClass()))); |
| 209 | + // Add these also so that static result are invocable on the type: e.g. Float.valueOf(..) |
| 210 | + Method[] methods = getMethods(type); |
| 211 | + for (Method method : methods) { |
| 212 | + if (Modifier.isStatic(method.getModifiers())) { |
| 213 | + result.add(method); |
| 214 | + } |
| 215 | + } |
| 216 | + return result; |
| 217 | + } |
| 218 | + else { |
| 219 | + return Arrays.asList(getMethods(type)); |
210 | 220 | }
|
211 |
| - return getMethods(type); |
212 | 221 | }
|
213 | 222 |
|
214 | 223 | /**
|
|
0 commit comments