/** * Clears the annotation for the given ranges of the document as indicated by * the {@link DocumentModifyAction}. * * @param operation the operation to execute. * @param doc the document to annotate. * @param view the view of the document. * @param hitIterator iterates over the ranges to remove the annotation from, * specified in {@link ApiView} offset. * @param modifyAction the {@link DocumentModifyAction} specifying what the * key of the annotation is annotation is. * @throws InvalidRequestException if the annotation could not be set. */ private void clearAnnotation(OperationRequest operation, Document doc, ApiView view, DocumentHitIterator hitIterator, DocumentModifyAction modifyAction) throws InvalidRequestException { Preconditions.checkArgument(modifyAction.getModifyHow() == ModifyHow.CLEAR_ANNOTATION, "This method only supports CLEAR_ANNOTATION"); String annotationKey = modifyAction.getAnnotationKey(); Range range = hitIterator.next(); while (range != null) { int start = view.transformToXmlOffset(range.getStart()); int end = view.transformToXmlOffset(range.getEnd()); setDocumentAnnotation(operation, doc, start, end, annotationKey, null); range = hitIterator.next(); } }
/** * Annotates the given ranges of the document as indicated by the * {@link DocumentModifyAction}. * * @param operation the operation to execute. * @param doc the document to annotate. * @param view the view of the document. * @param hitIterator iterates over the ranges to annotate, specified in * {@link ApiView} offset. * @param modifyAction the {@link DocumentModifyAction} specifying what the * annotation is. * @throws InvalidRequestException if the annotation could not be set. */ private void annotate(OperationRequest operation, Document doc, ApiView view, DocumentHitIterator hitIterator, DocumentModifyAction modifyAction) throws InvalidRequestException { Preconditions.checkArgument( modifyAction.getModifyHow() == ModifyHow.ANNOTATE, "This method only supports ANNOTATE"); String annotationKey = modifyAction.getAnnotationKey(); int valueIndex = 0; Range range = hitIterator.next(); while (range != null) { int start = view.transformToXmlOffset(range.getStart()); int end = view.transformToXmlOffset(range.getEnd()); setDocumentAnnotation( operation, doc, start, end, annotationKey, modifyAction.getValue(valueIndex)); valueIndex++; range = hitIterator.next(); } }
DocumentHitIterator hitIterator = getDocumentHitIterator(operation, view); switch (modifyAction.getModifyHow()) { case ANNOTATE: annotate(operation, doc, view, hitIterator, modifyAction); default: throw new UnsupportedOperationException( "Unsupported ModifyHow " + modifyAction.getModifyHow());