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

Method coerceToString

java/org/apache/el/lang/ELSupport.java:491–522  ·  view source on GitHub ↗

Coerce an object to a string. @param ctx the context in which this conversion is taking place @param obj the object to convert @return the String value of the object

(final ELContext ctx, final Object obj)

Source from the content-addressed store, hash-verified

489 * @return the String value of the object
490 */
491 public static String coerceToString(final ELContext ctx, final Object obj) {
492
493 if (ctx != null) {
494 boolean originalIsPropertyResolved = ctx.isPropertyResolved();
495 try {
496 String result = ctx.getELResolver().convertToType(ctx, obj, String.class);
497 if (ctx.isPropertyResolved()) {
498 return result;
499 }
500 } finally {
501 ctx.setPropertyResolved(originalIsPropertyResolved);
502 }
503 }
504
505 if (obj == null) {
506 return "";
507 } else if (obj instanceof String) {
508 return (String) obj;
509 } else if (obj instanceof Enum<?>) {
510 return ((Enum<?>) obj).name();
511 } else {
512 try {
513 return obj.toString();
514 } catch (ELException e) {
515 // Unlikely but you never know
516 throw e;
517 } catch (Throwable t) {
518 ExceptionUtils.handleThrowable(t);
519 throw new ELException(t);
520 }
521 }
522 }
523
524 /**
525 * Coerces an object to the specified target type.

Callers 5

compareMethod · 0.95
equalsMethod · 0.95
coerceToTypeMethod · 0.95
getValueMethod · 0.95
getValueMethod · 0.95

Calls 6

handleThrowableMethod · 0.95
toStringMethod · 0.65
isPropertyResolvedMethod · 0.45
convertToTypeMethod · 0.45
getELResolverMethod · 0.45
setPropertyResolvedMethod · 0.45

Tested by

no test coverage detected