private static boolean addAnnotations(StringBuilder destination, WeightedSetItem weightedSet,
                                          String optionalAnnotations) {
        int preAnnotationValueLen;
        int incomingLen = destination.length();
        String annotations = leafAnnotations(weightedSet);

        if (!optionalAnnotations.isEmpty() || !annotations.isEmpty()) {
            destination.append("({");
        }
        preAnnotationValueLen = destination.length();
        if (!annotations.isEmpty()) {
            destination.append(annotations);
        }
        if (!optionalAnnotations.isEmpty()) {
            comma(destination, preAnnotationValueLen);
            destination.append(optionalAnnotations);
        }
        if (destination.length() > incomingLen) {
            destination.append("}");
            return true;
        }
        else {
            return false;
        }
    }
Adds annotations and returns whether any were added
container-search/src/main/java/com/yahoo/search/yql/VespaSerializer.java