(ELContext context, Class<?> clazz, List<Wrapper<T>> wrappers, String name,
Class<?>[] paramTypes, Object[] paramValues)
| 124 | * This method duplicates code in org.apache.el.util.ReflectionUtil. When making changes keep the code in sync. |
| 125 | */ |
| 126 | @SuppressWarnings("null") |
| 127 | private static <T> Wrapper<T> findWrapper(ELContext context, Class<?> clazz, List<Wrapper<T>> wrappers, String name, |
| 128 | Class<?>[] paramTypes, Object[] paramValues) { |
| 129 | |
| 130 | Map<Wrapper<T>,MatchResult> candidates = new HashMap<>(); |
| 131 | |
| 132 | int paramCount = paramTypes.length; |
| 133 | |
| 134 | for (Wrapper<T> w : wrappers) { |
| 135 | Class<?>[] mParamTypes = w.getParameterTypes(); |
| 136 | int mParamCount; |
| 137 | if (mParamTypes == null) { |
| 138 | mParamCount = 0; |
| 139 | } else { |
| 140 | mParamCount = mParamTypes.length; |
| 141 | } |
| 142 | |
| 143 | // Check the number of parameters |
| 144 | // Multiple tests to improve readability |
| 145 | if (!w.isVarArgs() && paramCount != mParamCount) { |
| 146 | // Method has wrong number of parameters |
| 147 | continue; |
| 148 | } |
| 149 | if (w.isVarArgs() && paramCount < mParamCount - 1) { |
| 150 | // Method has wrong number of parameters |
| 151 | continue; |
| 152 | } |
| 153 | if (w.isVarArgs() && paramCount == mParamCount && paramValues != null && paramValues.length > paramCount && |
| 154 | !paramTypes[mParamCount - 1].isArray()) { |
| 155 | // Method arguments don't match |
| 156 | continue; |
| 157 | } |
| 158 | if (w.isVarArgs() && paramCount > mParamCount && paramValues != null && paramValues.length != paramCount) { |
| 159 | // Might match a different varargs method |
| 160 | continue; |
| 161 | } |
| 162 | if (!w.isVarArgs() && paramValues != null && paramCount != paramValues.length) { |
| 163 | // Might match a different varargs method |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | // Check the parameters match |
| 168 | int exactMatch = 0; |
| 169 | int assignableMatch = 0; |
| 170 | int coercibleMatch = 0; |
| 171 | int varArgsMatch = 0; |
| 172 | boolean noMatch = false; |
| 173 | for (int i = 0; i < mParamCount; i++) { |
| 174 | // Can't be null |
| 175 | if (w.isVarArgs() && i == (mParamCount - 1)) { |
| 176 | if (i == paramCount || (paramValues != null && paramValues.length == i)) { |
| 177 | // Var args defined but nothing is passed as varargs |
| 178 | // Use MAX_VALUE so this matches only if nothing else does |
| 179 | varArgsMatch = Integer.MAX_VALUE; |
| 180 | break; |
| 181 | } |
| 182 | Class<?> varType = mParamTypes[i].getComponentType(); |
| 183 | for (int j = i; j < paramCount; j++) { |
no test coverage detected