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

Method importStatic

java/jakarta/el/ImportHandler.java:314–366  ·  view source on GitHub ↗

Imports a static field or method so it can be referenced by its simple name in EL expressions. The argument must be a fully qualified name in the form className.staticMemberName. The static member must be public. @param name the fully qualified name of the static member to import @throws E

(String name)

Source from the content-addressed store, hash-verified

312 * member does not exist, or the import would be ambiguous
313 */
314 public void importStatic(String name) throws ELException {
315 int lastPeriod = name.lastIndexOf('.');
316
317 if (lastPeriod < 0) {
318 throw new ELException(Util.message(null, "importHandler.invalidStaticName", name));
319 }
320
321 String className = name.substring(0, lastPeriod);
322 String fieldOrMethodName = name.substring(lastPeriod + 1);
323
324 Class<?> clazz = findClass(className, true);
325
326 if (clazz == null) {
327 throw new ELException(Util.message(null, "importHandler.invalidClassNameForStatic", className, name));
328 }
329
330 boolean found = false;
331
332 for (Field field : clazz.getFields()) {
333 if (field.getName().equals(fieldOrMethodName)) {
334 int modifiers = field.getModifiers();
335 if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) {
336 found = true;
337 break;
338 }
339 }
340 }
341
342 if (!found) {
343 for (Method method : clazz.getMethods()) {
344 if (method.getName().equals(fieldOrMethodName)) {
345 int modifiers = method.getModifiers();
346 if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) {
347 found = true;
348 break;
349 }
350 }
351 }
352 }
353
354 if (!found) {
355 throw new ELException(
356 Util.message(null, "importHandler.staticNotFound", fieldOrMethodName, className, name));
357 }
358
359 Class<?> conflict = statics.get(fieldOrMethodName);
360 if (conflict != null) {
361 throw new ELException(Util.message(null, "importHandler.ambiguousStaticImport", name,
362 conflict.getName() + '.' + fieldOrMethodName));
363 }
364
365 statics.put(fieldOrMethodName, clazz);
366 }
367
368
369 /**

Callers 5

testImportStatic01Method · 0.95
testImportStatic02Method · 0.95
testImportStatic03Method · 0.95
testImportStatic04Method · 0.95
getELContextMethod · 0.95

Calls 6

messageMethod · 0.95
findClassMethod · 0.95
equalsMethod · 0.65
getNameMethod · 0.65
getMethod · 0.65
putMethod · 0.65

Tested by 4

testImportStatic01Method · 0.76
testImportStatic02Method · 0.76
testImportStatic03Method · 0.76
testImportStatic04Method · 0.76