MCPcopy Index your code
hub / github.com/apache/groovy / text

Method text

src/main/java/groovy/util/Node.java:378–414  ·  view source on GitHub ↗

Returns the textual representation of the current node and all its child nodes. @return the text value of the node including child text

()

Source from the content-addressed store, hash-verified

376 * @return the text value of the node including child text
377 */
378 public String text() {
379 if (value instanceof String) {
380 return (String) value;
381 }
382 if (value instanceof NodeList) {
383 return ((NodeList) value).text();
384 }
385 if (value instanceof Collection coll) {
386 String previousText = null;
387 StringBuilder sb = null;
388 for (Object child : coll) {
389 String childText = null;
390 if (child instanceof String) {
391 childText = (String) child;
392 } else if (child instanceof Node) {
393 childText = ((Node) child).text();
394 }
395 if (childText != null) {
396 if (previousText == null) {
397 previousText = childText;
398 } else {
399 if (sb == null) {
400 sb = new StringBuilder();
401 sb.append(previousText);
402 }
403 sb.append(childText);
404 }
405 }
406 }
407 if (sb != null) {
408 return sb.toString();
409 } else {
410 return Objects.requireNonNullElse(previousText, "");
411 }
412 }
413 return "" + value;
414 }
415
416 /**
417 * Returns an <code>Iterator</code> of the children of the node.

Callers 8

toIntegerMethod · 0.95
toLongMethod · 0.95
toFloatMethod · 0.95
toDoubleMethod · 0.95
toBigDecimalMethod · 0.95
toBigIntegerMethod · 0.95
toMapMethod · 0.95
textIsEmptyOrNullMethod · 0.95

Calls 3

textMethod · 0.65
toStringMethod · 0.65
appendMethod · 0.45

Tested by

no test coverage detected