// Short circuit if it's a text node, implementation is simpler
public static <N, T extends N> int getItemSize(ReadableWDocument<N, ?, T> doc, N node) {
    // Short circuit if it's a text node, implementation is simpler
    T textNode = doc.asText(node);
    if (textNode != null) {
      return doc.getLength(textNode);
    }
    // Otherwise, calculate two locations and subtract
    N parent = doc.getParentElement(node);
    if (parent == null) {
      // Requesting size of the document root.
      // TODO(danilatos/anorth) This would change if we have multiple roots.
      noteCodeThatWillBreakWithMultipleRoots();
      return doc.size();
    }
    N next = doc.getNextSibling(node);
    int locationAfter = next != null ? doc.getLocation(next)
        : doc.getLocation(Point.end(parent));
    return locationAfter - doc.getLocation(node);
  }
public static <N, T extends N> int getItemSize(ReadableWDocument<N, ?, T> doc, N node) {
// Short circuit if it's a text node, implementation is simpler
T textNode = doc.asText(node);
if (textNode != null) {
public static <N, T extends N> int getItemSize(ReadableWDocument<N, ?, T> doc, N node) {
// Short circuit if it's a text node, implementation is simpler
T textNode = doc.asText(node);
if (textNode != null) {
return doc.getLength(textNode);
}
// Otherwise, calculate two locations and subtract
N parent = doc.getParentElement(node);
if (parent == null) {
// Requesting size of the document root.
// TODO(danilatos/anorth) This would change if we have multiple roots.
noteCodeThatWillBreakWithMultipleRoots();
public static <N, T extends N> int getItemSize(ReadableWDocument<N, ?, T> doc, N node) {
// Short circuit if it's a text node, implementation is simpler
T textNode = doc.asText(node);
if (textNode != null) {
return doc.getLength(textNode);
}
// Otherwise, calculate two locations and subtract
N parent = doc.getParentElement(node);
if (parent == null) {
// Requesting size of the document root.
// TODO(danilatos/anorth) This would change if we have multiple roots.
noteCodeThatWillBreakWithMultipleRoots();
return doc.size();
}
N next = doc.getNextSibling(node);
int locationAfter = next != null ? doc.getLocation(next)
: doc.getLocation(Point.end(parent));
return locationAfter - doc.getLocation(node);
}