public void simple5() {
        //the following two lines work inside process(Document, Arguments, Processing) in a DocumentProcessor
        DocumentTypeManager dtm = processing.getService().getDocumentTypeManager();
        AnnotationTypeRegistry atr = dtm.getAnnotationTypeRegistry();

        StringFieldValue text = new StringFieldValue("<body><p>I live in San </p>Francisco</body>");
                                                    //012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789

        SpanList root = new SpanList();
        SpanTree tree = new SpanTree("html", root);

        var docType = dtm.getDocumentType("blogpost");
        StructDataType positionType = docType.getDeclaredStructType("position");

        AnnotationType textType = atr.getType("text");
        AnnotationType beginTag = atr.getType("begintag");
        AnnotationType endTag = atr.getType("endtag");
        AnnotationType bodyType = atr.getType("body");
        AnnotationType paragraphType = atr.getType("paragraph");
        AnnotationType cityType = atr.getType("city");

        Struct position = new Struct(positionType);
        position.setFieldValue("latitude", 37.774929);
        position.setFieldValue("longitude", -122.419415);

        Annotation sanAnnotation = new Annotation(textType);
        Annotation franciscoAnnotation = new Annotation(textType);

        Struct positionWithRef = (Struct) cityType.getDataType().createFieldValue();
        positionWithRef.setFieldValue("position", position);

        Field referencesField = ((StructDataType) cityType.getDataType()).getField("references");
        Array<FieldValue> refList = new Array<FieldValue>(referencesField.getDataType());
        AnnotationReferenceDataType annRefType = (AnnotationReferenceDataType) ((ArrayDataType) referencesField.getDataType()).getNestedType();
        refList.add(new AnnotationReference(annRefType, sanAnnotation));
        refList.add(new AnnotationReference(annRefType, franciscoAnnotation));
        positionWithRef.setFieldValue(referencesField, refList);

        Annotation city = new Annotation(cityType, positionWithRef);

        SpanList paragraph = new SpanList();
        {
            Span span1 = new Span(6, 3);
            Span span2 = new Span(9, 10);
            Span span3 = new Span(19, 4);
            Span span4 = new Span(23, 4);
            paragraph.add(span1)
                    .add(span2)
                    .add(span3)
                    .add(span4);
            tree.annotate(span1, beginTag)
                    .annotate(span2, textType)
                    .annotate(span3, sanAnnotation)
                    .annotate(span4, endTag)
                    .annotate(paragraph, paragraphType);
        }

        {
            Span span1 = new Span(0, 6);
            Span span2 = new Span(27, 9);
            Span span3 = new Span(36, 8);
            root.add(span1)
                    .add(paragraph)
                    .add(span2)
                    .add(span3);

            tree.annotate(span1, beginTag)
                    .annotate(span2, franciscoAnnotation)
                    .annotate(span3, endTag)
                    .annotate(root, bodyType)
                    .annotate(city);
        }

        text.setSpanTree(tree);
    }
Contains code snippets that are used in the documentation. Not really a test case.

@author Einar M R Rosenvinge
document/src/test/java/com/yahoo/document/annotation/DocTestCase.java