doc.rangedAnnotations(annotationStart, annotationEnd, null)) { setDocumentAnnotation( operation, doc, annotationStart, annotationEnd, annotation.key(), null);
/** * Extracts all annotations that span inside the body tag of the given * document. * * @param doc the document to get the annotations from. * @param apiView provides a utility function to convert an xml offset point * into text offset. * @return the annotations represented as a list of {@link Annotation}. */ private static List<Annotation> extractAnnotations(Document doc, ApiView apiView) { List<Annotation> result = Lists.newArrayList(); for (RangedAnnotation<String> annotation : doc.rangedAnnotations(0, doc.size(), null)) { if (annotation.key() != null && annotation.value() != null) { int start = apiView.transformToTextOffset(annotation.start()); int end = apiView.transformToTextOffset(annotation.end()); result.add(new Annotation(annotation.key(), annotation.value(), new Range(start, end))); } } return result; } }
private void checkRangedAnnotation(List<RangedAnnotation<String>> extracted, int from, int to, String key, String value) { boolean hasAnnotation = true; for (RangedAnnotation<String> annotation : extracted) { if (annotation.start() == from && annotation.end() == to && ValueUtils.equal(key, annotation.key()) && ValueUtils.equal(value, annotation.value())) { return; } } fail(); }
private void checkRangedAnnotation(List<RangedAnnotation<String>> extracted, int from, int to, String key, String value) { boolean hasAnnotation = true; for (RangedAnnotation<String> annotation : extracted) { if (annotation.start() == from && annotation.end() == to && ValueUtils.equal(key, annotation.key()) && ValueUtils.equal(value, annotation.value())) { return; } } fail(); }
protected static <V> void expectRanges(Iterable<? extends RangedAnnotation<V>> iterable, List<RangedAnnotation<V>> expectedRanges) { ArrayList<RangedAnnotation<V>> ranges = new ArrayList<RangedAnnotation<V>>( expectedRanges); for (RangedAnnotation<V> a : iterable) { boolean found = false; find: for (RangedAnnotation<V> b : ranges) { if (a.start() == b.start() && a.end() == b.end() && a.key().equals(b.key()) && equal(a.value(), b.value())) { found = true; ranges.remove(b); break find; } } assertTrue("unexpected RangedAnnotation: " + a, found); } for (RangedAnnotation<V> b : ranges) { fail("ranged annotation expected but not found: " + b); } }
protected static <V> void expectRanges(Iterable<? extends RangedAnnotation<V>> iterable, List<RangedAnnotation<V>> expectedRanges) { ArrayList<RangedAnnotation<V>> ranges = new ArrayList<RangedAnnotation<V>>( expectedRanges); for (RangedAnnotation<V> a : iterable) { boolean found = false; find: for (RangedAnnotation<V> b : ranges) { if (a.start() == b.start() && a.end() == b.end() && a.key().equals(b.key()) && equal(a.value(), b.value())) { found = true; ranges.remove(b); break find; } } assertTrue("unexpected RangedAnnotation: " + a, found); } for (RangedAnnotation<V> b : ranges) { fail("ranged annotation expected but not found: " + b); } }
assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals("2", r.value()); assertEquals(5, r.start()); assertEquals(6, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(6, r.start()); assertEquals(12, r.end()); assertEquals("b", r.key()); assertEquals(null, r.value()); assertEquals(0, r.start()); assertEquals(3, r.end()); if ("c".equals(r.key())) { RangedAnnotation<String> tmp = r2; r2 = r; assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end());
assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals("2", r.value()); assertEquals(5, r.start()); assertEquals(6, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(6, r.start()); assertEquals(12, r.end()); assertEquals("b", r.key()); assertEquals(null, r.value()); assertEquals(0, r.start()); assertEquals(3, r.end()); if ("c".equals(r.key())) { RangedAnnotation<String> tmp = r2; r2 = r; assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end());
assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(5, r.start()); assertEquals(12, r.end()); assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(5, r.start()); assertEquals(12, r.end());
assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(5, r.start()); assertEquals(12, r.end()); assertEquals("a", r.key()); assertEquals("1", r.value()); assertEquals(1, r.start()); assertEquals(5, r.end()); assertEquals("a", r.key()); assertEquals(null, r.value()); assertEquals(5, r.start()); assertEquals(12, r.end());