For correctness, this should be (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0. Though, we don't supported nested annotations, so in practice this won't cause bugs.