コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * Serializes a list of rangedAnnotations
  *
  * @param rangedAnnotations
  */
 public static String serializeAnnotation(Iterable<RangedAnnotation<String>> rangedAnnotations) {
   Builder entries = new Builder();
   for (RangedAnnotation<String> ann : rangedAnnotations) {
     if (ann.value() != null) {
       entries.pushEntry(ann.start(), ann.end(), ann.key(), ann.value());
     }
   }
   return entries.toString();
 }