MCPcopy Index your code
hub / github.com/apache/tomcat / findWrapper

Method findWrapper

java/jakarta/el/Util.java:126–278  ·  view source on GitHub ↗
(ELContext context, Class<?> clazz, List<Wrapper<T>> wrappers, String name,
            Class<?>[] paramTypes, Object[] paramValues)

Source from the content-addressed store, hash-verified

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++) {

Callers 2

findMethodMethod · 0.95
findConstructorMethod · 0.95

Calls 15

isAssignableFromMethod · 0.95
isCoercibleFromMethod · 0.95
getExactCountMethod · 0.95
messageMethod · 0.95
paramStringMethod · 0.95
isArrayMethod · 0.80
equalsMethod · 0.65
putMethod · 0.65
compareToMethod · 0.65
getValueMethod · 0.65
getParameterTypesMethod · 0.45

Tested by

no test coverage detected